部署NFS服务
3-1 .安装NFS 服务器端
3.1-1 .nfs软件安装
[root@nfs ~]#yum -y install nfs-utils rpcbind
3-1-2 .创建共享目录
[root@nfs ~]#mkdir /www
3-1-3. 修改/etc/exports配置文件
[root@nfs ~]# vim /etc/exports
/www 192.168.2.0/24(rw,sync,no_all_squash,no_root_squash)
###
rw: 读写权限
sync: 资料同步到写入存储器中
no_all_squash:不以匿名nobody)身份访问
no_root_squash:登录到主机的用户如果是root,该用户即拥有root权限.
3-1-4. 启动服务,开机自启
[root@nfs ~]# systemctl restart rpcbind
[root@nfs ~]# systemctl enable rpcbind
[root@nfs ~]# systemctl restart nfs
[root@nfs ~]# systemctl enable nfs
NFS使用的是随机端口,每次启动NFS都需要将自己的随机端口注册到rpcbind服务,这样客户端访问NFS时先到rpcbind查询端口信息,得到端口信息后再访问NFS服务。
3-1-5. 本地挂载测试
[root@nfs~]# mount 192.168.2.31:/www /mnt
[root@nfs ~]# ll -d /mnt drwxr-xr-x. 2 root root 4096 3月 14 00:14 /mnt
[root@nfs ~]# df
文件系统 1K-块 已用 可用 已用% 挂载点
/dev/vda1 31445996 2651320 28794676 9% /
devtmpfs 712928 0 712928 0% /dev
tmpfs 723768 0 723768 0% /dev/shm
tmpfs 723768 8620 715148 2% /run
tmpfs 723768 0 723768 0% /sys/fs/cgroup
192.168.2.31:/www 144696 0 144696 /mnt
[root@nfs ~]# umount /mnt
3-2. 部署web客户端挂载nfs存储
3-2-1.配置web服务器
[root@web1 ~]#yum install nfs-utils
3-2-2.手动挂载-临时挂载
[root@web1 ~]#mount 192.168.2.31:/www /usr/loca/nginx/html
[root@web1 ~]# df
文件系统 1K-块 已用 可用 已用% 挂载点
/dev/vda1 31445996 2614140 28831856 9% /
devtmpfs 712928 0 712928 0% /dev
tmpfs 723768 0 723768 0% /dev/shm
tmpfs 723768 8648 715120 2% /run
tmpfs 723768 0 723768 0% /sys/fs/cgroup
tmpfs 144696 0 144696 0% /run/user/0
192.168.2.31:/www 31446016 2651136 28794880 9% /usr/local/nginx/html
3-2-3. 配置开机自动挂载-永久挂载
[root@web1 ~]# tail -1 /etc/rc.d/rc.local
mount -t nfs 192.168.2.31:/www /usr/local/nginx/html/ -o \ nolock,nfsvers=3,vers=3
3-2-4.安装其他web服务器
需要在web2,web3 上执行web1相同的操作
3-3. 部署rsync备份服务器
3-3-1.修改配置文件,添加nfsbackup新模块
在配置文件/etc/rsyncd.conf里添加nfsbackup新模块
[nfsbackup]
#使用目录
path = /www-bak
#备份路径
ignore errors
#有错误时忽略
read only = false
#阻止远程列表(不让通过远程方式看服务端共享内容)
list = false
hosts allow = 192.168.2.0/24
#允许IP
hosts deny = 0.0.0.0/32
#禁止IP
3-3-2.启动rsync服务,开机自启
[root@rsync ~]# systemctl restart rsyncd
[root@rsync ~]# systemctl enable rsyncd
[root@rsync ~]# netstat -ntlup | grep rsync
tcp 0 0 0.0.0.0:873 0.0.0.0:* LISTEN 8259/rsync
tcp6 0 0 :::873 :::* LISTEN 8259/rsync
3-4在NFS服务器端配置inotify事件监控工具
3-4-1.安装inotify 监控工具
[root@nfs ~]# yum -y install inotify-tools
3-4-2.编写inotify + rsync 实时监控同步脚本
[root@nfs ~]#vim /root/.inotify-www.sh
#!/bin/bash
while inotifywait -rqq /www/
do
rsync -az –delete /www/ root@192.168.2.22:/www-bak/
done &
[root@nfs ~]#chmod +x /root/.inotify-www.sh
3-4-3添加脚本到开机脚本中:
[root@nfs ~]#echo “/root/.inotify-www.sh” >> /etc/rc.d/rc.local
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END
暂无评论内容