查看是否可以YUM安装
yum list nginx
YUM
安装
yum install -y nginx
启动Nginx
systemctl start nginx
配置Nginx开机自启
systemctl enable nginx
编写Nginx宕机自启脚本
vi /etc/nginx/nginx_check.sh
#!/bin/bash
A=`ps -C nginx -no-header |wc -l`
if [ $A -eq 1 ];then
echo $(date +%F%n%T) " nginx未启动,启动nginx..."
systemctl start nginx
sleep 10
fi
设置脚本可执行权限
chmod a+x /etc/nginx/nginx_check.sh
编写宕机自启脚本的启动脚本
vi /etc/nginx/nginx_check_start.sh
#!/bin/bash
nohup /etc/nginx/nginx_check.sh > /dev/null &
将宕机自启脚本的启动脚本加到开启启动项中
vi /etc/rc.local
将命令: nohuo /etc/nginx/nginx_check_start.sh 添加到/etc/rc.local文件中
保存退出后执行:chmod +x /etc/rc.local