Home Database Mysql Tutorial Corosync 实现 MariaDB 数据库服务的高可用

Corosync 实现 MariaDB 数据库服务的高可用

Jun 07, 2016 pm 04:44 PM
mariadb

Corosync 实现 MariaDB 数据库服务的高可用,corosync + pacemaker 提供HA的解决方案。使用NFS共享服务器导出的共享文件系统做为

方案:

    corosync + pacemaker  提供HA的解决方案。

    使用NFS共享服务器导出的共享文件系统做为数据目录;

拓扑图如下:

Corosync 实现 MariaDB 数据库服务的高可用

在 CentOS/RHEL/Scientific Linux 6 下安装 LAMP (Apache with MariaDB and PHP)

MariaDB Proxy读写分离的实现

MySQL+Corosync+Pacemaker+DRBD构建高可用MySQL

搭建基于Corosync+DRBD的高可用MySQL集群

分别基于NFS服务和DRBD服务利用Corosync配置高可用集群

Linux 高可用(HA)集群之Corosync详解

pacemaker + Corosync 搭建高可用集群

Corosync+pacemaker+RA实现MySQL高可用

一、配置HA高可用集群的各节点间能够基于主机名通讯。

1、设置主机名

(1)、在 192.168.60.128 主机设置

编辑/etc/sysconfig/network文件,使得主机名永久有效

[root@www ~]# vim /etc/sysconfig/network HOSTNAME=node2.linuxidc.com

使用hostname命令设置主机名,,让它即时生效

[root@www ~]# hostname node2.linuxidc.com

(2)、在 192.168.60.22 主机设置

编辑/etc/sysconfig/network文件,使得主机名永久有效

[root@stu13 ~]# vim /etc/sysconfig/network HOSTNAME=node1.linuxidc.com

使用hostname命令设置主机名,让它即时生成

[root@stu13 ~]# hostname node1.linuxidc.com

2、为了,操作方便设置节点之间能够基于密钥通讯。也就是所谓的建立信任主机。

[root@node1 ~]# ssh-keygen -t rsa [root@node1 ~]# ssh-copy-id -i /root/.ssh/id_rsa.pub 192.168.60.128 [root@node2 ~]# ssh-keygen -t rsa [root@node2 ~]# ssh-copy-id -i /root/.ssh/id_rsa.pub 192.168.60.22

3、节点之间基于主机名通讯,要能够解析主机名才可以。解析主机名有两种方式:

(1)、使用DNS地址解析服务器;

(2)、使用本地hosts文件解析

基于效率和安全方面考虑,这里使用hosts文件解析主机名。

[root@node1 ~]# vim /etc/hosts 192.168.60.22   node1.linuxidc.com node1 192.168.60.128  node2.linuxidc.com node2

把/etc/hosts文件复制到node2节点

[root@node1 ~]# scp /etc/hosts node2:/etc/ hosts                                         100%   78     0.1KB/s   00:00

4、测试两个节点能够实现基于密钥的方式进行通讯和能否基于主机名进行通讯

root@node2 ~]# ssh node1 'hostname' node1.linuxidc.com [root@node1 ~]# ssh node2 'hostname' node2.linuxidc.com [root@node1 ~]# ssh node2 'ping -c 1  node2.linuxidc.com' PING node2.linuxidc.com (192.168.60.128) 56(84) bytes of data. 64 bytes from node2.linuxidc.com (192.168.60.128): icmp_seq=1 ttl=64 time=0.061 ms --- node2.linuxidc.com ping statistics --- 1 packets transmitted, 1 received, 0% packet loss, time 0ms rtt min/avg/max/mdev = 0.061/0.061/0.061/0.000 ms [root@node1 ~]# ping -c 1 node1.linuxidc.com PING node1.linuxidc.com (192.168.60.22) 56(84) bytes of data. 64 bytes from node1.linuxidc.com (192.168.60.22): icmp_seq=1 ttl=64 time=0.069 ms --- node1.linuxidc.com ping statistics --- 1 packets transmitted, 1 received, 0% packet loss, time 0ms rtt min/avg/max/mdev = 0.069/0.069/0.069/0.000 ms

 

说明:

   从上述可以看出,两个节点已经能够实现基于主机名的方式进行通讯。

 

二、配置NFS服务器

Ubuntu下搭建NFS网络文件系统服务器

Heartbeat_ldirector+LB+NFS实现HA及LB、文件共享

CentOS 5.5配置NFS服务器教程

Ubuntu 12.10下NFS的安装使用

1、提供NFS服务器共享的文件系统

使用LVM逻辑卷做为数据库的数据目录,为了使用逻辑卷的快照功能备份数据。

(1)、创建分区

[root@nsf ~]# fdisk -l /dev/sda | grep "/dev/sda3" /dev/sda3            7859        9164    10489446   8e  Linux LVM

(2)、把该分区做成pv 

[root@nsf ~]# pvcreate /dev/sda3   Physical volume "/dev/sda3" successfully created

(3)、创建逻辑卷组myvg,PE大小为8E.

[root@nsf ~]# vgcreate -s 8M myvg /dev/sda3   Volume group "myvg" successfully created

(4)、创建lvm,大小为:2G

[root@nsf ~]# lvcreate -L 2G -n sharedir myvg   Logical volume "sharedir" created [root@nsf ~]# mke2fs -t ext4  /dev/myvg/sharedir [root@nsf ~]# echo $? 0

(5)、创建挂载点

[root@nsf ~]# mkdir /mydata

(6)、编辑/etc/fstab文件,实现开机可以自动挂载“/dev/myvg/sharedir”

[root@nsf ~]# vim /etc/fstab /dev/mapper/myvg-sharedir /mydata               ext4    defaults,acl    0 0

(7)、挂载

[root@nsf ~]# mount -a

查看是否挂载

[root@nsf ~]# mount | grep "mydata" /dev/mapper/myvg-sharedir on /mydata type ext4 (rw,acl)

 

2、配置挂载NFS服务器共享的文件系统的客户端中的数据库服务进程(mysql)具有共享文件系统(目录)的读写权限。

     把NFS服务器导出的文件系统中,作为数据库的数据目录,根据NFS服务器的工作原理,NFS的客户端可以往NFS服务器导出的文件系统(目录)写数据要满足两个条件:

     (A)、在NFS服务器级别,做访问控制时候是否授写NFS客户端写(w)的权限;

     (B)、在NFS客户端发起写(W)操作的进程的属主对应的UID,在NFS服务器端所在的主机是否该UID

          对应的用户。

     1)、如果有的话,那么就检查该用户是否有NFS服务器导出的文件系统(目录)的写权限。如果有

         写权限的话,那么NFS客户端的进程就可以往NFS服务器导出的文件系统发起写操作了。否则

         的话NFS客户端是无权限往NFS服务器导出的文件系统写数据的。

     2)、如果没有的话,那就就检查nobody用户是否有NFS服务器导出的文件系统(目录)的写权限。

         不过在Linux系统上,nobody用户的权限是最小。

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 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
1654
14
PHP Tutorial
1252
29
C# Tutorial
1225
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