1、如果未安装http服务则安装服务
2、放行防火墙
3、设置selinux为强制模式、web服务器的端口8080
5、web服务器的内容目录为/www、所有操作开机有效
7、所有的操作必须进行判断
8、在合适的实际输出合适的信息,如果有日志就更好了
function httpd(){
if rpm -qa | grep httpd >/dev/null 2>&1
then
echo "httpd already exists!"
if systemctl is-active httpd &>/dev/null
then
echo "http is active"
else
echo "The httpd service is starting"
systemctl start httpd
systemctl enable httpd
fi
else
yum install httpd -y &>/dev/null
systemctl start httpd
systemctl enable httpd
echo "downloading http service "
fi
}
function firewall(){
if ! firewall-cmd --query-port=8080/tcp
then
firewall-cmd --zone=public --add-port=8080/tcp --perman &>/dev/null
systemctl restart firewalld.service
echo "Releasing ports and restarting services"
else
echo "Release successful"
fi
}
function selinux(){
echo "Configuring SELinux..."
setenforce 1 >/dev/null 2>&1
if [ $? -ne 0 ]; then
echo "Error: Failed to configure SELinux. maybe selinux is disable please change opt"
# exit 1
fi
echo "SELinux configured successfully."
}
function set_web_port(){
if ! grep 'Listen 8080' /etc/httpd/conf/httpd.conf &>/dev/null
then
echo "Listen 8080">>/etc/httpd/conf/httpd.conf
else
echo "Port listening successful for 8080"
fi
}
function set_web_content(){
file="/root/www"
if ! [ -d $file ]
then
mkdir $file
echo "mkdir $file success"
else
echo " $file already exists!"
# set_web_content
fi
dire="/etc/httpd/conf.d/vhost.conf"
if ! [ -f $dire ]
then
touch $dire
else
echo "$dire already exists"
# set_web_content
fi
cp vhost.f $dire
systemctl restart httpd
file="$file/index.html"
if ! [ -f $file ]
then
touch $file
echo "hell world">>$file
fi
}
file='/etc/yum.repos.d/redhat.repo'
if [ -f $file ]
then
echo "正在检测htpp服务 "
httpd
echo "正在检测firewall服务 "
firewall
echo "正在检测selinux服务 "
selinux
echo "正在检测web端口服务 "
set_web_port
echo "正在检测web服务 "
set_web_content
else
repo="
[repo] \n
name=AppStream\n
baseurl=/mnt/AppStream \n
gpgcheck=0 \n
[repo2] \n
name=BaseOS\n
baseurl=/mnt/BaseOs \n
gpgcheck=0 \n
"
touch $file
echo -e $repo >>$file
fi