天天看点

Systemd基础篇:systemd vs SysVinit命令比较: SysVinit vs SystemdRunLevel: SysVinit vs Systemd日志确认方式Systemd特殊命令管理locale:localectl

Systemd基础篇:systemd vs SysVinit命令比较: SysVinit vs SystemdRunLevel: SysVinit vs Systemd日志确认方式Systemd特殊命令管理locale:localectl

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

命令比较: SysVinit vs Systemd

命令用途 SysVInit命令 Systemd命令
服务启动 service 服务名 start systemd start 服务名.service (.service可省略,后同)
服务停止 service 服务名 stop systemctl stop 服务名
服务重启 service 服务名 restart systemctl restart 服务名
服务重新加载 service 服务名 reload systemctl reload 服务名
服务状态确认 service 服务名 status systemctl status 服务名
服务开机启动设定 chkconfig 服务名 on systemctl enable 服务名
取消服务开机启动设定 chkconfig service off systemctl disable 服务名
确认服务开机启动设定状态 chkconfig 服务名 systemctl is-enabled 服务名
加载服务配置文件 chkconfig 服务名 -add systemctl deamon-reload
关机 halt systemctl halt
关机(电源) poweroff systemctl poweroff
重启 reboot systemctl reboot
休眠 pm-hibernate systemctl hibernate
挂起 pm-suspend systemctl suspend

RunLevel: SysVinit vs Systemd

RunLevel SysVInit Systemd
System halt runlevel0.target, poweroff.target
Single user mode 1 runlevel1.target, rescure.target
Multi user 2 runlevel02target, multi-user.target
Multi user with network 3 runlevel3.target, multi-user.target
Experimental 4 runlevel4.target, multi-user.target
Multi user with network, graphical mode 5 runlevel5.target, graphical.target
Reboot 6 runlevel6.target, reboot.target

日志确认方式

SysVinit方式

  • 确认系统日志文件

文件名: /var/log/message

文件名:/var/log/syslog

Systemd

  • 确认系统日志信息
使用命令: journalctl -f
  • 确认某一时间点之后的日志信息
使用命令:journalctl -since=xxx

Systemd特殊命令

确认启动时间

使用命令:systemd-analyze 或者 systemd-analyze time
[[email protected] ~]# systemd-analyze
Startup finished in 1.638s (kernel) + 1.951s (initrd) + 14.177s (userspace) = 17.767s
[[email protected] ~]# 
[[email protected] ~]# systemd-analyze time
Startup finished in 1.638s (kernel) + 1.951s (initrd) + 14.177s (userspace) = 17.767s
[[email protected] ~]#
           

停止服务相关进程

使用命令:systemctl kill 服务名

hostname设定

使用命令:hostnamectl
[[email protected] shell]# hostnamectl
   Static hostname: host.localdomain
         Icon name: computer-vm
           Chassis: vm
        Machine ID: d27a659b15fc379d24204584d5c051bd
           Boot ID: 3fe84ed9506248b9a41c492ca543748a
    Virtualization: kvm
  Operating System: CentOS Linux 7 (Core)
       CPE OS Name: cpe:/o:centos:centos:7
            Kernel: Linux 4.10.4-1.el7.elrepo.x86_64
      Architecture: x86-64
[[email protected] shell]# 
[[email protected] shell]# 
[[email protected] shell]# hostnamectl set-hostname liumiaocn
[[email protected] shell]# 
           

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

时间设定

使用命令: timedatectl

注:使用方法可参看:

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

管理login:loginctrl

使用例:查看当前登录用户的Session状况
[[email protected] ~]# loginctl
   SESSION        UID USER             SEAT            
        10          0 root                             

1 sessions listed.
[[email protected] ~]#
           

管理locale:localectl

使用例:查看当前本地化设定信息
[[email protected] ~]# localectl
   System Locale: LANG=en_US.UTF-8
       VC Keymap: us
      X11 Layout: us
[[email protected] ~]#
           

继续阅读