一著觉、實驗?zāi)康?/h1>
全新系統(tǒng)析校,通過網(wǎng)絡(luò)(wget http://ftp.wangshuai.tech/script/install.sh && cat install.sh |bash |tee log)妥凳,實現(xiàn)在線自動編譯安裝httpd服務(wù)又厉,且重啟也生效
二校摩、實驗過程
(1)準(zhǔn)備安裝環(huán)境
1几睛、關(guān)閉防火墻
systemctl stop firewalld
systemctl disable firewalld
2败晴、關(guān)閉SELINUX
sed -i.bak 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
setenforce 0
3浓冒、準(zhǔn)備用戶
groupadd -g 48 apache
useradd -u 48 -g 48 -r -s /sbin/nologin apache
4、配置YUM庫
yum install wget -y -q
cd /etc/yum.repos.d/
rm -rf *
wget http://ftp.wangshuai.tech/yum_repo/base-aliyun.repo
wget http://ftp.wangshuai.tech/yum_repo/epel-aliyun.repo
5尖坤、源碼包安裝環(huán)境依賴的包
yum install apr-devel apr-util-devel openssl-devel pcre-devel gcc -y
安裝開發(fā)工具組
yum groupinstall "Development Tools" >/dev/null
6稳懒、下載httpd源碼包
cd /tmp/
rm -rf *
wget http://mirrors.hust.edu.cn/apache//httpd/httpd-2.4.29.tar.gz
(2)編譯安裝http服務(wù)
1、解壓httpd源碼包
cd /tmp/
tar -zxvf httpd*
2慢味、編譯安裝httpd
進(jìn)入源目錄
cd httpd-2.4.29
configure腳本场梆,指定安裝位置、指定啟用的特性
./configure --prefix=/usr/local/httpd24 --sysconfdir=/etc/httpd/ --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre --enable-modules=most --enable-mpms-shared=all --with-mpm=prefork
遇到如下類似畫面表示配置成功
按腳本生成的文件去編譯安裝
make && make install
(3)編譯后細(xì)節(jié)配置
1纯路、配置環(huán)境變量并使環(huán)境變量生效
echo 'export PATH=/usr/local/httpd24/bin:$PATH' > /etc/profile.d/apache2.sh
. /etc/profile.d/apache2.sh
2辙谜、導(dǎo)入幫助手冊
編輯文件
vim /etc/man_db.conf
MANDATORY_MANPATH /usr/local/httpd24/man //添加此行
如果沒出現(xiàn),更新man數(shù)據(jù)庫
mandb
3感昼、導(dǎo)入庫文件路徑
編輯創(chuàng)建如下文件装哆,添加新的庫文件所在目錄至此文件中
vim /etc/ld.so.conf.d/httpd24.conf
/usr/local/httpd24/modules
讓系統(tǒng)重新生成緩存:
ldconfig [-v]
(4)準(zhǔn)備修改配置文件,以及權(quán)限問題
先備份
cp /etc/httpd/httpd.conf /etc/httpd/httpd.conf.bak
修改配置文件
vim /etc/httpd/httpd.conf
User apache
Group apache
創(chuàng)建日志生成目錄
默認(rèn)在/usr/local/httpd24/logs
刪除該目錄,創(chuàng)建軟連接指向自己指定的日志生成目錄
cd /usr/local/httpd24/
rm -rf logs
mkdir /var/log/httpd
ln -s /var/log/httpd /usr/local/httpd24/logs
chown -R apache.apache /usr/local/httpd24/
chown -R apache.apache /etc/httpd/
choown -R apache.apache /var/log/httpd
(5)制作啟動http服務(wù)腳本
vim /etc/rc.d/init.d/httpd
#!/bin/bash
# chkconfig: 2345 11 99
# Description: start/syop httpd service
cmd_path="/usr/local/httpd24/bin"
httpd_pid="/usr/local/httpd24/logs/httpd.pid"
function_start_http()
{
if [ ! -e "{cmd_path}/httpd -k start &> /dev/null
else
printf "http is running...\n"
exit
fi
}
function_stop_http()
{
if [ ! -e "{cmd_path}/httpd -k stop &> /dev/null
fi
}
function_restart_http()
{
printf "Restarting http...\n"
function_stop_http
sleep 2
function_start_http
}
case $1 in
start)
function_start_http
;;
stop)
function_stop_http
;;
restart)
function_restart_http
;;
*)
printf "Usage: service httpd {start|stop|restart}\n"
esac
修改權(quán)限并添加SysV的服務(wù)腳本
cd /etc/rc.d/init.d/
chmod 750 httpd
chkconfig --add httpd
(6)啟動服務(wù)設(shè)置開機(jī)自啟
service httpd start
chkconfig httpd on
三定嗓、實現(xiàn)腳本自動安裝編譯
最終腳本如下
#!/bin/bash
# ------------------------------------
# Filename: install45.sh
# Revision: 6.6
# Author: wang shuai
# Date: 2017-12-01
# Description: This is a script
# ------------------------------------
# Copyright: 2017 shuai
# License: NI DA YE
ver=`sed -nr 's/.release ([^.]+)../\1/p' /etc/centos-release`
# 開啟自動掛載并開機(jī)啟動,關(guān)閉防火墻
echo "正在開啟自動掛載服務(wù)并開機(jī)啟動,關(guān)閉防火墻蜕琴,需要時間,請稍等..."
[[ "$ver" -eq 7 ]] && systemctl stop firewalld && systemctl disable firewalld || { service iptables stop && chkconfig iptables off ; }
# 關(guān)閉SELINUX
echo "正在關(guān)閉SELINUX"
sed -i.bak 's/SELINUX=enforcing/SELINUX=permissive/' /etc/selinux/config
setenforce 0
echo "配置ftp服務(wù)器上YUM源宵溅,請保證能ping通外網(wǎng)"
# 配置YUM庫
cd /etc/yum.repos.d/
rm -rf *
wget http://ftp.wangshuai.tech/yum_repo/base-aliyun.repo
wget http://ftp.wangshuai.tech/yum_repo/epel-aliyun.repo
# 清除yum緩存
yum clean all
# 卸載httpd的rpm安裝包
echo "正在卸載舊版本rpm包凌简,如果沒有安裝,無影響"
rpm -qa |grep http &>/dev/null
[[ $? -eq 0 ]] && rpm -qa |grep http|xargs yum -y remove
ls /usr/local/httpd24 -ld &>/dev/null
[[ $? -eq 0 ]] && \rm -rf /usr/local/httpd24
# 安裝開發(fā)工具組
echo "安裝開發(fā)工具組恃逻,請稍等..."
yum groupinstall "Development Tools" -y
#源碼包安裝環(huán)境依賴的包
echo "安裝httpd源碼包環(huán)境依賴的包雏搂,請稍等..."
yum install apr-devel apr-util-devel openssl-devel pcre-devel gcc -y
#準(zhǔn)備用戶
groupadd -g 48 apache
useradd -u 48 -g 48 -r -s /sbin/nologin apache
echo "馬上下載httpd源碼包并解壓"
# 下載httpd源碼包并解壓
cd /tmp/
rm -rf *
wget http://mirrors.hust.edu.cn/apache//httpd/httpd-2.4.29.tar.gz
tar xf httpd*
echo "編譯安裝httpd藕施,時間較長,請稍等......."
# 編譯安裝httpd
cd httpd*
./configure --prefix=/usr/local/httpd24 --sysconfdir=/etc/httpd/ --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre --enable-modules=most --enable-mpms-shared=all --with-mpm=prefork
make
make install
echo "配置httpd環(huán)境變量"
# 配置環(huán)境變量
cat /etc/profile.d/apache2.sh &>/dev/null
[[ PATH' >>/etc/profile.d/apache2.sh && source /etc/profile.d/apache2.sh && echo "配置環(huán)境變量成功且已生效" ; }
#導(dǎo)入幫助手冊
echo 'MANDATORY_MANPATH /usr/local/httpd24/man' >>/etc/man_db.conf
#導(dǎo)入庫文件路徑讓重新生成緩存
echo '/usr/local/httpd24/modules' >/etc/ld.so.conf.d/httpd24.conf
ldconfig
#準(zhǔn)備修改配置文件,以及權(quán)限問題
cp /etc/httpd/httpd.conf /etc/httpd/httpd.conf.bak
sed -ir 's/^User deamon/User apache/' /etc/httpd/httpd.conf
sed -ir 's/^Group deamon/Group apache/' /etc/httpd/httpd.conf
#創(chuàng)建日志生成目錄
cd /usr/local/httpd24/
rm -rf logs
ls /var/log/httpd -ld &>/dev/null
[[ $? -eq 0 ]] || mkdir /var/log/httpd
ln -s /var/log/httpd /usr/local/httpd24/logs
chown -R apache.apache /usr/local/httpd24/
chown -R apache.apache /etc/httpd/
chown -R apache.apache /var/log/httpd
#下載啟動腳本
wget http://ftp.wangshuai.tech/other//httpd -O /etc/rc.d/init.d/httpd
cd /etc/rc.d/init.d/
chmod 750 httpd
chkconfig --add httpd
echo "啟動httpd服務(wù)"
# 啟動http服務(wù)
service httpd start
echo "設(shè)置開機(jī)啟動httpd服務(wù)"
# 設(shè)置開機(jī)啟動http服務(wù)
chkconfig httpd on
echo "安裝完成凸郑!"