一、下载httpd, apr, apr-util 源码包
httpd 源码包
http://httpd.apache.org/download.cgi#apache24
apr和apr-util源码包
http://apr.apache.org/download.cgi
二、编译httpd
1、解压三个软件包,将apr和apt-util解压放入httpd-2.4.25/srclib/目录下,apr和apr-util解压后去掉版本号,srclib存放如下图:
2、安装依赖软件
yum install -y zlib-devel pcre pcre-devel apr apr-devel
3、进入httpd源码包目录下编译
./configure --prefix=/usr/local/httpd --with-included-apr --enable-so --enable-deflate=shared --enable-expires=shared --enable-rewrite=shared --with-pcre make && make install
4、修改配置文件httpd.conf
找到ServerName行,去掉注释修改如下:
ServerName localhost
三、压缩编译后的代码
tar -cvf /usr/local/src/httpd-2.4.25.tar.gz /usr/local/httpd/
四、Centos 7 写httpd.servie 脚本文件名就是 httpd.service
[Unit] Description=httpd After=httpd.target [Service] Type=forking ExecStart=/etc/init.d/httpd start ExecReload=/etc/init.d/httpd restart ExecStop=/etc/init.d/nginx stop PrivateTmp=true [Install] WantedBy=multi-user.target
五、复制一个文件 /usr/loca/httpd/bin/apachectl 为httpd,并在文件开头的地方加上 " # chkconfig: 345 33 33" 暂时随便放一个地方,到后面自动化的时候需要该文件 文件开头内容如下
#!/bin/sh # chkconfig: - 33 33 # Licensed to the Apache Software Foundation (ASF) under one or more
六、ansible 自动脚本编写
1、创建如下目录的文件,路径自定义 我这里写在 /etc/ansible/httpd-install/
其中 httpd-2.4.25.tar.gz 是编译的httpd的压缩包,
httpd 是第五步拷贝处理的 httpd文件
httpd.service 是第四步做的文件,Centos7使用,如果不是Centos7可不要这个文件
2、创建文件 roles/http/tasks/main.yml文件
--- # src 指定的文件是 http/files 下的文件 - name: Copy Httpd Software copy: src=httpd-2.4.25.tar.gz dest=/tmp/httpd-2.4.25.tar.gz owner=root group=root - name: Uncompression Httpd Software shell: tar -xvf /tmp/httpd-2.4.25.tar.gz -C /usr/local/ - name: copy apachectl to /etc/init.d copy: src=httpd dest=/etc/init.d/httpd owner=root group=root - name: copy http start service copy: src=httpd.service dest=/usr/lib/systemd/ owner=root group=root - name: Install initializtion require software yum: name={{ item }} state=installed with_items: - zlib-devel - pcre-devel - apr-devel - name: start httpd service: name=httpd state=restarted - name: Delete Httpd Compression files shell: rm -rf /tmp/httpd-2.4.25.tar.gz3、创建文件install.yml