Home Database Mysql Tutorial Mysql测试三:Mysql + DRBD + Heartbeat(v1)基本配置笔记及切换

Mysql测试三:Mysql + DRBD + Heartbeat(v1)基本配置笔记及切换

Jun 07, 2016 pm 04:31 PM
drbd mysql basic configuration test

1、下载对应版本的heartbeat包 由于安装beartbeat的rpm包需要其他一些包为前提条件,所以可能还需要下载对应版本的其他的几个rpm包,像如下: [root@mysql1 heartbeat]# rpm -ivh heartbeat-2.1.3-3.el4.centos.i386.rpm warning: heartbeat-2.1.3-3.el4.cen

1、下载对应版本的heartbeat包
由于安装beartbeat的rpm包需要其他一些包为前提条件,所以可能还需要下载对应版本的其他的几个rpm包,像如下:
[root@mysql1 heartbeat]# rpm -ivh heartbeat-2.1.3-3.el4.centos.i386.rpm
warning: heartbeat-2.1.3-3.el4.centos.i386.rpm: V3 DSA signature: NOKEY, key ID 443e1821
error: Failed dependencies:
heartbeat-pils = 2.1.3-3.el4.centos is needed by heartbeat-2.1.3-3.el4.centos.i386
heartbeat-stonith = 2.1.3-3.el4.centos is needed by heartbeat-2.1.3-3.el4.centos.i386
libpils.so.1 is needed by heartbeat-2.1.3-3.el4.centos.i386
libstonith.so.1 is needed by heartbeat-2.1.3-3.el4.centos.i386

然后下载heartbeat-pils-2.1.3-3.el4.centos.i386.rpm和heartbeat-stonith-2.1.3-3.el4.centos.i386.rpm,
在安装这两个包之后,即可正常安装heartbeat了。

2、配置相关文件
1) 找到安装后heartbeat的文档目录,将三个需要的配置文件样例copy到/etc/ha.d目录下准备后面的配置设
置(这样会更方便,而且有较为详细的配置说明):
[root@mysql1 ha.d]# rpm -q heartbeat -d

/usr/share/doc/heartbeat-2.1.3/AUTHORS

[root@mysql1 ha.d]# cp /usr/share/doc/heartbeat-2.1.3/ha.cf .
[root@mysql1 ha.d]# cp /usr/share/doc/heartbeat-2.1.3/authkeys .
[root@mysql1 ha.d]# cp /usr/share/doc/heartbeat-2.1.3/haresources .

2) 配置ha.cf(ha主要配置文件):
logfacility local0 #这个是设置heartbeat的日志,这里是用的系统日志
keepalive 500ms #多长时间检测一次
deadtime 10 #连续多长时间联系不上后认为对方挂掉了(单位是妙)
warntime 5 #连续多长时间联系不上后开始警告提示
initdead 100 #这里主要是给重启后预留的一段忽略时间段(比如:重启后启动网络等,
如果在网络还没有通,keepalive检测肯定通不过,但这时候并不能切换)
bcast eth0
auto_failback off #恢复正常后是否需要再自动切换回来
node mysql1 #节点名(必须是集群中机器的主机名,通过uname -n取得)
node mysql2 #节点名(必须是集群中机器的主机名,通过uname -n取得)

ping 10.0.65.250
respawn hacluster /usr/lib/heartbeat/ipfail #这里是配置ip绑定和切换的功能,
ipfail就是控制ip切换的程序
apiauth ipfail gid=haclient uid=hacluster #控制ip切换的时候所使用的用户
deadping 5

2) haresources 资源组文件配置(v1 style):
[root@mysql1 ha.d]# cat haresources
mysql1 drbddisk Filesystem::/dev/drbd0::/drbddata::ext3 mysql 10.0.65.44

资源组配置文件主要是配置切换过程需要管理的各种资源的,有一个很关键的点,那就是一个资源组中的各个资源
的排列顺序是需要注意的,在hearbeat管理资源组的时候,获取资源的过程是从左往右依次处理,释放资源的时候是从
右往左依次处理。
资源组里面的资源可以是ip的管理,可以是各种服务,也可以是我们自己写的各种脚本,甚至可以是需要传参数的
脚本(通过::来分割参数)。每一行代表一个资源组,每个资源组之间没有必然的关系。
资源组的第一列是我们在ha.cf配置文件中的node之一,而且应该是当前准备作为primary节点的那一个node。
上面资源组中的各项含义如下:
mysql1 当前primary节点名(uname -n)
drbddisk 告诉heartbeat要管理drbd的资源
Filesystem 这里是告诉heartbeat需要管理文件系统资源,其实实际上就是执行mount/umount命令,
后面的“::”符号之后是跟的Filesystem的参数(设备名和mount点)
mysql 告诉需要管理mysql
10.0.65.44 这里是让heartbeat帮你管理一个service ip,会跟着主节点一起漂移

3) authkeys 通信认证配置文件
root@mysql2:/root>cat /etc/ha.d/authkeys
auth 2 #认证方式,有如下三种
#1 crc #
2 sha1 HI!
#3 md5 Hello!

3、测试切换:
1) 手工调用heartbeat的节点切换脚本:
执行/usr/lib/heartbeat/hb_standby 脚本,让heartbeat通知对方节点自己请求变成standby节点,
请求对方成为primary节点,切换工作在10s左右即完成.
2) 拔掉网线,测试在primary节点的网络断开后的切换情况
通过测试,在拔掉网线后,当主节点发现无法和standby节点无法通信后,会在log中记录warn信息,
如果延续时间达到在ha.cf中设定的时长后,会开始释放资源,standby节点发现无法和主节点通信一段时间(ha.cf设定)后,
开始尝试启动资源并将自己active成primary节点。切换过程除开ha.cf中设定的时长之外的时间段同样非常短。
3) shutdown primary主机,测试是否能够正常切换,基本上和上面测试2差不多。
4) primary node 掉电测试,这里还没有到机房实际操作过,后面会继续测试这个操作。

注:以上测试都是基于Heartbeat v1 style的设置情况下所作,由于v1 style配置的heartbeat没办法做到对资源状态的监控,
主要职能通过监控与对方节点以及集群对外的网络状况的监控,而v2 style的配置已经提控了对资源状态的监控,所以后面准备再
针对v2 style的heartbeat进行详细一点的测试。不过,在linux-ha网站上面发现有一个声明,说drbd的作者建议用户继续
使用v1 style来让heartbeat管理drbd资源(http://www.linux-ha.org/DRBD/HowTov2),详细的原因并没有说明。
原文如下:
Note: as of 2008-02-15, the DRBD developers recommend to use the v1 drbddisk RA, although
the v2 drbd RA has been reported to work by some users (decide on your own!)

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1664
14
PHP Tutorial
1268
29
C# Tutorial
1248
24
MySQL's Role: Databases in Web Applications MySQL's Role: Databases in Web Applications Apr 17, 2025 am 12:23 AM

The main role of MySQL in web applications is to store and manage data. 1.MySQL efficiently processes user information, product catalogs, transaction records and other data. 2. Through SQL query, developers can extract information from the database to generate dynamic content. 3.MySQL works based on the client-server model to ensure acceptable query speed.

Laravel Introduction Example Laravel Introduction Example Apr 18, 2025 pm 12:45 PM

Laravel is a PHP framework for easy building of web applications. It provides a range of powerful features including: Installation: Install the Laravel CLI globally with Composer and create applications in the project directory. Routing: Define the relationship between the URL and the handler in routes/web.php. View: Create a view in resources/views to render the application's interface. Database Integration: Provides out-of-the-box integration with databases such as MySQL and uses migration to create and modify tables. Model and Controller: The model represents the database entity and the controller processes HTTP requests.

MySQL and phpMyAdmin: Core Features and Functions MySQL and phpMyAdmin: Core Features and Functions Apr 22, 2025 am 12:12 AM

MySQL and phpMyAdmin are powerful database management tools. 1) MySQL is used to create databases and tables, and to execute DML and SQL queries. 2) phpMyAdmin provides an intuitive interface for database management, table structure management, data operations and user permission management.

MySQL vs. Other Programming Languages: A Comparison MySQL vs. Other Programming Languages: A Comparison Apr 19, 2025 am 12:22 AM

Compared with other programming languages, MySQL is mainly used to store and manage data, while other languages ​​such as Python, Java, and C are used for logical processing and application development. MySQL is known for its high performance, scalability and cross-platform support, suitable for data management needs, while other languages ​​have advantages in their respective fields such as data analytics, enterprise applications, and system programming.

Solve database connection problem: a practical case of using minii/db library Solve database connection problem: a practical case of using minii/db library Apr 18, 2025 am 07:09 AM

I encountered a tricky problem when developing a small application: the need to quickly integrate a lightweight database operation library. After trying multiple libraries, I found that they either have too much functionality or are not very compatible. Eventually, I found minii/db, a simplified version based on Yii2 that solved my problem perfectly.

Laravel framework installation method Laravel framework installation method Apr 18, 2025 pm 12:54 PM

Article summary: This article provides detailed step-by-step instructions to guide readers on how to easily install the Laravel framework. Laravel is a powerful PHP framework that speeds up the development process of web applications. This tutorial covers the installation process from system requirements to configuring databases and setting up routing. By following these steps, readers can quickly and efficiently lay a solid foundation for their Laravel project.

MySQL for Beginners: Getting Started with Database Management MySQL for Beginners: Getting Started with Database Management Apr 18, 2025 am 12:10 AM

The basic operations of MySQL include creating databases, tables, and using SQL to perform CRUD operations on data. 1. Create a database: CREATEDATABASEmy_first_db; 2. Create a table: CREATETABLEbooks(idINTAUTO_INCREMENTPRIMARYKEY, titleVARCHAR(100)NOTNULL, authorVARCHAR(100)NOTNULL, published_yearINT); 3. Insert data: INSERTINTObooks(title, author, published_year)VA

Solve MySQL mode problem: The experience of using the TheliaMySQLModesChecker module Solve MySQL mode problem: The experience of using the TheliaMySQLModesChecker module Apr 18, 2025 am 08:42 AM

When developing an e-commerce website using Thelia, I encountered a tricky problem: MySQL mode is not set properly, causing some features to not function properly. After some exploration, I found a module called TheliaMySQLModesChecker, which is able to automatically fix the MySQL pattern required by Thelia, completely solving my troubles.

See all articles