centos7 配置nginx服务、开机自动启动
2016-09-20 00:00
796 查看
摘要: 在配置nginx开机自启和服务配置的时候,遇到了一些问题,特此记录
在以上都已经安装完成,能正常启动之后
启动、停止、重启、重载、检查服务:
6: service httpd start|stop|restart|reload|status
7: systemctl start|stop|restart|reload|status httpd.service
允许、禁止服务自启动:
6: chkconfig httpd on|off
7: system enable|disable httpd.service
列出服务:
6: chkconfig –list
7: systemctl list-unit-files –type=service 或 ls /etc/systemd/system/*.wants/
添加服务:
6: chkconfig httpd –add
7: systemctl daemon-reload
可以先通过上述命令查询是否已经配置nginx服务,如果没有
centos7:
服务文件
启动服务
设置开机自启
centos6:
在 /etc/init.d 中新增 nginx 文件,内容如下
然后设置自启
启动服务
环境:
centos7、nginx 1.10.1在以上都已经安装完成,能正常启动之后
配置服务:
centos7 的服务管理 与 centos6 发生了一些变化 ,此处参考 http://www.ebanban.com/?p=476启动、停止、重启、重载、检查服务:
6: service httpd start|stop|restart|reload|status
7: systemctl start|stop|restart|reload|status httpd.service
允许、禁止服务自启动:
6: chkconfig httpd on|off
7: system enable|disable httpd.service
列出服务:
6: chkconfig –list
7: systemctl list-unit-files –type=service 或 ls /etc/systemd/system/*.wants/
添加服务:
6: chkconfig httpd –add
7: systemctl daemon-reload
可以先通过上述命令查询是否已经配置nginx服务,如果没有
centos7:
服务文件
#systemd 下的 system 或 usr 创建 nginx.service 文件 vim /usr/lib/systemd/system/nginx.service #nginx服务配置到该文件中 #服务描述性的配置 [Unit] Description=nginx - high performance web server Documentation=http://nginx.org/en/docs/ After=network.target remote-fs.target nss-lookup.target #服务关键配置 [Service] Type=forking #pid文件位置 #要与nginx配置文件中的pid配置路径一致,这个很重要,否则会服务启动失败 PIDFile=/var/run/nginx.pid #启动前检测 nginx配置文件 是否正确 ExecStartPre=/usr/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf #启动 ExecStart=/usr/sbin/nginx -c /usr/local/nginx/conf/nginx.conf #重启 ExecReload=/bin/kill -s HUP $MAINPID #关闭 ExecStop=/bin/kill -s QUIT $MAINPID PrivateTmp=true [Install] WantedBy=multi-user.target
启动服务
systemctl start nginx.service
设置开机自启
systemctl enable nginx.service
centos6:
在 /etc/init.d 中新增 nginx 文件,内容如下
#!/bin/bash # nginx Startup script for the Nginx HTTP Server # it is v.0.0.2 version. # chkconfig: - 85 15 # description: Nginx is a high-performance web and proxy server. # It has a lot of features, but it's not for everyone. # processname: nginx # pidfile: /var/run/nginx.pid # config: /usr/local/nginx/conf/nginx.conf nginxd=/usr/local/nginx/sbin/nginx nginx_config=/usr/local/nginx/conf/nginx.conf nginx_pid=/var/run/nginx.pid RETVAL=0 prog="nginx" # Source function library. . /etc/rc.d/init.d/functions # Source networking configuration. . /etc/sysconfig/network # Check that networking is up. [ ${NETWORKING} = "no" ] && exit 0 [ -x $nginxd ] || exit 0 # Start nginx daemons functions. start() { if [ -e $nginx_pid ];then echo "nginx already running...." exit 1 fi echo -n $"Starting $prog: " daemon $nginxd -c ${nginx_config} RETVAL=$? echo [ $RETVAL = 0 ] && touch /var/lock/subsys/nginx return $RETVAL } # Stop nginx daemons functions. stop() { echo -n $"Stopping $prog: " killproc $nginxd RETVAL=$? echo [ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx /var/run/nginx.pid } # reload nginx service functions. reload() { echo -n $"Reloading $prog: " #kill -HUP `cat ${nginx_pid}` killproc $nginxd -HUP RETVAL=$? echo } # See how we were called. case "$1" in start) start ;; stop) stop ;; reload) reload ;; restart) stop start ;; status) status $prog RETVAL=$? ;; *) echo $"Usage: $prog {start|stop|restart|reload|status|help}" exit 1 esac exit $RETVAL
然后设置自启
#添加服务 chkconfig --add nginx chkconfig nginx on
启动服务
service nginx start
相关文章推荐
- centos7 配置nginx服务、设置开机自动启动
- 添加服务到开机自动启动(centos7开机自启动nginx,php-fpm)
- centos6.9下设置nginx服务开机自动启动
- CentOS7 下配置Keepalived为系统服务,开机自动启动。
- centos 6.5+ 开机自动联网配置 && 开启启动服务
- CentOS7 下配置Keepalived为系统服务,开机自动启动。
- 虚拟机设置选择NAT模式CentOS 6.3开机启动服务及自动联网
- centos开机自动启动Apache,Mysql,Samba、Svn等服务的方法
- CentOS下配置ORACLE开机自动启动
- CentOS设置开机自动启动某服务
- centos开机自动启动Apache,Mysql,Samba、Svn等服务的方法
- CentOS设置开机自动启动某服务
- centos设置apache、mysql及ftp服务开机自动启动的方法
- Centos搭建nginx环境,编译,添加服务,开机启动。
- CentOS设置开机自动启动某服务
- CentOS设置开机自动启动某服务
- CentOS Linux下配置Oracle 11gR2为系统服务自动启动
- CentOS6.3配置Nginx开机启动
- [转]CentOS设置服务开机自动启动
- Linux(centos) 编译安装 Mysql 后配置开机自动启动