使用Shell腳本一鍵部署Apache 服務

執行腳本之前將Apache 所需的三個軟件包上傳到/opt 目錄下
鏈接:Apache所需軟件包下載鏈接
提取碼:a4zr

#!/bin/bash
systemctl stop firewalld
systemctl disable firewalld
setenforce 0

df | grep "sr0"   
if [ $? -eq 0 ];then
   yum -y install gcc gcc-c++ make pcre pcre-devel expat-devel perl &>/dev/null
else
   mount /dev/sr0 /mnt
   yum -y install gcc gcc-c++ make pcre pcre-devel expat-devel perl &>/dev/null
fi

read -p "請輸入Apache源碼包所在絕對路徑:" a
cd $a
echo "----開始配置軟件模塊----"
tar zxvf apr-1.6.2.tar.gz &>/dev/null
tar zxvf apr-util-1.6.0.tar.gz &>/dev/null
tar jxvf httpd-2.4.29.tar.bz2 &>/dev/null

mv /opt/apr-1.6.2 /opt/httpd-2.4.29/srclib/apr
mv /opt/apr-util-1.6.0 /opt/httpd-2.4.29/srclib/apr-util

cd /opt/httpd-2.4.29/
./configure --prefix=/usr/local/httpd --enable-so --enable-rewrite --enable-charset-lite --enable-cgi


make
make install

ln -s /usr/local/httpd/conf/httpd.conf /etc/httpd.conf
ln -s /usr/local/httpd/bin/* /usr/local/bin/

cd /lib/systemd/system
touch httpd.service

echo "[Unit]
Description=The Apache HTTP Server
After=network.target
[Service]
Type=forking
PIDFile=/usr/local/httpd/logs/httpd.pid
ExecStart=/usr/local/bin/apachectl $OPTIONS
ExecReload=/bin/kill -HUP $MAINPID
[Install]
WantedBy=multi-user.target" >/lib/systemd/system/httpd.service

systemctl start httpd.service
systemctl enable httpd.service


b=$(sed -n '/IPADDR/p' /etc/sysconfig/network-scripts/ifcfg-ens33 | awk -F "=" '{print $2}')
sed -i 's/Listen 80/Listen $b:80/g' /etc/httpd.conf
sed -i 's/#ServerName www.example.com:80/ServerName www.benet.com:80/g'  /etc/httpd.conf


systemctl restart httpd.service

echo "$b www.benet.com" >> /etc/hosts

echo "apache服務已安裝成功!"
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章