systemctl命令
systemctl是Linux中用于管理系统和服务(systemd)的核心命令,它是systemd初始化系统的控制工具
基本语法:
systemctl [选项] 命令 [服务名]常用命令分类:
1.服务管理
# 启动服务 systemctl start service_name # 停止服务 systemctl stop service_name # 重启服务 systemctl restart service_name # 重新加载配置(不中断服务) systemctl reload service_name # 查看服务状态 systemctl status service_name # 启用服务(开机自启) systemctl enable service_name # 禁用服务(取消开机自启) systemctl disable service_name # 检查服务是否启用 systemctl is-enabled service_name # 检查服务是否正在运行 systemctl is-active service_name2.服务查询
# 列出所有已加载的服务 systemctl list-units --type=service # 列出所有已安装的服务(包括未启动的) systemctl list-unit-files --type=service # 列出失败的服务 systemctl --failed --type=service # 查看服务依赖关系 systemctl list-dependencies service_name3.系统管理
# 重启系统 systemctl reboot # 关机 systemctl poweroff # 暂停系统(挂起到内存) systemctl suspend # 使系统进入休眠(挂起到磁盘) systemctl hibernate # 进入救援模式 systemctl rescue # 进入紧急模式 systemctl emergency # 设置默认启动目标(运行级别) systemctl set-default multi-user.target # 命令行模式 systemctl set-default graphical.target # 图形界面模式4.查看系统状态
# 查看系统状态 systemctl status # 查看系统日志 journalctl -u service_name # 查看特定服务日志 journalctl -f # 实时跟踪日志 journalctl --since today # 查看今日日志https://chat.deepseek.com/share/tqs9jsqpl2zdjfeytu
