就搭建nfs

搭建nfs,就搭着玩

基于rocky8.5的镜像搭建,并且有两台机器,就称为 node1 和node2 了,设置了一个主飘逸到从,但是一旦在回来就会GG,因为master的数据已经跟从的不一致,需要先同步数据,所以需要两边都同步

# 两台机器一样的操作
systemctl disable firewalld
systemctl stop firewalld

dnf install nfs-utils -y
echo '/data/nfs_data  192.168.142.0/24(rw,sync,no_root_squash)' >> /etc/exports
mkdir -p /data/nfs_data
systemctl enable nfs-server
systemctl start nfs-server
showmount -e localhost

dnf install keepalived -y
systemctl enable keepalived.service

sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
setenforce 0

cat >> /etc/sysctl.d/k8s.conf <<EOF
net.ipv4.ip_forward = 1
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
modprobe br_netfilter
sysctl -p /etc/sysctl.d/k8s.conf
vim /etc/keepalived/keepalived.conf # 两台机器的配置就根据下面的进行修改即可, state和虚拟IP改了就行
vrrp_instance VI_1 {
    # 指定 keepalived 的角色,MASTER 表示此主机是主服务器,BACKUP 表示此主机是备用服务器
    state MASTER

    # 指定网卡
    interface ens33

    # 虚拟路由标识,这个标识是一个数字,同一个vrrp实例使用唯一的标识。
    # 即同一vrrp_instance下,MASTER和BACKUP必须是一致的
    virtual_router_id 51

    # 定义优先级,数字越大,优先级越高(0-255)。
    # 在同一个vrrp_instance下,MASTER 的优先级必须大于 BACKUP 的优先级
    priority 150

    # 设定 MASTER 与 BACKUP 负载均衡器之间同步检查的时间间隔,单位是秒
    advert_int 1

    # 设置验证类型和密码
    authentication {
        #设置验证类型,主要有PASS和AH两种
        auth_type PASS
        #设置验证密码,在同一个vrrp_instance下,MASTER与BACKUP必须使用相同的密码才能正常通信
        auth_pass 1111
    }

    #设置虚拟IP地址,可以设置多个虚拟IP地址,每行一个
    virtual_ipaddress {
        # 虚拟 IP
        192.168.142.41
      }
}
# 两台机器操作
systemctl restart keepalived.service
ip a # 查看一下
showmount -e 192.168.142.41

接下来 两台机器的数据进行同步。这个肯定有问题

node02

dnf install -y rsync-daemon rsync-bpc
useradd nfsnobody
cat > /etc/rsyncd.conf <<EOF
uid = nfsnobody
gid = nfsnobody
port = 873
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
log file = /var/log/rsyncd.log
use chroot = no
max connections = 200
read only = false
list = false
fake super = yes
ignore errors
[test_nfs]
path = /data/nfs_data/
auth users = test_nfs
secrets file = /etc/rsync.pass
hosts allow = 192.168.142.0/24
EOF
echo 'test_nfs:123456' > /etc/rsync.pass
chmod 600 /etc/rsync.pass
chown nfsnobody:nfsnobody /data/nfs_data/

node01

# 测试一下
echo "123456" > /etc/rsync.pass
chmod 600 /etc/rsync.pass
rsync -arv /data/nfs_data/ test_nfs@192.168.142.32::test_nfs --password-file=/etc/rsync.pass
cd /usr/local/
wget https://raw.githubusercontent.com/wsgzao/sersync/master/sersync2.5.4_64bit_binary_stable_final.tar.gz
tar xvf sersync2.5.4_64bit_binary_stable_final.tar.gz
mv GNU-Linux-x86/ sersync
cd sersync/
sed -ri 's#<delete start="true"/>#<delete start="false"/>#g' confxml.xml
# 设置监听的目录
sed -ri '24s#<localpath watch="/opt/tongbu">#<localpath watch="/data/nfs_data/">#g' confxml.xml
# 设置 传输的地址,也就是部署了rsyncd的地址
sed -ri '25s#<remote ip="127.0.0.1" name="tongbu1"/>#<remote ip="192.168.142.32" name="test_nfs"/>#g' confxml.xml
# 设置rsync的命令
sed -ri '30s#<commonParams params="-artuz"/>#<commonParams params="-az"/>#g' confxml.xml
# 设置rsync的密码文件
sed -ri '31s#<auth start="false" users="root" passwordfile="/etc/rsync.pas"/>#<auth start="true" users="test_nfs" passwordfile="/etc/rsync.pass"/>#g' confxml.xml
sed -ri '33s#<timeout start="false" time="100"/><!-- timeout=100 -->#<timeout start="true" time="100"/><!-- timeout=100 -->#g' confxml.xml
# 启动监测
/usr/local/sersync/sersync2 -dro /usr/local/sersync/confxml.xml
posted @ 2021-11-22 14:18  汉克书  阅读(47)  评论(0编辑  收藏  举报