欢迎光临
我们一直在努力

CentOS6.3下rsync服务器的安装与配置

五、rsync 服务器应用案例

5.1. 在服务器端TS-DEV上配置rsync 服务

a. 编辑配置文件

# vi /etc/rsyncd/rsyncd.conf

# 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
# GLOBAL OPTIONS uid = root gid = root
use chroot = no
read only = yes #limit access to private LANs hosts allow=172.16.0.0/255.255.0.0 192.168.1.0/255.255.255.0 10.0.1.0/255.255.255.0 hosts deny=*
max connections = 5 

pid file = /var/run/rsyncd.pid

secrets file = /etc/rsyncd/rsyncd.secrets
#lock file = /var/run/rsync.lock 
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
# MODULE OPTIONS [davidhome] path = /home/david/ list=yes ignore errors auth users = david comment = David home exclude = important/ [chinatmp] path = /tmp/china/ list=no ignore errors auth users = china comment = tmp_china

b. 建立/etc/rsyncd/rsyncd.secrets文件

# vim /etc/rsyncd/rsyncd.secrets

david:asdf           #格式   用户名:口令
china:jk               #该用户不要求是系统用户

c. 为了密码的安全性,我们把权限设为600

# chown root:root /etc/rsyncd/rsyncd.secrets

# chmod 600 /etc/rsyncd/rsyncd.secrets

d. 建立连接到服务器的客户端看到的欢迎信息文件/etc/rsyncd/rsyncd.motd

# vim /etc/rsyncd/rsyncd.motd

+++++++++++++++++++++++++++
+                  David Camp                    +
+++++++++++++++++++++++++++

e. 启动rsync

# /etc/init.d/xinetd restart

f. 查看873端口是否起来

# netstat -an | grep 873

如果rsync启动成功的话可以看到873端口已经在监听了。

g. 服务器端文件详细

CentOS6.3下rsync服务器的安装与配置

5.2. 客户端配置

a. 客户端安装rsync

# yum -y install rsync

b. 通过rsync客户端来同步数据

场景一:

# rsync -avzP david@172.16.1.135::davidhome  /tmp/david/

CentOS6.3下rsync服务器的安装与配置

Password: 这里要输入david的密码,是服务器端提供的,在前面的例子中,我们用的是 asdf,输入的密码并不显示出来;输好后就回车;
注: 这个命令的意思就是说,用david 用户登录到服务器上,把davidhome数据,同步到本地目录/tmp/david/上。当然本地的目录是可以你自己定义的,比如 dave也是可以的;当你在客户端上,当前操作的目录下没有davidhome这个目录时,系统会自动为你创建一个;当存在davidhome这个目录中,你要注意它的写权限。

说明:
-a 参数,相当于-rlptgoD,-r 是递归 -l 是链接文件,意思是拷贝链接文件;-p 表示保持文件原有权限;-t 保持文件原有时间;-g 保持文件原有用户组;-o 保持文件原有属主;-D 相当于块设备文件;
-z 传输时压缩;
-P 传输进度;
-v 传输时的进度等信息,和-P有点关系,自己试试。可以看文档;

场景二:
# rsync -avzP  --delete david@172.16.1.135::davidhome  /tmp/david/

CentOS6.3下rsync服务器的安装与配置

这回我们引入一个 –delete 选项,表示客户端上的数据要与服务器端完全一致,如果 /tmp/david/目录中有服务器上不存在的文件,则删除。最终目的是让/tmp/david/目录上的数据完全与服务器上保持一致;用的时候要小心点,最好不要把已经有重要数所据的目录,当做本地更新目录,否则会把你的数据全部删除;

场景三:
# rsync -avzP  --delete  --password-file=/tmp/rsync.password  david@172.16.1.135::davidhome  /tmp/david/

CentOS6.3下rsync服务器的安装与配置

这次我们加了一个选项 –password-file=rsync.password ,这时当我们以david用户登录rsync服务器同步数据时,密码将读取 /tmp/rsync.password 这个文件。这个文件内容只是david用户的密码。我们要如下做;

# touch /tmp/rsync.password
# chmod 600 /tmp/rsync.password
# echo "asdf"> /tmp/rsync.password
# rsync -avzP  --delete  --password-file=/tmp/rsync.password  david@172.16.1.135::davidhome  /tmp/david/

注: 这样就不需要密码了;其实这是比较重要的,因为服务器通过crond 计划任务还是有必要的;

5.3. rsync 客户端自动与服务器同步数据

编辑crontab
# crontab -e
加入如下代码:

10 0 * * * rsync -avzP --delete --password-file=/tmp/rsync.password david@172.16.1.135::davidhome /tmp/david/

表示每天0点10分执行后面的命令。

六、错误分析

  • 海报
海报图正在生成中...
赞(0) 打赏
声明:
1、本博客不从事任何主机及服务器租赁业务,不参与任何交易,也绝非中介。博客内容仅记录博主个人感兴趣的服务器测评结果及一些服务器相关的优惠活动,信息均摘自网络或来自服务商主动提供;所以对本博客提及的内容不作直接、间接、法定、约定的保证,博客内容也不具备任何参考价值及引导作用,访问者需自行甄别。
2、访问本博客请务必遵守有关互联网的相关法律、规定与规则;不能利用本博客所提及的内容从事任何违法、违规操作;否则造成的一切后果由访问者自行承担。
3、未成年人及不能独立承担法律责任的个人及群体请勿访问本博客。
4、一旦您访问本博客,即表示您已经知晓并接受了以上声明通告。
文章名称:《CentOS6.3下rsync服务器的安装与配置》
文章链接:https://www.456zj.com/3863.html
本站资源仅供个人学习交流,请于下载后24小时内删除,不允许用于商业用途,否则法律问题自行承担。

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址