服务器:ubuntu-10.04.3-server-amd64

服务器端(192.168.10.200):

安装

$sudo apt-get install rsync xinetd

配置

1. 编辑/etc/default/rsync 启动rsync作为使用xinetd的守护进程


$sudo vim /etc/default/rsync

RSYNC_ENABLE=inetd

2. 创建 /etc/xinetd.d/rsync 通过xinetd使rsync开始工作

$sudo vim /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
    }


3. 创建 /etc/rsyncd.conf 配置rsync使其在.


$sudo vim /etc/rsyncd.conf

uid = root
gid = root
use chroot = no
max connections = 4
timeout = 300
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsyncd.lock
log file = /var/log/rsyncd.log
[datemail]
path = /gitecroot/databackup
ignore errors
read only = true
list = false
hosts allow = 192.168.10.205
auth users = root
secrets file = /etc/rsyncd.secrets
[home]
path = /home/vmail
ignore errors
read only = true
list = false
hosts allow = 192.168.10.206
auth users = root
secrets file = /etc/rsyncd.secrets
[sqlmail]
path = /gitecroot/sqlbackup
ignore errors
read only = true
list = false
hosts allow = 192.168.10.207
auth users = root
secrets file = /etc/rsyncd.secrets

4. 创建 /etc/rsyncd.secrets 配置用户名和密码.


$sudo vim /etc/rsyncd.secrets

root:123456

4.修改密码文件权限


$sudo chmod 600 /etc/rsyncd.secrets

5. 启动/重启 xinetd


$sudo /etc/init.d/xinetd restart

6. 添加防火墙

$sudo ufw allow 873

#iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 873 -j ACCEPT(redhat系统)

iptables -A INPUT -p tcp --dport 873 -j ACCEPT

iptables -A OUTPUT -p tcp --sport 873 -j ACCEPT

-----------------------------------------------------------

客户端(192.168.10.206):

1、创建密码文件:

$sudo vim /etc/rsyncd.secrets

123456


2、修改密码文件权限

$sudo chmod 600 /etc/rsyncd.secrets //与服务器端名字一致


3、连接测试

/usr/bin/rsync -vzrtopg --progress --delete --password-file=/etc/rsyncd.secrets [email protected]::home  /home/vmail

============================================

排除某些目录:

法1、--exclude=Upload --exclude=uploadfiles

法2、--exclude-from=exfile //exfile 一定要写全路径

cat exfile

Upload

uploadfiles