Rsync项目案例

节点名称 用途 IP地址 网站发布路径

Web1 服务节点1 192.168.1.11 /web1/wwwroot

Web2 服务节点2 192.168.1.22 /web2/wwwroot

Server 内容发布节点 192.168.1.99 /web/wwwroot

Setup-1、在2个服务节点上配置rsync

1-1、 在web1上的配置

[root@web1 ~]# ifconfig eth0

eth0      Link encap:Ethernet  HWaddr 00:0C:29:4E:07:88

inet addr:192.168.1.11  Bcast:192.168.1.255  Mask:255.255.255.0

inet6 addr: fe80::20c:29ff:fe4e:788/64 Scope:Link

UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

RX packets:571 errors:0 dropped:0 overruns:0 frame:0

TX packets:172 errors:0 dropped:0 overruns:0 carrier:0

collisions:0 txqueuelen:1000

RX bytes:137838 (134.6 KiB)  TX bytes:26054 (25.4 KiB)

Interrupt:59 Base address:0x2024

[root@web1 ~]# cat /etc/hosts

# Do not remove the following line, or various programs

# that require network functionality will fail.

192.168.1.11 web1.benet.com web1

192.168.1.22 web2.benet.com web2

192.168.1.99 web.benet.com web

[root@web1 ~]# cat /etc/sysconfig/network

NETWORKING=yes

NETWORKING_IPV6=no

HOSTNAME=web1.benet.com

[root@web1 ~]# vi /etc/rsyncd.conf

uid = nobody

gid = nobody

use chroot = yes

port 873

log file = /var/log/rsyncd.log

pid file = /var/run/rsyncd.pid

hosts allow = 192.168.1.0/24

[web1]

path = /web1/wwwroot/

comment = web1 file

read only = no

uid = root

gid = root

dont compress = *.gz *.bz2 *.tgz *.zip *.rar *.Z

auth users = webuser

secrets file = /etc/web.pass

[root@web1 ~]# vi /etc/web.pass

webuser:pwd123

[root@web1 ~]# chmod 600 /etc/web.pass

[root@web1 ~]# rsync --daemon

[root@web1 ~]# netstat -anpt |grep rsync

tcp        0      0 :::873                      :::*                        LISTEN      4383/rsync

[root@web1 ~]# echo "rsync –daemon &" >> /etc/rc.local

[root@web1 ~]# mkdir -p /web1/wwwroot

1-2、 在web2上的配置

[root@web2 ~]# ifconfig eth0

eth0      Link encap:Ethernet  HWaddr 00:0C:29:FE:39:09

inet addr:192.168.1.22  Bcast:192.168.1.255  Mask:255.255.255.0

inet6 addr: fe80::20c:29ff:fefe:3909/64 Scope:Link

UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

RX packets:322 errors:0 dropped:0 overruns:0 frame:0

TX packets:135 errors:0 dropped:0 overruns:0 carrier:0

collisions:0 txqueuelen:1000

RX bytes:84643 (82.6 KiB)  TX bytes:21765 (21.2 KiB)

Interrupt:59 Base address:0x2024

[root@web2 ~]# cat /etc/hosts

# Do not remove the following line, or various programs

# that require network functionality will fail.

192.168.1.11 web1.benet.com web1

192.168.1.22 web2.benet.com web2

192.168.1.99 web.benet.com web

[root@web2 ~]# cat /etc/sysconfig/network

NETWORKING=yes

NETWORKING_IPV6=no

HOSTNAME=web2.benet.com

[root@web2 ~]# vi /etc/rsyncd.conf

uid = nobody

gid = nobody

use chroot = yes

port 873

log file = /var/log/rsyncd.log

pid file = /var/run/rsyncd.pid

hosts allow = 192.168.1.0/24

[web2]

path = /web2/wwwroot

comment = web2 file

read only = no

uid = root

gid = root

dont compress = *.gz *.bz2 *.tgz *.zip *.rar *.Z

auth users = webuser

secrets file = /etc/web.pass

[root@web2 ~]# vi /etc/web.pass

webuser:pwd123

[root@web2 ~]# chmod 600 /etc/web.pass

[root@web2 ~]# mkdir -p /web2/wwwroot

[root@web2 ~]# rsync --daemon

[root@web2 ~]# netstat -antp |grep rsync

tcp        0      0 0.0.0.0:873                0.0.0.0:*                  LISTEN      4278/rsync

tcp        0      0 :::873                      :::*                        LISTEN      4278/rsync

[root@web2 ~]# echo "rsync --daemon &" >> /etc/rc.local

Setup-2、在内容发布节点上的配置

[root@web ~]# ifconfig eth0

eth0      Link encap:Ethernet  HWaddr 00:0C:29:6C:9D:FF

inet addr:192.168.1.99  Bcast:192.168.1.255  Mask:255.255.255.0

inet6 addr: fe80::20c:29ff:fe6c:9dff/64 Scope:Link

UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

RX packets:184 errors:0 dropped:0 overruns:0 frame:0

TX packets:163 errors:0 dropped:0 overruns:0 carrier:0

collisions:0 txqueuelen:1000

RX bytes:31797 (31.0 KiB)  TX bytes:23579 (23.0 KiB)

Interrupt:59 Base address:0x2024

[root@web ~]# cat /etc/sysconfig/network

NETWORKING=yes

NETWORKING_IPV6=no

HOSTNAME=web.benet.com

[root@web ~]# cat /etc/hosts

# Do not remove the following line, or various programs

# that require network functionality will fail.

192.168.1.11 web1.benet.com web1

192.168.1.22 web2.benet.com web2

192.168.1.99 web.benet.com web

2-1、安装inotify-tools工具

[root@web ~]# tar zxf inotify-tools-3.13.tar.gz

[root@web ~]# cd inotify-tools-3.13

[root@web inotify-tools-3.13]# ./configure ; make ; make install

[root@web ~]# ls /usr/local/bin/

inotifywait  inotifywatch

[root@web ~]# mkdir -p /web/wwwroot

[root@web ~]# vi /etc/server.pass

pwd123

[root@web ~]# chmod 600 /etc/server.pass

2-2、

[root@web ~]# vi /opt/inotify.sh

#!/bin/bash

#

host1=web1

host2=web2

src="/web/wwwroot/"

dst1=web1

dst2=web2

user=webuser

/usr/local/bin/inotifywait -mrq --timefmt '%d/%m/%y %H:%M' --format '%T %w%f%e' -e modify,delete,create,attrib,move $src |while read files

do

/usr/bin/rsync -vzrtopg --delete --password-file=/etc/server.pass $src $user@$host1::$dst1

/usr/bin/rsync -vzrtopg --delete --password-file=/etc/server.pass $src $user@$host2::$dst2

echo "${files} was rsynced" >> /tmp/rsync.log 2>&1

done



同步两个文件夹(被同步端)

uid = nobody

gid = nobody

use chroot = yes

port 873

log file = /var/log/rsyncd.log

pid file = /var/run/rsyncd.pid

#必须修改

hosts allow =10.132.14.153/32

[web1]

path = /eduvideo/mount1

comment = web1 file

read only = no

uid = root

gid = root

dont compress = *.gz *.bz2 *.tgz *.zip *.rar *.Z

auth users = webuser

secrets file = /etc/web.pass

[web2]

path = /eduvideo/mount2

comment = web2 file

read only = no

uid = root

gid = root

dont compress = *.gz *.bz2 *.tgz *.zip *.rar *.Z

auth users = webuser

secrets file = /etc/web.pass


inotify脚本,两个目录分开写即可

你可能感兴趣的:(Rsync项目案例)