rsync小实验

实验要求: 3 台服务器需要配置 rsync C/S 模式,配置成一个客户端,多个 服务器端的模式。在 serverO 中部署 rsync 客户端,在 serverP 和 serverQ 中部署 rsync 的服务器端,需要编写 rsync 的配置文件,配置文件内要包含认证的用户名和密码信息,以及同步模块, 同步的目录为/opt。测试文件使用/var/log/message,将此文件拷贝到/opt 目录下,然后从 serverO 同步到 serverP 和 serverQ 中。

实验环境

客户端   server o 192.168.64.10 rsync inotify

服务器端 server p 192.168.64.20 rsync

服务器端 server q 192.168.64.30 rsync

server p (192.168.64.20)

systemctl stop firewalld.service 
setenforce 0

yum -y install rsync 

vim /etc/rsyncd.conf 

uid = root
gid = root
use chroot = yes                                                
address = 192.168.64.20
port 873                                                                
log file = /var/log/rsyncd.log                  
pid file = /var/run/rsyncd.pid                  
hosts allow = 192.168.64.0/24
[wwwroot]                                                               
path = /opt                                    
comment = Document Root of www.wmc.com
read only = no                                                  
dont comperss = *.gz *.bz2 *.tgz *.zip *.rar *.z        
auth users = p                                               
secrets file = /etc/rsyncd_users.db

vim /etc/rsyncd_users.db
p:995620

chmod 600 /etc/rsyncd_users.db

rsync --daemon

 

server q (192.168.64.30)

systemctl stop firewalld.service 
setenforce 0

yum -y install rsync 

vim /etc/rsyncd.conf 

uid = root
gid = root
use chroot = yes                                                
address = 192.168.64.30
port 873                                                                
log file = /var/log/rsyncd.log                  
pid file = /var/run/rsyncd.pid                  
hosts allow = 192.168.64.0/24
[wwwroot]                                                               
path = /opt                                    
comment = Document Root of www.wmc.com
read only = no                                                  
dont comperss = *.gz *.bz2 *.tgz *.zip *.rar *.z        
auth users = q                                               
secrets file = /etc/rsyncd_users.db

vim /etc/rsyncd_users.db
q:995620

chmod 600 /etc/rsyncd_users.db

rsync --daemon

 

server o (192.168.64.10)

systemctl stop firewalld.service 
setenforce 0

yum -y install rsync

chmod 777 /opt

vim /etc/server.pass
995620

chmod 600 /etc/server.pass 

vim /etc/sysctl.conf 

fs.inotify.max_queued_events = 32768
fs.inotify.max_user_instances = 1024
fs.inotify.max_user_watches = 1048576

sysctl -p

yum -y install gcc gcc-c++ 


tar xf inotify-tools-3.14.tar.gz


cd inotify-tools-3.14/

./configure
make && make install

同步脚本

#!/bin/bash
INOTIFY_CMD="inotifywait -mrq -e create,delete,move,modify,attrib /opt/"
RSYNC_CMDp="rsync -azH --delete --password-file=/etc/server.pass /opt/ p@192.168.64.20::wwwroot"
RSYNC_CMDq="rsync -azH --delete --password-file=/etc/server.pass /opt/ q@192.168.64.30::wwwroot"
$INOTIFY_CMD | while read DIRECTORY EVENT FILE
do
    if [ $(pgrep rsync | wc -l) -le 0 ] ; then
        $RSYNC_CMDp
        $RSYNC_CMDq
        fi
done

 

执行验证

测试文件使用/var/log/message,将此文件拷贝到/opt 目录下,然后从 serverO 同步到 serverP 和 serverQ 中。

server o (192.168.64.10)

vim inotify.sh
cp /var/log/messages /opt


server p (192.168.64.20) server q (192.168.64.30)

ls /opt

另开终端 

 

server p  server q 都同步了messages文件

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值