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

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
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
Explain the InnoDB Buffer Pool and its importance for performance.Explain the InnoDB Buffer Pool and its importance for performance.Apr 19, 2025 am 12:24 AM

InnoDBBufferPool reduces disk I/O by caching data and indexing pages, improving database performance. Its working principle includes: 1. Data reading: Read data from BufferPool; 2. Data writing: After modifying the data, write to BufferPool and refresh it to disk regularly; 3. Cache management: Use the LRU algorithm to manage cache pages; 4. Reading mechanism: Load adjacent data pages in advance. By sizing the BufferPool and using multiple instances, database performance can be optimized.

MySQL vs. Other Programming Languages: A ComparisonMySQL vs. Other Programming Languages: A ComparisonApr 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.

Learning MySQL: A Step-by-Step Guide for New UsersLearning MySQL: A Step-by-Step Guide for New UsersApr 19, 2025 am 12:19 AM

MySQL is worth learning because it is a powerful open source database management system suitable for data storage, management and analysis. 1) MySQL is a relational database that uses SQL to operate data and is suitable for structured data management. 2) The SQL language is the key to interacting with MySQL and supports CRUD operations. 3) The working principle of MySQL includes client/server architecture, storage engine and query optimizer. 4) Basic usage includes creating databases and tables, and advanced usage involves joining tables using JOIN. 5) Common errors include syntax errors and permission issues, and debugging skills include checking syntax and using EXPLAIN commands. 6) Performance optimization involves the use of indexes, optimization of SQL statements and regular maintenance of databases.

MySQL: Essential Skills for Beginners to MasterMySQL: Essential Skills for Beginners to MasterApr 18, 2025 am 12:24 AM

MySQL is suitable for beginners to learn database skills. 1. Install MySQL server and client tools. 2. Understand basic SQL queries, such as SELECT. 3. Master data operations: create tables, insert, update, and delete data. 4. Learn advanced skills: subquery and window functions. 5. Debugging and optimization: Check syntax, use indexes, avoid SELECT*, and use LIMIT.

MySQL: Structured Data and Relational DatabasesMySQL: Structured Data and Relational DatabasesApr 18, 2025 am 12:22 AM

MySQL efficiently manages structured data through table structure and SQL query, and implements inter-table relationships through foreign keys. 1. Define the data format and type when creating a table. 2. Use foreign keys to establish relationships between tables. 3. Improve performance through indexing and query optimization. 4. Regularly backup and monitor databases to ensure data security and performance optimization.

MySQL: Key Features and Capabilities ExplainedMySQL: Key Features and Capabilities ExplainedApr 18, 2025 am 12:17 AM

MySQL is an open source relational database management system that is widely used in Web development. Its key features include: 1. Supports multiple storage engines, such as InnoDB and MyISAM, suitable for different scenarios; 2. Provides master-slave replication functions to facilitate load balancing and data backup; 3. Improve query efficiency through query optimization and index use.

The Purpose of SQL: Interacting with MySQL DatabasesThe Purpose of SQL: Interacting with MySQL DatabasesApr 18, 2025 am 12:12 AM

SQL is used to interact with MySQL database to realize data addition, deletion, modification, inspection and database design. 1) SQL performs data operations through SELECT, INSERT, UPDATE, DELETE statements; 2) Use CREATE, ALTER, DROP statements for database design and management; 3) Complex queries and data analysis are implemented through SQL to improve business decision-making efficiency.

MySQL for Beginners: Getting Started with Database ManagementMySQL for Beginners: Getting Started with Database ManagementApr 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

See all articles

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use