日志分割
每一台都需要做
vi /etc/logrotate.conf
# see "man logrotate" for details
# rotate log files weekly
monthly
# keep 4 weeks worth of backlogs
rotate 4
# create new (empty) log files after rotating old ones
create
# use date as a suffix of the rotated file
dateext
# uncomment this if you want your log files compressed
#compress
# RPM packages drop log rotation information into this directory
#注释掉
#include /etc/logrotate.d
# no packages own wtmp and btmp -- we'll rotate them here
#注释掉
#/var/log/wtmp {
# monthly
# create 0664 root utmp
# minsize 1M
# rotate 1
#}
#/var/log/btmp {
# missingok
# monthly
# create 0600 root utmp
# rotate 1
#}
脚本存储文件夹
mkdir /usr/shell
编写脚本
cd /usr/shell
vi
具体查看 shell脚本.txt,
cd /usr/shell
vi alllog
#/bin/bash
#xxx是你脚本名字
/usr/shell/xxx
/usr/shell/xxx
/usr/shell/xxx
/usr/shell/xxx
/usr/shell/xxx
/usr/shell/xxx
/usr/shell/xxx
/usr/shell/xxx
/usr/shell/xxx
/usr/shell/xxx
/usr/shell/xxx
/usr/shell/xxx
/usr/shell/xxx
赋予脚本权限
chmod a+x /usr/shell/*
mkdir /opt/log
分割全部日志
/usr/shell/alllog
脚本定时运行
crontab –e
加一句
10 00 * * * /bin/bash /usr/shell/alllog
服务器文件同步
只在nginx服务器上面做
vi /etc/rsyncd.conf
uid = root
gid = root
max connections = 4
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
log file = /var/log/rsyncd.log
[logs]
path = /opt/log
ignore errors
read only = true
list = true
auth users = backup
secrets file = /etc/rsyncd.pwd
vi /etc/rsyncd.pwd
backup:dadao
只在日志储存节点上面做
vi /usr/shell/daylog
#/bin/bash
rsync -avzP --password-file=/etc/rsyncd.pwd backup@第一台nginx的ip::logs /opt/log-nginx1
rsync -avzP --password-file=/etc/rsyncd.pwd backup@第二胎nginx的ip::logs /opt/log-nginx2
mkdir /opt/log-nginx1
mkdir /opt/log-nginx2
同步文件
/usr/shell/daylog
定时
crontab -e
20 00 * * * /bin/bash /usr/shell/daylog