Systemd基础篇:systemd vs SysVinit

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

命令比较: SysVinit vs Systemd

命令用途SysVInit命令Systemd命令
服务启动service 服务名 startsystemctl 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]# 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
[root@host shell]# 
[root@host shell]# 
[root@host shell]# hostnamectl set-hostname liumiaocn
[root@host shell]# 

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

[root@liumiaocn ~]#

时间设定

使用命令: timedatectl

注:使用方法可参看:

管理login:loginctrl

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

[root@liumiaocn ~]# loginctl
   SESSION        UID USER             SEAT            
        10          0 root                             

1 sessions listed.
[root@liumiaocn ~]#

管理locale:localectl

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

[root@liumiaocn ~]# localectl
   System Locale: LANG=en_US.UTF-8
       VC Keymap: us
      X11 Layout: us
[root@liumiaocn ~]#
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值