Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Use rsync to synchronize files remotely in CentOS 6.x 7.x

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Remote file synchronization with rsync in CentOS 6.x

System environment: Centos 6.9 x64 (Centos 7.3 x64)

Purpose:

The/u01 folder in server 110.112.200.12 needs to be replicated to 110.210.250.58 for backup.

Make 200.12 the xinetd server, copy and synchronize its/u01 folder to 250.58, and 250.58 the client.

I. Configuration of server side

Centos 6.9 x64

configured in origin server 110.112.200.12

[root@mail test]# yum -y install xinetd rsync

Modify the configuration again: # vi /etc/xinetd.d/rsync

service rsync

{

disable = NO

socket_type = stream

wait = no

user = root

server = /usr/bin/rsync

server_args = --daemon

log_on_failure += USERID

}

Change the original disable from YES to NO

[root@mail test]# vi /etc/rsyncd.conf

uid = root

gid = root

use chroot = no

max connections = 20

secrets file = /etc/rsync_pass

pid file = /var/run/rsyncd.pid

log file = /var/log/rsyncd.log

[backup]

path = /u01

comment = Rsync share test

auth users = ruser

read only = yes

hosts allow = 110.210.250.58

hosts deny = *

Note that path = /u01 ; indicates that the folder to be backed up is/u01

Configure synchronized accounts and passwords

[root@mail test]# vi /etc/rsync_pass

ruser:123456

[root@mail test]# chown root:root /etc/rsync_pass

[root@mail test]# chmod 600 /etc/rsync_pass

[root@mail test]# chkconfig xinetd on

[root@mail test]# service xinetd restart

Check for port 873

[root@mail test]# netstat -natp

tcp 0 0 0.0.0.0:873 0.0.0.0:* LISTEN 20959/xinetd

Note: If the server is equipped with a firewall, remember to open the port. The default port is 873.

Another way to start and stop (not recommended)

Some people like to start rsync with the command rsync --daemon --config=/etc/rsyncd.conf, and kill the process with the pkill command when disabling it. It is not as convenient as using xinetd to manage rsync startup.

Some people like to write a script to start and stop rsync, the system itself has xinetd to manage the start of rsync without it, a bit of a taste of seeking distance.

[root@mail test]# rsync --daemon --config=/etc/rsyncd.conf

[root@mail test]# pgrep -l rsync

5132 rsync

[root@mail test]# pkill rsync

[root@mail test]# pgrep -l rsync

------------------------------------------------------------------------------------------

If you are using Centos 7.3 x64 as a server, please see the configuration below.

[root@mail test]# rpm -qa|grep rsync

rsync-3.0.9-17.el7.x86_64

4. Configure the rsync configuration file

vi /etc/rsyncd.conf

uid = root

gid = root

use chroot = no

port = 873

max connections = 20

timeout = 200

secrets file = /etc/rsync_pass

pid file = /var/run/rsyncd.pid

log file = /var/log/rsyncd.log

lock file = /var/run/rsyncd.lock

log format = %t %a %m %f %b

[backup]

path = /u01

comment = Rsync share test

list = yes

auth users = ruser

read only = yes

hosts allow = 110.210.250.58

hosts deny = *

[root@mail test]# yum install xinetd.x86_64

[root@mail test]# rpm -qa xinetd

xinetd-2.3.15-13.el7.x86_64

Modify the configuration again: # vi /etc/xinetd.d/rsync

service rsync

{

disable = NO

socket_type = stream

wait = no

user = root

server = /usr/bin/rsync

server_args = --daemon

log_on_failure += USERID

}

Change the original disable from YES to NO

After installation, add xinetd service to boot:

[root@mail test]# systemctl enable xinetd.service

Finally, restart the service:

[root@mail test]# systemctl restart xinetd

Check for port 873

[root@mail test]# netstat -natp

tcp6 0 0 :::873 :::* LISTEN 25167/xinetd

Join Firewall Allow

[root@mail test]# firewall-cmd --add-service=rsyncd --permanent

[root@mail test]# firewall-cmd --reload

[root@mail test]# systemctl restart firewalld

-------------------------------------------------------------------------------------------

II. Client configuration

Configure in target server 250.58

[root@vmevan test]# yum -y install rsync

[root@vmevan test]# vi /etc/rsync_pass

123456

Note that the client password file only requires a password, not a username!

[root@vmevan test]# chmod 600 /etc/rsync_pass

Create a folder for backup

[root@vmevan test]# mkdir /bakcup200.12

On the client side, some files (such as named.run) do not need to be synchronized, so they are added to the exclude.list.

[root@vmevan test]# vi /etc/exclude.list

named.run

[root@vmevan test]# chmod 600 /etc/exclude.list

[root@vmevan test]# vi /usr/sbin/rsyncdns

#!/ bin/bash

# by evan.li 2017.6.21

rsync -vzrtopgu --progress --delete --exclude-from="/etc/exclude.list" --password-file=/etc/rsync_pass ruser@110.112.200.12::backup /bakcup200.12

[root@vmevan test]# chmod +x /usr/sbin/rsyncdns

Sync every 1 hour

[root@vmevan test]# vi /etc/crontab

0 */1 * * * root /usr/sbin/rsyncdns

1. In the client, set synchronization between remote hosts

[root@vmevan test]# rsync -vzrtopgu --progress --delete --password-file=/etc/rsync_pass ruser@110.112.200.12::backup /bakcup200.12

or use

[root@vmevan test]# rsync -zrtopgu --delete --password-file=/etc/rsync_pass ruser@110.112.200.12::backup /bakcup200.12

The v in-vzrtopg on this command line is verbose, detailed.

z is compressed transmission,

R is recursive, recursive.

topg is a parameter that preserves the original attributes of the file, such as ownership and time.

u is to synchronize only the files that have been updated, so as to avoid the files that have not been updated being updated repeatedly, but pay attention to the synchronization of the clocks of the two machines.

-progress means showing detailed progress,

-delete means that if the server deletes the file, the client deletes the file accordingly, maintaining true consistency.

In ruser@110.112.200.12::backup on the back, backup is the module name, which is the custom name in/etc/rsyncd.conf, and ruser is the user name specified in the specified module that can be synchronized.

The final/bakcup200.12 is the directory name backed up locally.

In this case, encrypted connections can also be established using the-e ssh parameter.

You can specify the password file with-password-file=/password/path/file, which can be used in scripts without having to enter the authentication password interactively. Note that the password file permissions attribute should be set to be readable only by the owner.

On the client side, put rsync into crontab schedule tasks, sync once a day at 5 a.m.

[root@vmevan test]# vi /etc/crontab

0 5 * * * root /usr/bin/rsync -vzrtopgu --delete --password-file=/etc/rsync_pass ruser@114.112.200.12::backup /bakcup200.12

50 6 * * * root /usr/bin/rsync -avu -progress -delete /u01 /u03/backup

2. On the server side (in the source server), synchronization between local directories can be established.

[root@vmevan test]# rsync -avu -progress -delete /u01/555 /mnt/sdb1/u01

Place the source directory/u01/555 synchronously in the/mnt/sdb1/u01 folder. The src-dir directory contents are updated differently to the dst-dir directory. If there is an increase/update, add and replace it, and if there is a decrease, delete it.

Testing completed on June 21, 2017

by evan.li

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report