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
















