您的位置:首页 > 其它

常用命令二:运行级别,开机服务【runlevel,chkconfig,service】

2017-04-01 21:43 453 查看
一、运行级别:
# Default runlevel. The runlevels used are:
#   0 - halt (Do NOT set initdefault to this) =》关闭(或停止)系统                 
                         
#   1 - Single user mode =》单用户模式
#   2 - Multiuser, without NFS (The same as 3, if you do not have networking) =》 没有联网的多用户模式
#   3 - Full multiuser mode =》联网的多用户模式
#   4 - unused =》
#   5 - X11 =》联网并且使用X Window系统的多用户模式
#   6 - reboot (Do NOT set initdefault to this) =》重启系统

参考资料:

0runlevel0.target, poweroff.target关闭系统。
1, s, singlerunlevel1.target, rescue.target单用户模式。
2, 4runlevel2.target, runlevel4.target, multi-user.target用户定义/域特定运行级别。默认等同于 3。
3runlevel3.target, multi-user.target多用户,非图形化。用户可以通过多个控制台或网络登录。
5runlevel5.target, graphical.target多用户,图形化。通常为所有运行级别 3 的服务外加图形化登录。
6runlevel6.target, reboot.target重启
emergencyemergency.target紧急 Shell
相关查看命令
runlevel , who -r



二、开机自动配置:
1、/etc/init.d/nginx 服务脚本
2、添加服务chkconfig --add nginx
3、设置服务运行级别
备注:
可以直接设置服务,绕过添加 chkconfig <service> on



配置相关命令

chkconfig 配置服务

chkconfig [--list] [--type type][name]
chkconfig --add name
chkconfig --del name
chkconfig --override name
chkconfig [--level levels] [--type type] name <on|off|reset|resetpriorities>,默认level 2345
chkconfig [--level levels] [--type type] name 



service - run a System V init script

service SCRIPT COMMAND [OPTIONS]
service --status-all
service --help | -h | --version

备注:

service  runs  a  System V init script in as predictable environment as possible, removing most environment vari-ables and with current working directory set to /.

service会尽可能使运行System V init脚本的环境可预测,从而消除大多数环境变量【只保留LANG和TERM两个环境变量】,并且设置当前工作目录为根目录。

当启动脚本依赖环境变量时,想通过service命令重启时,需在启动脚本中增加source /etc/profile

案列:
php项目用到环境变量时,重启脚本不加入source /etc/profile会导致重启环境变量一直不生效,
即使执行命令的顺序如下:1、source /etc/profile 2、service php-fpm restart依旧不生效
反而1、source /etc/profile 2、/etc/init.d/php-fpm restart生效的原因就是在这里


查看命令的路径 : ls -al $(which java)



参考链接:

https://www.ibm.com/developerworks/cn/linux/l-lpic1-v3-101-3/

https://www.zhihu.com/question/20126189

https://www.ibm.com/developerworks/cn/linux/1407_liuming_init3/index.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: