1. 程式人生 > >CentOS 6.10源碼編譯及使用ansible編譯安裝httpd2.4.39

CentOS 6.10源碼編譯及使用ansible編譯安裝httpd2.4.39

with pre 配置 user 準備 oot art mode profile

一、編譯安裝
編譯環境準備
主機 系統
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.解壓所有壓縮包

[[email protected] ~]# tar -xf apr-util-1.6.1.tar.gz 
[[email protected] ~]# tar -xf apr-1.7.0.tar.gz 
[[email protected] ~]# tar -xf httpd-2.4.39.tar.gz 

3.將apr及apr-util復制到httpd-2.4.39/srclib目錄中

[[email protected] ~]# cp -a apr-1.7.0 httpd-2.4.39/srclib/apr
[[email protected] ~]# cp -a apr-util-1.6.1 httpd-2.4.39/srclib/apr-util

4.編譯httpd

[[email protected] ~]# cd httpd-2.4.39
[[email protected] 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.安裝

[[email protected] ~]# make && make install

6.為httpd創建系統用戶

[[email protected] ~]# useradd -r -s /sbin/nologin apache

7.修改配置文件,將httpd運行的用戶和組改為apache

[[email protected] ~]# vim /app/httpd24/conf/httpd.conf 
User apache
Group apache

8.配置環境變量

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

9.設置為開機啟動

[[email protected] ~]# vim /etc/rc.d/rc.local 
/app/httpd24/bin/apachectl start

ansible編譯安裝httpd2.4


創建app目錄
[[email protected] ~]# ansible ws -m file -a "path=/app state=directory"
解壓httpd
[[email protected] ~]# ansible ws -m unarchive -a ‘src=~/httpd-2.4.39.tar.gz  dest=/app copy=yes‘
解壓apr-util
[[email protected] ~]# ansible ws -m unarchive -a ‘src=~/apr-util-1.6.1.tar.gz  dest=/app/httpd-2.4.39/srclib/ copy=yes‘
解壓apr
[[email protected] ~]# 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軟連接
[[email protected] ~]# 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軟連接
[[email protected] ~]# 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"
編譯
[[email protected] ~]# 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"
安裝
[[email protected] ~]# ansible ws -m shell -a "make && make install"
創建apache用戶
[[email protected] ~]# ansible ws -m user -a "name=apache  system=yes shell=/sbin/nologin create_home=no "
配置開機啟動
[[email protected] ~]# ansible ws -m lineinfile -a ‘path=/etc/rc.d/rc.local insertafter="^touch.*" line="/app/httpd24/bin/apachectl start"‘
為rc.local設置執行權限
[[email protected] ~]# ansible ws -m file -a "path=/etc/rc.d/rc.local mode=755 "
復制配置文件
[[email protected] ~]# ansible ws -m copy -a ‘src=/root/httpd.conf dest=/app/httpd24/conf/httpd.conf‘
添加環境變量配置文件
[[email protected] ~]# ansible ws -m copy -a ‘src=/root/httpd.sh dest=/etc/profile.d/httpd.sh‘
讀取環境變量
[[email protected] ~]# ansible ws -m shell -a ‘source /etc/profile.d/httpd.sh‘
啟動服務
[[email protected] ~]# ansible ws -m shell -a ‘apachectl start‘

CentOS 6.10源碼編譯及使用ansible編譯安裝httpd2.4.39