今天给大家分享一个我在实际工作中用到的 把 systemd 输出日志重定向的案例,纯干货,很实用!
![abb9a3c523ba1240f3efe1479c47f0de.png](https://i-blog.csdnimg.cn/blog_migrate/1d71c699f49fa0e187fe5ffed24cb895.jpeg)
前段时间我们公司 新上线了几个 go 语言写的 程序,我准备用systemd 做成启动脚本,最开始是这样写的:
[Unit]Description=H1 serverAfter=rc-local.service nss-user-lookup.target[Service]User=wvttGroup=wvttType=simpleWorkingDirectory=/data/sites/h1/runExecStart=/data/sites/h1/run/h1_serverExecStop=/usr/bin/kill -9 $MAINPIDRestart=always[Install]WantedBy=multi-user.target
但是发现一个问题,systemd 服务会把输出写到 /var/log/messages 系统日志中,这肯定不行,好几个程序一会 就写了 1G 多了,于是把 systemd 启动脚本改成下面这样的:
[Unit]Description=H1 serverAfter=rc-local.service nss-user-lookup.target[Service]User=wvttGroup=wvttType