logging - 限制 systemd 中“journalctl 服务”的日志 - Centos 7
问题描述
我有一个服务**/etc/systemd/sysem/horses.service**
[Unit]
Description=Description for sample script goes here
After=rc-local.service
[Service]
Type=simple
ExecStart=/opt/horses/startSanic2.sh
TimeoutStartSec=0
Environment="REDIS_HOST=192.168.150.220"
Environment="REDIS_PORT=6379"
[Install]
WantedBy=default.target
它使用以下代码运行 shell 脚本:
#!/bin/bash
gunicorn horses.server:app --bind 0.0.0.0:9000 --worker-class sanic.worker.GunicornWorker --reload
我成功运行它,我可以看到正在写入服务的日志并且可以从以下位置读取:
journalctl -u horses.service
如果我运行该命令 - 我可以看到 horses.service 记录的所有事件。
我对 systemd 服务的日志没有任何经验。我非常担心的是,因为该服务将一直运行 - 例如是否可以设置将信息(日志)保留在 journalctl -u horses.service 中,例如仅过去 10 天,或者定义一些回合日志记录或建议的任何方法,以确保我的日志不会满,因为我确实想以我的整个磁盘(分区)满结束。请建议我如何限制日志。
先感谢您!!!!!!!
解决方案
你通过运行看到的journalctl -u
是你的应用程序的输出到控制台(或错误),它systemd
会为你处理它们。
可以在此处找到全局配置/etc/systemd/journald.conf
,默认值将满足您的需求,因此您可以使用默认值。
顺便说一句,以下是可用于更改日志记录行为的配置:
SystemKeepFree
:为其他应用程序留出多少磁盘空间(默认值 = 15%)。SystemMaxuse
:最大磁盘空间使用率(默认 = 10%)。
默认情况下systemd
,尽可能保留日志(受上述规则限制),但是如果您需要基于轮换的配置,您可以使用MaxRetentionSec
.
同样,您无需担心磁盘使用情况systemd
,只需使用默认配置即可。
推荐阅读
- hdf - 如何制作 HDF-3.4.1.1-centos7-rpm.tar.gz 文件?
- c# - 如何将元素添加到其他方法的列表
- types - 如何让集装箱船浮起来?
- swift - 发送 POST 请求后控制台中的消息
- javascript - 过滤和操作数组中的对象
- reactjs - react-select 改变菜单高度
- optaplanner - 在 optaplanner 任务分配过程中无法重新分配或取消分配分配的任务
- java - 我的动画课程是否不必要地在 RAM 中保留了太多图像?
- python - 找到 3 个 aruco 标记之间的最大距离
- python - 处理使用 FastAPI 实现的 RESTful API 上的资源授权