1、使用的资源:
1.1 系统centos6.9 mini
1.2 两台节点主机node1、node2
192.168.1.132 node1
192.168.1.124 node2
1.3 DRBD
disk: /dev/sdb1 10G
DRBD device: /dev/drbd1
DRBD resource: vz1
挂载目录 /vz/vz1
2、设置hostname,ip地址,关闭iptables,selinux
2.1 node1
[[email protected] ~]# hostname
node1
[[email protected] ~]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.1.132 node1
192.168.1.124 node2
[[email protected] ~]# service iptables status
iptables: Firewall is not running.
[[email protected] ~]# getenforce
Disabled
[[email protected] ~]# ifconfig eth0
eth0 Link encap:Ethernet HWaddr 00:0C:29:BC:22:FE
inet addr:192.168.1.132 Bcast:192.168.1.255 Mask:255.255.255.0
2.2 node2
[[email protected] ~]# hostname
node2
[[email protected] ~]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.1.132 node1
192.168.1.124 node2
[[email protected] ~]# service iptables status
iptables: Firewall is not running.
[[email protected] ~]# getenforce
Disabled
[[email protected] ~]# ifconfig eth0
eth0 Link encap:Ethernet HWaddr 00:0C:29:D6:96:1C
inet addr:192.168.1.124 Bcast:192.168.1.255 Mask:255.255.255.0
3.配置ssh无密钥通信
3.1 在node1上
[[email protected] ~]# ssh-keygen -t rsa -b 1024
#按enter键
[[email protected] ~]# ssh-copy-id -i /root/.ssh/id_rsa.pub [email protected]
#输入node2的密码
3.2 在node2上
[[email protected] ~]# ssh-keygen -t rsa -b 1024
#按enter键
[[email protected] ~]# ssh-copy-id -i /root/.ssh/id_rsa.pub [email protected]
#输入node1的密码
4.在node1和node2上建立同样大小的分区/dev/sdb1
4.1 分区
[[email protected] ~]# fdisk /dev/sdb
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-2610, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-2610, default 2610): +10G
Command (m for help): p
Disk /dev/sdb: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x7b1a86d9
Device Boot Start End Blocks Id System
/dev/sdb1 1 1306 10490413+ 83 Linux
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
4.2 在node1和node2 格式分区格式为ext4
[[email protected] ~]# mkfs -t ext4 /dev/sdb1
[[email protected] ~]# tune2fs -c 0 -i -1 /dev/sdb1
[[email protected] ~]# mkfs -t ext4 /dev/sdb1
[[email protected] ~]# tune2fs -c 0 -i -1 /dev/sdb1
5.安装perl* 包和drbd的安装包上传到node1和node2上的/root/tools/hbvz/目录
[[email protected] hbvz]#yum install -y perl*
[[email protected] hbvz]# yum install -y lrzsz
[[email protected] ~]# cd /root/tools/hbvz/
[[email protected] hbvz]# ls
[[email protected] hbvz]# rz
[[email protected] hbvz]# ls
drbd83-utils-8.3.13-1.el6.elrepo.x86_64.rpm
[[email protected] hbvz]#yum install -y perl*
[[email protected] hbvz]# yum install -y lrzsz
[[email protected] ~]# cd /root/tools/hbvz/
[[email protected] hbvz]# ls
[[email protected] hbvz]# rz
[[email protected] hbvz]# ls
drbd83-utils-8.3.13-1.el6.elrepo.x86_64.rpm
6.安装drbd包
6.1检查内核版本,内核版本要和drbd的版本相对应(由于版本不一样,现在升级内核版本)
[[email protected] hbvz]# uname -r
2.6.32-696.el6.x86_64
[[email protected] hbvz]# cd /etc/yum.repos.d/
[[email protected] yum.repos.d]# ls
CentOS-Base.repo CentOS-Debuginfo.repo CentOS-fasttrack.repo CentOS-Media.repo CentOS-Vault.repo
[[email protected] yum.repos.d]#cd /etc/yum.repos.d
[[email protected] yum.repos.d]#wget http://download.openvz.org/openvz.repo
[[email protected] yum.repos.d]#rpm --import http://download.openvz.org/RPM-GPG-Key-OpenVZ
[[email protected] yum.repos.d]# yum install -y vzkernel
#配置OS内核参数,进入/etc/sysctl.conf文件,需要重启才会生效
kernel.sysrq = 1
[[email protected] hbvz]# uname -r
2.6.32-696.el6.x86_64
[[email protected] hbvz]# cd /etc/yum.repos.d/
[[email protected] yum.repos.d]# ls
CentOS-Base.repo CentOS-Debuginfo.repo CentOS-fasttrack.repo CentOS-Media.repo CentOS-Vault.repo
[[email protected] yum.repos.d]#cd /etc/yum.repos.d
[[email protected] yum.repos.d]#wget http://download.openvz.org/openvz.repo
[[email protected] yum.repos.d]#rpm --import http://download.openvz.org/RPM-GPG-Key-OpenVZ
[[email protected] yum.repos.d]# yum install -y vzkernel
6.2 在node1和node2安装drbd,并且加载模块(drbd包也可以直接yum 下载)
[[email protected] hbvz]# rpm -Uvh drbd83-utils-8.3.13-1.el6.elrepo.x86_64.rpm
warning: drbd83-utils-8.3.13-1.el6.elrepo.x86_64.rpm: Header V4 DSA/SHA1 Signature, key ID baadae52: NOKEY
Preparing... ########################################### [100%]
1:drbd83-utils ########################################### [100%]
[[email protected] hbvz]# modprobe drbd
[[email protected] ~]# cd /root/tools/hbvz/
[[email protected] hbvz]# rpm -Uvh drbd83-utils-8.3.13-1.el6.elrepo.x86_64.rpm
warning: drbd83-utils-8.3.13-1.el6.elrepo.x86_64.rpm: Header V4 DSA/SHA1 Signature, key ID baadae52: NOKEY
Preparing... ########################################### [100%]
1:drbd83-utils ########################################### [100%]
[[email protected] hbvz]# modprobe drbd
7.在node1、node2 上测试/dev/sdb1分区的磁盘
[[email protected] hbvz]# dd if=/dev/zero of=/dev/sdb1 bs=1M count=1
1+0 records in
1+0 records out
1048576 bytes (1.0 MB) copied, 0.0968801 s, 10.8 MB/s
[[email protected] hbvz]# dd if=/dev/zero of=/dev/sdb1 bs=1M count=1
1+0 records in
1+0 records out
1048576 bytes (1.0 MB) copied, 0.0968801 s, 10.8 MB/s
8.编写drbd的配置文件
8.1 在node1上
[[email protected] hbvz]# /bin/cp /root/tools/hbvz/global_common.conf -f /etc/drbd.d/
[[email protected] hbvz]# vi vz1.res
[[email protected] hbvz]# cat vz1.res
resource vz1 {
on node1 {
device /dev/drbd1;
disk /dev/sdb1;
address 192.168.1.132:7788;
flexible-meta-disk internal;
}
on node2 {
device /dev/drbd1;
disk /dev/sdb1;
address 192.168.1.124:7788;
meta-disk internal;
}
}
[[email protected] hbvz]# /bin/cp /root/tools/hbvz/vz1.res -f /etc/drbd.d/
8.2 将node1机器上的drbd配置文件都复制到node2机器上
[[email protected] hbvz]# scp -r /etc/drbd* [email protected]:/etc/
drbd.conf 100% 133 0.1KB/s 00:00
vz1.res 100% 293 0.3KB/s 00:00
global_common.conf 100% 1896 1.9KB/s 00:00
9、启动drbd服务
9.1 在node1 上
[[email protected] hbvz]# drbdadm create-md all
Writing meta data...
initializing activity log
NOT initialized bitmap
New drbd meta data block successfully created.
[[email protected] hbvz]# drbdadm up all
[[email protected] hbvz]# drbd-overview
1:vz1 WFConnection Secondary/Unknown Inconsistent/DUnknown C r----s
[[email protected] hbvz]# /etc/init.d/drbd start
#填入yes
9.2 在node2 上
[[email protected] hbvz]# drbdadm create-md all
Writing meta data...
initializing activity log
NOT initialized bitmap
New drbd meta data block successfully created.
[[email protected] hbvz]# drbdadm up all
[[email protected] hbvz]# drbd-overview
1:vz1 Connected Secondary/Secondary Inconsistent/Inconsistent C r-----
[[email protected] hbvz]# /etc/init.d/drbd start
Starting DRBD resources: [ ].
#注意红色的字体,现在两个节点都是备份节点
10.将vz1资源的master机器是node1
[[email protected] hbvz]# drbdadm -- --overwrite-data-of-peer primary vz1
[[email protected] hbvz]# drbd-overview
1:vz1 SyncSource Primary/Secondary UpToDate/Inconsistent C r-----
[>...................] sync‘ed: 5.2% (9724/10244)M
#现在看到node1为主节点了,并且在同步数据
11.在node1上创建文件系统,并且挂载
[[email protected] hbvz]# mkfs.ext4 /dev/drbd1
[[email protected] hbvz]# tune2fs -c 0 -i -1 /dev/drbd1
[[email protected] hbvz]# mkdir /vz/vz1 -p
[[email protected] hbvz]# mount /dev/drbd1 /vz/vz1/
12.上传数据到/vz/vz1上
[[email protected] vz1]# ls
lost+found openstack-sdn.wmv
13.测试
13.1 重启node1,在node2 上新建目录/vz/vz1,然后把node2 设置为主节点,将/dev/drbd1挂载到/vz/vz1
[[email protected] vz1]# drbdadm -- --overwrite-data-of-peer primary vz1
[[email protected] vz1]# mount /dev/drbd1 /vz/vz1
[[email protected] vz1]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 9.8G 1.5G 7.8G 16% /
tmpfs 233M 0 233M 0% /dev/shm
/dev/sda1 477M 53M 399M 12% /boot
/dev/drbd1 9.8G 289M 9.0G 4% /vz/vz1
[[email protected] vz1]# cd /vz/vz1
[[email protected] vz1]# ls
lost+found openstack-sdn.wmv
#看到之前上传的东西恢复了
[[email protected] ~]# drbd-overview
1:vz1 Connected Secondary/Secondary UpToDate/UpToDate C r-----
[[email protected] ~]# drbd-overview
1:vz1 Connected Secondary/Primary UpToDate/UpToDate C r-----
#看到node1上的变化从次节点变为主节点
13.2 现在node2为主节点,当它崩溃之后,把node1设置为主节点,看看node2上的数据还在
[[email protected] vz1]# echo c >/proc/sysrq-trigger
#此为测试环境,慎用这个命令,node2 已经崩溃
[[email protected] ~]# ping 192.168.1.124
PING 192.168.1.124 (192.168.1.124) 56(84) bytes of data.
From 192.168.1.132 icmp_seq=2 Destination Host Unreachable
From 192.168.1.132 icmp_seq=3 Destination Host Unreachable
From 192.168.1.132 icmp_seq=5 Destination Host Unreachable
[[email protected] ~]# drbdadm -- --overwrite-data-of-peer primary vz1
[[email protected] ~]# mount /dev/drbd1 /vz/vz1/
[[email protected] ~]# cd /vz/vz1/
[[email protected] vz1]# ls
hadoop脚本.docx iaas平台搭建.mp4 lost+found openstack-sdn.wmv
原文地址:https://www.cnblogs.com/derrickrose/p/8386103.html