您的位置:首页 > 运维架构 > Linux

【转】CentOS5.6下配置rsync内网同步数据到外网

2016-04-17 20:03 567 查看

【转】CentOS5.6下配置rsync内网同步数据到外网

本文转自:http://www.linuxidc.com/Linux/2012-06/64070.htm

一、需求

卫士那边有一个需求,就是要把一台内网服务器的数据同步到外网的一台服务器上,之前我用的是rsync+intify-tool+ssh实现的实时同步更新,前几天我还在东莞出差,开发的人给我打电话说这两台服务器的数据不同步了,我上去检查一遍,原来是用来同步数据的这个系统账号被北京的同事修改,ssh免密码登陆失败了,所以数据同步不了,后来想想这样在系统开着个单用户用来同步数据确实是存在安全风险,我有具体和开发的沟通了一下,这个项目的数据同步也不是那么的需要实时同步,所以现在我要改成单用rsync同步,具体步骤如下:

二、环境

内网:10.20.220.247

同步目录1:/data/appsdata/softmgr-v3/static-file/update

同步目录2:/data/appsdata/softmgr-v3/static-file/v1_0

外网:114.112.36.X

同步目录1:/data/apps/ksoftmgr/ksafe/client/update

同步目录2:/data/apps/ksoftmgr/ksafe/client/v1_0

三、安装配置

1.服务器端(114.112.36.69)

A、[root@localhost ~]# yum -y install rsync xinetd

B、[root@localhost ~]# vi /etc/xinetd.d/rsync

将 disable = no 改成yes

[root@localhost ~]# /etc/init.d/xinetd start

C、撰写rsync的配置文件http://www.linuxidc.com

[root@localhost ~]# vi /etc/rsyncd.conf

uid = root

gid = root

use chroot = no

max connections = 10

strict modes = yes

pid file = /var/run/rsyncd.pid

lock file = /var/run/rsync.lock

log file = /var/log/rsyncd.log

[update]

path = /data/apps/ksoftmgr/ksafe/client/update

comment = update file

ignore errors

read only = no

write only = no

hosts allow = 125.89.65.194

hosts deny = *

uid = root

auth users = wcm

secrets file = /etc/web.pass

[v1_0]

path = /data/apps/ksoftmgr/ksafe/client/v1_0

comment = v1_0 file

ignore errors

read only = no

write only = no

hosts allow = 125.89.65.194

hosts deny = *

uid = root

auth users = wcm

secrets file = /etc/web.pass

D、撰写密码文件

[root@localhost ~]# vi /etc/web.pass (格式 账号:密码)

wcm:8888888

[root@localhost ~]# chown root:root /etc/web.pass

权限必须为600,否则无法同步。

[root@localhost ~]# chmod 600 /etc/web.pass

E、启动rsync

[root@localhost ~]# rsync --daemon

[root@localhost ~]# echo "rsync --daemon" >> /etc/rc.local

2、客户端(10.20.220.247)

A、[root@localhost ~]# yum -y install rsync

B、撰写密码文件

[root@localhost ~]# vi /etc/web.pass (主要:只写用来同步的账号的密码)

8888888

[root@localhost ~]# chown root:root /etc/web.pass

权限必须为600,否则无法同步。

[root@localhost ~]# chmod 600 /etc/web.pass

C、撰写crontab,没一分钟同步一次

[root@localhost v1_0]# crontab -e

*/1 * * * * /usr/bin/rsync -avz --progress --delete /data/appsdata/softmgr-v3/static-file/update/ wcm@114.112.36.x::update --password-file=/etc/web.pass

*/1 * * * * /usr/bin/rsync -avz --progress --delete /data/appsdata/softmgr-v3/static-file/v1_0/ wcm@114.112.36.X::v1_0 --password-file=/etc/web.pass

四、测试

在内网的update和v1_0下面删除或者新建文件,看对应外网的机器上是否也是做了相应的操作,如果是,说明OK,我的肯定是撒,线上的不同步就悲剧了。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: