Ubuntu:systemd 常用命令
前言
- 前言
- systemd
- systemd命令组
- 主命令systemctl
- 系统相关
- 服务相关
- 主机命令hostnamectl
- 时区命令timedatectl
- 用户命令loginctl
本篇记录Ubuntu18 systemd命令的使用。
systemdUbuntu18版本开始,systemd
被用于系统进程启动,d
表示守护进程daemon,也就是系统后台运行的服务进程,取代了之前的initd
。
systemctl
是最核心的命令,用于系统管理。
查看systemd版本:
sudo systemctl --version
查看系统状态:
sudo systemctl status
重启系统:
sudo systemctl reboot
关机:
sudo systemctl poweroff
停止CPU工作:
sudo systemctl halt
暂停系统:
sudo systemctl suspend
休眠系统:
sudo systemctl hibernate
救援模式:
sudo systemctl rescue
服务相关
查看某个服务的状态:
sudo systemctl status myservice.service
启动,停止,重启服务:
sudo systemctl start myservice.service
sudo systemctl stop myservice.service
sudo systemctl restart myservice.service
服务开机自启动,取消开机自启动:
sudo systemctl enable myservice.service
sudo systemctl disable myservice.service
重新加载某个服务,所有服务的配置文件:
sudo systemctl reload myservice.service
sudo systemctl daemon-reload
查看某个服务设置的参数:
sudo systemctl show myservice.service
杀死某个服务的所有子进程:
sudo systemctl kill myservice.service
主机命令hostnamectl
查看主机名:
hostnamectl
设置主机名:
# 把主机名设为myubuntu
sudo hostnamectl set-hostname myubuntu
时区命令timedatectl
查看当前时区:
sudo timedatectl
查看可设置的时区:
sudo timedatectl list-timezones
设置时区,时间,日期:
sudo timedatectl set-timezone China/Shang_Hai
sudo timedatectl set-time 2022-02-03
sudo timedatectl set-time 14:01:12
用户命令loginctl
查看当前sessions:
sudo loginctl list-sessions
查看当前登录用户:
sudo loginctl list-users
查看指定用户信息:
sudo loginctl show-user myubuntu