Home Database Mysql Tutorial heartbeat v1 实现 MariaDB数据库的高可用

heartbeat v1 实现 MariaDB数据库的高可用

Jun 07, 2016 pm 04:48 PM
mariadb

MariaDB数据库服务的高可用:使用heartbeatv1版实现两个节点的MariaDB数据库服务的高可用。节点:node1192.168.60.33node2192.168.60...

MariaDB数据库服务的高可用:

使用 heartbeat v1 版实现两个节点的 MariaDB数据库服务的高可用。

节点:

    node1        192.168.60.33

    node2        192.168.60.88

MySQL数据库的数据文件使用nfs共享文件系统解决

nfs Server       192.168.60.22

架构如下图:

wKiom1QMRl3gE_cJAAIe0TaKqHs158.jpg

一、heartbeat 节点之间通信要求的设置;

(1)、解决节点的主机名解析

因为 heartbeat 的节点间通讯基于名称。基于名称进行通讯就要实现域名解析:而名称解析有两种方法:

A、 基于本地hosts 文件实现主机名到IP地址的解析; B、 使用DNS域名服务器进行域名解析;

基于效率等方面考虑,使用本地hosts 文件进行主名与IP地址的解析。

把 192.168.60.88 主机设置为HA高可用的节点2 node2. 

设置基于本地hosts文件实现域名解析

[root@nfs admin]# echo "192.168.60.88 node2.9527du.com node2" > /etc/hosts [root@nfs admin]# echo "192.168.60.33 node1.9527du.com node2" >> /etc/hosts

把配置好的hosts 文件复制一份到另一节点:

[root@nfs admin]# scp -p /etc/hosts root@192.168.60.33

(2)、给HA高可用集群的各节点设置主机名

A)、设置192.168.60.88主机的主机名为:node2.9527du.com

[root@nfs admin]# vim /etc/sysconfig/network HOSTNAME=node2.9527du.com

使用【hostname】命令设置主机名立即生效

[root@nfs admin]# hostname node2.9527du.com

测试主机名能否解析成功

[root@nfs admin]# ping -c 1 node2.9527du.com PING node2.9527du.com (192.168.60.88) 56(84) bytes of data. 64 bytes from node2.9527du.com (192.168.60.88): icmp_seq=1 ttl=64 time=0.010 ms --- node2.9527du.com ping statistics --- 1 packets transmitted, 1 received, 0% packet loss, time 0ms rtt min/avg/max/mdev = 0.010/0.010/0.010/0.000 ms

B)、设置192.168.60.33主机的主机名为:node1.9527du.com

[root@www admin]# vim /etc/sysconfig/network HOSTNAME=node2.9527du.com

使用【hostname】命令设置主机名立即生效

[root@www admin]# hostname node1.9527du.com

检测使用hosts文件是否能够解析主机名

[root@www admin]# ping -c 1 node2.9527du.com PING node2.9527du.com (192.168.60.88) 56(84) bytes of data. 64 bytes from node2.9527du.com (192.168.60.88): icmp_seq=1 ttl=64 time=0.010 ms --- node2.9527du.com ping statistics --- 1 packets transmitted, 1 received, 0% packet loss, time 0ms rtt min/avg/max/mdev = 0.010/0.010/0.010/0.000 ms[root@node2 admin]# ping -c 1 node1.9527du.com PING node1.9527du.com (192.168.60.33) 56(84) bytes of data. 64 bytes from node1.9527du.com (192.168.60.33): icmp_seq=1 ttl=64 time=0.010 ms --- node1.9527du.com ping statistics --- 1 packets transmitted, 1 received, 0% packet loss, time 0ms rtt min/avg/max/mdev = 0.010/0.010/0.010/0.000 ms

说明:

    从上面测试结果,已经两个节点都可以成功实现主机名的解析。


2、为了操作heartbeat 方便,把两节点配置成信任主机。不需要口令就可以直接通信。

(1)、建立基于密钥通讯

在node1节点生成密钥对

[root@node1 ha.d]# ssh-keygen -t rsa

把“公钥”拷贝到 node2 节点

[root@node1 ha.d]# ssh-copy-id -i /root/.ssh/id_rsa.pub root@192.168.60.33

在 node2 节点生成密钥对

[root@node2 ~]# ssh-keygen -t rsa

把“公钥”拷贝到 node1 节点

[root@node2 ~]# ssh-copy-id -i /root/.ssh/id_rsa.pub root@192.168.60.88

(2)、测试基于密钥是否能够实现无障碍通讯

[root@node1 ha.d]# ssh node2 -- 'hostname' node2.9527du.com [root@node2 ~]# ssh node1 'hostname' node1.9527.com

说明:

    从上述测试结果,两节点已经能够实现基于密钥实现通讯。



二、配置 node1 和 node2 节点的mysql用户都有 nfs 共享文件系统的:rwx 权限

    使用nfs服务器共享MySQL的数据文件,用户向MySQL数据库服务器,发起SQL操作时,MySQL数据库服务器以mysql用户的身份执行用户对数据库的操作的。

    所以,mysql用户一定要有 nfs 服务器导出的共享文件系统的:"读/写“ 权限。

而根据 nfs 的资源访问控制模型:

(1)、在nfs服务器导出的文件系统中要有读写权限。意思是说:nfs设置导出共享文件系统时,要授权客户端有:读写权限。 (2)、往nfs共享文件系统中读写数据的用户映射到nfs服务器的本地文件系统一定要有读写权限。

只要满足上述两个条件,mysql用户才可以往nfs共享文件系统中读写数据的。

所以,基于上述要求和mysql初始化数据库时一定要使用mysql用户等方面的考虑。在HA高可用的每个节点都创建一样的用户:

                    用户:               mysql           UID:                388          属于那个组:                388

这样就保证了:两个节点的 mysqld 都可以使用同一份数据文件。

说明:

    把mysql 创建为系统用户,且登记shell 为: /sbin/nologin 这样,即使某人获得了mysql的密码也没法登陆我们的系统的。

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 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
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
1665
14
PHP Tutorial
1269
29
C# Tutorial
1249
24
Connect to MariaDB database using PHP Connect to MariaDB database using PHP May 17, 2023 am 08:24 AM

MariaDB is an open source relational database management system, which is a branch of MySQL. PHP, as an open source server-side scripting language, is widely used in web development. In many web development projects, you need to use PHP to connect to the MariaDB database in order to store and retrieve data in the web application. This article will introduce how to use PHP to write code to connect to the MariaDB database. 1. Install the MariaDB server and use PHP to connect to Maria.

How to connect to MariaDB database using PDO How to connect to MariaDB database using PDO Jul 28, 2023 pm 02:49 PM

How to use PDO to connect to MariaDB database 1. Introduction PDO (PHPDataObjects) is a lightweight abstraction layer used in PHP to access the database. It provides developers with a unified set of interfaces to connect and operate different types of databases, including MariaDB, MySQL, SQLite, etc. This article will introduce how to use PDO to connect to the MariaDB database and give sample code. 2. Install and configure using PDO to connect to MariaDB

An article explaining the difference between MariaDB and MySQL in detail An article explaining the difference between MariaDB and MySQL in detail Mar 09, 2023 am 11:39 AM

This article brings you relevant knowledge about MariaDB and MySQL. It mainly talks about the differences between MariaDB and MySQL. Friends who are interested can take a look at it together. I hope it will be helpful to everyone.

Best Practices for Docker Compose, Nginx, and MariaDB: Monitoring and Optimizing Deployed PHP Applications Best Practices for Docker Compose, Nginx, and MariaDB: Monitoring and Optimizing Deployed PHP Applications Oct 12, 2023 pm 02:19 PM

Best Practices for DockerCompose, Nginx and MariaDB: Monitoring and Optimization of Deployed PHP Applications Introduction: In modern application development, containerization has become a popular way to help us better manage and deploy applications. DockerCompose is a tool for defining and running multiple containers, which simplifies the application deployment and management process. This article will introduce how to use DockerCompose to combine Nginx and

How to install MariaDB database on Debian 12 How to install MariaDB database on Debian 12 Feb 20, 2024 pm 02:24 PM

MariaDB is an open source multi-threaded relational database management system and a replacement for MySQL. MariaDB is the default replacement for MySQL in Debian. This tutorial explains how to install MariaDB on Debian12. Preparation conditions 1. A VPS virtual machine with Debian12 installed (it is recommended that you purchase an Alibaba Cloud VPS or Tencent Cloud VPS virtual host. If you prefer foreign servers, it is recommended that you try VPS on Vultr, and you will receive a $50 trial experience when you register) , very cost-effective), of course you can also use it on your own computer or virtual machine. 2. If you use VPS, for security reasons, it is recommended to use a non-root account, which can be done in Debian12

Optimize network performance of PHP applications using Docker Compose, Nginx and MariaDB Optimize network performance of PHP applications using Docker Compose, Nginx and MariaDB Oct 12, 2023 pm 12:49 PM

Introduction to optimizing network performance of PHP applications using DockerCompose, Nginx and MariaDB: In today's Internet era, network performance is crucial to the stability and responsiveness of web applications. In order to improve the network performance of PHP applications, we can use the containerization technology DockerCompose, the efficient web server Nginx and the stable database MariaDB. This article will introduce in detail how to use these tools to optimize the network of PHP applications.

The perfect combination of Docker Compose, Nginx and MariaDB: best practices for deploying PHP applications The perfect combination of Docker Compose, Nginx and MariaDB: best practices for deploying PHP applications Oct 12, 2023 am 11:24 AM

The perfect combination of DockerCompose, Nginx and MariaDB: Best practices for deploying PHP applications Introduction: In modern web application development, the use of containerization technology has become a trend. Containerization technology can package an application and its dependencies into a single container, so that the application can run in any environment that supports containerization technology. Docker is currently the most popular containerization technology, which can simplify the deployment, management and expansion of applications. For use

Optimizing performance issues of PHP applications using Docker Compose, Nginx and MariaDB Optimizing performance issues of PHP applications using Docker Compose, Nginx and MariaDB Oct 12, 2023 pm 12:55 PM

Optimizing Performance Issues in PHP Applications Using DockerCompose, Nginx, and MariaDB When developing and deploying PHP applications, performance issues are often encountered. To solve these problems, we can leverage DockerCompose, Nginx, and MariaDB to optimize application performance. DockerCompose is a tool for defining and managing multiple Docker containers. It helps us create and run multiple containers easily

See all articles