一、前言
1、rsync原理及rsync+inotify触发同步
http://nmshuishui.blog.51cto.com/1850554/1387048
2、本篇说明
为了保证数据的绝对可靠性:
首先,所有的服务器的数据都用脚本打包备份在本地一份,如上篇博客
其次,单独拿出一台pc机做备份机,为rsync客户端,每天定时却拉取各rsync服务器备份好的数据包
再次,使用rsync同步 linux 及 windows 服务器
3、服务器说明
rsync服务器:192.168.200.16,192.168.200.18
rsync客户端:192.168.1.186
这三台服务器都是linux,rsync同步windows服务器到linux服务器在第四条
二、部署rsync服务端
1、 禅道服务器(192.168.200.16)
(1)安装超级守护进程
#yum –y install xinetd
(2)为rsync服务提供配置文件
#vim /etc/rsyncd.conf
#Global Settings uid = nobody gid = nobody use chroot = no max connections = 5 timeout = 600 pid file = /var/run/rsyncd.pid lockfile = /var/run/rsyncd.lock log file = /var/log/rsyncd.log #module [chandao] path = /opt/backup/ ignore errors = yes read only = no write only = no hosts allow = * hosts deny = * list = yes uid = root gid = root auth users = dianyi secrets file = /etc/chandao.passwd
(3)配置rsync认证文件/etc/chandao.passwd
[root@chandao ~]#echo “dianyi:dianyi” > /etc/chandao.passwd [root@chandao ~]#cat /etc/chandao.passwd dianyi:dianyi
(4)修改/etc/chandao.passwd的权限为600
[root@chandao ~]#chmod 600 /etc/chandao.passwd [root@chandao ~]# ll /etc/chandao.passwd -rw------- 1 root root 14 Jul 29 18:18 /etc/chandao.passwd
(5)配置服务启动
[root@chandao ~]# chkconfig rsync on [root@chandao ~]# service xinetd start
(6)检查873端口是否成功监听
[root@chandao ~]# ss -antlp | grep 873
(7)检查rsync运行状态
[root@chandao ~]# chkconfig --list
2、禅道数据库服务器(192.168.200.18)
(1)安装超级守护进程
#yum –y install xinetd
(2)为rsync服务提供配置文件
#vim /etc/rsyncd.conf
#Global Settings uid = nobody gid = nobody use chroot = no max connections = 5 timeout = 600 pid file = /var/run/rsyncd.pid lockfile = /var/run/rsyncd.lock log file = /var/log/rsyncd.log #module [db_chandao] path = /opt/backup/ ignore errors = yes read only = no write only = no hosts allow = * hosts deny = * list = yes uid = root gid = root auth users = dianyi secrets file = /etc/db_chandao.passwd
(3)配置rsync认证文件/etc/db_chandao.passwd
[root@DBSlave ~]#echo “dianyi:dianyi” > /etc/db_chandao.passwd [root@DBSlave ~]#cat /etc/db_chandao.passwd dianyi:dianyi
(4)修改/etc/db_chandao.passwd 的权限为600
[root@DBSlave ~]#chmod 600 /etc/db_chandao.passwd [root@DBSlave ~]# ll /etc/db_chandao.passwd -rw------- 1 root root 14 Jul 29 18:18 /etc/db_chandao.passwd
(5)配置服务启动
[root@DBSlave ~]# chkconfig rsync on [root@DBSlave ~]# service xinetd start
(6)检查873端口是否成功监听
[root@DBSlave ~]# ss -antlp | grep 873
(7)检查rsync运行状态
[root@DBSlave ~]# chkconfig --list
三、部署rsync客户端(192.168.1.186)
1、设置rsync客户端的密码文件
(1)禅道的密码文件
[root@backup ~]#echo dianyi > /etc/chandao.passwd [root@backup ~]# cat /etc/chandao.passwd dianyi
(2)禅道数据库的密码文件
[root@backup ~]#echo dianyi > /etc/db_chandao.passwd [root@backup ~]# cat /etc/db_chandao.passwd dianyi
2、修改密码文件的的权限为600
[root@backup ~]# chmod 600 /etc/chandao.passwd [root@backup ~]# chmod 600 /etc/db_chandao.passwd [root@backup ~]# ll /etc/chandao.passwd /etc/db_chandao.passwd -rw------- 1 root root 7 Jul 29 17:17 /etc/chandao.passwd -rw------- 1 root root 7 Jul 29 16:19 /etc/db_chandao.passwd
3、测试rsync客户端是否可以从rsync服务器拉成功
[root@backup ~]# rsync -vzrtopg --password-file=/etc/chandao.passwd dianyi@192.168.200.16::chandao/* /tmp
4、rsync同步脚本
#!/bin/bash #func:rsync for chandao #Date:first write on 2014.7.29 #Version:v1.0 ntpdate 192.168.200.16 > /dev/null 2>&1 date=`date +%Y-%m-%d` dest_chandao=/opt/backup/chandao/zentao dest_db=/opt/backup/chandao/db_chandao remote_chandao=192.168.200.16 remote_db=192.168.200.18 module_chandao=chandao module_db=db_chandao user1=13910892224@139.com user2=15048088251@139.com main(){ rsync -vzrtopg --password-file=/etc/chandao.passwd dianyi@$remote_chandao::$module_chandao/*$date* $dest_chandao if [ $? -eq 0 ];then echo "chandao-*$date* was rsynced" >> /opt/log/chandao_rsync.log 2>&1; else echo "chandao-*$date* was not rsynced" >> /opt/log/chandao_rsync.log 2>&1; echo "Chandao rsync was faild " | mail -s "chandao backup" $user2; fi rsync -vzrtopg --password-file=/etc/db_chandao.passwd dianyi@$remote_db::$module_db/*$date* $dest_db if [ $? -eq 0 ];then echo "db_chandao_*$date* was rsynced" >> /opt/log/chandao_rsync.log 2>&1; else echo "db_chandao_*$date* was not rsynced" >> /opt/log/chandao_rsync.log 2>&1; echo "db_chandao rsync was faild " | mail -s "chandao backup" $user2; fi } main
四、定时任务
[root@backup ~]# crontab -e ##rsync for chandao 20 09 * * * /bin/sh /opt/scripts/rs_chandao.sh
五、同步windows数据到linux备份机上
主体思想还是和linux保持一致的
rsync服务器需要配置2个方面:(1)配置文件 (2)密码文件
接下来就是rsync客户端配置: (1)密码文件 (2)权限设为600
1、下载cwrsync server
安装时,设置的用户和密码均为dianyi,即两台机器使用rsync相互通信时会使用到的用户名和密码
2、在这台windows上配置rsync服务器,远程linux做为rsync的客户端来拉取windows服务器上的文件
(1)修改配置文件
在C:\Program Files (x86)\ICW\rsyncd.conf 添加模块
use chroot = false strict modes = false hosts allow = * log file = rsyncd.log # Module definitions # Remember cygwin naming conventions : c:\work becomes /cygwin/c/work # [svn] path = /cygdrive/e/Repositories #e代表e盘 ignore errors = yes read only = no transfer logging = yes write only = no hosts allow = * hosts deny = * list = yes uid = 0 #这里的udi和gid不再是root或是nobody,而应该是0,如果不填会报会报:@ERROR: invalid uid nobody gid = 0 auth users = dianyi secrets file = etc/svn.passwd
(2)创建密码文件
在C:\Program Files (x86)\ICW\etc中创建密码文件svn.passwd
内容为 dianyi:dianyi
(3)启动rsync服务
运行 --> services.msc --> RsyncServer 启动类型:自动
(4)查看873端口是否监听成功
运行 --> cmd --> netstat -ano
3、配置rsync客户端(remote linux:192.168.1.186)
(1)创建密码认证文件
vim /etc/svn.passwd dianyi
(2)设置权限
chmod 600 /etc/svn.passwd
(3)测试
# rsync -vzrtopg --password-file=/etc/svn.passwd dianyi@192.168.1.64::svn/* /opt/111/
5、把命令添加到脚本
本文出自 “nmshuishui的博客” 博客,请务必保留此出处http://nmshuishui.blog.51cto.com/1850554/1532927
rsync 远程同步 linux 及 windows 主机,布布扣,bubuko.com
原文:http://nmshuishui.blog.51cto.com/1850554/1532927