搭建NFS
假设有2台Server,分别是Server1和Server2。现在要在Server1上安装NFS,在Server2上挂载该目录。
1. 在两台Server上都安装:
yum install portmap nfs-utils nfs-utils-lib
2. 编辑Server1文件/etc/exports:
/var/www/commentator/images 192.168.10.1(rw,sync,no_root_squash)
3. 在Server1上启动NFS:
service rpcbind start
扫描二维码关注公众号,回复:
1230155 查看本文章
service nfs start
4. 在Server2上挂载该目录
mount -t nfs 192.168.10.1:/var/www/commentator/images /mnt/images
设置rsync+inotify实时备份
现在要将Server1上的NFS目录备份到Server3上。
1. 在Server1和Server3上安装rsync和inotify。
yum install rsync inotify-tools
2. 配置SSH,让Server1可以远程访问Server3。
3. 在Server1上创建同步脚本rsync_images_backup.sh。
#!/bin/sh source=/var/www/commentator/images/profile [email protected]:/var/local/commentator/backup/images inotifywait -mrq -e modify,delete,create,attrib $source | while read D E F do /usr/bin/rsync -ahqzt --delete $source $destination done
4. 运行该脚本。
nohup ./rsync_images_backup.sh >/dev/null 2>&1 &
配置结束,在Server1上添加一个文件,在Server2上查看挂载目录里的文件是否更新,在Server3上查看文件是否自动备份。