欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程资源 > 编程问答 >内容正文

编程问答

Systemd基础篇:systemd vs SysVinit

发布时间:2023/12/20 编程问答 37 豆豆
生活随笔 收集整理的这篇文章主要介绍了 Systemd基础篇:systemd vs SysVinit 小编觉得挺不错的,现在分享给大家,帮大家做个参考.


Systemd已经基本取代了SysV的Init,这篇文章从几个方面整理一下Systemd与Init的使用上的区别。

命令比较: SysVinit vs Systemd

命令用途SysVInit命令Systemd命令
服务启动service 服务名 startsystemd start 服务名.service (.service可省略,后同)
服务停止service 服务名 stopsystemctl stop 服务名
服务重启service 服务名 restartsystemctl restart 服务名
服务重新加载service 服务名 reloadsystemctl reload 服务名
服务状态确认service 服务名 statussystemctl status 服务名
服务开机启动设定chkconfig 服务名 onsystemctl enable 服务名
取消服务开机启动设定chkconfig service offsystemctl disable 服务名
确认服务开机启动设定状态chkconfig 服务名systemctl is-enabled 服务名
加载服务配置文件chkconfig 服务名 -addsystemctl deamon-reload
关机haltsystemctl halt
关机(电源)poweroffsystemctl poweroff
重启rebootsystemctl reboot
休眠pm-hibernatesystemctl hibernate
挂起pm-suspendsystemctl suspend

RunLevel: SysVinit vs Systemd

RunLevelSysVInitSystemd
System halt0runlevel0.target, poweroff.target
Single user mode1runlevel1.target, rescure.target
Multi user2runlevel02target, multi-user.target
Multi user with network3runlevel3.target, multi-user.target
Experimental4runlevel4.target, multi-user.target
Multi user with network, graphical mode5runlevel5.target, graphical.target
Reboot6runlevel6.target, reboot.target

日志确认方式

SysVinit方式

  • 确认系统日志文件

文件名: /var/log/message
文件名:/var/log/syslog

Systemd

  • 确认系统日志信息

使用命令: journalctl -f

  • 确认某一时间点之后的日志信息

使用命令:journalctl -since=xxx

Systemd特殊命令

确认启动时间

使用命令:systemd-analyze 或者 systemd-analyze time

[root@host ~]# systemd-analyze Startup finished in 1.638s (kernel) + 1.951s (initrd) + 14.177s (userspace) = 17.767s [root@host ~]# [root@host ~]# systemd-analyze time Startup finished in 1.638s (kernel) + 1.951s (initrd) + 14.177s (userspace) = 17.767s [root@host ~]#

停止服务相关进程

使用命令:systemctl kill 服务名

hostname设定

使用命令:hostnamectl

[root@host shell]# hostnamectlStatic hostname: host.localdomainIcon name: computer-vmChassis: vmMachine ID: d27a659b15fc379d24204584d5c051bdBoot ID: 3fe84ed9506248b9a41c492ca543748aVirtualization: kvmOperating System: CentOS Linux 7 (Core)CPE OS Name: cpe:/o:centos:centos:7Kernel: Linux 4.10.4-1.el7.elrepo.x86_64Architecture: x86-64 [root@host shell]# [root@host shell]# [root@host shell]# hostnamectl set-hostname liumiaocn [root@host shell]#

再次登录之后,hostname的变化即可看到

[root@liumiaocn ~]#

时间设定

使用命令: timedatectl

注:使用方法可参看:

  • https://liumiaocn.blog.csdn.net/article/details/88408155

管理login:loginctrl

使用例:查看当前登录用户的Session状况

[root@liumiaocn ~]# loginctlSESSION UID USER SEAT 10 0 root 1 sessions listed. [root@liumiaocn ~]#

管理locale:localectl

使用例:查看当前本地化设定信息

[root@liumiaocn ~]# localectlSystem Locale: LANG=en_US.UTF-8VC Keymap: usX11 Layout: us [root@liumiaocn ~]#

总结

以上是生活随笔为你收集整理的Systemd基础篇:systemd vs SysVinit的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。