写一个关于安装nginx的shell脚本
时间: 2023-03-14 08:20:46 浏览: 64
#!/bin/bash
#安装Nginx
sudo apt-get update
sudo apt-get install nginx
#启动Nginx
sudo systemctl start nginx
#检查Nginx是否已启动
sudo systemctl status nginx
相关问题
给我写一个监控nginx的shell脚本
这个脚本可以监控nginx服务器的运行状态:
#!/bin/bash# 检查nginx进程
# 如果不存在,则启动nginx
if ! pgrep nginx &>/dev/null; then
echo "Nginx process not found, starting nginx.."
sudo service nginx start
fi# 检查nginx进程是否正常运行
# 如果不正常,则重新启动nginx
if [[ $(systemctl is-active nginx) != "active" ]]; then
echo "Nginx process is not active, restarting nginx.."
sudo service nginx restart
fi
写一个关于源码安装nginx的shell脚本,关于centos7的
#!/bin/bash# 安装nginx
yum -y install nginx# 启动nginx
systemctl start nginx# 开放80端口
firewall-cmd --zone=public --add-port=80/tcp --permanent# 重启防火墙
systemctl restart firewalld.service# 添加nginx服务
systemctl enable nginx.service