Environment: CentOS 6.6
Web server: 192.168.2.82
Content Publishing point: 192.168.2.39
One, install rsync on the Web server and configure
1. Install rsync
Yum Install Rsync-y
2. Start Configuring Rsync files
MKDIR/ETC/RSYNCD(default without this file, need to create manually)
Touch/etc/rsyncd/rsyncd.conf
Ln-s/etc/rsyncd/rsyncd.conf/etc/rsyncd.conf
Vi/etc/rsyncd.conf
UID = root GID = root Use chroot = no #limit access to private LANs Hosts allow=192.168.2.0/255.255.255.0 Hosts deny=* Max connections = 5
PID file =/var/run/rsyncd.pid Secrets file =/etc/rsyncd/rsyncd.secrets Log file =/var/log/rsync.log #This would log every file transferred-up to 85,000+ per user, per sync Transfer logging = yes Log format =%t%a%m%f%b Syslog facility = Local3 Timeout = 300 # MODULE OPTIONS [Rsync_test] Path =/rsync_test List=yes WriteOnly = False Read Only = False Ignore errors Auth users = Sandy Comment = Test rsync |
Chmod-r 755/var/run
Vi/etc/rsyncd/rsyncd.secrets
For the security of the password, we set the permission to 600:
Chown Root:root/etc/rsyncd/rsyncd.secrets
chmod 600/etc/rsyncd/rsyncd.secrets
To start the Rsync service:
1. Running the Rsync service with XINETD
CentOS runs the Rsync service by default in xinetd mode. Rsync's xinetd configuration file
In/etc/xinetd.d/rsync. To configure the Rsync service to run with xinetd, you need to execute the following command:
# chkconfig rsync on# service xinetd restart
Administrators can modify the/etc/xinetd.d/rsync configuration file to suit your needs. For example, you can modify the configuration line
Server_args =--daemon
Add the service options for rsync later.
2. Running the rsync service independently
The simplest way to run the Rsync service independently is to execute the following command:
#/usr/bin/rsync--daemon
You can write the above command to the/etc/rc.local file to run the Rsync service each time you start the server. Of course, you can also write a script to start the RYSNC service automatically at boot time.
To start the Rsync service:
/etc/init.d/xinetd restart
See if Port 873 is up
Netstat-an | grep 873
If you see that port 873 is already listening, the rsync service has started
Second, client installation rsync,inotify-tools and configuration
1. Install rsync and configure
Yum Install Rsync-y
The client configures Rsync, creates a password file, synchronizes with this file later and does not need to fill in the password:
touch/etc/rsync_passwd
chmod 600/etc/rsync_passwd
echo "123456" >/etc/rsync_passwd(writes the account password of the server user Sandy to the password file)
2, install Inotify-tools (because the centos6.6 system has built-in inotify, so there is no need to install inotify, see/proc/sys/fs/directory under the INotify folder, if there is already installed, If not, Yum installs)
Yum Install Inotify-tools-y
III. Create a content publishing point file directory and write a live synchronization script file
Mkdir/src
vi/crontab/rsync.sh
#!/bin/bash /usr/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/src/[email protected]::rsync_test--password-file=/etc/rsync_passwd Done |
Iv. execute the script file and verify
1. Execute script file in background
SH +x/crontab/rsync.sh>/crontab/rsync.log &
Boot start:
Echo ' sh +x/crontab/rsync.sh>/crontab/rsync.log & ' >>/etc/rc.local
2. Verification
Client-Created files:
Cd/src
Touch Test.txt
See if the server side automatically has the Test.txt file
CD Rsync_test
Ls
Rsync+inotify synchronizing data in real time