Summary of file synchronization technology

File synchronization technology:
Linux->Linux: rsync+inotify
Window –> Linux: cwRsync + scheduled task
linux uses NSF to map remote disk directories File synchronization is often required in
distributed , overall performance is better than rsync, synchronizing files to local , NSF mount installation and maintenance are relatively

simple . Linux
one. Install rsync
1. Install Rsync server on two target servers
1. Close SELINUX
vi /etc/selinux/config #Edit firewall configuration file
#SELINUX=enforcing #Comment out
#SELINUXTYPE=targeted #Comment out
SELINUX=disabled #Add
wq! #Save, exit
setenforce 0 #Effective immediately

2. Open firewall tcp 873 port (Rsync default port)
vi /etc/sysconfig/iptables #Edit firewall configuration file
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 873 -j ACCEPT
:wq! #Save and exit
/etc/init.d/iptables restart #Finally restart the firewall to make the configuration take effect

3. Install the Rsync server software
yum install rsync xinetd #Install
vi /etc/xinetd.d/rsync #Edit the configuration file, set the boot to start rsync
disable = no #Modify to no
:wq! #Save and exit
/etc/init.d/xinetd start #Start (CentOS xinetd is used to manage the Rsync service)

4. Create the rsyncd.conf configuration file
vi /etc/rsyncd.conf #Create a configuration file and add the following code
logfile = /etc/rsyncd.log
pidfile = /etc/rsyncd.pid
lock file = /etc/rsync.lock
secrets file = /etc/rsync.pass
motd file = /etc/rsyncd.Motd
[test]
path = /tmp/test
comment = test
uid = root
gid = root
port=873
use chroot = no
read only = no
list = no
max connections = 200
timeout = 600
auth users = root
hosts allow = 192.20.34.122


:wq! #Save, exit
5. Create a user authentication file
Note that the destination is username: password, the source is only password, the permission must be 600
vi /etc/rsync.pass #Configuration file, add The following content
root:123456
sets file permissions:
chmod 600 /etc/rsyncd.conf
start rsync
/etc/init.d/xinetd start #start
service xinetd stop #stop
service xinetd restart #restart
On the source side:
vi /etc/passwd .txt write
123456
:wq! Save and exit
chmod 600 /etc/passwd.txt #Set file permissions, only set the file owner to have read and write permissions


6. Run the command:
rsync -avH /tmp/test [email protected] .34.144::test --password-file=/etc/passwd.txt


2. Install and configure the inotify service
1. Download and install
# wget http://nchc.dl.sourceforge.net/project/inotify-tools/inotify-tools/3.13/inotify-tools-3.13.tar.gz
# tar xzvf inotify-tools-3.14.tar.gz
# cd inotify-tools-3.13
# ./configure  --prefix=/usr/local/inotify
# make
# make install
2、创建inotify_rsync.sh脚本
# vi inotify_rsync.sh
#!/bin/sh
if [ ! -f /etc/ passwd.txt];then
        echo "123456">/etc/passwd.txt
        /bin/chmod 600 /etc/passwd.txt
fi
log=/usr/local/inotify/logs/rsync.log
src="/tmp/test"
host="目标IP"
module="test"

/usr/local/inotify/bin/inotifywait -mr --timefmt '%d/%m/%y %H:%M' --format '%T %w %f' -e close_write,modify,delete,create ,attrib $src | while read DATE TIME DIR FILE; do
 
       FILECHANGE=${DIR}${FILE}
 
/usr/bin/rsync -avH --delete --progress --password-file=/etc/passwd.txt $ src rsyncuser@$host::$module &
echo "At ${TIME} on ${DATE}, file $FILECHANGE was backed up via rsync" >> $log
done


Give the script executable permission
#chmod +x inotify_rsync.sh
run
#./inotify_rsync.sh &



/usr/local/bin/inotifywait -mrq -e modify,delete,create,attrib ${src}
-m is to keep listening
-r is to recursively view directories
-q is to print out events
-e close_write,modify,delete,create,attrib refers to the event "listen to create move delete write permission"

/usr/bin/rsync -avH --delete --progress --password-file
-a archive mode
-H save hard link
-delete delete in redundant files
--password-file password file

2.

Cwrsync needs to be installed under Windows window.

1. Download cwRsync_5.5.0_x86_Free.zip.
2. Configure environment variables to E:\cwRsync_5.5.0_x86_Free\bin
3. Create configuration files to configure rsync.conf and rsync.pass, the same as linux
4. Run
Rsync -avP /cygdrive/e/cwRsync_5.5.0_x86_Free/etc /tmp/test [email protected]::test/ --password-file=/cygdrive/e/cwRsync_5.5.0_x86_Free/etc/rsync.pass

5. How long to run through timed task configuration

III . NSF maps remote disk directories 1. Install nsf and portmap yum install nfs-utils portmap
on two machines 2. Modify the source machine exports file directory IP (rw,sync,no_root_squash) such as:






/usr/local/platform/file 192.20.34.144(rw,sync,no_root_squash)

.
service rpcbind start 
service nfs start

3. Modify the target machine

service rpcbind start 
service nfs start

and run the mount command
mount -t nfs 192.20.34.122: /usr/ local/platform/file /usr/local/platform/file

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326676019&siteId=291194637
Recommended