centos下配置rsyncd服务器

来源:互联网 发布:ps软件如何放大 编辑:程序博客网 时间:2024/05/29 18:06
首先要保证xinetd守护进程开启,配置文件如下
/etc/xinetd.d/rsync 配置文件
# default: off
# description: The rsync server is a good addition to an ftp server, as it \
#       allows crc checksumming etc.
service rsync
{
        disable = no
        flags           = IPv6
        socket_type     = stream
        wait            = no
        user            = root
        server          = /usr/bin/rsync
        server_args     = --daemon --config=/etc/rsyncd/rsyncd.conf
        log_on_failure  += USERID
}

启动rsyncd服务
rsyncd 服务负载比较高的时候,设定rsyncd为独立的守护进程
#默认配置文件是/etc/rsyncd.conf,所以需要显式的指定配置文件
/usr/bin/rsync --daemon --config=/etc/rsyncd/rsyncd.conf
#假设使用putty,xshell终端操作,保证终端断开进程仍然执行
nohup /usr/bin/rsync --daemon --config=/etc/rsyncd/rsyncd.conf
chkconfig --list  如果rsync no,要把rsync开启
chkconfig rsync on

为了保证开机时自动启动,需要手动加上面的命令(/usr/bin/rsync --daemon --config=/etc/rsyncd/rsyncd.conf)加入 /etc/rc.local 文件中
如果服务器开启了防火墙,必须保证端口能穿过防火墙

iptables -A INPUT -p tcp -m state --state NEW  -m tcp --dport 873 -j ACCEPT

端口号修改为实际端口号即可

  • rsyncd 使用xinetd运行
    xinetd的rsync配置文件是/etc/xinetd.d/rsync
    需要编辑此文件修改一个参数,显式的指定rsyncd服务的配置文件
server_args     = --daemon --config=/etc/rsyncd/rsyncd.conf

注意系统如果没有安装xinetd,需要 yum intall xinetd


service xinetd  restart
首先,检查rsync是否安装,如果没有需要手动安装
#检查是否安装过rsync,或者使用命令  rpm -qa|grep rsync 也可以#使用yum安装rsyncyum install rsync
创建rsyncd服务的配置文件

默认安装后,在/etc目录下,并不存在rsyncd目录,需要手动创建配置文件目录

makdir /etc/rsyncd

在/etc/rsyncd目录下创建如下文件

touch /etc/rsyncd/rsyncd.conf       #主配置文件touch /etc/rsyncd/rsyncd.secrets       #用户名密码文件,一组用户一行,用户名和密码使用 : 分割

必须注意的是,rsyncd服务的密码文件权限必须是600 (如果不行,就弄成400)

chmod 0600 /etc/rsyncd/rsyncd.secrets 
vim rsyncd.secrets 
 test:111222  

编辑主配置文件 rsyncd.conf
uid = www
gid = www
use chroot = no
max connections = 10
strict modes = yes
port = 873
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
log file = /www/logs/rsyncd.log


[backup]
path = /www/htdocs/gutou
comment = This is test
auth users = test
uid = www
gid = www
secrets file = /etc/rsyncd/rsyncd.secrets

read only = no
list = no


客户端端传输数据


rsync -avz --password-file=/usr/pwd/testserver.ps --exclude ".svn" --exclude "other" --exclude "config" --exclude "protected/data" --exclude "APP.php" --exclude "APPbase.php" --exclude "db" --exclude "index.php"  /home/wwwroot/gutou/  svnupload@111.140.161.176::backup

参考文章: http://segmentfault.com/a/1190000000444614


inotify 安装搭建

参考文章
http://www.godblessyuan.com/2015/02/06/rsync_inotify-tools_real-time_mode/
http://www.cnblogs.com/davidwang456/p/3684945.html
https://www.centos.bz/2012/06/inotify-tools-introduction/


wget http://github.com/downloads/rvoicilas/inotify-tools/inotify-tools-3.14.tar.gz  #下载inotify源码包

root@inotify-master tools]# ll inotify-tools-3.14.tar.gz
-rw-r--r-- 1 root root 358772 3月  14 2010 inotify-tools-3.14.tar.gz
[root@inotify-master tools]# tar zxf inotify-tools-3.14.tar.gz
[root@inotify-master tools]# cd inotify-tools-3.14
[root@inotify-master inotify-tools-3.14]# ./configure --prefix=/usr/local/inotify-3.14 #配置inotify,并指定安装路径为/usr/local/inotify-3.14
................................
[root@inotify-master inotify-tools-3.14]# make && make install

修改inotify相关配置:

echo 1638400 > /proc/sys/fs/inotify/max_queued_events
echo 12800 > /proc/sys/fs/inotify/max_user_instances
echo  819200  > /proc/sys/fs/inotify/max_user_watches



#!/bin/sh
src=/www/htdocs/gutou/
/www/server/inotify/bin/inotifywait -mrq \
   --timefmt '%d/%m/%y%H:%M' \
   --exclude "(.swp|.inc|.svn|.rar|.tar.gz|.gz|.txt|.zip|.bak|.swx|.log)" \
   --format '%T%w%f' \
   -e modify,create,attrib $src \
 | while read DATE TIME FILE file 
   do
       #FILECHANGE=${DIR}${FILE}
rsync -avz --password-file=/usr/pwd/testserver.ps --bwlimit=200 \
      --exclude ".svn" \
   $src  svnupload@1.1.1.1::backup  
      echo "${DATE} was rsynced " >> /www/logs/rsync.log 2>&1
   done 

0 0
原创粉丝点击