1、自动安装 apache 脚本
#!/bin/bash
function apache_install(){
# install httpd
yum list installed | grep httpd
if [ $? -ne 0 ];then
yum install httpd -y
systemctl start httpd
systemctl enable httpd
fi
# close SELINUX
sed -i '/^SELINUX=/cSELINUX=disabled' /etc/selinux/config
setenforce 0
# install iptables
yum list installed | grep iptables
if [ $? -ne 0 ];then
systemctl stop firewalld
systemctl disable firewalld
yum install iptables-services -y
systemctl start iptables
systemctl enable iptables
fi
# iptables config
iptables -I INPUT -p tcp --dport 80 -j ACCEPT
service iptables save
systemctl restart iptables
# test httpd
curl --connect-timeout 5 http://127.0.0.1 >/dev/null
if [ $? -eq 0 ];then
echo "apache is ok!"
fi
}