COROSYNC+PACEMAKER+NFS provides MySQL high availability

Source: Internet
Author: User
Tags yum repolist aliyun

COROSYNC/OPENAIS+PACEMAKER+NFS offers mariadb high availability

Node I, one, 172.16.249.122/16, 172.16.0.1, CentOS6.6, mariadb
Node two, 172.16.249.123/16, 172.16.0.1, CentOS6.6, mariadb
Node III, three, 172.16.249.124/16, 172.16.0.1, CentOS6.6, NFS
vip:172.16.249.121

Node I: one 172.16.249.122
Setup #设定ip
Hostname One.centos
sed-i [email protected]=.*@[email protected]/etc/sysconfig/network
Vim/etc/hosts
172.16.249.122 One.centos One
172.16.249.123 Two.centos
======
Ssh-keygen-t rsa-p '-F '/root/.ssh/id_rsa '
Ssh-copy-id-i./.ssh/id_rsa.pub [Email protected]
Ntpdate-u 202.112.10.60
Date; SSH ' Date '

Node II: two 172.16.249.123
Setup #设定ip
Hostname Two.centos
sed-i [email protected]=.*@[email protected]/etc/sysconfig/network
Vim/etc/hosts
172.16.249.122 One.centos One
172.16.249.123 Two.centos
======
Ssh-keygen-t rsa-p '-F '/root/.ssh/id_rsa '
Ssh-copy-id-i./.ssh/id_rsa.pub [Email protected]
Ntpdate-u 202.112.10.60
Date; SSH One ' date '


Node Three: three 172.16.249.124
Cfdisk-ps/dev/sda
Cfdisk/dev/sda
Create two partitions with a size of 20G, type 8e, and partition Files of/dev/sda3 and/DEV/SDA4 respectively (process slightly)
Partx-a/DEV/SDA (performed two times)
pvcreate/dev/sda{3,4}
PVs
Vgcreate myvg/dev/sda{3,4}
Lvcreate-l 20g-n MyData MYVG
Mke2fs-j-L Mydata/dev/myvg/mydata
Blkid/dev/myvg/mydata

Mkdir-pv/sharedata
Vim/etc/fstab
Append the following content
Label=mydata/sharedata ext3 defaults 0 0
Mount-a
Mount
>/dev/mapper/myvg-mydata on/sharedata type ext3 (rw)
Df-h/sharedata/
/dev/mapper/myvg-mydata 20G 173M 19G 1%/sharedata

Useradd-r-U-Max MySQL
Chown-r mysql:mysql/sharedata/
Vim/etc/exports
/sharedata 172.16.249.122 (Rw,no_root_squash) 172.16.249.123 (Rw,no_root_squash)
==============
Service NFS Start
Chkconfig NFS On
SHOWMOUNT-E localhost
>export list for localhost:
>/sharedata 172.16.249.122,172.16.249.123


Node I: one 172.16.249.122
Useradd-r-U-Max MySQL
Mkdir-pv/data/mydata
Mount-t NFS 172.16.249.124:/sharedata/data/mydata
ls/data/mydata/
>lost+found
Df-h/data/mydata/
>filesystem Size used Avail use% mounted on
>172.16.249.124:/sharedata 20G 172M 19G 1%/data/mydata
Su-mysql
cd/data/mydata/#确认mysql用户对改目录有读写权限
Touch OneFile
RM OneFile
Exit


Node II: two 172.16.249.123
Useradd-r-U-Max MySQL
Mkdir-pv/data/mydata
Mount-t NFS 172.16.249.124:/sharedata/data/mydata
ls/data/mydata/
>lost+found
Df-h/data/mydata/
>filesystem Size used Avail use% mounted on
>172.16.249.124:/sharedata 20G 172M 19G 1%/data/mydata
Su-mysql
cd/data/mydata/#确认mysql用户对改目录有读写权限
Touch Twofile
RM Twofile
Exit



Node I: one 172.16.249.122
Installing MARIADB
Ls
>mariadb-5.5.43-binary-linux-x86_64.tar.gz
Tar XF mariadb-5.5.43-binary-linux-x86_64.tar.gz-c/usr/local/
cd/usr/local/
LN-SV mariadb-5.5.43-linux-x86_64 MySQL
CD MySQL
Chown-r Root:mysql.
scripts/mysql_install_db--datadir=/data/mydata/--user=mysql
\CP support-files/my-large.cnf/etc/my.cnf
Vim/etc/my.cnf
Thread_concurrency = 2 #修改
DataDir =/data/mydata #添加
=========
CP Support-files/mysql.server/etc/rc.d/init.d/mysqld
Chkconfig--add mysqld
Service mysqld Start
vim/etc/profile.d/mysql.sh
Export path=/usr/local/mysql/bin/: $PATH
===========
Export path=/usr/local/mysql/bin/: $PATH
MySQL #连接数据库
show databases;
Quit #退出数据库
Service Mysqld Stop
Chkconfig mysqld off
Chkconfig mysqld--list
umount/data/mydata/


Node II: two 172.16.249.123
Installing MARIADB
Ls
>mariadb-5.5.43-binary-linux-x86_64.tar.gz
Tar XF mariadb-5.5.43-binary-linux-x86_64.tar.gz-c/usr/local/
cd/usr/local/
LN-SV mariadb-5.5.43-linux-x86_64 MySQL
CD MySQL
Chown-r Root:mysql.
\CP support-files/my-large.cnf/etc/my.cnf
Vim/etc/my.cnf
Thread_concurrency = 2 #修改
DataDir =/data/mydata #添加
=========
CP Support-files/mysql.server/etc/rc.d/init.d/mysqld
Chkconfig--add mysqld
Service mysqld Start
vim/etc/profile.d/mysql.sh
Export path=/usr/local/mysql/bin/: $PATH
===========
Export path=/usr/local/mysql/bin/: $PATH
MySQL #连接数据库
show databases;
Quit #退出数据库
Service Mysqld Stop
Chkconfig mysqld off
Chkconfig mysqld--list #确保开机不自启
umount/data/mydata/



Node I: one 172.16.249.122
Prepare the Yum source
Wget-o/etc/yum.repos.d/epel6.repo Http://mirrors.aliyun.com/repo/epel-6.repo
Mount/dev/cdrom/mnt/cdrom
Cat/etc/yum.repos.d/c6cdrom.repo
[CentOS6.6]
Name=dvd1
Baseurl=file:///mnt/cdrom
Gpgcheck=0
Cost=1
===========
Yum Repolist
Yum-y Install Corosync corosynclib pacemaker pacemaker-cts pacemaker-libs cluster-glue cluster-glue-libs resource-agent S LIBESMTP Heartbeat Heartbeat-libs




Node II: two 172.16.249.123
Prepare the Yum source
Wget-o/etc/yum.repos.d/epel6.repo Http://mirrors.aliyun.com/repo/epel-6.repo
Mount/dev/cdrom/mnt/cdrom
Cat/etc/yum.repos.d/c6cdrom.repo
[CentOS6.6]
Name=dvd1
Baseurl=file:///mnt/cdrom
Gpgcheck=0
Cost=1
===========
Yum Repolist
Yum-y Install Corosync corosynclib pacemaker pacemaker-cts pacemaker-libs cluster-glue cluster-glue-libs resource-agent S LIBESMTP Heartbeat Heartbeat-libs




Node I: one 172.16.249.122
cd/etc/corosync/
CP Corosync.conf.example corosync.conf
Vim corosync.conf
Modify the following options
Secauth:on
bindnetaddr:172.16.249.121 #vip
mcastaddr:226.100.7.1
To_syslog:no
Add the following: What is the role of these two pieces of content?
Service {
ver:0
Name:pacemaker
}
aisexec {
User:root
Group:root
}
==============
Corosync-keygen
(If you are stuck executing \cp/mnt/cdrom/packages/c*.rpm/tmp/, disk reads and writes can generate random numbers)
mkdir-pv/var/log/cluster/
Service Corosync Start
To see if the Corosync engine starts properly:
Grep-e "Corosync Cluster Engine"-E "configuration file"/var/log/cluster/corosync.log
To view the initialization of a member node notification if it is issued normally:
grep totem/var/log/cluster/corosync.log
Check the startup process for any errors that occur:
grep ERROR:/var/log/cluster/corosync.log | Grep-v unpack_resources
To see if the pacemaker starts normally:
grep pcmk_startup/var/log/cluster/corosync.log



SSH to ' mkdir-pv/var/log/cluster/'
SCP Authkey corosync.conf two:/etc/corosync/
SSH to '/etc/rc.d/init.d/corosync start '


Node I: one 172.16.249.122
Download RPM packages for three and related Crmsh
Python-pssh-2.3.1-4.2.x86_64
Pssh-2.3.1-4.2.x86_64
Crmsh-2.1-1.6.x86_64
Cd
wget http://download.opensuse.org/repositories/network:/ha-clustering:/Stable/CentOS_CentOS-6/x86_64/ crmsh-2.1-1.6.x86_64.rpm
wget http://download.opensuse.org/repositories/network:/ha-clustering:/Stable/CentOS_CentOS-6/x86_64/ pssh-2.3.1-4.2.x86_64.rpm
wget http://download.opensuse.org/repositories/network:/ha-clustering:/Stable/CentOS_CentOS-6/x86_64/ python-pssh-2.3.1-4.2.x86_64.rpm
Yum-y Install *.rpm
CRM Status
>online: [One.centos Two.centos]

SCP *.rpm
SSH to ' yum-y install *.rpm '




Node I: one 172.16.249.122
Add a cluster resource
Disable Stonith:
# CRM Configure Property Stonith-enabled=false
Modify a cluster status check that ignores quorum:
# CRM Configure Property No-quorum-policy=ignore
Specify a default stickiness value for a resource:
# CRM Configure Rsc_defaults resource-stickiness=100

Add IP resources to access mariadb
CRM Configure primitive VIP OCF:HEARTBEAT:IPADDR params ip=172.16.249.121
Adding NFS File system resources
CRM Configure primitive Mynfs Ocf:heartbeat:Filesystem params device= "172.16.249.124:/sharedata" directory= "/data/ MyData "Fstype=" NFS "OP start timeout=60s op stop timeout=60s
To view defined resources
CRM Configure Show
CRM Status
>VIP (OCF::HEARTBEAT:IPADDR): Started One
>mynfs (Ocf::heartbeat:filesystem): Started

IP addr Show
>inet 172.16.249.122/16
>inet 172.16.249.121/16
SSH to ' ls/data/mydata/'

SSH two ' CRM node standby ' #必须滴, let two resources run on One.centos

CRM Status
>node Two.centos:standby
>online: [One.centos]
> VIP (OCF::HEARTBEAT:IPADDR): Started One.centos
> Mynfs (ocf::heartbeat:filesystem): Started One.centos


Add mysqld Service Resource
CRM Configure primitive Mysqld Lsb:mysqld

The boot order for VIPs, Mynfs, and mysqld resources is vip-->mynfs-->mysqld
Defining an arrangement constraint
CRM Configure collocation mysqld_with_mynfs_vip INF:VIP Mynfs mysqld

Defining Order Constraints
CRM Configure Order Mysqld_after_mynfs_after_vip MANDATORY:VIP Mynfs mysqld

CRM Configure Show

View collocation and order constraints defined in the cluster repository
CRM Configure show XML
collocation constraint configuration information//
<rsc_colocation id= "Mysqld_with_mynfs_vip" score= "INFINITY" >
<resource_set id= "mysqld_with_mynfs_vip-0" >
<resource_ref id= "VIP"/>
<resource_ref id= "Mynfs"/>
<resource_ref id= "Mysqld"/>
Order constraint configuration Information//
<rsc_order id= "Mysqld_after_mynfs_after_vip" score= "INFINITY" > #INFINITY =>mandatory (mandatory)
<resource_set id= "mysqld_after_mynfs_after_vip-0" >
<resource_ref id= "VIP"/>
<resource_ref id= "Mynfs"/>
<resource_ref id= "Mysqld"/>



CRM Status
>online: [One.centos Two.centos]

> VIP (OCF::HEARTBEAT:IPADDR): Started Two.centos
> Mynfs (ocf::heartbeat:filesystem): Started Two.centos
> mysqld (lsb:mysqld): Started Two.centos
===================

SSH to ' CRM node online '
CRM Status
>online: [One.centos Two.centos]
CRM node Standby
CRM Status
>node One.centos:standby
>online: [Two.centos]
> VIP (OCF::HEARTBEAT:IPADDR): Started Two.centos
> Mynfs (ocf::heartbeat:filesystem): Started Two.centos
> mysqld (lsb:mysqld): Started Two.centos
=================




Node II: two 172.16.249.123
Mysql
mysql> show databases;
mysql> CREATE DATABASE Twodb;
Mysql> quit;

SSH One ' CRM node online '
CRM Status
>online: [One.centos Two.centos]
> VIP (OCF::HEARTBEAT:IPADDR): Started Two.centos
> Mynfs (ocf::heartbeat:filesystem): Started Two.centos
> mysqld (lsb:mysqld): Started Two.centos
=============

CRM node Standby
>node Two.centos:standby
>online: [One.centos]
> VIP (OCF::HEARTBEAT:IPADDR): Started One.centos
> Mynfs (ocf::heartbeat:filesystem): Started One.centos
> mysqld (lsb:mysqld): Started One.centos
===============



Node I: one 172.16.249.122
Mysql
mysql> show databases;
+---------------------+
| Database |
+---------------------+
| Information_schema |
| #mysql50 #lost+found |
| MySQL |
| Performance_schema |
| Test |
|                 Twodb | ---See this database stating that the highly available service configuration was successful
+---------------------+
Mysql> quit;

COROSYNC+PACEMAKER+NFS provides MySQL high availability

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.