一、问题描述
1、安装完nginx后,无法使用service或systemctl命令管理nginx服务
二、问题分析
1、/etc/init.d/目录下缺少nginx默认启动脚本
三、在/etc/init.d/路径下添加脚本文件,名称为nginx,并添加文件可执行权限,如下:
1 #!/bin/bash 2 #Startup script for the nginx Web Server 3 #chkconfig: 2345 85 15 4 nginx=/usr/local/nginx/sbin/nginx 5 conf=/usr/local/nginx/conf/nginx.conf 6 case $1 in 7 start) 8 echo -n "Starting Nginx" 9 $nginx -c $conf 10 echo " done." 11 ;; 12 stop) 13 echo -n "Stopping Nginx" 14 killall -9 nginx 15 echo " done." 16 ;; 17 test) 18 $nginx -t -c $conf 19 echo "Success." 20 ;; 21 reload) 22 echo -n "Reloading Nginx" 23 ps auxww | grep nginx | grep master | awk '{print $2}' | xargs kill -HUP 24 echo " done." 25 ;; 26 restart) 27 $nginx -s reload 28 echo "reload done." 29 ;; 30 *) 31 echo "Usage: $0 {start|restart|reload|stop|test|show}" 32 ;; 33 esac
四、问题验证
1、service命令