Skip to main content

tplogin.cn首页 > 新闻资讯 >

Rsync配置远程同步

2014-04-25 23:35 浏览:

  昨天终于拿到服务器权限,今天第一次登上线上的服务器协助开发人员做远程备份。由于是第一次,心里多少有点负担,生怕做不好(其实更怕做出什么惊天动地的事...)

  开发人员要求将积分的目录备份到两台服务器上,用到的工具是rsync,本来挺简单的一件事,结果由于太久没用,还有不够细心,过程中出现了一些小问题,还好leader帮忙指导一二最终也算是顺利交付任务了,下面记录下今天的过程和遇到的问题。

  任务具体要求如下:

  协助开发人员小许将积分副本同步到目标主机下。

  源服务器:192.168.1.1

  目标服务器:192.168.1.2 192.168.1.3

  服务器平台Ubuntu

  配置过程

  目标服务器上,配置文件(默认不存在),需要手动添加

  wuguihong1@ubuntu:~$ vim /etc/rsyncd.conf

  uid = www

  gid = www

  pid file=/tmp/rsyncd.pid

  log file = /var/log/rsyncd.log

  [jifen]

  path=/data/app-jifen/

  auth users=jifen

  read only = no

  strict modes = yes

  secrets file = /etc/rsyncd.pass

  hosts allow= 192.168.1.1

  hosts deny = *

  创建密码文件

  wuguihong1@ubuntu:~$ sudo vim /etc/rsyncd.pass

  jifen:jifen@rsync

  确保密码文件权限为600,否则会报错

  wuguihong1@ubuntu:~$ sudo chmod 600 /etc/rsyncd.pass

  确保同步的目标目录存在,否则会报错

  wuguihong1@ubuntu:~$ sudo mkdir /data/app-jifen/

  确保目录属主与 rsyncd.conf 中的配置一致

  wuguihong1@ubuntu:~$ sudo chown www.www /data/app-jifen/

  测试

  root@ubuntu:/etc# rsync -vzrtopg --delete /tmp/testrsync jifen@192.168.1.2::jifen --password-file=/etc/rsync.pass

  sending incremental file list

  testrsync

  sent 70 bytes received 27 bytes 194.00 bytes/sec

  total size is 0 speedup is 0.00

  root@ubuntu:/etc# rsync -vzrtopg --delete /tmp/testrsync jifen@192.168.1.3::jifen --password-file=/etc/rsync.pass

  sending incremental file list

  testrsync

  sent 70 bytes received 27 bytes 64.67 bytes/sec

  total size is 0 speedup is 0.00

  到这里配置就完成了,实际上不是什么难事,只不过原本上面就跑了一个进程(/usr/local/rsync),我一上去就往这个目录上配,一直出错,后来问过才知道是要自己搞多一个进程...wtf,看来得事先多做做沟通才行。

  操作过程中遇到的问题:

  问题一

  root@ubuntu:/etc# rsync -vzrtopg --delete /tmp/testrsync jifen@192.168.1.1::jifen --password-file=/etc/rsync.pass

  @ERROR: chroot failed

  rsync error: error starting client-server protocol (code 5) at main.c(1522) [sender=3.0.5]

  解决办法:

  (1) 检查服务、客户端密码文件是否正确:服务端密码文件(这里为/etc/rsync.pass) 的格式为 用户:密码; 客户端密码文件为:密码(没有用户名)

  (2)检查密码文件的权限是否正确

  wuguihong1@ubuntu:~$ ps aux|grep rsync

  root 3978 0.0 0.0 12576 752 ? Ss 16:44 0:00 rsync --daemon --config /etc/rsyncd.conf

  wuguihong1@ubuntu:~$ ll /etc/rsyncd.*

  -rw-r--r-- 1 root root 298 Apr 25 17:04 /etc/rsyncd.conf

  -rw------- 1 root root 18 Apr 25 17:05 /etc/rsyncd.pass

  问题二

  root@ubuntu:/etc# rsync -vzrtopg --delete /tmp/testrsync jifen@192.168.1.1::jifen --password-file=/etc/rsync.pass

  sending incremental file list

  testrsync

  rsync: mkstemp "/.testrsync.k4hMJP" (in jifen) failed: Permission denied (13)

  sent 70 bytes received 27 bytes 64.67 bytes/sec

  total size is 0 speedup is 0.00

  rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1058) [sender=3.0.5]

  解决办法:

  检查服务器端的目录(备份目录)是否存在,并检查其权限。创建目录并修正权限可解决问题。

  问题三

  root@ubuntu:/etc# rsync -vzrtopg --delete /tmp/testrsync jifen@192.168.1.1::jifen --password-file=/etc/rsync.pass

  password file must not be other-accessible

  continuing without password file

  Password:

  解决办法:

  检查服务端和客户端上的密码配置文件权限是否为600(只能为600),若不是可以通过命令 chmod 600 rsync.pass 修改即可

相关文章

优畅享50plus参数配置

2022-04-02 11:15:36    浏览: 107

荣耀play6t参数配置详细介绍

2022-04-02 11:17:16    浏览: 88

iqoo neo6参数配置详情

2022-03-31 10:22:29    浏览: 56

win7查看电脑配置信息教程

2022-03-31 10:27:58    浏览: 107

win7系统对电脑配置有什么要求

2022-03-31 10:29:30    浏览: 81