Hi!请登陆

centos 安装rsync实现数据同步

2020-10-27 56 10/27

1、保存下面的代码为一个文件,上传到服务器端,名称为rsync.sh

复制代码代码如下:

#!/bin/bash
#rsync Written by zhumaohai
#For more information please visit http://www.centos.bz
echo "Please input the rsync username:"
read username
echo "Please input the rsync username password:"
read password
echo "Please input the server ip address:"
read serverip
echo "Please input the allow ip address:"
read allowip
echo "Please input the path you want to rsync:"
read rsyncpath
echo "==========================input all completed========================"
echo "==========================install rsync========================"
yum -y install rsync
useradd $username
mkdir /etc/rsyncd
cat >/etc/rsyncd/rsyncd.conf<<eof
# Minimal configuration file for rsync daemon
# See rsync(1) and rsyncd.conf(5) man pages for help
# This line is required by the /etc/init.d/rsyncd script
pid file = /var/run/rsyncd.pid
port = 873
address = $serverip
#uid = nobody
#gid = nobody
uid = root
gid = root
use chroot = yes
read only = yes
#limit access to private LANs
hosts allow=192.168.1.0/255.255.255.0 10.0.1.0/255.255.255.0 $allowip
hosts deny=*
max connections = 5
motd file = /etc/rsyncd/rsyncd.motd
#This will give you a separate log file
#log file = /var/log/rsync.log
#This will 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
[$username home]
path = $rsyncpath
list=yes
ignore errors
auth users = $username
secrets file = /etc/rsyncd/rsyncd.secrets
eof
echo "$username:$password" > /etc/rsyncd/rsyncd.secrets
chmod 600 /etc/rsyncd/rsyncd.secrets
cat >/etc/rsyncd/rsyncd.motd<<eof
+++++++++++++++++++++++++++
+ centos.bz rsync 2011-2012 +
+++++++++++++++++++++++++++
eof
/usr/bin/rsync --daemon --config=/etc/rsyncd/rsyncd.conf
ps -aux | grep rsync

2、赋予脚本权限

chmod +x rsync.sh

3、执行脚本

./rsync.sh

4、客户端同样需要安装rsync

[root@linux docbook]$  rsync rsync://www.9812.net/netkiller
[root@linux tmp]$ rsync rsync://[email protected]/netkiller
Password:
[chen@linux temp]$  rsync -vzrtopg --progress --delete [email protected]::postfix /tmp
Password:
rsync rsync://认证用户@主机/模块
rsync -vzrtopg --progress --delete 认证用户@主机::模块 /mirror目录
Tag:

相关推荐