Deploy Percona XtraDB Cluster in CentOS6 Environment
Host planning:
192.168.0.221os6—221
192.168.0.222os6—222
192.168.0.223os6—223
192.168.0.224os6—224haproxy
192.168.0.225os6—225haproxy
Installation script:
#!/bin/bash
sed
-i
"s/SELINUX=enforcing/SELINUX=disabled/g"
/etc/selinux/config
setenforce0
serviceiptablesstart
iptables-F
iptables-AINPUT-ptcp-ieth0--dport3306-mstate--stateNEW,ESTABLISHED-jACCEPT
iptables-AINPUT-ptcp-ieth0--dport4444-mstate--stateNEW,ESTABLISHED-jACCEPT
iptables-AINPUT-ptcp-ieth0--dport4567-mstate--stateNEW,ESTABLISHED-jACCEPT
iptables-AINPUT-ptcp-ieth0--dport4568-mstate--stateNEW,ESTABLISHED-jACCEPT
yum
install
ntp-y
ntpdatecn.pool.ntp.org
echo
"*/1****rootntpdatecn.pool.ntp.org"
>>
/etc/crontab
Before installing percona, you must delete mysql-libs. This package conflicts with percona.
yumremovemysql-libs-y
rpm-ivhhttp:
//dl
.fedoraproject.org
/pub/epel/6/x86_64/epel-release-6-8
.noarch.rpm
yum
install
socat-y
yum
install
http:
//www
.percona.com
/downloads/percona-release/redhat/0
.1-3
/percona-release-0
.1-3.noarch-y
yum
install
Percona-XtraDB-Cluster-56-y
Configuration File:/etc/my. cnf
Boot server configuration, that is, os6 --- 221
[mysqld]
#wsrep
wsrep_provider=
/usr/lib64/libgalera_smm
.so
wsrep_cluster_address=gcomm:
//os6---221
,os6-222,os6---223
binlog_format=ROW
default_storage_engine=InnoDB
innodb_autoinc_lock_mode=2
wsrep_node_address=os6---221
wsrep_sst_method=xtrabackup-v2
wsrep_cluster_name=singulax
wsrep_sst_auth=“wsrep:wsrep”
Start os6-221 Database
/etc/init
.d
/myslq
bootstrap-pxc
Create a replication user (this step only needs to be performed on the init server and will be automatically copied when other servers are started. See PXC replication Principles)
GRANTRELOAD,LOCKTABLES,REPLICATIONCLIENTON*.*TOwsrep@
'localhost'
IDENTIFIEDBY‘wsrep';
FLUSHPRIVILEGES;
Os6 --- 221 Server
[mysqld]
#wsrep
wsrep_provider=
/usr/lib64/libgalera_smm
.so
wsrep_cluster_address=gcomm:
//os6---221
,os6-222,os6---223
binlog_format=ROW
default_storage_engine=InnoDB
innodb_autoinc_lock_mode=2
wsrep_node_address=os6---222
wsrep_sst_method=xtrabackup-v2
wsrep_cluster_name=singulax
wsrep_sst_auth=“wsrep:wsrep”
Start os6-222 Database
/etc/init
.d
/mysql
start||servicemysqlstart
Os6 --- 223 Server
[mysqld]
#wsrep
wsrep_provider=
/usr/lib64/libgalera_smm
.so
wsrep_cluster_address=gcomm:
//os6---221
,os6-222,os6---223
binlog_format=ROW
default_storage_engine=InnoDB
innodb_autoinc_lock_mode=2
wsrep_node_address=os6---223
wsrep_sst_method=xtrabackup-v2
wsrep_cluster_name=singulax
wsrep_sst_auth=“wsrep:wsrep”
Start os6-223 Database
/etc/init
.d
/mysql
start||servicemysqlstart
After pxc is installed, the clustercheck command and port 9200 are automatically executed to check whether the mysql service is normal.
Usage:
/usr/bin/clustercheck
<user><pass><available_when_donor=0|1><log_file><available_when_readonly=0|1><defaults_extra_file>
Add detection User:
grantprocesson*.*toclustercheckuser@
'localhost'
identifiedby‘clustercheckuser';
Check Result: 200 or 503. For example:
clustercheckclustercheckuserclustercheckuser
HTTP
/1
.1200OK
Content-Type:text
/plain
Connection:close
Content-Length:40
PerconaXtraDBClusterNodeissynced.
Port 9200: Install xinetd and use xinetd to generate port 9200.
yum
install
xinetd-y
After xinetd is installed, the mysqlchk file is generated and configured.
#default:on
#description:mysqlchk
servicemysqlchk
{
#thisisaconfigforxinetd,placeitin/etc/xinetd.d/
disable=no
flags=REUSE
socket_type=stream
type
=UNLISTED
port=9200
wait=no
user=nobody
server=
/usr/bin/clustercheck
log_on_failure+=USERID
only_from=0.0.0.0
/0
#
#Passingargumentstoclustercheck
#<user><pass><available_when_donor=0|1><log_file><available_when_readonly=0|1><defaults_extra_file>"
#Recommended:server_args=userpass1/var/log/log-file0/etc/my.cnf.local"
#Compatibility:server_args=userpass1/var/log/log-file1/etc/my.cnf.local"
#55-to-56upgrade:server_args=userpass1/var/log/log-file0/etc/my.cnf.extra"
server_args=clustercheckuserclustercheckuser
#recommendedtoputtheIPsthatneed
#toconnectexclusively(securitypurposes)
per_source=UNLIMITED
}
Then, add a new service for port 9200 in/etc/services.
mysqlchk9200
/tcp
#mysqlchk
Start xinetd
servicexinetdstart
chkconfigxinetdon
Haproxy load balancing and Detection
Install haproxy
yum
install
haproxy-y
# Centos6 official built-in installation package, directly install yum
Configure Firewall
iptables-AINPUT-ptcp--dport8080-mstate--stateNEW,ESTABLISHED-jACCEPT
iptables-AINPUT-ptcp--dport3306-mstate--stateNEW,ESTABLISHED-jACCEPT
iptables-AINPUT-ptcp--dport3307-mstate--stateNEW,ESTABLISHED-jACCEPT
Configuration file:
frontendstats-front
bind*:8080
modehttp
default_backendstats-back
frontendpxc-front
bind*:3307
modetcp
default_backendpxc-back
frontendpxc-onenode-front
bind*:3308
modetcp
default_backendpxc-onenode-back
backendstats-back
modehttp
balanceroundrobin
statsuri
/haproxy/stats
statsauthhaproxy:haproxy
backendpxc-back
modetcp
balanceleastconn
optionhttpchk
serverc1192.168.115.221:3306checkport9200inter12000rise3fall3
serverc2192.168.115.222:3306checkport9200inter12000rise3fall3
serverc3192.168.115.223:3306checkport9200inter12000rise3fall3
backendpxc-onenode-back
modetcp
balanceleastconn
optionhttpchk
serverc1192.168.115.221:3306checkport9200inter12000rise3fall3
serverc2192.168.115.222:3306checkport9200inter12000rise3fall3backup
serverc3192.168.115.223:3306checkport9200inter12000rise3fall3backup
Start
servicehaproxystart
servicehaproxystop
Access:
http:
//192
.168.115.224:8080
/haproxy/stats