一、/etc/rc.local
在文件最后一行添加要执行程序的全路径。
如mongodb、tomcat、jenkins(放在tomcat中启动只需要添加tomcat启动脚本)
numactl --interleave=all /data/app/mongodb/bin/mongod -f /data/work/mongodb/conf/mongod.yaml
sleep 3
numactl --interleave=all /data/app/mongodb/bin/mongod -f /data/work/mongodb/conf/shard1.yaml
numactl --interleave=all /data/app/mongodb/bin/mongod -f /data/work/mongodb/conf/shard2.yaml
numactl --interleave=all /data/app/mongodb/bin/mongod -f /data/work/mongodb/conf/shard3.yaml
numactl --interleave=all /data/app/mongodb/bin/mongod -f /data/work/mongodb/conf/shard4.yaml
numactl --interleave=all /data/app/mongodb/bin/mongod -f /data/work/mongodb/conf/shard5.yaml
numactl --interleave=all /data/app/mongodb/bin/mongod -f /data/work/mongodb/conf/shard6.yaml
sleep 3
numactl --interleave=all /data/app/mongodb/bin/mongos -f /data/work/mongodb/conf/mongos.yaml
二、注册系统服务
chkconfig --add 服务名
chkconfig -leve 启动级别 服务名 on (说明,3级别代表在命令行模式启动,5级别代表在图形界面启动,on表示开启)
chkconfig -leve 启动级别 服务名 off (说明,off表示关闭自启动)
等级代号列表:
-
等级0表示:表示关机
-
等级1表示:单用户模式
-
等级2表示:无网络连接的多用户命令行模式
-
等级3表示:有网络连接的多用户命令行模式
-
等级4表示:不可用
-
等级5表示:带图形界面的多用户模式
-
等级6表示:重新启动
如何增加一个服务:
- 服务脚本必须存放在
/etc/ini.d/
目录下; chkconfig --add servicename
在chkconfig工具服务列表中增加此服务,此时服务会被在/etc/rc.d/rcN.d
中赋予K/S入口了;chkconfig --level 35 mysqld on
修改服务的默认启动等级。
如mysql、gitlab、jira、confluence
[root@MySQL init.d]# chkconfig --add mysql
[root@MySQL init.d]# chkconfig mysql on
问题:
[root@gitlab init.d]# chkconfig --add xxx
service xxx does not support chkconfig
解决:
在服务配置文件中添加
# chkconfig: 2345 10 90
#服务必须在运行级2,3,4,5下被启动或关闭,启动的优先级是90,关闭的优先级是10。
# description: Start and Stop xxx