Linux下Rsync服务器/客户端搭建实战(2)

service rsync
{
    disable = no
    socket_type    = stream
    wait            = no
    user            = root
    server          = /usr/bin/rsync
    server_args    = --daemon --config=/etc/rsyncd/rsynd.conf
    log_on_failure  += USERID
}

    3).重启 xinetd

service xinetd restart

六、客户端配置

  创建密码文件,/etc/rsyncd/rsyncd.pass,并修改为 600 权限

touch /etc/rsyncd/rsyncd.pass
chmod 600 /etc/rsyncd/rsyncd.pass

  /etc/rsyncd/rsyncd.pass 其内密码需要和服务端内/etc/rsyncd/rsyncd.pass指定用户的密码保持一致

239fjdalk@893246dasaATDFBSad 

七、客户端向服务端传输文件,如果是 873 端口,可以把 --port 去掉

rsync -vzrtopg --delete --progress /var/log/access.log linuxidc@192.168.1.100::logs  --password-file=/etc/rsyncd/rsyncd.pass --port=873

  若有需要也可以从服务端拉取文件,需要把服务器的 /etc/rsyncd/rsyncd.conf 中的 write only = yes 给去掉

#拉取整个目录
rsync -vzrtopg --delete --progress  --password-file=/etc/rsyncd/rsyncd.pass --port=873 linuxidc@192.168.1.100::logs  /var/log

#拉取单个文件
rsync -vzrtopg --delete --progress  --password-file=/etc/rsyncd/rsyncd.pass --port=873 linuxidc@192.168.1.100::logs/a.log  /var/log

八、附赠 /etc/init.d/rsync

#!/bin/bash

# chkconfig:  - 85 15
# description: rsync

status1=$(ps -ef | egrep "rsync --daemon.*rsyncd.conf" | grep -v 'grep')
pidfile="/var/run/rsyncd.pid"
start_rsync="rsync --daemon --config=/etc/rsyncd/rsyncd.conf"

function rsyncstart() {
    if [ "${status1}X" == "X" ]; then
        rm -f $pidfile     
        ${start_rsync} 
        status2=$(ps -ef | egrep "rsync --daemon.*rsyncd.conf" | grep -v 'grep')
        if [  "${status2}X" != "X"  ]; then
            echo "rsync service start.......OK"
        fi
    else
        echo "rsync service is running !"   
    fi
}

function rsyncstop() {
    if [ "${status1}X" != "X" ]; then
        kill -9 $(cat $pidfile)
        status2=$(ps -ef | egrep "rsync --daemon.*rsyncd.conf" | grep -v 'grep')
        if [ "${statusw2}X" == "X" ]; then
            echo "rsync service stop.......OK"
        fi
    else
        echo "rsync service is not running !"   
    fi
}

function rsyncstatus() {
    if [ "${status1}X" != "X" ]; then
        echo "rsync service is running !" 
     
    else
        echo "rsync service is not running !" 
    fi
}

function rsyncrestart() {
    if [ "${status1}X" == "X" ]; then
              echo "rsync service is not running..."
              rsyncstart
        else
              rsyncstop
              rsyncstart   
        fi     

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/1fb779320f5300320b734b77eb3496bd.html