CentOS6.4_X86_X64-Rsync3.0.9自动同步图片服务器资源
客户端/服务器系统环境 CentOS6.4_X86_X64 最小化安装
客户端IP:10.10.0.182
服务端IP:10.10.0.187
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
[root@localhost ~]# yum update -y 更新系统 [root@localhost ~]# yum install -y gcc gcc-c++ make sudo autoconf libtool-ltdl-devel wget lsof nmap [root@localhost ~]# [root@localhost ~]# mkdir -p /data1/webroot/ #客户端同步资源的主目录 [root@localhost ~]# [root@localhost ~]# mkdir -p /data1/source/ #软件源码包存放目录 [root@localhost ~]# [root@localhost ~]# cd /data1/source/ |
服务器端和客户端rsync的安装方法,两个都是一样的装法。
1 2 3 4 5 6 7 |
[root@localhost ~]# wget http://rsync.samba.org/ftp/rsync/rsync-3.0.9.tar.gz [root@localhost ~]# tar zxvf rsync-3.0.9.tar.gz && cd rsync-3.0.9 [root@localhost ~]# ./configure --prefix=/usr/local/rsync [root@localhost ~]# make && make install |
服务器端和客户端主配置文件,其中客户端配置文件中模块配置部分,根据需要,更改 read only 和 write only 参数即可
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
[root@localhost ~]# vim /etc/rsyncd.conf uid = nobody gid = nobody use chroot = no max connections = 30 #最大连接数 pid file = /var/run/rsyncd.pid lock file = /var/run/rsyncd.lock log file = /usr/local/rsync/rsyncd.log #日志路径 transfer logging = yes #是否存放日志 #log format = %t %a %m %f %b #日志格式 timeout = 300 #超时时间 #motd file = /usr/local/rsync/rsyncd.motd #欢迎信息文件名称和存放位置(此文件没有,可以自行添加) #模块配置部分 [webroot] #需要同步的模块名 #list = yes #是否提供资源列表 read only = yes #no客户端可上传文件,yes只读 write only = no #no客户端可下载文件,yes不能下载 path = /data0/webroot/ #要同步的目录 comment = webroot #这个名名称无所谓,和模块名一致就可以了 auth users = jm_backup #认证的用户名,没有默认为匿名。 secrets file = /usr/local/rsync/rsync.pas #认证用户以及密码文件 hosts allow = 10.10.0.182 #本模块允许通过的IP地址 #hosts deny = 123.123.123.123 #禁止主机IP [root@localhost ~]# vim /usr/local/rsync/rsync.pas jm_backup:23#sf2r2323r2d2342@()F#对应的是 用户名:密码 [root@localhost ~]# chmod 600 /usr/local/rsync/rsync.pas [root@localhost ~]# [root@localhost ~]# /usr/local/rsync/bin/rsync --daemon #启动rsync [root@localhost ~]# |
同步文件:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
[root@localhost ~]# rsync -avz --password-file=/usr/local/rsync/rsync.pas \ /data1/webroot jm_backup@10.10.0.187::webroot #从客户端传到服务器上去 [root@localhost ~]# [root@localhost ~]# rsync -aP --delete jm_backup@10.10.0.187::webroot /data1/webroot/ --password-file=/usr/local/rsync/rsync.pas #webroot 指的是模块名,/data1/webroot/ 是客户端的目录,不是服务器端的目录,也可以改成其他你需要同步的目录 [root@localhost ~]# [root@localhost ~]# rsync -vzrtopg --delete --progress jm_backup@10.10.0.187::webroot /data1/webroot [root@localhost ~]# |
No Comments