一、查看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 12月 9 10:54 conf
drwxr-xr-x. 2 root root 40 12月 8 23:38 html
drwxr-xr-x. 2 root root 6 12月 9 11:03 logs
drwxr-xr-x. 2 root root 19 12月 8 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/ 欢迎转载,一起技术交流探讨!