http://blog.51cto.com/lavender7n/2047418
1.chkconfig 命令
chkconfig 命令主要用来更新 (启动或停止) 和查询系统服务的运行级信息.
[root@test_01 ~]# chkconfig --list
注意: 该输出结果只显示 SysV 服务, 并不包含原生 systemd 服务. SysV 配置数据可能被原生 systemd 配置覆盖.
如果您想列出 systemd 服务, 请执行'systemctl list-unit-files' .
欲查看对特定 target 启用的服务请执行
'systemctl list-dependencies [target]'.
netconsole 0: 关 1: 关 2: 关 3: 关 4: 关 5: 关 6: 关
network 0: 关 1: 关 2: 开 3: 开 4: 开 5: 开 6: 关
参数用法:
--add 增加所指定的系统服务, 让 chkconfig 指令得以管理它, 并同时在系统启动的叙述文件内增加相关数据.
--del 删除所指定的系统服务, 不再由 chkconfig 指令管理, 并同时在系统启动的叙述文件内删除相关数据.
--level < 等级代号> 指定读系统服务要在哪一个执行等级中开启或关毕.
等级 0 表示: 表示关机
等级 1 表示: 单用户模式
等级 2 表示: 无网络连接的多用户命令行模式
等级 3 表示: 有网络连接的多用户命令行模式
等级 4 表示: 保留级别
等级 5 表示: 带图形界面的多用户模式
等级 6 表示: 重新启动
需要说明的是, level 选项可以指定要查看的运行级而不一定是当前运行级. 对于每个运行级, 只能有一个启动脚本或者停止脚本. 当切换运行级时, init 不会重新启动已经启动的服务, 也不会再次去停止已经停止的服务.
chkconfig --list [name]: 显示所有运行级系统服务的运行状态信息(on 或 off). 如果指定了 name, 那么只显示指定的服务在不同运行级的状态.
chkconfig --add name: 增加一项新的服务. chkconfig 确保每个运行级有一项启动 (S) 或者杀死 (K) 入口. 如有缺少, 则会从缺省的 init 脚本自动建立.
chkconfig --del name: 删除服务, 并把相关符号连接从 / etc/rc[0-6].d 删除.
chkconfig [--level levels] name: 设置某一服务在指定的运行级是被启动, 停止还是重置.
2.systemd
LinuxSystemctl 是一个系统管理守护进程, 工具和库的集合, 用于取代 System V,service 和 chkconfig 命令, 初始进程主要负责控制 systemd 系统和服务管理器. 通过 Systemctl -help 可以看到该命令主要分为: 查询或发送控制命令给 systemd 服务, 管理单元服务的命令, 服务文件的相关命令, 任务, 环境, 快照相关命令, systemd 服务的配置重载, 系统开机关机相关的命令.
查看所有系统服务
- [root@test_01 ~]# systemctl list-units --all --type=service
- UNIT LOAD ACTIVE SUB DESCRIPTION
- auditd.service loaded active running Security Aud
- brandbot.service loaded inactive dead Flexible Bra
调整服务为开机启动状态
- [root@test_01 ~]# systemctl enable crond
- Created symlink from /etc/systemd/system/multi-user.target.wants/crond.service to /usr/lib/systemd/system/crond.service.
调整服务为开机不启动状态
- [root@test_01 ~]# systemctl disable crond
- Removed symlink /etc/systemd/system/multi-user.target.wants/crond.service.
查询服务是否为开机启动
- [root@test_01 ~]# systemctl is-enabled crond.service
- enabled
查询状态
[root@test_01 ~]# systemctl status crond.service
● crond.service - Command Scheduler
Loaded: loaded (/usr/lib/systemd/system/crond.service; enabled; vendor preset: enabled)
Active: active (running) since 四 2017-11-30 23:42:37 CST; 4 days ago
- Main PID: 566 (crond)
- CGroup: /system.slice/crond.service
└─566 /usr/sbin/crond -n
11 月 30 23:42:37 test_01 systemd[1]: Started Command Scheduler.
11 月 30 23:42:37 test_01 systemd[1]: Starting Command Scheduler...
11 月 30 23:42:37 test_01 crond[566]: (CRON) INFO (RANDOM_DELAY ...
11 月 30 23:42:40 test_01 crond[566]: (CRON) INFO (running with ...
12 月 04 21:23:01 test_01 crond[566]: (root) RELOAD (/var/spool/...
- Hint: Some lines were ellipsized, use -l to show in full.
- 3.unit
systemd 可以管理系统资源, 不相同的系统资源被称为 unit
Service unit: 系统服务
Target unit: 多个 Unit 构成的一个组
Device Unit: 硬件设备
Mount Unit: 文件系统的挂载点
Automount Unit: 自动挂载点
Path Unit: 文件或路径
Scope Unit: 不是由 Systemd 启动的外部进程
Slice Unit: 进程组
Snapshot Unit:Systemd 快照, 可以切回某个快照
Socket Unit: 进程间通信的 socket
Swap Unit:swap 文件
Timer Unit: 定时器
查看 active 的 unit
- [root@test_01 ~]# systemctl list-units
- UNIT LOAD ACTIVE SUB DESCRIPTION
- proc-sys-fs-binfmt_misc.automount loaded active waiting Arbitra
- sys-devices-pci0000:00-0000:00:07.1-ata2-host1-target1:0:0-1:0:0:
- sys-devices-pci0000:00-0000:00:10.0-host2-target2:0:0-2:0:0:0-blo
- [root@test_01 ~]# systemctl list-units --all --state=inactive
- UNIT LOAD ACTIVE SUB DESCRIPTION
- proc-sys-fs-binfmt_misc.mount loaded inactive dead Arbitrary E
- sys-fs-fuse-connections.mount loaded inactive dead FUSE Contro
- tmp.mount loaded inactive dead Temporary Direc
- systemd-ask-password-console.path loaded inactive dead Dispatc
查看某个服务是否为 active 状态
- [root@test_01 ~]# systemctl is-active crond
- active
- 4.target
查看系统下的 target
- [root@test_01 ~]# systemctl list-unit-files --type=target
- UNIT FILE STATE
- basic.target static
- bluetooth.target static
- cryptsetup-pre.target static
- cryptsetup.target static
- ctrl-alt-del.target disabled
- default.target enabled
查看某个 target 下的 unit
[root@test_01 ~]# systemctl list-dependencies multi-user.target
查看系统默认的 target
- [root@test_01 ~]# systemctl get-default
- multi-user.target
服务管理
来源: http://www.bubuko.com/infodetail-2915906.html