linux系统日志管理工具logrotate之批量部署脚本
附上生产环境批量apache日志轮询部署脚本管理机利用ssh-key免密钥登录,使用普通管理员帐号adms(需sudo授权)批量部署日志轮询脚本。 管理机m-logrotate.sh,实现批量部署 #!/bin/sh cat <<EOF +----------------------------------------------------------+ | ===log reserved 99 days === + +-------------------by wyan 2012.9.14--------------+ EOF echo "start remote host to exec logrotate:" # iplist.txt file is server list for host in `cat /tmp/iplist.txt` do if [ $? -eq 0 ];then echo "$host log reserve is ok" else echo "$host log reserve is false" fi done
yum源路径上脚本wy-logrotate.sh,实现日志轮询 #!/bin/sh [ ! -f /etc/logrotate.d/httpd ] && echo logrotate was not installed && yum -y install logrotate PATH=/etc/logrotate.d/httpd /bin/sed -i 's/^/#/g' $PATH /bin/cat >>$PATH <<EOF /var/log/httpd/*access_log { rotate 99 daily compress delaycompress nomail missingok notifempty sharedscripts postrotate /sbin/service httpd reload > /dev/null 2>/dev/null || true endscript } /var/log/httpd/*error_log { rotate 2 daily compress delaycompress nomail missingok notifempty sharedscripts postrotate /sbin/service httpd reload > /dev/null 2>/dev/null || true endscript } EOF
web服务器列表文件: $ cat /tmp/iplist.txt 172.x.50.31 172.x.50.32.......
172..58.32 ……
|