rsync的主要有以下三个配置文件rsyncd.conf(主配置文件)、rsyncd.secrets(密码文件)、rsyncd.motd(rysnc服务器信息)
服务器配置文件(/etc/rsyncd.conf),该文件默认不存在,请创建它。
具体步骤如下:
#touch /etc/rsyncd.conf #创建rsyncd.conf,这是rsync服务器的配置文件。
#touch /etc/rsyncd.secrets #创建rsyncd.secrets ,这是用户密码文件。
#chmod 600 /etc/rsyncd/rsyncd.secrets #将rsyncd.secrets这个密码文件的文件属性设为root拥有, 且权限要设为600, 否则无法备份成功!
#touch /etc/rsyncd.motd
下一就是我们修改rsyncd.conf和rsyncd.secrets和rsyncd.motd文件的时候了。
设定/etc/rsyncd.conf
rsyncd.conf是rsync服务器主要配置文件。我们先来个简单的示例,后面在详细说明各项作用。
比如我们要备份服务器上的/home和/opt,在/home中我想把easylife和samba目录排除在外;
# Distributed under the terms of the GNU General Public License v2
# 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 = 192.168.1.171
#uid = nobody
#gid = nobody
uid = root
gid = root
use chroot = yes
read on
ly = yes
#limit access to private LANs
hosts deny=*
max connections = 5
motd file = /etc/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
[rhel4home]
path = /home
list=yes
ignore errors
auth users = root
secrets file = /etc/rsyncd.secrets
comment = This is RHEL 4 data
exclude = easylife/ samba/
[rhel4opt]
path = /opt
list=no
ignore errors
comment = This is RHEL 4 opt
auth users = easylife
secrets file = /etc/rsyncd/rsyncd.secrets
注:关于auth users是必须在服务器上存在的真实的系统用户,如果你想用多个用户以,号隔开,比如auth users = easylife,root
设定密码文件
密码文件格式很简单,rsyncd.secrets的内容格式为:
用户名:密码
我们在例子中rsyncd.secrets的内容如下类似的;在文档中说,有些系统不支持长密码,自己尝试着设置一下吧。
创建rsync的密码文件,格式 username:password
$ vi /etc/rsyncd.secrets创建rsync共享配置文件
$ vi /etc/rsyncd.conf添加如下内容:
pid file = /var/run/rsyncd.pidport = 873 uid = rootgid = rootuse chroot = yes read only = nomax connections = 1000 secrets file=/etc/rsyncd.secrets#This will give you a separate log filelog file = /var/log/rsync.loglog format = %t %a %m %f %bsyslog facility = local3timeout = 300 #For ACLhosts allow = 10.0.0.0/255.0.0.0hosts deny = *[transcode]path=/home/testread only = nouid=rootgid=root
auth users = root
启动
rsync server:rsync --daemon /etc/rsyncd.conf用法:
rsync -rvaq --password-file=/data/secret.txt --delete --exclude "*.pyc" --exclude ".git" username@ip:transcode/test.txt .注意事项:本机上的/data/secret.txt文件里只需要保存密码即可,用户名已经在命令中有了,并且权限应为600。
欢迎分享,转载请注明来源:夏雨云
评论列表(0条)