RHCE之WEB服务

作业要求

1、判断web服务是否运行(1、查看进程的方式判断该程序是否运行,2、通过查看端口的方式判断该程序是否运行),如果没有运行,则启动该服务并配置防火墙规则。
​2、使用curl命令访问第二题的web服务,看能否正常访问,如果能正常访问,则返回web server is running;如果不能正常访问,返回12状态码。
3、for创建20用户
用户前缀由用户输入
用户初始密码由用户输入
例如:test01,test10

1.查看Web服务器

启动httpd

[root@localhost_1 ~]# systemctl restart httpd

查看进程

[root@localhost_1 ~]# ps -ef | grep httpd

 查看端口

[root@localhost_1 ~]# ss -lntup | grep httpd

配置防火墙:可以让防火墙通过80,443端口,还可以关闭防火墙

写shell脚本

#!/bin/bash
#########################
#File name:5.sh
#Version:v1.0
#Email:admin@test.com
#Created time:2023-04-06 20:17:38
#Description:
#########################
ps_num=`ps -ef | grep httpd | grep -v grep | wc -l`       
ss_num=`ss -lntup | grep httpd | wc -l`
if [ $ps_num -gt 0 ] && [ $ss_num -gt 0 ]
then
        echo "web is running"
else
        systemctl restart httpd;
        if [ $? -eq 0 ]
        then
                echo "web starts successfully"
        else
                echo "web starts unsuccessfully"
        fi
        systemctl disable firewalld --now                
fi

测试

[root@localhost1 test]# bash 5.sh
web is running
[root@localhost1 test]# systemctl stop httpd
[root@localhost1 test]# bash 5.sh
web starts successfully

2.

写shell脚本

#!/bin/bash
#########################
#File name:6.sh
#Version:v1.0
#Email:admin@test.com
#Created time:2023-04-06 20:56:43
#Description:
#########################
curl 10.10.112.182 > /dev/null 2>&1          
if [ $? -eq 0 ]
then
        echo "web server is running"
else
        echo "web server is not running";
        exit 12              
fi

测试

[root@localhost1 test]# bash 6.sh
web server is running
[root@localhost1 test]# systemctl stop httpd
[root@localhost1 test]# bash 6.sh
web server is not running

3.

使用for循环创建20个用户

#!/bin/bash
#########################
#File name:7.sh
#Version:v1.0
#Email:admin@test.com
#Created time:2023-04-06 21:22:12
#Description:
#########################
read -p "please input user perfix:" name
read -p "please input password:" passwd
for uname in ${name}{01..20}            
do
        useradd $uname          
        echo $passwd | passwd --stdin $uname > /dev/null      
        echo "$uname user is added"    
done

测试

[root@localhost1 test]# bash 7.sh
please input user perfix:test
please input password:redhat
test01 user is added
test02 user is added
.......
test19 user is added
test20 user is added

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值