平顶山城市建设局网站,酷特智能服装定制,免费开网店,wordpress更换域名图片不显示NFS搭建 单节点安装配置服务器安装配置启动并使NFS服务开机自启客户端挂载查看是否能发现服务器的共享文件夹创建挂载目录临时挂载自动挂载 双节点安装配置服务器安装配置服务端配置NFS服务端配置Keepalived编辑nfs_check.sh监控脚本安装部署RsyncInofity 客户端 单节点安装配置… NFS搭建 单节点安装配置服务器安装配置启动并使NFS服务开机自启客户端挂载查看是否能发现服务器的共享文件夹创建挂载目录临时挂载自动挂载 双节点安装配置服务器安装配置服务端配置NFS服务端配置Keepalived编辑nfs_check.sh监控脚本安装部署RsyncInofity 客户端 单节点安装配置
服务器
操作系统IP地址子网掩码角色alma linux9.310.168.31.18016serveralma linux9.310.168.31.18116clientalma linux9.310.168.31.18216clientalma linux9.310.168.31.18316client
安装
在每台机器上执行下列的命令
dnf install -y nfs-utils rpcbind配置
NFS配置文件 /etc/exports
挂载目录 一般来说会挂载一块高性能磁盘作为NFS的目录使用。本文未挂载额外磁盘磁盘挂载请参考此文章其余相同。 这里使用数据目录为/nfs如果没有需要自行创建。
mkdir /nfs访问的主机
IP允许范围10.168.31.180单个主机10.168.0.0/1610.168.31.18110.168.0.*10.168.31.182主机名DNS A解析 轮询
权限
权限作用rw可读可写ro只读sync写到磁盘才算完成安全慢async异步写到远程缓冲区快不安全no_root_squash允许NFS客户端上的root用户对NFS共享目录拥有至高权限no_all_squash客户端所有用户拥有服务端匿名用户权限
echo /nfs 10.168.0.0/16(rw,sync,no_root_squash,no_all_squash) /etc/exports启动并使NFS服务开机自启
systemctl start nfs-server.service
systemctl enable nfs-server.service客户端挂载
查看是否能发现服务器的共享文件夹
showmount -e IP创建挂载目录
mkdir /nfs临时挂载
NFS客户端挂载的命令格式
# 挂载命令 挂载的格式类型 NFS服务器提供的共享目录 NFS客户端要挂载的目录必须存在
# mount -t nfs server-ip:/shared-directory /nfs
# 示例
mount -t nfs 10.168.31.180:/nfs /nfs自动挂载
# NFS服务器提供的共享目录 NFS客户端要挂载的目录必须存在 挂载的格式类型 挂载时使用的参数 是否进行备份 fsck检查文件系统的优先级
# server-ip:/shared-directory /nfs nfs defaults 0 0
# 示例
echo 10.168.31.180:/nfs /nfs nfs defaults 0 0 /etc/fstab双节点安装配置
服务器
操作系统IP地址子网掩码角色alma linux9.310.168.31.18016serveralma linux9.310.168.31.18116serveralma linux9.310.168.31.18216clientalma linux9.310.168.31.18316clientalma linux9.310.168.31.17116vip
安装
在每台机器上执行下列的命令
dnf install -y nfs-utils rpcbind同时对10.168.31.180和10.168.31.181两个服务端做Keepalived负载均衡。具体配置参考Keepalived部署。
配置
服务端
配置NFS服务端
参考单节点服务端配置
配置Keepalived
参考Keepalived部署
配置文件需要在参考文章基础上做修改
mkdir -p /etc/keepalived
cat EOF | tee /etc/keepalived/keepalived.conf
! Configuration File for keepalivedglobal_defs {router_id LVS_DEVEL
}# 增加脚本
vrrp_script chk_nfs {script /etc/keepalived/nfs_check.sh interval 2weight -20
}
vrrp_instance VI_1 {state MASTER #主节点interface ens160virtual_router_id 51 #相同id管理同一个虚拟路由priority 100 #优先级advert_int 1authentication {auth_type PASSauth_pass 1111}# 引用脚本track_script {chk_nfs}virtual_ipaddress {10.168.31.171/16 dev ens160 label ens160:1}
}
EOF编辑nfs_check.sh监控脚本
mkdir -p /etc/keepalived
cat EOF | tee /etc/keepalived/nfs_check.sh
#!/bin/bash
A\ps -C nfsd --no-header | wc -l\
if [ \$A -eq 0 ];thensystemctl restart nfs-server.servicesleep 2if [ \ps -C nfsd --no-header| wc -l\ -eq 0 ];thenpkill keepalivedfi
fi
EOF
chmod x /etc/keepalived/nfs_check.sh安装部署RsyncInofity
两台master节点都要操作
安装软件
dnf install -y rsync inotify-toolsinotify-tools无法安装可以先换成阿里源
dnf install -y https://mirrors.aliyun.com/epel/epel-release-latest-9.noarch.rpm
sed -i s|^#baseurlhttps://download.example/pub|baseurlhttps://mirrors.aliyun.com| /etc/yum.repos.d/epel*
sed -i s|^metalink|#metalink| /etc/yum.repos.d/epel*
dnf install -y inotify-tools配置 在第一个主节点
cat EOF | tee /etc/rsyncd.conf
uid root
gid root
# 如果use chroot指定为true那么rsync在传输文件以前首先chroot到path参数所指定的目录下。
# 这样做的原因是实现额外的安全防护但是缺点是需要以roots权限并且不能备份指向外部的符号连接所指向的目录文件。
# 默认情况下chroot值为true。
use chroot yes
port 873
#允许ip访问设置可以指定ip或ip段
hosts allow 10.168.0.0/16
max connections 0
timeout 300
pid file /var/run/rsyncd.pid
lock file /var/run/rsyncd.lock
log file /var/log/rsyncd.log
log format %t %a %m %f %b
transfer logging yes
syslog facility local3# 模块名称和comment对应
[master]
# 要同步的目录
path /nfs
# 当前节点模块名称
comment master
# 是否允许客户端上传文件
ignore errors
read only no
list no
# 指定由空格或逗号分隔的用户名列表只有这些用户才允许连接该模块
auth users rsync
# 保存密码和用户名文件需要自己生成
secrets file /etc/rsync/rsyncd.passwd
EOF# 创建自定义配置文件目录
mkdir /etc/rsync# 密码和用户文件格式为用户名:密码
cat EOF | tee /etc/rsync/rsyncd.passwd
rsync:123456
EOF# 编辑同步密码注意这个文件和上面的密码和用户文件路径不一样
# 该文件内容只需要填写从服务器的密码例如这里从服务器配的用户名密码都是rsync:123456则主服务器则写123456一个就可以了
cat EOF | tee /etc/rsync/slave.passwd
123456
EOF# 设置文件执行权限
chmod 600 /etc/rsync/rsyncd.passwd
chmod 600 /etc/rsync/slave.passwd# 设置开机启动
echo /usr/bin/rsync --daemon /etc/rc.d/rc.local
chmod x /etc/rc.d/rc.local另外一个节点的配置需要修改rsyncd.conf文件内模块的名称为slave其余相同。
测试
rsync -avzP --progress --delete --timeout100 /nfs/ rsync10.168.31.181::slave --password-file/etc/rsync/slave.passwd rsync常用命令
# -v--verbose 详细模式输出传输是的进度信息
# -z--compress 传输是进行压缩以提高传输效率--comperess -level NUM可以按级别压缩
# -a--archive 归档模式表示以递归方式传输文件并保持所有文件属性等于-rtopgDl
# --port 指定端口
# -e ssh -p 2222 指定使用ssh及其端口
# --timeout 超时时间
# --partial-dir 临时目录传输完毕移动到正式目录
# --password-file 指定存密码的文件
# --progress 打印进度
# --delete 删除目标目录中源目录没有的文件
# -P 支持断点综合了--partial --progress两个参数配置自动同步
在主节点
# 自动同步脚本
cat EOF | tee /etc/rsync/rsync_inotify.sh
#!/bin/bash
#配置另外一个节点的IP
host10.168.31.181
#配置另外一个节点的名称
desslave
src/nfs/
password/etc/rsync/slave.passwd
userrsync
inotifywait/usr/bin/inotifywait\$inotifywait -mrq --timefmt %Y%m%d %H:%M --format %T %w%f%e -e modify,delete,create,attrib /nfs/ \\
| while read files ;dorsync -avzP --progress --delete --timeout100 /nfs/ rsync10.168.31.181::slave --password-file/etc/rsync/slave.passwd done
EOF# VIP监控脚本
cat EOF | tee /etc/rsync/vip_monitor.sh
#!/bin/bash
VIP_NUM\ip addr|grep 31.171|wc -l\
RSYNC_INOTIRY_NUM\ps -ef|grep /usr/bin/inotifywait|grep -v grep|wc -l\
if [ \${VIP_NUM} -ne 0 ];thenecho VIP在当前NFS节点服务器上 /dev/null 21if [ \${RSYNC_INOTIRY_NUM} -ne 0 ];thenecho rsync_inotify.sh脚本已经在后台执行中 /dev/null 21elseecho 需要在后台执行rsync_inotify.sh脚本 /dev/null 21/bin/bash -x /etc/rsync/rsync_inotify.sh /dev/null 21fi
elseecho VIP不在当前NFS节点服务器上 /dev/null 21if [ \${RSYNC_INOTIRY_NUM} -ne 0 ];thenecho 需要关闭后台执行的rsync_inotify.sh脚本 /dev/null 21ps -ef|grep rsync_inotify.sh|grep -v grep|awk {print \$2}|xargs kill -9ps -ef|grep /usr/bin/inotifywait|grep -v grep|awk {print \$2}|xargs kill -9elseecho rsync_inotify.sh脚本当前未执行 /dev/null 21fi
fi
EOF# 持续执行脚本
cat EOF | tee /etc/rsync/rsync_monit.sh
#!/bin/bash
while [ 1 1 ]
do/bin/bash -x /etc/rsync/vip_monitor.sh /dev/null 21
done
EOF# 设置rsync_monit.sh脚本的开机启动
chmod 755 /etc/rsync/rsync_inotify.sh
chmod 755 /etc/rsync/vip_monitor.sh
chmod 755 /etc/rsync/rsync_monit.sh
echo nohup sh /etc/rsync/rsync_monit.sh /tmp/rsync_monit.log 21 /etc/rc.d/rc.local
在从节点
# 自动同步脚本
cat EOF | tee /etc/rsync/rsync_inotify.sh
#!/bin/bash
#配置另外一个节点的IP
host10.168.31.180
#配置另外一个节点的名称
desmaster
src/nfs/
password/etc/rsync/slave.passwd
userrsync
inotifywait/usr/bin/inotifywait\$inotifywait -mrq --timefmt %Y%m%d %H:%M --format %T %w%f%e -e modify,delete,create,attrib /nfs/ \\
| while read files ;dorsync -avzP --progress --delete --timeout100 /nfs/ rsync10.168.31.180::master --password-file/etc/rsync/slave.passwd done
EOF# VIP监控脚本
cat EOF | tee /etc/rsync/vip_monitor.sh
#!/bin/bash
VIP_NUM\ip addr|grep 31.171|wc -l\
RSYNC_INOTIRY_NUM\ps -ef|grep /usr/bin/inotifywait|grep -v grep|wc -l\
if [ \${VIP_NUM} -ne 0 ];thenecho VIP在当前NFS节点服务器上 /dev/null 21if [ \${RSYNC_INOTIRY_NUM} -ne 0 ];thenecho rsync_inotify.sh脚本已经在后台执行中 /dev/null 21elseecho 需要在后台执行rsync_inotify.sh脚本 /dev/null 21/bin/bash -x /etc/rsync/rsync_inotify.sh /dev/null 21fi
elseecho VIP不在当前NFS节点服务器上 /dev/null 21if [ \${RSYNC_INOTIRY_NUM} -ne 0 ];thenecho 需要关闭后台执行的rsync_inotify.sh脚本 /dev/null 21ps -ef|grep rsync_inotify.sh|grep -v grep|awk {print \$2}|xargs kill -9ps -ef|grep /usr/bin/inotifywait|grep -v grep|awk {print \$2}|xargs kill -9elseecho rsync_inotify.sh脚本当前未执行 /dev/null 21fi
fi
EOF# 持续执行脚本
cat EOF | tee /etc/rsync/rsync_monit.sh
#!/bin/bash
while [ 1 1 ]
do/bin/bash -x /etc/rsync/vip_monitor.sh /dev/null 21
done
EOF# 设置rsync_monit.sh脚本的开机启动
chmod 755 /etc/rsync/rsync_inotify.sh
chmod 755 /etc/rsync/vip_monitor.sh
chmod 755 /etc/rsync/rsync_monit.sh
echo nohup sh /etc/rsync/rsync_monit.sh /tmp/rsync_monit.log 21 /etc/rc.d/rc.local
客户端
挂载同单节点挂在但是挂载IP为配置的VIP