DRBD安装:(HA高可用集群。在CentOS 7的版本下)
环境:
172.25.0.29 node1
172.25.0.30 node2
1.首先我们需要在node1和node2上添加一块硬盘,我这里就添加2G的硬盘来做演示:
[root@node1 ~]# fdisk -l | grep /dev/sdb
Disk /dev/sdb: 2147 MB, 2147483648 bytes, 4194304 sectors
[root@node2 ~]# fdisk -l | grep /dev/sdb
Disk /dev/sdb: 2147 MB, 2147483648 bytes, 4194304 sectors
2、我们需要修改hosts文件保证hosts之间能够互相访问:
node1上:
[root@node1 ~]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
172.25.0.29 node1
172.25.0.30 node2
node2上:
[root@node2 ~]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
172.25.0.29 node1
172.25.0.30 node2
3、在node1修改ssh互信:
[root@node1 ~]# ssh-keygen
[root@node1 ~]# ssh-copy-id node2
The authenticity of host 'node2 (172.25.0.30)' can't be established.
ECDSA key fingerprint is ae:88:02:59:f9:7f:e9:4f:48:8d:78:d2:6f:c7:7a:f1.
Are you sure you want to continue connecting (yes/no)? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: WARNING: All keys were skipped because they already exist on the remote system.
4、在node1和node2上设置时钟同步:
node1:
[root@node1 ~]# crontab -e
*/5 * * * * ntpdate cn.pool.ntp.org ###添加任务
node2:
[root@node1 ~]# crontab -e
*/5 * * * * ntpdate cn.pool.ntp.org ###添加任务
在node1和node2上可以看到已经添加时间任务:
[root@node1 ~]# crontab -l
*/5 * * * * ntpdate cn.pool.ntp.org
[root@node2 ~]# crontab -l
*/5 * * * * ntpdate cn.pool.ntp.org
5、现在我们就要开始安装drbd包在node1和node2操作:
node1上:
[root@node1 ~]# rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
[root@node1 ~]# rpm -Uvh
Retrieving http://www.elrepo.org/elrepo-release-7.0-2.el7.elrepo.noarch.rpm
Retrieving http://elrepo.org/elrepo-release-7.0-3.el7.elrepo.noarch.rpm
Preparing... ################################# [100%]
Updating / installing...
1:elrepo-release-7.0-3.el7.elrepo ################################# [100%]
[root@node1 ~]#yum install -y kmod-drbd84 drbd84-utils kernel* ##装完重启一下
node2上:
[root@node2 ~]# rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
[root@node2 ~]# rpm -Uvh
Retrieving http://www.elrepo.org/elrepo-release-7.0-2.el7.elrepo.noarch.rpm
Retrieving http://elrepo.org/elrepo-release-7.0-3.el7.elrepo.noarch.rpm
Preparing... ################################# [100%]
Updating / installing...
1:elrepo-release-7.0-3.el7.elrepo ################################# [100%]
[root@node2 ~]#yum install -y kmod-drbd84 drbd84-utils kernel*
6、主配置文件:
/etc/drbd.conf #主配置文件
/etc/drbd.d/global_common.conf #全局配置文件
7、查看主配置文件:
[root@node1 ~]# 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";
8、配置文件说明:
[root@node1 ~]# vim /etc/drbd.d/global_common.conf
global {
usage-count no; #是否参加DRBD使用统计,默认为yes。官方统计drbd的装机量,改为no
# minor-count dialog-refresh disable-ip-verification
}
common {
protocol C; #使用DRBD的同步协议,添加这一行
handlers {