题目:通过shell脚本分析部署nginx网络服务
1.接收用户部署的服务名称
2.判断服务是否安装
已安装;自定义网站配置路径为/www;并创建共享目录和网页文件;重启服务
没有安装;安装对应的软件包
3.测试
判断服务是否成功运行;
已运行,访问网站
未运行,提示服务未启动,并显示自定义的配置文件内容
4.以上配置没有问题,请邮件告知我,并将脚本代码(代码文件)邮件发送我
我的邮箱账号:lxx1065372838@163.com
一、邮箱配置
[root@localhost redhat]# systemctl stop firewalld
[root@localhost redhat]# setenforce 0
[root@localhost redhat]# mount /dev/sr0 /mnt
[root@localhost redhat]# dnf install s-nail -y
[root@localhost redhat]# tail -5 /etc/s-nail.rc
set from=m17384403619@163.com
set smtp=smtp.163.com
set smtp-auth-user=17802590135@163.com
set smtp-auth-password=DSrcqtw8CgKSLeQJ
set smtp-auth=login
二
[root@localhost redhat]# vim rly.sh
[root@localhost redhat]# cat rly.sh
#!/bin/bash
1.接收用户部署的服务名称
read -p "请输入要部署的服务名称:" service_name
2.判断服务是否安装
if rpm -q $service_name &> /dev/null;thenecho "服务已安装"config_path="/www" mkdir -p $config_path echo "hello,this is a test page" > $config_path/index/html systemctl restart $service_name
elseecho "服务未安装。开始安装"yum install -y $service_name
fiif systemctl is-active $service_name;then echo "服务正在运行,访问网站:http://localhost"curl http://localhost
elseecho "服务未启动"cat $config_path/index.html
fiif systemctl is-active $service_name;then echo "nginx服务已成功部署并运行" | mail -s "rly" lxx1065372838@163.com mail -s "rly的nginx脚本" lxx1065372838@163.com < $0
fi
三
[root@localhost ~]# bash rly.sh
请输入要部署的服务名称:nginx
服务已安装
Job for nginx.service failed because the control process exited with error code.
See "systemctl status nginx.service" and "journalctl -xeu nginx.service" for details.
failed
服务未启动
hello,this is a test page
failed
测试