运维技能 - 同步lsync

来源:互联网 发布:unity3d培训多久学完 编辑:程序博客网 时间:2024/06/06 20:15

今天不是很高兴,为啥呢?之前,A在B找工作的时候 一直帮助B,然后有次B写了一段cpp代码,实现,变量都放在了类的内部,很臃肿的一个,然后A说了一句,太烂了,要放在公司肯定挨骂的,然后A和B就关系变差了。A很苦恼。

lsync 是啥呢? 其实可以简单的理解成inotufy+rsync, 

机器角色:

A 10.210.71.144  安装了 rsync lsync

B 10.210.71.146  安装了 rsync

A机器做出了改变,会在某个特定的时间内,将变化同步到B,甚至更多的机器,inotify 感知文件的变化,rsync 用来把文件推送过去。

配置方案如下:

B机器上的配置:

安装rsync,目录树如下所示:

[root@test test]# tree  /etc/rsyncd/etc/rsyncd├── rsyncd.conf├── rsyncd.motd└── rsyncd.secrets0 directories, 3 files
为了方便,简单的配置文件如下所示:

[root@test test]# cat /etc/rsyncd/rsyncd.conf pid file = /var/run/rsyncd.piduid = rootgid = rootuse chroot = yesread only = nowrite only = nohosts allow = 10.209.65.21 10.210.71.146 192.168.0.1/255.255.255.0 198.162.145.1 10.0.1.0/255.255.255.0 10.210.71.145 10.210.71.144 10.210.71.143 hosts deny = *max connections = 5#motd file = /etc/rsyncd/rsyncd.motdlog file = /tmp/rsyncd.logtransfer logging = yeslog format = %t %a %m %f %bsyslog facility = local3timeout = 300[data1]path=/tmp/testlist=yescomment = some description about this moudleexclude = test1/ test2/[root@test test]# vim /etc/rsyncd/rsyncd.conf [root@test test]# cat  /etc/rsyncd/rsyncd.conf pid file = /var/run/rsyncd.piduid = rootgid = rootuse chroot = yesread only = nowrite only = nohosts allow = 10.210.71.146 10.210.71.145 10.210.71.144 10.210.71.143 hosts deny = *max connections = 5#motd file = /etc/rsyncd/rsyncd.motdlog file = /tmp/rsyncd.logtransfer logging = yeslog format = %t %a %m %f %bsyslog facility = local3timeout = 300[data1]path=/tmp/test
在A机器上执行如下的命令进行测试:

[root@test test]# rsync root@10.210.71.146::data1/drwxr-xr-x        4096 2015/01/23 13:28:53 .-rw-r--r--           0 2015/01/23 13:28:53 test[root@test test]# 

通了,配置成功。

配置A,A上面需要安装inotify 和lsync,比较新版本的系统可以支持yum安装了,省略

A机器上最简单的一个配置:

[root@test test]# cat /etc/lsyncd.conf ------ User configuration file for lsyncd.---- Simple example for default rsync, but executing moves through on the target.---- For more examples, see /usr/share/doc/lsyncd*/examples/-- -- -- sync{--     default.rsync, --     source="/tmp/", --     host="10.210.71.146", --     targetdir="/tmp/test/"--}settings {    logfile = "/var/log/lsyncd.log",    statusFile = "/var/log/lsyncd-status.log",    statusInterval = 20}sync{    default.rsync,    source = "/tmp/test",    target = "10.210.71.146::data1/",}[root@test test]# 

source 指定的是A端的目录,B目录需要去同步的目录

target   指定的是B端的需要承接同步目录的目录。

测试如下

[root@test test]# rsync root@10.210.71.146::data1/drwxr-xr-x        4096 2015/01/23 13:28:53 .-rw-r--r--           0 2015/01/23 13:28:53 test[root@test test]# pwd/tmp/test[root@test test]# lltotal 0-rw-r--r-- 1 root root 0 Jan 23 13:28 test[root@test test]# touch test1[root@test test]# dateFri Jan 23 13:46:38 CST 2015[root@test test]# rsync root@10.210.71.146::data1/drwxr-xr-x        4096 2015/01/23 13:28:53 .-rw-r--r--           0 2015/01/23 13:28:53 test[root@test test]# dateFri Jan 23 13:46:51 CST 2015[root@test test]# dateFri Jan 23 13:47:21 CST 2015[root@test test]# rsync root@10.210.71.146::data1/drwxr-xr-x        4096 2015/01/23 13:46:37 .-rw-r--r--           0 2015/01/23 13:28:53 test-rw-r--r--           0 2015/01/23 13:46:37 test1[root@test test]#

同步的工具很多,但是感觉这个非常的易用。

0 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 生完孩子肛门痒怎么办 把达克宁软膏摸到肛门怎么办 痔疮手术后肛门痒怎么办 便秘拉完屁股疼怎么办 屁股拉屎拉破了怎么办 6岁小朋友屁眼痒怎么办 孩子屁屁偶尔痒怎么办 1岁半宝宝屁眼痒怎么办 3岁宝宝肛门痒怎么办 得痔疮发烧了怎么办啊 痔疮手术后肚子胀气怎么办 乙肝引起的发烧头痛怎么办 肠癌手术后吃了会胃疼怎么办 来月经肛门坠痛怎么办 总想排便还有血怎么办 闻了别人的口臭怎么办 有内痔肛门经常不舒服怎么办 做完肠镜肛门疼怎么办 3周宝宝得皮彦怎么办 痔疮有蚕豆大了怎么办 顺生肛门坠胀怎么办 生孩子痔疮脱出不能回纳怎么办 痔疮犯了屁眼疼怎么办 孕晚期得痔疮了怎么办 孕39周痔疮严重怎么办 顺产后长痔疮了怎么办 怀孕了犯痔疮了怎么办 怀孕了痔疮犯了怎么办 痔疮手术后肛裂怎么办 痔疮引起的肛裂怎么办 痔疮手术后伤口不愈合怎么办 痔疮手术后伤口痒怎么办 肛瘘手术十五天后伤口疼怎么办 leep刀后hpv还是阳性怎么办 结肠息肉钳除后怎么办 痔疮手术后排便困难怎么办 住院未结账跑了怎么办 来月经痔疮犯了怎么办 安保压不下宫缩怎么办 肛周脓肿术后假性愈合怎么办 肛门的皱褶肿了怎么办