Centos7 comes with rsync, which is briefly recorded today.

Centos7 comes with rsync, which is briefly recorded today.

yum -y install rsync #Start rsync service

systemctl start rsyncd.service systemctl enable rsyncd.service #Check whether it has been successfully started

netstat -lnp|grep 873

Rsync installation and configuration steps

Service-Terminal:

  1. Modify the default configuration file /etc/rsyncd.conf, which should be as follows:

/etc/rsyncd: configuration file for rsync daemon mode

See rsyncd.conf man page for more options.

configuration example:

uid = root //Set the user who runs the rsync process

gid = root

use chroot = no

max connections = 4

pid file = /var/run/rsyncd.pid //The yum installation in CentOS7 does not need to specify the pid file, otherwise an error will be reported

lock file=/var/run/rsyncd.lock

log file = /var/log/rsyncd.log //The system will automatically create this file after the definition is completed

exclude = lost+found/

transfer logging = yes

timeout = 900

ignore nonreadable = yes //Skip directories without permission during synchronization

dont compress = *.gz *.tgz *.zip *.z *.Z *.rpm *.deb *.bz2 //Files that are not compressed during transmission

[ ftp] //The system comes with examples, not deleted

path = /home/ftp

comment = ftp export area

[ simba] //This name is the path that the client uses to synchronize with rsync. It is just the module name and does not need to be the same as the folder name

path=/usr/local/simba //The actual path that needs to be synchronized

comment=simba //Just the same as the name in the brackets, note the content that can be displayed during the startup process

ignore errors

read only=yes // means it can be pulled

write only=no // means that you can push

list=no

auth user=rsyncuser //The identity of the client to obtain the file. This user is not a user that does exist in this machine

secrets file=/etc/rsyncd.passwd //The secret key file format used to authenticate the client USERNAME:PASSWD This file right

//The limit must be changed to 600, and the owner must be the same as the user running rsync.

hosts allow=* //Allow all hosts to access

  1. Create key file

echo'rsyncuser:123456'>/etc/rsyncd.passwd //The user name and path of the file are defined above, don’t make a mistake, set the password yourself

chmod 600 /etc/rsyncd.passwd //Modify permissions

  1. Start rsync service

systemctl start rsyncd.service

systemctl enable rsyncd.service

After startup, you can check the log to see if it is normal

tail /var/log/rsyncd.log

Are there any hints as follows:

rsyncd version 3.0.9 starting, listening on port 873

Client:

  1. Create a password file

echo '123456' >>/etc/rsyncd.passwd //Note that only the password in the server rsyncd.passwd is required here

chmod 600 /etc/rsyncd.passwd

  1. test

Synchronize the contents of the simba directory under the server ip to the local client/tmp directory

rsync -auv --password-file=/etc/rsyncd.passwd [email protected]::simba /tmp

To add automatic synchronization in crontab, you must specify --password-file and rsyncuser must be defined in rsyncd.passwd, and rsynctest is defined in the server side []

rsync -vzrtopg --delete  --port 878  --progress /da/ [email protected]::data  --password-file=/etc/rsyncd.passwd

rsync -vzrtopg --delete  --port 878  --progress [email protected]::data /da/ --password-file=/etc/rsyncd.passwd

Server

vi /etc/rsyncd.conf

uid = root
        gid = root
        port = 878
        use chroot = no
        max connections = 100
        timeout = 600
        pid file = /var/run/rsyncd.pid
        lock file = /var/run/rsyncd.lock
        log file = /var/log/rsyncd.log
        exclude = lost+found/
        transfer logging = yes
        ignore nonreadable = yes
        dont compress = *.gz *.tgz *.zip *.z *.Z *.rpm *.deb *.bz2
        [data]
        comment=data
        path = /data/rsyncdata/
        ignore errors
        read only = no
        list = no
        hosts allow = *
        auth users = lgsync
        secrets file = /etc/rsyncd.passwd
        [lgbak]
        path = /data/leguan_bak/
        ignore errors
        read only = no
        list = no
        hosts allow = 10.30.188.194 120.35.10.209
        hosts deny = *
        auth users = lgsync
        secrets file = /etc/rsyncd.passwd

Server vi /etc/rsyncd.passwd

lgsync:root@2018

Client vi /etc/rsyncd.passwd

root@2018

rsync -vzrtopg --delete  --port 878  --progress /da/ [email protected]::data  --password-file=/etc/rsyncd.passwd

rsync -vzrtopg --delete  --port 878  --progress [email protected]::data /da/ --password-file=/etc/rsyncd.passwd

CentOS / RHEL 7

inotify-tools is available through EPEL repository. Install EPEL:

Client

yum install -y epel-release && yum update

Then install the package:

yum install inotify-tools

vi /data/inotify.sh

#! /bin/bash`` INOTIFY_CMD="inotifywait -mrq -e modify,create,attrib,move,delete /da/"`` RSYNC_CMD="rsync -vzrtopg --delete  --port 878  --progress /da/ [email protected]::data  --password-file=/etc/rsyncd.passwd"`` $INOTIFY_CMD | while read DIRECTORY EVENT FILE`` do``     if [ $(pgrep rsync | wc -l) -le 0 ] ; then``         $RSYNC_CMD``     fi`` done

. /inotify.sh

Run nohup ./inotify.sh &

Or nohup sh inotify.sh &

v3.14-8.el7. ×86_64 as of 18-18-2018

( adsbygoogle = window.adsbygoogle || []).push({});

Recommended Posts

Centos7 comes with rsync, which is briefly recorded today.
Centos6.7 comes with python upgrade to
Where is the IDE that comes with Python