使用shell脚本完成指定要求的web服务器

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
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值