该文档是在很早之前写的,一直存在草稿箱中,最近在整理其它学习资料时发现还没有发布,内容和方法有可能和现在的操作系统版本有些不符合了,但处理思路没有变化,大家可以根据最新版本要求,参照该文档进行配置学习,有些不对的地方还望大家多多理解。
一、为什么要实现同步备份
服务器上有些重要文件或数据时,可以把他们多备份一份到其他服务器上,这样就不怕数据或文件丢失了。
二、环境的搭建
**服务器A:**192.168.1.10 源服务器
**服务器B:**192.168.1.20 目的服务器
我们要实现的就是把A服务器上的文件同步到B服务器上,从而实现备份。我们主要是在B服务器上安装配置rsync,在A服务器上安装配置sersync,通过sersync把文件推送到B服务器上
三、开始搭建
3.1、配置B服务器
3.1.1、关闭selinux
在/etc/sysconfig/selinux 这个文件,设置SELINUX=disable
3.1.2、防火墙开通873端口
可以使用以下命令,也可以把防火墙关闭
-A INPUT -m state --state NEW -m tcp -p tcp --dport 873 -j ACCEPT
3.1.3、开始安装rsync
bash
[root@Test ~]# yum install rsync -y
3.1.4、配置rsync
rsync的配置文件是/etc/rsyncd.conf,配置如下:
bash
#Gobal Setting
uid = root
gid = root
use chroot = no
read only = no
hosts allow = 192.168.1.0/24
hosts deny = *
max connections = 5
pid file = /var/run/rsyncd.pid
secrets file = /etc/rsyncd/rsyncd.password
log file = /var/log/rsyncd.log
motd file = /etc/rsyncd/rsyncd.motd
transfer logging = yes
log format = %t %a %m %f %b
ignore errors = yes
#User Options
[test]
path=/test
list = yes
auth users = tom1
comment = Tom1's home
secrets file:这个是配置同步密码文件的。
test\]:这个是配置同步模块的名称 path:是配置同步的目录 hosts allow:是允许同步的主机 hosts deny:拒绝同步的主机。 ##### 3.1.5、创建同步的用户与密码的文件 即上图中的secrets file这个配置选项中的文件。/etc/rsync.passwd,同进要设置这个文件的权限为600 ```bash [root@Test ~]# echo "user:password" >> /etc/rsync.passwd [root@Test ~]# chmod 600 /etc/rsync.passwd ``` ##### 3.1.6、创建同步的目录 即上图中path配置选项中的目录。 ```bash [root@Test ~]# mkdir /home/rsynctest ``` ##### 3.1.7、启动rsync ```bash [root@Test ~]# rsync --daemon --config=/etc/rsyncd.conf ``` 接着重启一下xinetd ```bash [root@Test ~]# /etc/init.d/xinetd restart ``` ##### 3.1.8、配置开机启动 ```bash [root@Test ~]# echo "rsync --daemon --config=/etc/rsyncd.conf" >> /etc/rc.d/rc.local ``` 到这B服务器基本就配置完成了。 #### 3.2、配置A服务器 ##### 3.2.1、sersync官网下载sersync 官网地址:http://sersync.sourceforge.net ```bash [root@Test ~]# wget http://sersync.googlecode.com/files/sersync2.1_64bit_binary.tar.gz ``` ##### 3.2.1、安装sersync ```bash [root@Test ~]# mkdir /usr/local/sersync [root@Test ~]# mkdir /usr/local/sersync/conf [root@Test ~]# mkdir /usr/local/sersync/bin [root@Test ~]# mkdir /usr/local/sersync/log [root@Test ~]# tar zxvf sersync2.5_32bit_binary_stable_final.tar.gz [root@Test ~]# cd GNU-Linux-x86/ [root@Test ~]# cp confxml.xml /usr/local/sersync/conf [root@Test ~]# cp sersync2 /usr/local/sersync/bin ``` ##### 3.2.3、创建密码文件 同B服务器一样,不过这个文件只要保存一个密码就行了,不用用户名,权限也是600 ```bash [root@Test ~]# echo "password" >> /etc/rsync.passwd [root@Test ~]# chmod 600 /etc/rsync.passwd ``` ##### 3.2.4、配置sersync 配置文件就是上第二步复制的confxml.xml这个文中,路径在/usr/local/sersync/conf中。 ```bash
# 设置本地IP和端口