开机自启动
查看Systemd版本:systemctl --version
子命令:
systemctl reboot //重启
systemd-analyze //查看启动耗时
hostnamectl //查看系统信息
localectl //查看本地化设置
timedatectl //查看时区设置
loginctl //查看当前登录的用户
Unit
systemctl list-units //查看当前系统所有Unit
systemctl status keepalived.service //查看某个Unit状态
systemctl start/stop keepalived.service //启动/停止服务
默认配置文件路径:/etc/systemd/system/ -> /usr/lib/systemd/system
systemctl enable xxx.service //建立符号链接(如果配置文件设置了开机启动,激活开机启动)
配置文件后缀名是Unit的种类:service系统服务、target多个Unit组
systemctl list-unit-files //列出配置文件的状态,enabled已建立启动链接,disabled未建立启动链接,static配置文件无Install部分,无法执行,只能作为其他配置文件的依赖,masked禁止建立启动链接
systemctl cat xxx.service //查看配置文件
[Unit]
Description=XXX
[Service]
Type=idle
ExecStart=/opt/elb_boot.sh
[Install]
WantedBy=multi-user.target //被包含在/etc/systemd/system/xxx.target.wants
参考:
http://www.ruanyifeng.com/blog/2016/03/systemd-tutorial-commands.html
http://www.ruanyifeng.com/blog/2016/03/systemd-tutorial-part-two.html
【推荐】博客园的心动:当一群程序员决定开源共建一个真诚相亲平台
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】Flutter适配HarmonyOS 5知识地图,实战解析+高频避坑指南
【推荐】开源 Linux 服务器运维管理面板 1Panel V2 版本正式发布
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步