Linux 高可用(HA)集群之DRBD详解
CentOS 6.3下DRBD安装配置笔记
基于DRBD+Corosync实现高可用MySQL
===============================
1. 为各主机设置主机名,IP地址,并测试主机连通性
分别为各节点设置主机名
node1:
hostname node1.linuxidc.com
node2:
hostname node2.linuxidc.com
确保各主机在重启之后,主机名保持不变
node1:
sed -i 's/\(HOSTNAME=\).*/\1node1.linuxidc.com/p' /etc/sysconfig/network
node2:
sed -i 's/\(HOSTNAME=\).*/\1node2.linuxidc.com/p' /etc/sysconfig/network
注: 主机重启过程中,会从配置文件 /etc/sysconfig/network中读取主机名,并将其设置为重启后主机名
2. 添加主机名解析: 确保每一个节点的名称都能互相解析
使用hosts文件做主机名解析,在各节点执行如下操作:
cat >ed.txt<<EOF
\$a\172.16.16.15 node1.linuxidc.com
\$a\172.16.16.16 node2.linuxidc.com
EOF
sed -i -f ed.txt /etc/hosts
3. 确保node1,node2之间时间同步
在命令行同步时间(立即生效,且临时生效)
ntpdate 172.16.0.1
设置定时任务(永久生效)
echo "*/5 * * * * /usr/sbin/ntpdate 172.16.0.1 &>/dev/null;/sbin/hwclock -w" >/var/spool/cron/root
4. 配置各节点之间基于ssh免密码免密钥认证通信(非必须)
生成密钥文件在各节点执行如下操作:
node1:
ssh-keygen -t rsa -P ''
ssh-copy-id .ssh/id_rsa.pub node2.linuxidc.com
node2:
ssh-keygen -t rsa -P ''
ssh-copy-id .ssh/id_rsa.pub node1.linuxidc.com
=======================================================================
二、安装配置drdb
=======================================================================
node1 & node2:
rpm -ivh drbd-8.4.3-33.el6.x86_64.rpm drbd-kmdl-2.6.32-358.el6-8.4.3-33.el6.x86_64.rpm
在node1创建并修改DRDB配置文件
# cat /etc/drbd.conf
# You can find an example in /usr/share/doc/drbd.../drbd.conf.example
include "drbd.d/global_common.conf";
include "drbd.d/*.res";
# cd /etc/drbd.d/
# ls
global_common.conf
编辑配置文件global_common.conf,最终内容如下:
# egrep -v '^$|^[[:space:]]*#' global_common.conf
global {
usage-count yes;
}
common {
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 {
protocol C;
cram-hmac-alg "sha1";
}
syncer {