使用Shell脚本一键部署Apache 服务

时间:2021-1-8 作者:admin

执行脚本之前将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服务已安装成功!"
声明:本文内容由互联网用户自发贡献自行上传,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任。如果您发现有涉嫌版权的内容,欢迎进行举报,并提供相关证据,工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。