CentOS 6.10源码编译及使用ansible编译安装httpd2.4.39

一、编译安装

编译环境准备
主机 系统
A centos6.10

编译所需的httpd、apr、apr-util

apr-1.7.0.tar.gz
apr-util-1.6.1.tar.gz
httpd-2.4.39.tar.gz

1.安装编译所需要的软件

yum install gcc gcc-c++ glibc glibc-devel pcre pcre-devel openssl openssl-devel systemd-devel zlib-devel vim lrzsz tree screen lsof tcpdump wget ntpdate net-tools iotop bc zip unzip nfs-utils expat-devel -y

2.解压所有压缩包

[root@CentOS6 ~]# tar -xf apr-util-1.6.1.tar.gz 
[root@CentOS6 ~]# tar -xf apr-1.7.0.tar.gz 
[root@CentOS6 ~]# tar -xf httpd-2.4.39.tar.gz 

3.将apr及apr-util复制到httpd-2.4.39/srclib目录中

[root@CentOS6 ~]# cp -a apr-1.7.0 httpd-2.4.39/srclib/apr
[root@CentOS6 ~]# cp -a apr-util-1.6.1 httpd-2.4.39/srclib/apr-util

4.编译httpd

[root@CentOS6 ~]# cd httpd-2.4.39
[root@CentOS6 httpd-2.4.39]# ./configure  --prefix=/app/httpd24  --enable-so  --enable-ssl  --enable-cgi --enable-rewrite  --with-zlib  --with-pcre  --with-included-apr=/root/httpd-2.4.39/srclib/  --enable-modules=most  --enable-mpms-shared=all  --with-mpm=prefork

5.安装

[root@CentOS6 ~]# make && make install

6.为httpd创建系统用户

[root@CentOS6 ~]# useradd -r -s /sbin/nologin apache

7.修改配置文件,将httpd运行的用户和组改为apache

[root@CentOS6 ~]# vim /app/httpd24/conf/httpd.conf 
User apache
Group apache

8.配置环境变量

[root@CentOS6 ~]# echo "PATH=/app/httpd24/bin:$PATH" > /etc/profile.d/httpd24.sh

9.设置为开机启动

[root@CentOS6 ~]# vim /etc/rc.d/rc.local 
/app/httpd24/bin/apachectl start

ansible编译安装httpd2.4


创建app目录
[root@localhost ~]# ansible ws -m file -a "path=/app state=directory"
解压httpd
[root@localhost ~]# ansible ws -m unarchive -a 'src=~/httpd-2.4.39.tar.gz  dest=/app copy=yes'
解压apr-util
[root@localhost ~]# ansible ws -m unarchive -a 'src=~/apr-util-1.6.1.tar.gz  dest=/app/httpd-2.4.39/srclib/ copy=yes'
解压apr
[root@localhost ~]# ansible ws -m file -a "src=/app/httpd-2.4.39/srclib/apr-1.7.0 dest=/app/httpd-2.4.39/srclib
创建apr-util软连接
[root@localhost ~]# ansible ws -m file -a "src=/app/httpd-2.4.39/srclib/apr-util-1.6.1 dest=/app/httpd-2.4.39/srclib/apr-util state=link"
创建apr软连接
[root@localhost ~]# ansible ws -m file -a "src=/app/httpd-2.4.39/srclib/apr-1.7.0 dest=/app/httpd-2.4.39/srclib/apr state=link"
编译
[root@localhost ~]# ansible ws -m shell -a "/app/httpd-2.4.39/configure  --prefix=/app/httpd24  --enable-so  --enable-ssl  --enable-cgi --enable-rewrite  --with-zlib  --with-pcre  --with-included-apr=/root/httpd-2.4.39/srclib/  --enable-modules=most  --enable-mpms-shared=all  --with-mpm=prefork"
安装
[root@localhost ~]# ansible ws -m shell -a "make && make install"
创建apache用户
[root@localhost ~]# ansible ws -m user -a "name=apache  system=yes shell=/sbin/nologin create_home=no "
配置开机启动
[root@localhost ~]# ansible ws -m lineinfile -a 'path=/etc/rc.d/rc.local insertafter="^touch.*" line="/app/httpd24/bin/apachectl start"'
为rc.local设置执行权限
[root@localhost ~]# ansible ws -m file -a "path=/etc/rc.d/rc.local mode=755 "
复制配置文件
[root@localhost ~]# ansible ws -m copy -a 'src=/root/httpd.conf dest=/app/httpd24/conf/httpd.conf'
添加环境变量配置文件
[root@localhost ~]# ansible ws -m copy -a 'src=/root/httpd.sh dest=/etc/profile.d/httpd.sh'
读取环境变量
[root@localhost ~]# ansible ws -m shell -a 'source /etc/profile.d/httpd.sh'
启动服务
[root@localhost ~]# ansible ws -m shell -a 'apachectl start'

猜你喜欢

转载自blog.51cto.com/11886307/2393113