实验拓扑:HK36(Server 192.168.2.102)====HK46(Client 192.168.2.190)
实验要求:对HK46 /data/目录备份到HK36的/backup/下
(1) rsync服务依赖于xinetd超级服务管理,首先安装xinetd服务
[root@HK36 ~]# yum -y install xinetd
(2) 进入rsync修改配置文件信息,将disable = yes改为no,重启服务,查看873端口是否起来
[root@HK36 ~]# service xinetd restart
Stopping xinetd: [ OK ]
Starting xinetd: [ OK ]
[root@HK36 ~]# netstat -anptu | grep 873
tcp 0 0 :::873 :::* LISTEN 2729/xinetd
(3) 创建非系统测试用户,并对目录/backup赋予用户nobody权限
[root@HK36 backup]# vim /etc/rsyncd.conf
uid = nobody
gid = nobody
address = 192.168.2.102
pid = 873
host allow = 192.168.2.190
use chroot = yes
max_connetion = 5
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsyncd.lock
log file = /var/log/rsyncd.log
motd file = /etc/rsyncd.motd
[backup]
path = /backup/
comment = data for backup
read only = no
auth users = gz
list = yes
[root@HK36 backup]# chown nobody:nobody /backup/
[root@HK36 backup]# vim /etc/rsyncd.motd 创建登入模板文件
welcome to backup data!
[root@HK36 backup]# vim /etc/rs.passwd 创建密码
gz:ggrr50152412
(4) 测试,HK46下创建备份目录测试:
[root@HK36 /]# mkdir /backup/
[root@HK46 /]# mkdir /data/
[root@HK46 data]# ls
22 55 a aaaaa erer kd s test
[root@HK46 data]# rsync -avz ./ --delete [email protected]::backup
(5) 上传inotify并解压安装
[root@HK46 ~]# tar -xvf inotify-tools-3.14.tar.gz -C /usr/local/src/
[root@HK46 inotify-tools-3.14]#./configure --prefix=/usr/local/inotify-tools;make;make install
(6) 直接调用命令
[root@HK36 ~]# ln -s /usr/local/inotify-tools/bin/* /usr/bin/
[root@HK46 ~]# vim /root/passfile 创建密码文件
ggrr50152412
[root@HK46 data]# chmod 600 /root/passfile并赋予600权限
(7) 测试
(8) 编辑脚本,并赋予执行权限
#!/bin/bash
backup_Server=192.168.2.102
/usr/bin/inotifywait -mrq --format '%w%f' -e create,close_write,delete /data/ | while read line
do
cd /data/
rsync -az ./ --delete gz@$backup_Server::backup --password-file=/root/ passfile
done
[root@HK46 ~]# vim inotify.sh
(9) 测试成功
使用LAMP环境搭建wordpress论坛 :https://blog.51cto.com/13719714/2108415