---
- hosts: 10.0.0.172
gather_facts: no
vars:
httpd_name: httpd-2.4.48
apr_name: apr-1.7.0
apr_util_name: apr-util-1.6.1
dir: /data/httpd24
htmldir: /var/www/html
tasks:
- name: install necessary packs
yum:
name:
- gcc
- make
- pcre-devel
- openssl-devel
- expat-devel
- bzip2
- rsync
state: present
- name: download apache
unarchive: src={{ item }} dest=/usr/local/src/ remote_src=yes
loop:
- http://mirrors.tuna.tsinghua.edu.cn/apache/httpd/{{httpd_name}}.tar.bz2
- http://mirrors.tuna.tsinghua.edu.cn/apache/apr/{{apr_name}}.tar.bz2
- http://mirrors.tuna.tsinghua.edu.cn/apache/apr/{{apr_util_name}}.tar.bz2
register: var1
until: var1 is succeeded
retries: 5
delay: 5
- name: merge src apr
synchronize: src=/usr/local/src/{{item.srcname }}/ dest=/usr/local/src/{{httpd_name}}/srclib/{{ item.destname }}
loop:
- {srcname: '{{apr_name}}',destname: 'apr' }
- {srcname: '{{apr_util_name}}',destname: 'apr-util'}
delegate_to: "{{ inventory_hostname }}"
- name: create app dir
file: name={{dir}} state=directory
- name: configure
shell: |
chdir=/usr/local/src/{{httpd_name}}
./configure \
--prefix={{dir}} \
--enable-so \
--enable-ssl \
--enable-cgi \
--enable-rewrite \
--with-zlib \
--with-pcre \
--with-included-apr \
--enable-modules=most \
--enable-mpms-shared=all \
--with-mpm=event
make -j 4 && make install
- name: create user
user: name=apache system=yes create_home=no shell=/sbin/nologin
- name: edit service1
lineinfile: path={{dir}}/conf/httpd.conf regexp="^User" line="User apache"
- name: edit service2
lineinfile: path={{dir}}/conf/httpd.conf regexp="^Group" line="Group apache"
- name: export var
shell: |
echo 'PATH={{dir}}/bin:$PATH' > /etc/profile.d/httpd.sh
. /etc/profile.d/httpd.sh
- name: create service
copy:
content: |
[Unit]
Description=The Apache HTTP Server
After=network.target remote-fs.target nss-lookup.target
Documentation=man:httpd(8)
Documentation=man:apachectl(8)
[Service]
Type=forking
#EnvironmentFile=/etc/sysconfig/httpd
ExecStart={{dir}}/bin/apachectl start
#ExecStart={{dir}}/bin/httpd $OPTIONS -k start
ExecReload={{dir}}/bin/apachectl graceful
#ExecReload={{dir}}/bin/httpd $OPTIONS -k graceful
ExecStop={{dir}}/bin/apachectl stop
KillSignal=SIGCONT
PrivateTmp=true
[Install]
WantedBy=multi-user.target
dest: /usr/lib/systemd/system/httpd24.service
- name: start service
shell: chkconfig -add httpd24;service httpd24 start
ansible源码编译安装apache
最新推荐文章于 2025-06-14 21:12:28 发布