【砖石局】Linux(CentOS7)中如何开启Nginx1.12.1、Redis3.2.5、FastDFS1.16服务开机自启动? - Go语言中文社区

【砖石局】Linux(CentOS7)中如何开启Nginx1.12.1、Redis3.2.5、FastDFS1.16服务开机自启动?


一、查看Linux中自启动服务列表

[root@localhost ~]#  

注:该输出结果只显示 SysV 服务,并不包含
原生 systemd 服务。SysV 配置数据
可能被原生 systemd 配置覆盖。 

      要列出 systemd 服务,请执行 'systemctl list-unit-files'。
      查看在具体 target 启用的服务请执行
      'systemctl list-dependencies [target]'。

fdfs_storaged  	0:1:2:3:4:5:6:关
fdfs_trackerd  	0:1:2:3:4:5:6:关
netconsole     	0:1:2:3:4:5:6:关
network        	0:1:2:3:4:5:6:关
zookeeper      	0:1:2:3:4:5:6:

二、打开nginx-pid日志信息

去掉注释"# pid logs/nginx.pid"

[root@localhost conf]# pwd
/usr/local/nginx/conf
[root@localhost conf]# vim nginx.conf
.......
[root@localhost conf]# vim /etc/rc.d/rc.local 
//fastDFS启动命令
/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart
/usr/bin/fdfs_storaged /etc/fdfs/storage.conf restart
//nginx启动命令
/usr/local/nginx/sbin/nginx  
//redis启动命令
/usr/local/redis/bin/redis-server /usr/local/redis/bin/redis.conf

在这里插入图片描述
创建logs文件夹

[root@localhost nginx]# mkdir logs
[root@localhost nginx]# ll
总用量 4
drwxr-xr-x. 2 root root 4096 129 10:54 conf
drwxr-xr-x. 2 root root   40 128 23:38 html
drwxr-xr-x. 2 root root    6 129 11:03 logs
drwxr-xr-x. 2 root root   19 128 23:38 sbin

三、编辑、保存rc.local文件

[root@localhost nginx]# vim /etc/rc.d/rc.local
-----------------------------------------------------------------------------------------
/usr/local/nginx/sbin/nginx

在这里插入图片描述
Esc退出编辑模式,命令“:wq”。

四、授权授权

[root@localhost etc]# chmod +x /etc/rc.d/rc.local

五、测试[步骤三]添加启动命令

[root@localhost nginx]# /usr/local/nginx/sbin/nginx
ngx_http_fastdfs_set pid=2852
    
[root@localhost nginx]# ps -ef|grep nginx
root       2853      1  0 11:05 ?        00:00:00 nginx: master process /usr/local/nginx/sbin/nginx
nobody     2854   2853  0 11:05 ?        00:00:00 nginx: worker process
root       2887   1282  0 11:08 pts/1    00:00:00 grep --color=auto nginx


注意:关闭Linux防火墙

systemctl status firewalld //查看防火墙状态
systemctl start firewalld //开启防火墙
systemctl stop  firewalld
systemctl disable  firewalld //永久关闭防火墙

六、reboot重启虚拟机测试

[root@localhost ~]# ps -ef|grep nginx
root       1099      1  0 11:18 ?        00:00:00 nginx: master process /usr/local/nginx/sbin/nginx
nobody     1100   1099  0 11:18 ?        00:00:00 nginx: worker process
root       2445   2375  0 11:21 pts/0    00:00:00 grep --color=auto nginx

Nginx服务自启动成功!!!

♚学习、实战、总结、分享,让生活变得更美好!
☞林大侠博客:
https://coding0110lin.blog.csdn.net/  欢迎转载,一起技术交流探讨!

版权声明:本文来源CSDN,感谢博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
原文链接:https://blog.csdn.net/LINHONG_1994/article/details/103455628
站方申明:本站部分内容来自社区用户分享,若涉及侵权,请联系站方删除。
  • 发表于 2021-12-11 20:49:45
  • 阅读 ( 2420 )
  • 分类:Linux

0 条评论

请先 登录 后评论

官方社群

GO教程

猜你喜欢