2009-09-11 16:59
一 什么是RSYNC rsync 是一个linux 系统下文件同步和传输工具,主要同步二个文件的异动部份,因此速度相当快。 rsync 的特性: 1. 能更新整个目录和树和文件系统 2. 有选择性的保持符号链链、硬链接、文件属于、权限、设备以及时间 等 3. 对于安装来说,无任何特殊权限要求 4. 对于多个文件来说,内部流水线减少文件等待的延时 5. 能用 rsh、ssh 或直接端口做为传输入端口 6. 支持匿名 rsync 同步文件,是理想的镜像工具; 二 配置rsync step 1 安装rsync rpm包 rpm -ivh rsync-2.6.8-3.1.i386.rpm rpm -ivh xinetd-2.3.14-10.el5.i386.rpm step 2 服务端的配置 chkconfig xinetd on chkconfig rsync on 开启xinetd 服务以及rsync 服务 vi /etc/xinetd.d/rsync 验证配置文件的内容是否正确 service rsync { disable = no socket_type = stream wait = no user = root server = /usr/bin/rsync server_args = --daemon log_on_failure += USERID } 以上为正确配置。 接下来配置rsync 服务全局配置文件 rsynd.conf vi /etc/rsyncd.conf uid = nobody 系统内建用户 gid = nobody use chroot = no 不使用chroot max connections = 4 最大连接数 pid file = /var/run/rsyncd.pid pid进程号文件保存位置 lock file = /var/run/rsyncd.lock 锁文件位置 log file = /var/log/rsyncd.log 日志文件位置 motd file = /etc/rsyncd.motd host allow = 127.0.0.1 192.168.0.0/255.255.255.0 允许访问 auth users = noah 可访问用户 secrets file = /etc/rsyncd.secrets 密码文件 [home] 名称 path = /home 目录 commnet = bakhome read only = true list = false 写好这个文件之后,接下来创建另外2个需要的文件 /etc/rsyncd.motd /etc/rsyncd.secrets cat > /etc/rsyncd.motd <<EOF this is a test EOF 这类似于一个欢迎画面 cat > /etc/rsyncd.secrets <<EOF noah:123456 EOF 密码文件的格式为 用户名:密码 OK,文件全部创建完了,我们需要修改它们的权限,否则rsyncd 不会正常工作 chmod 600 /etc/rsyncd.conf chmod 600 /etc/rsyncd.motd chmod 600 /etc/rsyncd.secrets 并且修改 /home 目录uid,gid 为nobody step 3 重启服务 service xinetd restart 2 客户端配置 首先创建密码文件,密码要和服务端设置的相同,并修改权限为600 vi /root/secret 123456 :wq 保存退出 chmod 600 /root/secret 然后使用如下命令同步服务端 rsync -Rav --delete --password-file=/root/secret [email protected]::home /tmp |