DRBD的主备安装配置

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

时间: 2024-11-06 03:49:16

DRBD的主备安装配置的相关文章

CentOS6.5和CentOS7.0双网卡主备模式配置

双网卡主备模式配置(bond0) 1     简述 通过双网卡设置主备模式,实现当一块网卡宕掉时,另外一块网卡可以自动顶替宕掉的网卡工作,保障网络正常访问. 2     实现 2.1.  查看网卡信息 执行ifconfig -a命令 2.2.  修改网卡配置文件 切换工作目录 cd /etc/sysconfig/network-scripts/ 修改网卡配置文件ifcfg-eth0 ,保证以下几项内容正确: TYPE=Ethernet BOOTPROTO=dhcp ONBOOT=yes MAST

centos下mysql源码编译安装和主备异步配置

安装机器:10.11.1.193.10.11.1.194 主备同步方式:异步同步 mysql版本:mysql community5.6.28 下载源码并解压: tar -zxf mysql-5.6.28.tar.gz cmake安装: 安装编译所需环境: sudo yum install make gcc-c++ cmake bison-develncurses-devel libaio libaio-devel net-tools perl 编译安装mysql cmake-DCMAKE_INS

Mysql5.7主主互备安装配置

一.安装说明 ======================================================================================= 环境:       10.1.4.57  Centos7.1 10.1.4.58  Centos7.1 说明:需要root权限,遇到的问题都有说明 下载地址: https://dev.mysql.com/downloads/mysql/(mysql-5.7.17-1.el7.x86_64.rpm-bundle

memcached主备安装

一.软件下载 wget http://memcached.googlecode.com/files/memcached-1.4.13.tar.gz wget http://memagent.googlecode.com/files/magent-0.6.tar.gz wget http://monkey.org/~provos/libevent-1.4.9-stable.tar.gz 二.安装libevent-1.4.9-stable.tar.gz tar zxvf libevent-2.0.1

zookeeper+activemq主备简单配置

硬件环境:       三台linux服务器:192.168.2.13,192.168.2.15,192.168.2.16.       推荐部署在三台机器上,都部署在一台机器还是会有单点故障,最少1G的内存就够了. 下载最新版本的zookeeper,apache-activemq(都是linux的64位,jdk什么的就不说了) 下面的配置三台机器基本都是一样,特别之处有备注,下面开始搭建. 1.新建文件夹 mqzk (可自己定义)2.解压zookeeper,activmq到此目录.这里路径为:

F5双机(主备)配置详解

详细请查看我的有道云笔记: http://note.youdao.com/noteshare?id=1a8fa875d57e1bab9af1c54c883727a3&sub=E834FFFD584041FE81B0EC2F93E797D8

文件系统:drbd主备服务器文件同步

一. DRBD介绍 DRBD是一种块设备,可以被用于高可用(HA)之中.它类似于一个网络RAID-1功能.当你将数据写入本地 文件系统时,数据还将会被发送到网络中另一台主机上.以相同的形式记录在一个文件系统中. 本地(主节点)与远程主机(备节点)的数据可以保证实时同步.当本地系统出现故障时,远程主机上还会 保留有一份相同的数据,可以继续使用. 在高可用(HA)中使用DRBD功能,可以代替使用一个共享盘阵.因为数据同时存在于本地主机和远程主机上,切换时,远程主机只要使用它上面的那份备份数据,就可以

mysql主从配置&&基于keepalived的主备切换

mysql互为主从设置 && 主备切换配置 需求说明: 1.公司架构一直是一台单独的mysql在线上跑,虽然一直没有出现什么宕机事件,但是出于一个高可用的考虑,提出主从备份.主备切换的需求: 2.实现这个需求的前一段时间只是在做数据库备份的时候实现了主从热备,为了实现主备切换功能,继续操作上述需求: 实验环境: master1:10.1.156.3:3306 master2:10.1.156.5:3306 my.cnf配置文件关于主从这块的修改: master1: server-id =

Mysql 5.6.27 双主模型&&主备模型安装测试

http://dev.mysql.com/get/Downloads/MySQL-5.6/MySQL-5.6.27-1.el6.x86_64.rpm-bundle.tar 测试环境:    两台服务器          MYSQL-1:10.11.22.78          MYSQL-2:10.11.22.248    测试系统          Centos 6.5_64    Mysql版本          MySQL-5.6.27    Keepalived版本          k