Rsync項(xiàng)目案例

節(jié)點(diǎn)名稱 用途 IP地址 網(wǎng)站發(fā)布路徑

Web1 服務(wù)節(jié)點(diǎn)1 192.168.1.11 /web1/wwwroot

Web2 服務(wù)節(jié)點(diǎn)2 192.168.1.22 /web2/wwwroot

Server 內(nèi)容發(fā)布節(jié)點(diǎn) 192.168.1.99 /web/wwwroot

Setup-1、在2個(gè)服務(wù)節(jié)點(diǎn)上配置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、在內(nèi)容發(fā)布節(jié)點(diǎn)上的配置

[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



同步兩個(gè)文件夾(被同步端)

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腳本,兩個(gè)目錄分開寫即可

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容