海运的博客

N1盒子armbian/ubuntu/linux系统修改日志输出到内存

发布时间:February 28, 2019 // 分类:N1 // No Comments

N1盒子的存储设备是emmc,为了延长emmc的使用寿命尽可能的将读写文件在内存中完成。
修改systemd journald日志存放目录为内存,也就是/run/log目录,限制最大使用内存空间64MB:

sed -i 's/#Storage=auto/Storage=volatile/' /etc/systemd/journald.conf
sed -i 's/#RuntimeMaxUse=/RuntimeMaxUse=64M/' /etc/systemd/journald.conf

然后重新启动systemd-journald服务:

systemctl restart systemd-journald

修改rsyslog日志存放目录为/run/log:

sed -i 's/\/var\/log/\/run\/log/g' /etc/rsyslog.d/50-default.conf

修改rsyslog运行用户为root,不然/run/log没写入权限:

sed 's/PrivDropToUser syslog/PrivDropToUser root/' /etc/rsyslog.conf  
sed 's/PrivDropToUser syslog/PrivDropToGroup root/' /etc/rsyslog.conf 

然后重启rsyslog即可:

systemctl restart rsyslog

修改nginx日志目录:

sed -i 's/\/var\/log/\/run\/log/g' /etc/nginx/nginx.conf
mkdir /run/log/nginx
systemctl restart nginx

修改php-fpm日志目录:

sed -i 's/\/var\/log/\/run\/log/g' /etc/php/7.2/fpm/php-fpm.conf
systemctl restart php7.2-fpm

cups修改日志目录:

sed -i 's/\/var\/log/\/run\/log/g' /etc/cups/cups-files.conf
mkdir /run/log/cups
systemctl restart cups

samba修改配置文件日志目录:

log file = /run/log/samba/log.%m
max log size = 50 
mkdir /run/log/samba
systemctl restart smbd

添加个开机启动脚本在启动时创建/run/log目录下nginx cups samba目录。

cat /lib/systemd/system/mklogdir.service
[Unit]
Description=mklogdir
Before=network.target

[Service]
Type=oneshot
ExecStart=/usr/bin/mklogdir.sh

[Install]
WantedBy=multi-user.target

修改日志轮询logrotate:

sed -i 's/\/var\/log/\/run\/log/g' /etc/logrotate.d/cups-daemon 
sed -i 's/\/var\/log/\/run\/log/g' /etc/logrotate.d/nginx 
sed -i 's/\/var\/log/\/run\/log/g' /etc/logrotate.d/php7.2-fpm 
sed -i 's/\/var\/log/\/run\/log/g' /etc/logrotate.d/rsyslog 
sed -i 's/\/var\/log/\/run\/log/g' /etc/logrotate.d/samba 

标签:none

评论已关闭

分类
最新文章
最近回复
  • 海运: 正常情况下编译整个内核执行make menuconfig后就不会出现此提示,当单独编译单个模块...
  • oijq: 就是用的armbian的配置文件哈,按你的教程做的,在执行make LOCALVERSION=...
  • 海运: 使用armbian的配置文件,其它添加或修改自己懂的部分,不懂的就不要碰了。
  • oijq: 编译时这些选项全部选Y吗?Actions Semi Platforms (ARCH_ACTIO...
  • 海运: n1编译bbr内核模块参考这个:https://www.haiyun.me/archives/...
  • jiqz: make M=net/ipv4/ CONFIG_TCP_CONG_BBR=m modules编...
  • ruralhunter: 哦,文档里应该是对的,是.config
  • ruralhunter: cp /mnt/boot/config-4.18.7-aml-s9xxx .config这里应...
  • 海运: 你是编译不成功呢?还是编译后不能运行呢?还是运行后不能访问web界面呢?
  • 白墨: 可能不清楚就是编译安装后启动后访问不了web界面