一步步构建基于DRBD的数据共享
DRBD(Distributed Replocated Blocak Device)分布式的复制块设备 在内核为2.6.33之后的版本中,DRBD就被编译进内核了,所以DRB
DRBD(Distributed Replocated Blocak Device)分布式的复制块设备
在内核为2.6.33之后的版本中,DRBD就被编译进内核了,所以DRBD是在内核中工作的
下面我们就看看DRBD的工作流程图:
当启用drbd功能,并将drbd设备挂载到本地之后,用户空间需要向磁盘上存数据的时候,当数据通过缓存时,drbd就将这些数据分成了两路,一路存储到本地的磁盘上,另一路通过本地的TCP/IP协议栈和网络将数据传输到另个开启drbd服务主机上,这个drbd主机接收数据并将数据存储到本地的drbd设备上,从而实现了数据的共享和同步,然而整个数据的同步过程都是在内核空间中进行的,所以对用户空间没有任何 影响
drbd共有两部分组成:内核模块和用户空间的管理工具
用户空间的管理工具:对内核中数据传输和共享的具体实施过程进行行为定义
内核模块:依用户空间的管理工具的定义的方式来进行数据的传输和共享
Drbd的模型两种:
单主节点:任何资源只能在主节点上进行读写操作,主节点的文件类型可以是任何的,只要是为高可用集群中的资源流转提供一个解决方案。
双主节点:在任何时刻任意用户可以通过任意节点来进行读写操作,但是要结合集群文件系统来实现,所以要通过GFS或者OCFS2来实现其应用,只有在drbd的8.0版本之后才支持
下面我们就通过具体的配置过程来了解drbd各个部分的工作原理
配置前提:
1)本配置共有两个测试节点,分别node1.a.org和node2.a.org,相的IP地址分别为192.168.0.202和192.168.0.204;
2)node1和node2两个节点上各提供了一个大小相同的分区作为drbd设备;我们这里为在两个节点上均为/dev/sda5,大小为1G;
1、准备工作
保证两个节点的主机名称和对应的IP地址解析服务可以正常工作,且每个节点的主机名称需要跟"uname -n“命令的结果保持一致;因此,需要保证两个节点上的/etc/hosts文件均为下面的内容:
192.168.0.202 node1.a.org node1
192.168.0.204 node2.a.org node2
为了使得重新启动系统后仍能保持如上的主机名称,,还分别需要在各节点执行类似如下的命令:
node1:
hostname node1.a.org
hostname node2.a.org
2、安装软件包
drbd共有两部分组成:内核模块和用户空间的管理工具。其中drbd内核模块代码已经整合进Linux内核2.6.33以后的版本中,因此,如果您的内核版本高于此版本的话,你只需要安装管理工具即可;否则,您需要同时安装内核模块和管理工具两个软件包,并且此两者的版本号一定要保持对应。
我们这里选用最新的8.3的版本
下载完成后直接安装即可:
yum -y --nogpgcheck localinstall drbd83-8.3.8-1.el5.CentOS.i386.rpm kmod-drbd83-8.3.8-1.el5.centos.i686.rpm
3、配置drbd
1)复制样例配置文件为即将使用的配置文件:
cp /usr/share/doc/drbd83-8.3.8/drbd.conf /etc
2)配置/etc/drbd.d/global_common.conf
global {
usage-count no;
# minor-count dialog-refresh disable-ip-verification
}
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";
# fence-peer "/usr/lib/drbd/crm-fence-peer.sh";
# split-brain "/usr/lib/drbd/notify-split-brain.sh root";
# out-of-sync "/usr/lib/drbd/notify-out-of-sync.sh root";
# before-resync-target "/usr/lib/drbd/snapshot-resync-target-lvm.sh -p 15 -- -c 16k";
# after-resync-target /usr/lib/drbd/unsnapshot-resync-target-lvm.sh;
}
startup {
wfc-timeout 120;
degr-wfc-timeout 120;
}
disk {
on-io-error detach;
fencing resource-only;
}
net {
cram-hmac-alg "sha1";
shared-secret "mydrbdlab";
}
syncer {
rate 100M;
}
}
3、定义一个资源/etc/drbd.d/web.res,内容如下:
将这两个配置文件拷贝到node2上,以保证配置文件相同
4、在两个节点上初始化已定义的资源并启动服务:
1)初始化资源,在Node1和Node2上分别执行:
2)启动服务,在Node1和Node2上分别执行:
3)查看启动状态:
也可以使用drbd-overview命令来查看:
从上面的信息中可以看出此时两个节点均处于Secondary状态。于是,我们接下来需要将node1设置为Primary,在node1上执行如下命令:
drbdsetup /dev/drbd0 primary –o
注: 也可以在要设置为Primary的节点上使用如下命令来设置主节点:
drbdadm -- --overwrite-data-of-peer primary web 这种方法更加标准
(注:这两个设置primary节点的命令只在第一次使用,以后就可以直接使用drbdadm primary web)
而后再次查看状态,可以发现数据同步过程已经开始:
此时我们还可以使用如下命令动态的查看同步过程
watch -n 1 'drbd-overview'
当数据同步完成以后再次查看状态
可以发现节点已经为实时状态,且节点已经有了主次:
5、创建文件系统
因为文件系统的挂载只能在Primary节点进行,所以只有在设置了主节点后才能对drbd设备进行格式化:
6、切换Primary和Secondary节点
对主Primary/Secondary模型的drbd服务来讲,在某个时刻只能有一个节点为Primary,因此,要切换两个节点的角色,只能在先将原有的Primary节点设置为Secondary后,才能原来的Secondary节点设置为Primary:
我们先在drbd设备上存储个网页文件,而后在主从节点改变后查看node1的index.html文件是否复制到node2上
node1:
为了进行验证而设置的文件
首先卸载drbd设备
将其设定为从节点
查看状态:
将node2设为primary
查看状态:
drbd-overview
状态显示node2已经成为从节点
挂载drbd设备
查看文件是否存在

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Go language is an efficient, concise and easy-to-learn programming language. It is favored by developers because of its advantages in concurrent programming and network programming. In actual development, database operations are an indispensable part. This article will introduce how to use Go language to implement database addition, deletion, modification and query operations. In Go language, we usually use third-party libraries to operate databases, such as commonly used sql packages, gorm, etc. Here we take the sql package as an example to introduce how to implement the addition, deletion, modification and query operations of the database. Assume we are using a MySQL database.

Hibernate polymorphic mapping can map inherited classes to the database and provides the following mapping types: joined-subclass: Create a separate table for the subclass, including all columns of the parent class. table-per-class: Create a separate table for subclasses, containing only subclass-specific columns. union-subclass: similar to joined-subclass, but the parent class table unions all subclass columns.

Apple's latest releases of iOS18, iPadOS18 and macOS Sequoia systems have added an important feature to the Photos application, designed to help users easily recover photos and videos lost or damaged due to various reasons. The new feature introduces an album called "Recovered" in the Tools section of the Photos app that will automatically appear when a user has pictures or videos on their device that are not part of their photo library. The emergence of the "Recovered" album provides a solution for photos and videos lost due to database corruption, the camera application not saving to the photo library correctly, or a third-party application managing the photo library. Users only need a few simple steps

HTML cannot read the database directly, but it can be achieved through JavaScript and AJAX. The steps include establishing a database connection, sending a query, processing the response, and updating the page. This article provides a practical example of using JavaScript, AJAX and PHP to read data from a MySQL database, showing how to dynamically display query results in an HTML page. This example uses XMLHttpRequest to establish a database connection, send a query and process the response, thereby filling data into page elements and realizing the function of HTML reading the database.

How to use MySQLi to establish a database connection in PHP: Include MySQLi extension (require_once) Create connection function (functionconnect_to_db) Call connection function ($conn=connect_to_db()) Execute query ($result=$conn->query()) Close connection ( $conn->close())

To handle database connection errors in PHP, you can use the following steps: Use mysqli_connect_errno() to obtain the error code. Use mysqli_connect_error() to get the error message. By capturing and logging these error messages, database connection issues can be easily identified and resolved, ensuring the smooth running of your application.

Analysis of the basic principles of the MySQL database management system MySQL is a commonly used relational database management system that uses structured query language (SQL) for data storage and management. This article will introduce the basic principles of the MySQL database management system, including database creation, data table design, data addition, deletion, modification, and other operations, and provide specific code examples. 1. Database Creation In MySQL, you first need to create a database instance to store data. The following code can create a file named "my

PHP is a back-end programming language widely used in website development. It has powerful database operation functions and is often used to interact with databases such as MySQL. However, due to the complexity of Chinese character encoding, problems often arise when dealing with Chinese garbled characters in the database. This article will introduce the skills and practices of PHP in handling Chinese garbled characters in databases, including common causes of garbled characters, solutions and specific code examples. Common reasons for garbled characters are incorrect database character set settings: the correct character set needs to be selected when creating the database, such as utf8 or u
