nginx + fastdfs 开机自启动

虚拟机每次启动之后都要重新启动一下 nginx 和fastdfs服务,比较麻烦,所以增加开机自启动。

1.编辑 /etc/rc.d/rc.local 文件,增加启动项

vim /etc/rc.d/rc.local

2.改为如下:

#!/bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
#
# In contrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
#
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.

touch /var/lock/subsys/local
# fastdfs start
/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart
/usr/bin/fdfs_storaged /etc/fdfs/storage.conf restart

# nginx start
/usr/local/nginx/sbin/nginx

3.在centos7中, /etc/rc.d/rc.local 文件的权限被降低了,需要给rc.local 文件增加可执行的权限

chmod +x /etc/rc.d/rc.local

4.但是重启虚拟机后,再次重启nginx会报错:

open() "/var/run/nginx/nginx.pid" failed (2: No such file or directory)

5.解决方案

进入 cd /usr/local/nginx/conf/ 目录,编辑配置文件nginx.conf ,在配置文件中有个注释的地方: #pid        logs/nginx.pid,它默认是被注释上的。我们把这个注释取消,并修改为:pid    /usr/local/nginx/logs/nginx.pid

接着保存完配置文件后,在 /usr/local/nginx 目录下创建 logs 目录:mkdir /usr/local/nginx/logs

使用命令测试nginx服务:
 

/usr/local/nginx/sbin/nginx

/usr/local/nginx/sbin/nginx -s reload

/usr/local/nginx/sbin/nginx -s quit

如果没有问题。重启虚拟机进行测试

成功。

猜你喜欢

转载自blog.csdn.net/tianyucxh/article/details/94593879