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进入黑洞而无法正常访问公司网站. 按之前的预计方法,采用加速乐及备用全配置前端的作法,将恶意短时流量攻击的损失时间降到最短.现将 ...
随机推荐
- JSON理解(一篇就够了)
可以看看视频讲解,视频几十分钟就结束了 JSON 1.什么是json 其实是一种数据格式的规范,与开发的语言无关,轻量级的数据格式 全称JavaScript Object Notation 2.优点: ...
- (day51)三、ORM、路由层、版本差异、流程图
目录 一.ORM关系建立 (一)ForeignKey(一对多) (二)ManyToManyField(多对多) (三)OneToOneField(一对一) 二.django请求生命周期流程图 三.ur ...
- @Component, @Service, @Controller, @Repository区别
@Component, @Service, @Controller, @Repository是spring注解,注解后可以被spring框架所扫描并注入到spring容器来进行管理 @Componen ...
- 在实际工作中使用requests+unittest进行接口测试
之前学习python做接口测试时,用的时requests+excel的方式来进行接口测试,后来在工作中也用unittest来做了一个项目的接口测试,接口测试用例完全基于unittest来编写,把大致步 ...
- 【2019.7.20 NOIP模拟赛 T1】A(A)(暴搜)
打表+暴搜 这道题目,显然是需要打表的,不过打表的方式可以有很多. 我是打了两个表,分别表示每个数字所需的火柴棒根数以及从一个数字到另一个数字,除了需要去除或加入的火柴棒外,至少需要几根火柴棒. 然后 ...
- Linux中$()和${}区别(转)
文章转自 https://blog.csdn.net/hxchuangxiaochuan/article/details/81204084 $( )中放的是命令,相当于` `,例如todaydate ...
- 为Azure DevOps Server (TFS) 配置安全访问(HTTPS with SSL)
Contents 1. 概述 2. HTTP和HTTS比较 支持HTTP和HTTPS两种方式 要求所有连接使用HTTPS 优点: 缺点: 3. 为Azure DevOps Server 配置安全访问 ...
- matplotlib动态绘图
目录 package Process 解决中文乱码问题 simple_plot() scatter_plot() three_dimension_scatter() Jupyter notebook ...
- css3 rem手机自适应框架
css3 rem手机自适应框架 rem是按照html的字体大小来 所以 不同宽度浏览器 htmlfont-size不一样 就可以做到自适应了 此方法比百分比方便<pre><!DOCT ...
- HTML+CSS基础 css的尺寸
css的尺寸 width 宽 height高 Line-light 行高 行高是由三部分构成,上间距.文本高度.下间距. 且上下间距相等.所以文字居中 行高.一旦设置行高了,元素内部必须 ...