RsyncPull
Lab Conditions
RsyncClient: content publishing node 192.168.71.20)
RsyncServer1: Service Node 1 (192.168.71.134)
RsyncServer2: Service Node 2 (192.168.71.132)
Synchronization directory
RsyncClient:/web/wwwroot/
RsyncServer1:/web1/wwwroot/
RsyncServer2:/web2/wwwroot/
Wireless network password: 123 qazwsx
Lab requirements
The content publishing node is responsible for generating static pages of user data, and updating static pages to the service node and service node 2 in real time.
Network Topology:
650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/051ZB505-0.jpg "style =" float: none; "title =" rsync. JPG "alt =" 085536366.jpg"/>
Lab procedure
1: Content publishing node 192.168.71.20.)
[Root @ localhost ~] # Cd Desktop/
[Root @ localhost Desktop] # tar zxfrsync-3.0.9.tar.gz-C/opt/
[Root @ localhost Desktop] # cd/opt/rsync-3.0.9/
[Root @ localhost inotify-tools-3.13] #./configure; make & make install
[Root @ localhost ~] # Cd Desktop/
[Root @ localhost Desktop] # tar xfz inotify-tools-3.13.tar.gz-C/opt/
[Root @ localhost Desktop] # cd/opt/inotify-tools-3.13/
[Root @ localhost inotify-tools-3.13] #./configure; make & make install
After compilation is successful
650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/051Z64414-1.jpg "title =" Capture. JPG "style =" float: none; "alt =" 085539227.jpg"/>
Sometimes you may prompt that Gcc is not in the path.
Solution:
Yum-y install gcc *
Now you can re-compile and install it.
[Root @ localhost ~] # Cat/web/wwwroot/inotifyrsync. sh
#! /Bin/bash
Host1 = 192.168.71.134
Src =/web/wwwroot/
Dst1 = web1
User1 = web1user
Host2 = 192.168.71.132
Src =/web/wwwroot/
Dst2 = web2
User2 = web2user
/Usr/local/bin/inotifywait-mrq -- timefmt '% d/% m/% y % H: % m' -- format' % T % w % f % e'-e modify, delete, create, attrib $ src | while read files
Do
/Usr/bin/rsync-vzrtopg -- delete -- progress -- password-file =/etc/server1.pass $ src $ user1 @ $ host1: $ dst1
/Usr/bin/rsync-vzrtopg -- delete -- progress -- password-file =/etc/server2.pass $ src $ user2 @ $ host2: $ dst2
Echo "was rsynced">/tmp/rsync. log2> & 1
Done
This script is stored on the server or the Publishing Server that requires active synchronization.) I call it rsyncClient.End
This script can also be written separately. Note that/etc/server. passAnd/etc/server2.passTwo rsyncserversStored in rysncClientI tried to put the two passwords in the same configuration file, but I couldn't find them. So I wrote them separately.
[Root @ localhost ~] # Mkdir/web/wwwroot/-p
[Root @ localhost ~] # Chmod 755/web/wwwroot/inotifyrsync. sh
[Root @ localhost ~] # Cat/etc/server1.pass
123
[Root @ localhost ~] # Cat/etc/server2.pass
321
[Root @ localhost ~] # Chmod 600/etc/server1.pass
[Root @ localhost ~] # Chmod 600/etc/server2.pass
[Root @ localhost ~] # Ll/etc/server1.pass
-Rw ------- 1 root 4 Mar 24/etc/server1.pass
[Root @ localhost ~] # Ll/etc/server2.pass
-Rw ------- 1 root 4 Mar 24/etc/server2.pass
[Root @ localhost ~] #/Web/wwwroot/inotifyrsync. sh &Transfer to the background as a daemon process
[Root @ localhost ~] # Echo "/web/wwwroot/inotifyrsync. sh &">/etc/rc. localAutomatic startup
2: Service Node 1192.168.71.134)
Cd Desktop/
Tar zxf rsync-3.0.9.tar.gz-C/opt/
Rsync-3.0.9/cd/opt/
./Configure; make & make install
[Root @ localhost ~] # Cat/etc/rsyncd. conf
Uid = nobody
Gid = nobody
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
[Web1]
Path =/web1/wwwroot/
Comment = web1 file
Ignore errors
Read only = no
Write only = no
Hosts allow = 192.168.71.133
Hosts deny = *
List = false
Uid = root
Gid = root
Auth users = web1user
Secrets file =/etc/web1.pass
[Root @ localhost ~] # Mkdir/web1/wwwroot/-p
[Root @ localhost ~] # Chmod 755/web1/wwwroot/
[Root @ localhost ~] # Touch/etc/web1.pass
[Root @ localhost ~] # Vi/etc/web1.pass
Web 1user: 321
[Root @ localhost ~] # Chmod 600/etc/web1.pass
[Root @ localhost ~] #/Usr/local/bin/rsync -- daemonEnable rsyncDaemon
[Root @ localhost ~] # Ps-ef | grep rsyncCheck whether the daemon is enabled
Root 16592 1 0 00:46? 00:00:00/usr/local/bin/rsync -- daemon
[Root @ localhost ~] # Lsof-I: 873View default port 873Enabled or not
COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME
Rsync 16592 root 4u IPv6 65197 TCP *: rsync (LISTEN)
Rsync 16592 root 5u IPv4 65198 TCP *: rsync (LISTEN)
[Root @ localhost ~] # Echo "/usr/local/bin/rsync-daemon">/etc/rc. localSet Automatic startup
3: Service Node 2192.168.71.132)
Cd Desktop/
Tar zxf rsync-3.0.9.tar.gz-C/opt/
Rsync-3.0.9/cd/opt/
./Configure; make & make install
[Root @ localhost ~] # Cat/etc/rsyncd. conf
Uid = nobody
Gid = nobody
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
[Web2]
Path =/web2/wwwroot/
Comment = web2 file
Ignore errors
Read only = no
Write only = no
Hosts allow = 192.168.71.133
Hosts deny = *
List = false
Uid = root
Gid = root
Auth users = web2user
Secrets file =/etc/web2.pass
[Root @ localhost ~] # Mkdir/web2/wwwroot/-p
[Root @ localhost ~] # Chmod 755/web2/wwwroot/
[Root @ localhost ~] # Touch/etc/web2.pass
[Root @ localhost ~] # Vi/etc/web2.pass
Web 2user: 321
[Root @ localhost ~] # Chmod 600/etc/web2.pass
[Root @ localhost ~] #/Usr/local/bin/rsync-daemonEnable rsyncDaemon
[Root @ localhost ~] # Ps-ef | grep rsyncCheck whether the daemon is enabled
Root 16592 1 0 00:46? 00:00:00/usr/local/bin/rsync -- daemon
[Root @ localhost ~] # Lsof-I: 873View default port 873Enabled or not
COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME
Rsync 16592 root 4u IPv6 65197 TCP *: rsync (LISTEN)
Rsync 16592 root 5u IPv4 65198 TCP *: rsync (LISTEN)
[Root @ localhost ~] # Echo "/usr/local/bin/rsync-daemon">/etc/rc. localSet Automatic startup
4: Test
Create a file under/web/wwwroot/on the content publishing node. Check whether the file can be synchronized in real time at the service node.
Note:
1: During the test, the following error will be prompted when the permission of the password file such as/etc/web2.pass is incorrect.
Rsync error: error starting client-serverprotocol (code 5) at main. c (1296) [sender = 2.6.8]
2: If the following error is reported, it is likely that iptables firewall problems are all firewall problems)
650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/051Z63W8-2.jpg "style =" float: none; "title =" error1.JPG "alt =" 085734893.jpg"/>
You can disable the firewalls of these three machines to check whether the firewalls are at fault.
After the firewall is turned off, if real-time update can be implemented, data packets are intercepted by the firewall.
Therefore, you need to set a firewall so that rsync can pass through
First, modify the content on the content publishing node.
1) vi/etc/sysconfig/iptables) write the rules to the configuration file to prevent policy invalidation after restart
650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/051ZBJ0-3.jpg "title =" Capture 2.JPG" style = "float: none;" alt = "085736136.jpg"/>
Note: This rule must be added before the REJECT rule.
2) service iptables restart Firewall
This article from the "heart" blog, please be sure to keep this source http://nihaomingtian.blog.51cto.com/5933084/1299081