09、日志轮转+rsync同步
logrotate - rotates, compresses, and mails system logs
/var/log/messages
/var/log/cron
/var/log/boot.log
/var/log/maillog
/var/log/secure
# see "man logrotate" for details
# rotate log files weekly
weekly --默认是一个星期rotate一次
# keep 4 weeks worth of backlogs
rotate 4 --默认保留4个
# use date as a suffix of the rotated file
dateext --表示轮转后,名字后不再以.1,.2这样的结尾,而以时间来结尾,时间格式也可以由dataformat参数来设定
# create new (empty) log files after rotating old ones
create --rotate后,创建一个新的代替
# uncomment this if you want your log files compressed
#compress --默认没有打开日志压缩功能
# RPM packages drop log rotation information into this directory
include /etc/logrotate.d --这表示/etc/logrotate.d目录下的所有配置文件都生效
# no packages own wtmp -- we'll rotate them here
/var/log/ssh {
weekly
minsize 2M
missingok
create 0600 root root
rotate 2
}
/var/log/messages /var/log/secure /var/log/maillog /var/log/spooler /var/log/boot.log /var/log/cron { --对哪些日志文件进行定义
sharedscripts --脚本开始
postrotate --表示rotate结束
/bin/kill -HUP `cat /var/run/syslogd.pid 2> /dev/null` 2> /dev/null || true
/bin/kill -HUP `cat /var/run/rsyslogd.pid 2> /dev/null` 2> /dev/null || true
endscript --脚本结束
}
sharedscripts
prerotate
xxxxx --轮转之前执行XXXX
endscript
sharedscripts
postrotate
xxxxx --轮转之后执行xxxx
endscript logger -t 'aa' 'bb' --在日志文件里加上一个标记
[root@li test]# tail -n 1 /var/log/messages
May 8 15:33:02 li aa: bb --可以看到刚才加的标记
/bin/logger -t 'rotate' 'end'
/bin/kill -HUP `cat /var/run/syslogd.pid 2> /dev/null` 2> /dev/null || true
/bin/kill -HUP `cat /var/run/rsyslogd.pid 2> /dev/null` 2> /dev/null || true
[root@li ~]# ps -ef |grep httpd |grep -v grep
[root@li ~]# lsof -i:80
# kill - .......
# ps -ef |grep httpd |grep -v grep|awk '{print $2}'|xargs kill -
# killall httpd
# pkill httpd
# kill -TERM 父PID --对比kill - 父PID
#!/bin/bash
year=`date -d '-1 day' +%Y`
month=`date -d '-1 day' +%m`
day=`date -d '-1 day' +%d`
mkdir /var/log/httpd/$year/$month -p mv /var/log/httpd/access_log /var/log/httpd/$year/$month/access_log-$day
touch /var/log/httpd/access_log
kill -HUP `cat /var/run/httpd/httpd.pid`
tcp 0.0.0.0: 0.0.0.0:* LISTEN /master
tcp ::: :::* LISTEN /master
Subject: hello user1 --主题
i am root
haha --正文
. -- 点表示结束
EOT
/var/log/ssh {
weekly
minsize 2M
missingok
mail root
create 0600 root root
rotate 2
}
# cat /var/mail/root
To: root@cluster.com
Subject: /var/log/ssh. --主题为轮转不存在的那个日志
/var/log/ssh {
weekly
minsize 2M
missingok
mail root
mailfirst --再加一个mailfirst
create 0600 root root
rotate 2
}
To: root@cluster.com
Subject: /var/log/ssh.1 --主题为just-rotate的日志
/var/log/ssh {
weekly
minsize 2M
missingok
mail root
maillast --换成maillast
create 0600 root root
rotate 2
}
To: root@cluster.com
Subject: /var/log/ssh.3 --主题为轮转不存在的那个日志,结果和什么都不加是一样的,是默认值
/var/log/ssh {
rotate 2
missingok
minsize 2M
create 0664 root root
sharedscripts
postrotate
kill -HUP `cat /var/run/sshd.pid`
echo "ssh.2 is gone!, ssh.1 变成了ssh.2 ,ssh 变成 了ssh.1 " |mail -s 'ssh日志轮转了' user1
endscript
}
[root@li ~]# wget http://10.1.1.35/extra/flash-plugin-10.0.32.18-release.i386.rpm
[root@li ~]# wget ftp://10.1.1.35/ule/ule12.txt
-v verbo
-a 归档模式,递归的方式传输文件,并保持文件的属性
-l 保留软链接
-R 保留相对路径
-H 保留硬链接
-p ,-o,-g,-A 分别保留权限,属主,属组,acl等,但如果加了-a,这些就都包括了
-D 等于--devices --specials 表示支持b,c,s,p类型的文件
-e ‘ssh –p 22’ 通过ssh协议安全同步
motd file=/etc/rsyncd.welcome
[abc]
path=/test
vim /etc/rsyncd.welcome --手动建立自己定义的motd文件,并写上欢迎信息
service rsync
{
disable = no --yes改为no 打开rsync服务功能
socket_type = stream
wait = no
user = root
server = /usr/bin/rsync
server_args = --daemon
log_on_failure += USERID
}
第三步:
netstat -ntlup |grep 873 --服务端就会有873的端口在监听了
tcp 0 0 0.0.0.0:873 0.0.0.0:* LISTEN 4080/xinetd
motd file=/etc/rsyncd.welcome
log file=/var/log/rsyncd.log
[abc]
path=/share/weekend4
list=false
max connections=1
hosts allow=192.168.20.123
#!/bin/bash
/usr/local/bin/inotifywait -mrq --timefmt '%d/%m/%y %H:%M' --format '%T %w%f%e' -e modify,delete,create,attrib /test |while read files
do
rsync -a --delete /test/ /test3/
echo "$files 被同步" >> /var/log/rsync.log 2>&1
done
/var/log/clientssh.log {
daily
rotate
sharedscripts
prerotate
cp /var/log/clientssh.log /var/log/`date -d '-4 day' %F`.clientssh.log
kill -HUP `cat /var/run/sshd.pid`
endscript
}
2012/11/19 00:41:12 [7653] rsync on weekend/ from li.cluster.com (172.16.2.35)
2012/11/19 01:41:12 [7653] building file list
2012/11/19 02:41:27 [7653] sent 466382582 bytes received 27709 bytes total size 466234513
2012/11/19 05:43:05 [7686] rsync on weekend/ from li.cluster.com (172.16.2.35)
2012/11/19 08:43:05 [7686] building file list
2012/11/19 18:43:11 [7686] sent 466382582 bytes received 27709 bytes total size 466234513
2012/11/19 08:41:12 [7653] rsync on weekend/ from li.cluster.com (172.16.2.35)
2012/11/19 09:41:12 [7653] building file list
2012/11/19 10:41:27 [7653] sent 466382582 bytes received 27709 bytes total size 466234513
2012/11/19 13:43:05 [7686] rsync on weekend/ from li.cluster.com (172.16.2.35)
2012/11/19 16:43:05 [7686] building file list
2012/11/19 02:18:43:11 [7686] sent 466382582 bytes received 27709 bytes total size 466234513
#!/bin/bash
touch /var/log/newrsyncd.log
sed '' /var/log/rsyncd.log | while read message
do
time=`echo $message | awk '{print $1" "$2}'`
newtime=`date +%Y-%m-%d" "%k:%M:%S -d "$time 8 hour"`
newmessage=`echo $message | awk -F[ '{print $2}'`
if [ `echo $newtime | awk '{print $2}' | awk -F: '{print $1}'` -le 9 ]
then
newtime=`echo $newtime | awk '{print $1" 0"$2}'`
fi
echo $newtime" ["$newmessage >> /var/log/newrsyncd.log
done
mv -f /var/log/newrsyncd.log /var/log/rsyncd.log
09、日志轮转+rsync同步的更多相关文章
- rsync同步Nginx日志遇到问题总结
一.目的 将nginx 日志通过普通用户利用rsync公钥认证的方式实时同步到本地服务器上,之后使用elk程序进行处理. 二.遇到问题及解决方法思路 问题1.文件权限:nginx 的日志默认权限如下: ...
- rsync同步工具学习笔记
rsync同步工具 1.rsync介绍 rsync是一款开源的.快速的.多功能的.可实现全量及增量的本地或远程数据同步备份的优秀工具.rsync软件适用于unix/linux/windows等多种操作 ...
- linux rsync同步工具
linux rsync同步工具 1.rsync介绍rsync是一款开源的.快速的.多功能的.可实现全量及增量的本地或远程数据同步备份的优秀工具.rsync软件适用于unix/linux/windows ...
- 运维工作中常用到的几个rsync同步命令
作为一个运维工程师,经常可能会面对几十台.几百台甚至上千台服务器,除了批量操作外,环境同步.数据同步也是必不可少的技能.说到“同步”,不得不提的利器就是rsync. 下面结合本人近几年运维工作中对这一 ...
- Linux rsync 同步实践
目录[-] 1. rsync 同步的大致思路 2. rsync的安装 3. rsync的配置 4. rsync的基本操作 服务器端启动 注2. 实时同步 注3. rsync通过linux防火墙 公司网 ...
- Ubuntu下多服务器 Rsync同步镜像服务配置
主服务器:192.168.5.13_ubuntu 从服务器:192.168.5.11_centos ================== 1> 在两台主机上分别安装rsync========== ...
- 【Linux】rsync同步文件 & 程序自启动
rsync使用 1. 为什么使用rsync? rsync解决linux系统下文件同步时, 增量同步问题. 使用场景: 线上需要定时备份数据文件(视频资源), 使用rsync完成每天的增量备份. 参见: ...
- Windows 之间用rsync同步数据(cwRsyncServer配置)
rsync是一款优秀的数据同步软件,在跨服务器,跨机房,跨国备份服务器的首选工具,下面就来介绍下如何配置安装cwRsyncServer很大多数软件一样是B/C架构,cwRsyncServer是rsyn ...
- 实现Rsync同步Nginx前端配置
近期,由于我们的阿里前端服务器频频受到恶意的流量攻击,导致前端NGINX进入黑洞而无法正常访问公司网站. 按之前的预计方法,采用加速乐及备用全配置前端的作法,将恶意短时流量攻击的损失时间降到最短.现将 ...
随机推荐
- Maven 跳过Junit单元测试
转载自:https://blog.csdn.net/arkblue/article/details/50974957 -DskipTests,不执行测试用例,但编译测试用例类生成相应的class文件至 ...
- 《Zabbix》
https://github.com/itnihao/zabbix-rpm https://github.com/itnihao/zabbix-book 一.zabbix支持的主要监控方式: zabb ...
- BZOJ1688 「USACO05OPEN」Disease Manangement 背包+状压DP
问题描述 BZOJ1688 题解 背包,在转移过程中使用状压. \(\mathrm{Code}\) #include<bits/stdc++.h> using namespace std; ...
- python中实现单例模式
单例模式的目的是一个类有且只有一个实例对象存在,比如在复用类的过程中,可能重复创建多个实例,导致严重浪费内存,此时就适合使用单例模式. 前段时间需要用到单例模式,就称着机会在网上找了找,有包含了__n ...
- Web前端开发框架大全-详述
可以说,前端技术的发展是互联网自身发展的一个缩影! 前端技术的发展经历了web1.0时代,即网页只能展示信息,几乎没有交互可言: web2.0时代,web2.0不再是单维的,逐渐发展为双向交流,另一特 ...
- Paper | Xception: Deep Learning with Depthwise Separable Convolutions
目录 故事 Inception结构和思想 更进一步,以及现有的深度可分离卷积 Xception结构 实验 这篇论文写得很好.只要你知道卷积操作或公式,哪怕没看过Inception,也能看懂. 核心贡献 ...
- 数据仓库002 - 复习Linux shell命令 - echo bash_profile bashrc which命令的理解 alias history
1.echo 打印 . echo 的作用是在屏幕上打印输出内容,与文件和持久化可以理解为没有丝毫关联.如:在屏幕上打印“ echo 的作用是打印文字! ” 实例1:输出系统的环境变量名称 $PATH ...
- Java文件上传的几种方式
文件上传与文件上传一样重要.在Java中,要实现文件上传,可以有两种方式: 1.通过Servlet类上传 2.通过Struts框架实现上传 这两种方式的根本还是通过Servlet进行IO流的操作. 一 ...
- Ubuntu 16.04 + OpenCV 自定义环境变量 pkg-config / PKG_CONFIG_PATH
0. 前言 今天在执行一段脚本的时候,爆出错误: Package opencv was not found in the pkg-config search path. Perhaps you sho ...
- 02Shell变量
Shell变量 什么是 shell 变量 shell变量就是 用一个固定的字符串去表示不固定的内容 变量的类型 自定义变量 定义变量 变量名=变量值 (显式赋值) 变量名必须以字母或下划线开头,区分大 ...