使用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服务已安装成功!"

你可能感兴趣的:(脚本,shell,apache,脚本语言,shell,apache)