Last active
January 11, 2018 23:24
-
-
Save zacker330/2544c98153b67fcba60af9d3260f6f6b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## 启动服务 | |
systemctl start <服务项名称> | |
## 停止服务 | |
systemctl stop <服务项名称> | |
## 重启服务 | |
systemctl restart <服务项名称> | |
## 重新读取配置文件 | |
systemctl reload <服务项名称> | |
## 使服务开机自启动 | |
systemctl enable <服务项名称> | |
## 使服务不要开机自启动 | |
systemctl disable <服务项名称> | |
## 禁用服务:这可以防止服务被其他服务间接启动,也无法通过 start 或 restart 命令来启动服务。 | |
systemctl mask <服务项名称> | |
## 启用服务 | |
systemctl unmask <服务项名称> | |
## 重新读取所有服务项 | |
systemctl daemon-reload | |
## 查看系统所有安装的服务项 | |
systemctl list-unit-files --type=service | |
## 查看系统所有运行的服务项 | |
systemctl list-units --type=service | |
##2.3 查看系统所有开机自启动的服务项 | |
systemctl list-unit-files --type=service | grep enabled | |
## 查看指定服务项状态 | |
systemctl status <服务项名称> | |
## 查看出错的服务 | |
systemctl list-units --type=service --state=failed | |
## 查看系统启动耗时 | |
systemd-analyze | |
## 查看各项服务启动耗时 | |
systemd-analyze blame | grep .service | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## 查看自从本次开机后所有的日志信息 | |
journalctl [-e] [-f] | |
## -e 表示输出之后跳转到末行,下同。 | |
## -f 表示实时滚动显示,下同。 | |
## 查看特定 Unit (服务)所有的日志信息 | |
journalctl [-e] [-f] -u <Unit 名> | |
## 查看特定时间点内所有的日志信息 | |
journalctl --since="yyyy-MM-dd hh:mm:ss" --until="yyyy-MM-dd hh:mm:ss" | |
## 查看日志当前占用的磁盘空间 | |
journalctl --disk-usage | |
## 修改日志最大占用的磁盘空间 | |
## 去掉 /etc/systemd/journald.conf 这个文件内 SystemMaxUse= 这一行前面的 # 号,然后在等号后面填上数值即可。 | |
## 例如 | |
## 修改日志最大占用的磁盘空间为 50M | |
SystemMaxUse=50M | |
##保存配置文件之后重启一下日志记录服务即可。 | |
systemctl restart systemd-journald.service |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Unit] | |
Description=<服务描述> | |
After=<在哪个模块(服务)之后启动(可选)> | |
[Service] | |
Type=forking | |
ExecStart=<程序或命令参数> | |
ExecReload=<重新读取配置文件的命令(可选)> | |
KillSignal=SIGTERM | |
KillMode=mixed | |
[Install] | |
WantedBy=multi-user.target | |
## 创建服务文件之后,最好执行一下 systemctl daemon-reload 再启用。 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment