Linux服务器rsync+inotify数据实时同步设置教程 |
摘要: 192.168.30.178 目标服务器(相当于备份服务器)192.168.30.160 源服务器一、目标服务器(192.168.30.178)上的设置:开启防火墙tcp873rsync默认的端口vim /etc/sysconfig/iptables-A INPUT -m state --state NEW - ... 192.168.30.178 目标服务器(相当于备份服务器) 192.168.30.160 源服务器 一、目标服务器(192.168.30.178)上的设置: 开启防火墙tcp873rsync默认的端口 vim /etc/sysconfig/iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 873 -j ACCEPT service iptables restart 安装rsync软件: yum install rsync xinetd -y vim /etc/xinetd.d/rsync #####设置开机自启动 把disable=yes ,改成no # default: off # description: The rsync server is a good addition to an ftp server, as it \ # allows crc checksumming etc. service rsync { disable = no flags = IPv6 socket_type = stream wait = no user = root server = /usr/bin/rsync server_args = --daemon log_on_failure += USERID } 添加新用户和组并赋给相应的权限: groupadd rsync useradd rsync mkdir /home/rsync/backup/ chown rsync:rsync /homersync/backup/ 创建rsync daemon的配置文件 ================================================= uid = rsync gid = rsync use chroot = no max connections = 40 timeout = 300 pid file = /var/run/rsyncd.pid lock file = /var/run/rsyncd.lock log file = /home/rsync/backup/rsyncd.log [backup] path = /home/rsync/backup/ ignore errors read only = false list = false hosts allow = 192.168.30.0/24 auth users = rsync secrets file =/etc/rsync.password ==================================== 创建密码文件 [ ~]# vim /etc/rsync.password ==================== rsync:vhost$1 ==================== 启动xinted服务 /etc/init.d/xinted start [ ~]# chmod 600 /etc/rsync.password [ ~]# chmod 600 /etc/rsyncd.conf 二、源服务器(192.168.30.160)安装rsync和inotify(作用) 开启防火墙tcp873rsync默认的端口 vim /etc/sysconfig/iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 873 -j ACCEPT service iptables restart 安装rsync软件: yum install rsync xinetd -y vim /etc/xinetd.d/rsync #####设置开机自启动 把disable=yes ,改成no ============================================ # default: off # description: The rsync server is a good addition to an ftp server, as it \ # allows crc checksumming etc. service rsync { disable = no flags = IPv6 socket_type = stream wait = no user = root server = /usr/bin/rsync server_args = --daemon log_on_failure += USERID } ===================================== 启动xinted服务 /etc/init.d/xinetd start 正在启动 xinetd: [确定] 查看端口: netstat -lntpgrep xinetd tcp 0 0 :::873 :::* LISTEN 38518/xinetd 创建认证文件 vim /etc/rsyncd.passwd vhost$1 []# chmod 600 /etc/rsyncd.passwd 此步骤测试rsync能否正常使用: rsync -avH --port=873 --progress / 三、www.lu0.com安装Inotify-tools工具,实时出发rsync进行同步 安装依赖的包 yum install make gcc gcc-c++ 下载inotify-tools软件包,此处官方打不开,使用的包是inotify-tools-3.14.tar 编译安装: tar zxvf inotify-tools-3.14.tar cd inotify-tools-3.14 ./configure --prefix=/usr/local//inotify make make install |