Nginx 安装后 /etc/init.d/ 没有nginx 配置得启动服务
【摘要】 配置/etc/init.d/下得Nginx的启动服务
第一步
检查nginx运行得进程
(proenv) [root@TXMaster init.d]# ps -ef | grep -i nginx root 2996 1 0 14:49 ? 00:00:00 nginx: master process ./nginx nginx 2997 2996 0 14:49 ? 00:00:00 nginx: worker process root 10247 2937 0 15:33 pts/0 00:00:00 grep --color=auto -i nginx
关闭nginx
(proenv) [root@TXMaster init.d]# kill 9 2996 (proenv) [root@TXMaster init.d]# kill 9 2997 bash: kill: (2997) - No such process (proenv) [root@TXMaster init.d]#
(proenv) [root@TXMaster init.d]# ps -ef | grep -i nginx root 10374 2937 0 15:34 pts/0 00:00:00 grep --color=auto -i nginx (proenv) [root@TXMaster init.d]#
创建nginx配置文件
(proenv) [root@TXMaster init.d]# vi /etc/init.d/nginx
#!/bin/bash # # nginx - this script starts and stops the nginx daemon # # chkconfig: - 85 15 # description: Nginx is an HTTP(S) server, HTTP(S) reverse \ # proxy and IMAP/POP3 proxy server # processname: nginx # config: /usr/local/nginx/conf/nginx.conf # pidfile: /usr/local/nginx/logs/nginx.pid # Source function library. . /etc/rc.d/init.d/functions # Source networking configuration. . /etc/sysconfig/network # Check that networking is up. [ "$NETWORKING" = "no" ] && exit 0 nginx="/usr/local/nginx/sbin/nginx" prog=$(basename $nginx) NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf" lockfile=/var/lock/subsys/nginx start() { [ -x $nginx ] || exit 5 [ -f $NGINX_CONF_FILE ] || exit 6 echo -n $"Starting $prog: " daemon $nginx -c $NGINX_CONF_FILE retval=$? echo [ $retval -eq 0 ] && touch $lockfile return $retval } stop() { echo -n $"Stopping $prog: " killproc $prog -QUIT retval=$? echo [ $retval -eq 0 ] && rm -f $lockfile return $retval } restart() { configtest || return $? stop start } reload() { configtest || return $? echo -n $"Reloading $prog: " killproc $nginx -HUP RETVAL=$? echo } force_reload() { restart } configtest() { $nginx -t -c $NGINX_CONF_FILE } rh_status() { status $prog } rh_status_q() { rh_status >/dev/null 2>&1 } case "$1" in start) rh_status_q && exit 0 start ;; stop) rh_status_q || exit 0 stop ;; restart|configtest) restart ;; reload) rh_status_q || exit 7 reload ;; force-reload) force_reload ;; status) rh_status ;; condrestart|try-restart) rh_status_q || exit 0 ;; *) echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}" exit 2 ;;
保存退出
第三步
修改文件权限
(proenv) [root@TXMaster init.d]# chmod +x /etc/init.d/nginx
第四步
(proenv) [root@TXMaster init.d]# /sbin/chkconfig nginx on Note: Forwarding request to 'systemctl enable nginx.service'. Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.
检查一下
(proenv) [root@TXMaster init.d]# /sbin/chkconfig --list nginx Note: This output shows SysV services only and does not include native systemd services. SysV configuration data might be overridden by native systemd configuration. If you want to list systemd services use 'systemctl list-unit-files'. To see services enabled on particular target use 'systemctl list-dependencies [target]'. service nginx supports chkconfig, but is not referenced in any runlevel (run 'chkconfig --add nginx')
完成!
启动Nginx服务
(proenv) [root@TXMaster init.d]# service nginx start Starting nginx (via systemctl): [ OK ] (proenv) [root@TXMaster init.d]# service nginx restart Restarting nginx (via systemctl): [ OK ] (proenv) [root@TXMaster init.d]# /etc/init.d/nginx status /etc/init.d/nginx: line 106: syntax error: unexpected end of file (proenv) [root@TXMaster init.d]#
之后,就可以使用以下命令了
service nginx start service nginx stop service nginx restart service nginx reload service nginx status /etc/init.d/nginx start /etc/init.d/nginx stop /etc/init.d/nginx restart /etc/init.d/nginx reload /etc/init.d/nginx status
【版权声明】本文为华为云社区用户原创内容,转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息, 否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)