centos7.9镜像 2台主机
1、关闭防火墙;禁用SELinux;2台;
systemctl stop firewalld
setenforce 0
2、配置hosts文件;2台;
vim /etc/hosts
192.168.164.130 node1
192.168.164.140 node2
配置2台服务器之间的免密
配置root用户免密;
主服务器
ssh-keygen -f ~/.ssh/id_rsa -P ;; -q
ssh-copy-id node2
备服务器
ssh-keygen -f ~/.ssh/id_rsa -P ;; -q
ssh-copy-id node1
3、安装软件 ;如果没有yum源;则需要先配置yum源;
导入yum源
rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
yum localinstall -y https://mirrors.tuna.tsinghua.edu.cn/elrepo/elrepo/el7/x86_64/RPMS/elrepo-release-7.0-6.el7.elrepo.noarch.rpm
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
安装DRBD软件包
yum install -y drbd90-utils kmod-drbd90
启动内核模块
modprobe drbd
echo drbd > /etc/modules-load.d/drbd.conf
查看
lsmod | grep drbd
4、配置DRBD
[root;node1 drbd.d]# egrep -v ;#|^$; /etc/drbd.d/global_common.conf
global {
usage-count no;
}
common {
protocol C;
handlers {
pri-on-incon-degr ;/usr/lib/drbd/notify-pri-on-incon-degr.sh; /usr/lib/drbd/notify-emergency-reboot.sh; echo b > /proc/sysrq-trigger ; reboot -f;;
pri-lost-after-sb ;/usr/lib/drbd/notify-pri-lost-after-sb.sh; /usr/lib/drbd/notify-emergency-reboot.sh; echo b > /proc/sysrq-trigger ; reboot -f;;
local-io-error ;/usr/lib/drbd/notify-io-error.sh; /usr/lib/drbd/notify-emergency-shutdown.sh; echo o > /proc/sysrq-trigger ; halt -f;;
}
startup {
}
options {
}
disk {
on-io-error detach;
}
net {
}
}
[root;node1 drbd.d]# cat nfs.res
resource nfs {
disk /dev/sdb;
device /dev/drbd0;
meta-disk internal;
on node1 {
address 192.168.164.130:7789;
}
on node2 {
address 192.168.164.140:7789;
}
}
将配置传送到node2
scp * node2:$PWD
5、启用DRBD
创建设备元数据
[root;node1 ~]# drbdadm create-md nfs
[root;node1 ~]# ssh node2 drbdadm create-md nfs
启用资源
[root;node1 ~]# drbdadm up nfs
[root;node1 ~]# ssh node2 drbdadm up nfs
初始设备同步
[root;node1 ~]# drbdadm primary --force nfs --- 只在node1上操作
等待一段时间进行检查同步情况
drbdadm status nfs
6、验证
2个节点创建挂载点目录;mkdir /data
主节点;mkfs.xfs /dev/drbd0
mount /dev/drbd0 /data
创建测试文件
touch /data/file{1..3}
卸载文件系统并切换为备节点
umount /data
drbdadm secondary nfs
在从上执行以下命令确认文件
drbdadm primary nfs
mount /dev/drbd0 /data
ls -l /data
total 0
-rw-r--r--. 1 root root 0 Jun 10 09:43 file1
-rw-r--r--. 1 root root 0 Jun 10 09:43 file2
-rw-r--r--. 1 root root 0 Jun 10 09:43 file3
启用服务
systemctl start drbd
systemctl enable drbd
基于centos7.9二进制部署kubernetes1.25.4