systemd--systemctl

简介:

systemd

POST---BOOT Sequence ---bootloader---kernel+initramfs(initrd)--rootfs---/sbin/init

init :

centos5:sysv init

centos6:unstart

centos7:systemd

systemd新特性:

系统引导时实现服务并行启动;

按需激活进程

系统状态快照

基于依赖关系定义服务控制逻辑

核心概念:unit

配置文件进行标识和配置;文件中主要包含系统服务,监听socket,保存系统快照以及其他与init相关的信息

保存至:/usr/lib/systemd/system

/run/systemd/system

/etc/systemd/system

ls -ltr /lib/systemd/system/runlevel*.target

unit的类型:

service unit:文件扩展名为.service,用于定义系统服务

target unit:文件扩展名为.target,用于模拟实现运行级别;

device unit:文件扩展名为.device,用于定义内核识别的设备;

mount unit:.mount定义文件系统挂载点:

socket unit:.socket,用于标识进程间通信用的socket文件

Snapshot unit:.snapshot,管理系统快照;

swap unit:.swap,用于标识swap设备

automount unit:.automount,文件系统的自动挂载点;

path unit:.path,用于定义文件系统中的 一个文件或者目录

关键特性:

基于socket的激活机制:socket与服务程序分离;

基于bus的激活机制;

基于device的激活机制;

基于path的激活机制;

系统快照:所有unit的当前状态保存于持久存储设备中;

向后兼容sysv init 脚本

不兼容:

systemctl命令固定不变

非由systemd启动的服务,systemctl无法与之通信


管理系统服务:

CentOS 7:service unit

注意:能兼容早期的服务脚本

命令:systemctl COMMAND name.service 

启动:service name start ==> systemctl start name.service

停止:service name stop ==> systemctl stop name.service

重启:service name restart ==> systemctl restart name.service

状态:service name status ==> systemctl status name.service

条件式重启:service name condrestart ==》 systemctl try-restart name.service

重载或重启服务:systemctl reload-or-restart name.service

重载或条件式重启服务:systemctl reload-or-try-restart name.service

禁止设置为开机自启:systemctl mask name.service

取消禁止设置为开机自启:systemctl unmask name.service

查看服务当前激活状态:systemctl is-active name.service

查看所有已经激活的服务:systemctl  list-units --type service

查看所有服务:systemctl  list-units --type service --all

chkconfig命令的对应关系:

设定某个服务开机自动启动:chkconfig name on ==> systemctl enable name.service

禁止:chkconfig name off ==> systemctl disable name.service

查看所有服务的开机启动状态:

chkconfig --list ==> systemctl list-unit-files --type service

查看服务是否开机自动启动:systemctl  is-enabled name.service

查看服务的依赖关系:systemctl list-dependencies name.service

targe units;

unit配置文件:.target

运行级别:

0:runlevel0.target,poweroff.target

1: runlevel1.target,rescue.target

2: runlevel2.target,multi-user.target

3: runlevel3.target,multi-user.target

4: runlevel4.target,multi-user.target

5:runlevel5.target,graphical.target

6: runlevel6.target,reboot.target

切换级别:

init N ==> systemctl isolate name.target

查看级别:

runleve ==> systemctl list-units -type target --all

获取默认运行级别:

/etc/inittab ==> systemctl get-default

设置默认运行级别:

/etc/inittab ==> systemctl set-default multi-user.target

 或者

 ln -svf /lib/systemd/system/runlevel3.target /etc/systemd/system/default.target

 或者

 ln -svf /lib/systemd/system/multi-user.target /etc/systemd/system/default.target

切换至紧急救援模式:

systemctl rescue

切换至emergency模式:

systemctl emergency

其他常用命令:

关机:systemctl halt ,systemctl poweroff

重启:systemctl reboot

挂起:systemctl suspend

快照:systemctl hibernate

快照并挂起:systemctl hybird-sleep





     本文转自阿伦艾弗森 51CTO博客,原文链接:http://blog.51cto.com/perper/1955152,如需转载请自行联系原作者



相关文章
|
11月前
|
监控 Java 数据库连接
服务--systemd的管理
服务--systemd的管理
115 0
|
Linux
Linux:systemctl、service、chkconfig
Linux:systemctl、service、chkconfig
105 0