常用命令二:运行级别,开机服务【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) =》重启系统
参考资料:
相关查看命令
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
# 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) =》重启系统
参考资料:
0 | runlevel0.target, poweroff.target | 关闭系统。 |
1, s, single | runlevel1.target, rescue.target | 单用户模式。 |
2, 4 | runlevel2.target, runlevel4.target, multi-user.target | 用户定义/域特定运行级别。默认等同于 3。 |
3 | runlevel3.target, multi-user.target | 多用户,非图形化。用户可以通过多个控制台或网络登录。 |
5 | runlevel5.target, graphical.target | 多用户,图形化。通常为所有运行级别 3 的服务外加图形化登录。 |
6 | runlevel6.target, reboot.target | 重启 |
emergency | emergency.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
相关文章推荐
- linux chkconfig命令 开机启动 运行级别 service sysv-rc-conf
- linux服务的开机启动和运行级别(chkconfig)
- linux服务的开机启动和运行级别
- Linux的常用命令(1) - 指定运行级别
- linux 添加 service 服务并自动添加 chkconfig 启动级别
- linxu系统中常用服务启动,关闭,防火墙重启,停止,关闭,服务开机启动常用命令
- Linux/CentOS 服务安装/卸载,开机启动chkconfig命令详解|如何让MySQL、Apache开机启动?
- chkconfig 命令将服务随开机启动或者关闭
- centos 7.0 ln命令 和chkconfig 命令介绍 开机自动启 服务
- Linux + javaEE 学习笔记---Linux常用命令设定运行级别
- chkconfig 开机启动服务命令
- chkconfig命令和添加开机启动服务
- 使用SHELL命令来停止或者运行服务---service
- Linux chkconfig --查询/修改系统服务的运行级别
- linux设置开机服务自动启动/关闭自动启动命令 chkconfig
- 设置服务及脚本或命令开机运行
- chkconfig命令主要用来更新(启动或停止)和查询系统服务的运行级信息
- linux设置开机服务自启动/关闭自启动 chkconfig命令
- 用service命令和chkconfig命令管理服务进程
- Linux的常用命令(1) - 指定运行级别