一.一键部署Apache
1.将安装Apache所需软件包传到/opt目录下
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/71411ddace5860e0aa40ef51e8d8d4d4.png#pic_center)
read -p "输入域名www.xxx.com:" a
systemctl stop firewalld
systemctl disable firewalld
setenforce 0
yum -y install gcc gcc-c++ make pcre pcre-devel expat-devel perl
cd /opt/
tar zxvf apr-1.6.2.tar.gz
tar zxvf apr-util-1.6.0.tar.gz
tar jxvf httpd-2.4.29.tar.bz2
mv apr-1.6.2 /opt/httpd-2.4.29/srclib/apr
mv 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/
ln -s /usr/local/httpd/bin/* /usr/local/bin/
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
cp /etc/httpd.conf{,.bak}
c=`ifconfig | awk 'NR==2{print $2}'`
sed -i "51c Listen $c:80" /etc/httpd.conf.bak
sed -i '52 s/^/#/' /etc/httpd.conf.bak
sed -i '197d' /etc/httpd.conf.bak
sed -i "196a ServerName $a:80" /etc/httpd.conf.bak
cat /etc/httpd.conf.bak > /etc/httpd.conf
httpd -t
cat /usr/local/httpd/htdocs/index.html
systemctl start httpd.service
systemctl restart httpd.service
echo "$c $a" >> /etc/hosts
netstat -anpt | grep 80
if [ $? -eq 0 ];then
echo "Apache服务已启动"
else
echo 启动失败
exit 1
fi
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/358645de8301e0ad9b8b1c46b4273fd9.png#pic_center)
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/99911cb904568af8bb62557b946e534d.png#pic_center)
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/5336eddec74652d8ce4d914833c75bfa.png#pic_center)