Corosync achieves high availability of MariaDB Database Service

Source: Internet
Author: User

Corosync achieves high availability of MariaDB Database Service

Solution:

Corosync + pacemaker provides HA solutions.

Use the shared file system exported by the NFS Shared Server as the data directory;

The topology is as follows:

Install LAMP (Apache with MariaDB and PHP) in CentOS/RHEL/Scientific Linux 6)

Implementation of MariaDB Proxy read/write splitting

MySQL + Corosync + Pacemaker + DRBD build highly available MySQL

Build a high-availability MySQL Cluster Based on Corosync + DRBD

Use Corosync to configure high-availability clusters based on the NFS service and DRBD service.

Corosync for Linux high availability (HA) CLUSTERS

Set up a high-availability cluster using pacemaker + Corosync

Corosync + pacemaker + RA for high MySQL availability

1. Configure the host name communication between nodes in the HA high-availability cluster.

1. Set the Host Name

(1) set on host 192.168.60.128

Edit the/etc/sysconfig/network file to make the host name permanently valid.

[root@www ~]# vim /etc/sysconfig/networkHOSTNAME=node2.bkjia.com

Use the hostname command to set the host name to take effect immediately

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

(2) set on host 192.168.60.22

Edit the/etc/sysconfig/network file to make the host name permanently valid.

[root@stu13 ~]# vim /etc/sysconfig/networkHOSTNAME=node1.bkjia.com

Use the hostname command to set the host name so that it can be generated instantly

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

2. To facilitate the setting of key-based communication between nodes. That is, building a trusted host.

[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. The host name communication between nodes must be able to parse the host name. You can use either of the following methods to resolve a Host Name:

(1) Use the DNS address to resolve the server;

(2) Use the local hosts file for parsing

In terms of efficiency and security, the hosts file is used to parse the host name.

[root@node1 ~]# vim /etc/hosts192.168.60.22   node1.bkjia.com node1192.168.60.128  node2.bkjia.com node2

Copy the/etc/hosts file to node2.

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

4. Test whether two nodes can implement key-based communication and host name-based communication.

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

 

Note:

From the above, we can see that the two nodes have been able to implement host name-based communication.

 

Ii. Configure the NFS server

Build an NFS Network File System server in Ubuntu

Heartbeat_ldirector + LB + NFS for HA, LB, and file sharing

How to Configure NFS server in CentOS 5.5

Install and use NFS in Ubuntu 12.10

1. Provides File Systems shared by NFS servers

Use the LVM logical volume as the data directory of the database and back up data using the snapshot function of the logical volume.

(1) create a partition

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

(2) Make the partition pv

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

(3) create a logical volume group myvg and the PE size is 8E.

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

(4) Create an lvm. The size is 2 GB.

[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) create a mount point

[root@nsf ~]# mkdir /mydata

(6) edit the/etc/fstab file to automatically mount "/dev/myvg/1_dir" at startup"

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

(7) Mounting

[root@nsf ~]# mount -a

Check whether mounting is enabled.

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

 

2. The database service process (mysql) in the client that configures to mount the file system shared by the NFS server has read and write permissions on the Shared File System (directory.

Use the file system exported from the NFS server as the data directory of the database. According to the working principle of the NFS server, the NFS client can export the File System (directory) to the NFS server) data Writing must meet two conditions:

(A) whether to grant the NFS client write (w) Permission during access control at the NFS server level;

(B) indicates whether the UID of the owner of the process that initiates the write (W) operation on the NFS client is the same as that of the host on the NFS server.

Corresponding user.

1) If yes, check whether the user has the write permission for the file system (directory) exported by the NFS server. If

If you have the write permission, the NFS client process can initiate a write operation to the file system exported by the NFS server. Otherwise

The NFS client has no permission to write data to the file system exported to the NFS server.

2) if not, check whether the nobody user has the write permission for the file system (directory) exported by the NFS server.

However, in Linux, the nobody user has the minimum permission.

In the MySQL database, the owner of the process that receives client SQL operation requests is mysql. therefore, we need to configure the user's UID to have the corresponding user name on the host where the NFS server is located, and require the user to have the file system (directory) exported by the NFS server ), you have read and write permissions. For HA high-availability nodes and NFS servers, add the following users to the three hosts:

It is planned to use system users on all three hosts, and the UID is: 404; the GID is: 404.

(1) set users on three hosts

(A) Create A mysql user on the node1 host

[root@node1 local]# useradd -r -u 404 -g 404 -s /sbin/nologin mysql[root@node1 local]# id mysqluid=404(mysql) gid=404(mysql) groups=404(mysql)[root@node1 local]# groupadd -r -g 404 mysql

(B) Create a mysql user on the node2 host

[root@node2 ~]# groupadd -r  -g 404 mysql[root@node2 ~]# useradd -r -u 404 -g 404 -s /sbin/nologin mysql[root@node2 ~]# id mysqluid=404(mysql) gid=404(mysql) groups=404(mysql)

(C) users who have created UID and GID on the NFS server: 404;

[root@nsf ~]# groupadd -g 404 -r usenfs[root@nsf ~]# useradd  -r -u 404 -g 404 -s /sbin/nologin usenfs[root@nsf ~]# id usenfsuid=404(usenfs) gid=404(usenfs) groups=404(usenfs)

(2) Authorization

(A) Authorization at the file system level. By using the control list method, the user with UID: 404 usenfs is authorized to read and write the file system exported by the NFS server.

[Root @ nsf/] # setfacl-m u: usenfs: rwx/mydata [root @ nsf/] # getfacl/mydeleetfacl: Removing leading '/' from absolute path names # file: mydata # owner: root # group: rootuser: rwxuser: usenfs: rwx ----> indicates that the usenfs user has the read and write permissions. Group: r-xmask: rwxother: r-x

(B) Set the file system exported by the NFS server and implement access control at the NFS level.

[root@nsf /]# vim /etc/exports/mydata 192.168.60.0/24(rw)

Start the NFS server

[root@nsf /]# service nfs startStarting NFS services:                                     [  OK  ]Starting NFS quotas:                                       [  OK  ]Starting NFS mountd:                                       [  OK  ]Stopping RPC idmapd:                                       [  OK  ]Starting RPC idmapd:                                       [  OK  ]Starting NFS daemon:                                       [  OK  ]

(3) view the file system exported by the NFS server

[root@nsf /]# showmount -e 192.168.60.40Export list for 192.168.60.40:/mydata 192.168.60.0/24

(4) create a data directory for the MariDB Database

[root@nsf /]mkdir /mydata/mysql

Grant usefs users the permission to read and write the directory by using the control list.

[Root @ nsf mysql] # setfacl-m u: usenfs: rwx/mydata/mysql/[root @ nsf mysql] # getfacl/mydata/mysql/getfacl: removing leading '/' from absolute path names # file: mydata/mysql/# owner: root # group: rootuser: rwxuser: usenfs: rwx ----> usenfs user permission group :: r-xmask: rwxother: r-x

For more details, please continue to read the highlights on the next page:

  • 1
  • 2
  • 3
  • 4
  • 5
  • Next Page

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.