现在的位置: 首页 > 综合 > 正文

rsync命令:

2018年05月07日 ⁄ 综合 ⁄ 共 1762字 ⁄ 字号 评论关闭

1首先在服务端和客户端检查是否都安装了rsync,我的RHEL5默认已经安装好了是安装,如果没安装,按照下面的方式进行:

wgethttp://rsync.samba.org/ftp/rsync/src/rsync-3.1.0.tar.gz 

tar –xzvf rsync-3.1.0.tar.gz

cd rsync-3.1.0/

./configure --prefix=/usr/local/rsync

make

make install

2修改服务端rsync的配置文件:(/etc/xinetd.d/rsync)

可以看到rysnc服务是关闭的(disable = yes),这里把它开启,把disable的值改为no

3创建rsync服务器配置文件/etc/rsyncd.conf(服务端)

[root@hyjetc]# vim /etc/rsyncd.conf

uid= root

gid= root

port= 873    #指定运行端口,默认是873,您可以自己指定

hostsallow = 192.168.0.204, 192.168.1.205         #
允许访问的客户机

#hostsdeny = 0.0.0.0/32                      #拒绝访问的

usechroot = no

maxconnections = 50  #最大连接数

timeout=10            #超时

 

##下面这些文件是安装完RSYNC服务后自动生成的文件,当然也可以手动配置到指定路径

pidfile = /var/run/rsyncd.pid      ##pid文件的存放

lockfile = /var/run/rsync.lock     ##锁文件的存放位置

logfile = /var/log/rsyncd.log      ##日志记录文件的存放

#motdfile = /etc/rsyncd.motd      #欢迎

 

##上面这段是全局配置,下面的模块可以有()

[test]                    ##
模块名字,自己命名

path= /home/hyj/workspace/test    #指定文件目录所在位置,这是必须指定——要同步的目录

comment= rsync files                         ##
注释

ignoreerrors                                 ##忽略IO

readonly = no

writeonly = no

list= no                 ##
是否把rsync 服务器上提供同步数据的目录显示

#下面这一行,同步验证时用的账号,如果没有这项就是匿名同步,client同步时不用用户名也能同步。该用户必须系统存在,密码需要再secrets文件中,不是系统密码

authusers = rsync

secretsfile = /etc/rsync.passwd             ##
指定认证文件

 

4)然后创建认证文件:(服务端)

A、创建文件

 [root@hyj etc]# vim /etc/rsync.passwd

 rsync:hyl ##
用户名:密码。注意这个不是系统用户,只是rsync用户。所以不用useradd。

(名字随便写,只要和上边配置文件里的“auth users”参数一致即可),格式(一行一个用户)

账号:密码

B、把密码文件的权限改成600

[root@hyjetc]# chmod 600 /etc/rsync.passwd         ##
只能所有者可读,否则报错

 

5如果在配置文件中指定了欢迎信息,在/etc下创建rsyncd.motd,设置欢迎信息:

[root@hyjetc]# vim /etc/rsyncd.motd

Welcomethe rsync services!

 

6)启动:#/usr/bin/rsync –daemon

配置rsync自动启动
[root@test etc]# chkconfig rsync on
[root@test etc]# chkconfig rsync --list
rsync on

 

7)对于客户端的配置可以和服务端的一样(以上都是服务端),这样就可以双向同步;如果客户端不需要同步,那么直接vi /etc/rsyncd.conf 文件内容为空就行。然后启动rsync

抱歉!评论已关闭.