原理和工作性质不在介绍,直接看安装:(很简单)
服务端:(备份服务器端)
useradd -s /sbin/nologin -M rsync
vi rsyncd.conf
##rsyncd.conf start##
uid = rsync
gid = rsync
use chroot = no
max connections = 200
timeout = 300
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
log file = /home/logs/rsync/rsyncd.log
ignore errors
read only = false
list = false
hosts allow = 192.168.10.0/24
auth users = user_backup
secrets file = /etc/rsync.password
[chandao]
path = /home/backup/
echo "rsync_backup:backupall" >/etc/rsync.password
chmod 600 /etc/rsync.password
mkdir /backup
chown -R rsync.rsync /backup
rsync --daemon
客户端:(业务主机端)
echo "backupall" >/etc/rsync.password
chmod 600 /etc/rsync.password
因为做的是实时同步,所以用到sersync:(客户端安装)
cd /home/tools/
wget http://dd.jb51.net:81/201111/tools/sersync_64bit_binary_stable_final.tar.gz
tar xf sersync_64bit_binary_stable_final.tar.gz -C /usr/local/
cd /usr/local/
mv GNU-Linux-x86/ sersync
cd sersync/
mkdir conf bin logs
mv confxml.xml conf/
mv sersync2 bin/sersync
配置文件修改
24 <localpath watch="/home/backup"> 要同步的本地目录
25 <remote ip="192.168.10.20" name="chandao"/> 同步的机器和模板名
<inotify>
<delete start="false"/> 关闭了无差异同步
</inotify>
<rsync>
<commonParams params="-artuz"/>
<auth start="true" users="rsync_backup" passwordfile="/etc/rsync.password"/>
<userDefinedPort start="false" port="874"/><!-- port=874 -->
<timeout start="true" time="100"/><!-- timeout=100 -->
<ssh start="false"/>
<rsync>
36 <failLog path="/usr/local/sersync/logs/rsync_fail_log.sh" timeToExecute="60"/><!--default every 60mins execute once-->
提示
这些其实就是在拼接同步命令
rsync -avzP --timeout=100 /backup/* rsync_backup@192.168.232.137::backup --password-file=/etc/rsync.password
加入环境变量
echo 'export PATH=$PATH:/usr/local/sersync/bin' >>/etc/profile
. /etc/profile
启动命令
sersync -r -d -o /usr/local/sersync/conf/confxml.xml
-r让服务器数据保持一致(第一次用),-o指定配置文件,-d 后台执行