域名城

{转}活用sersync实时采集日志

已有 886 次阅读2011-5-27 15:00 |

  最近开发的同事有个需求,让我帮忙收集四个平台上面新加入的日志文件,这些文件不大,但是比较多而且生成的很快,要求最好是实时下载到本地服务器进行分析.开始的时候我想过
在本地服务器上面建一个 rsync daemon 然后上每台服务器上面写一个计划任务每两分钟向本地推送就可以了,但后来一想到计划任务如果相隔时间太短容易出问题,而且也不能保证实时同步,想来想去最后想到了 金山的sersync,配置简单效果明显可以用来实时同步...他的介绍和详细的使用教程请看这个地址:http://blog.johntechinfo.com/sersyncguild周洋的博客.不过 sersync一般是一台服务器向多台服务器同步,这可怎么办,给周洋发信他说现在也没什么好办法.这时突然给自己
来了个脑筋急转弯,把他反过来用不就行了;具体的结构如图:



先到本地服务器上面建了一个文件 /data/rsync/rsyncd.conf 内容如下:(ip地址随便写的别当真)
uid=root
gid=root
max connections=36000
use chroot=no
log file=/var/log/rsyncd.log
pid file=/var/run/rsyncd.pid
lock file=/var/run/rsyncd.lock

[logs_xman]
path=/data/logs/xman
comment = xman logs
ignore errors = yes
read only = no
hosts allow = 10.123.18.111
hosts deny = *

[logs_ufo]
path=/data/logs/ufo
comment = ufo logs
ignore errors = yes
read only = no
hosts allow = 10.123.18.132
hosts deny = *

[logs_BT]
path=/data/logs/BT
comment = BT logs
ignore errors = yes
read only = no
hosts allow = 10.123.17.191
hosts deny = *

[logs_max]
path=/data/logs/max
comment = max logs
ignore errors = yes
read only = no
hosts allow = 10.123.6.131
hosts deny = *


好了保存退出,执行 rsync --daemon --config=/data/rsync/rsyncd.conf
启动以后,依次在 所有的服务器上面装上 sersync ,安装过程很简单下载 安装包 解压就能用了
wget http://sersync.googlecode.com/files/sersync2.5_32bit_binary_stable_final.tar.gz
tar xf sersync2.5_32bit_binary_stable_final.tar.gz
cd GNU-Linux-x86
你会发现有两个文件 confxml.xml  sersync2 对,就两个-_- ,一个配置文件一个执行文件.
好了我们简单修改一下配置文件就可以直接用了,vim confxml.xml 找到下面几项
    <sersync>
        <localpath watch="/data/logs/xman"> 
注:这里是要让sersync监控的本地目录
            <remote ip="59.131.120.166" name="logs_xman"/>  注:这里是目标服务器ip也就是要收集日志的服务器ip 和rsync对象名
        </localpath>
        上面这个是 10.123.18.111 这台服务器的,下面是10.123.18.132
    <sersync>
        <localpath watch="/data/logs/ufo">
            <remote ip="59.131.120.166" name="logs_ufo"/>
        </localpath>

  其他两台都按照类似方法设置就好了,其他的用默认配置就好,保存退出后 执行 sersync -o /data/sersync/GNU-Linux-x86/confxml.xml -d
set the system param
execute:echo 50000000 > /proc/sys/fs/inotify/max_user_watches
execute:echo 327679 > /proc/sys/fs/inotify/max_queued_events
parse the command param
option: -d     run as a daemon
daemon thread num: 10
parse xml config file
host ip : localhost    host port: 8008
daemon start,sersync run behind the console
config xml parse success
please set /etc/rsyncd.conf max connections=0 Manually
sersync working thread 12  = 1(primary thread) + 1(fail retry thread) + 10(daemon sub threads)
Max threads numbers is: 22 = 12(Thread pool nums) + 10(Sub threads)
please according your cpu ,use -n param to adjust the cpu rate
run the sersync:
watch path is: /data/logs/xman

如果没有出错提示就表示启动ok ,剩下的三台服务器都按照相同的步骤执行即可.好了,让我们写个脚本建一些文件试试吧!
分别在四台服务器上面随便建了1000个文件 然后马上到 59.131.120.166 的四个文件夹里面去观察一下,都在呢,一个不少 呵呵
总结:如果在需要同步文件不大且又不经常修改的情况下用sersync来做文件同步还是很方便的^_^
sersync 的主页和相关的操作说明配置文件说明可以去这里看,很详细的
http://code.google.com/p/sersync/

本文出自 “story的天空” 博客,请务必保留此出处http://storysky.blog.51cto.com/628458/538357


路过

雷人

握手

鲜花

鸡蛋

评论 (0 个评论)

facelist

您需要登录后才可以评论 登录 | 注册

易介集团旗下品牌 - 域名城| 国域| 中付通| 中介通| 中华知识产权网| 商标城| DoName| 域名论坛

电信与信息服务业务经营许可证 京ICP证090790号  京ICP备10003495号  电信业务审批[2010]字第598号函  京公网安备110108903585号

Archiver|手机版|小黑屋|侵权投诉|Club.domain.cn 中国域名论坛 论坛管理员邮箱:club@domain.cn

Powered by Discuz!X3.2GMT+8, 2024-5-7 23:57 © 2001-2024 Comsenz Inc.

返回顶部