Deployment of Percona XtraDB Cluster in CentOS6 environment

Source: Internet
Author: User
Tags iptables percona haproxy



Host Planning:

192.168.0.221 os6-221192.168.0.222 os6-222192.168.0.223 os6-223192.168.0.224 os6-224 haproxy192.168.0.225 os6-225 Haproxy


Installation script:

#!/bin/bashsed  -i  "S/selinux=enforcing/selinux=disabled/g"    /etc/selinux/ Configsetenforce 0service iptables  startiptables  -fiptables  -a   input -p  tcp -i eth0  --dport 3306 -m state  --state new,established -j   acceptiptables  -a  input  -p  tcp -i eth0  --dport 4444 -m state --state  New,established -j   acceptiptables  -a  input -p  tcp  -i eth0  --dport 4567 -m state --state new,established -j    ACCEPTiptables  -A  INPUT -p  tcp -i eth0   --dport 4568 -m state --state NEW,ESTABLISHED -j    Acceptyum  install  ntp  -yntpdate cn.pool.ntp.orgecho  "*/1 * * * * root   Ntpdate cn.pool.ntp.org "   >> /etc/crontab


Before installing Percona, you must remove Mysql-libs, this package and Percona conflict.

Yum Remove mysql-libs-y
RPM-IVH Http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpmyum Install Socat-y
Yum Install Http://www.percona.com/downloads/percona-release/redhat/0.1-3/percona-release-0.1-3.noarch-yyum Install Percona-xtradb-cluster-56-y


Configuration file:/etc/my.cnf

Boot server configuration, i.e. OS6---221

[mysqld] #wsrepwsrep_provider =/usr/lib64/libgalera_smm.sowsrep_cluster_address=gcomm://os6---221,os6-222, OS6---223binlog_format=rowdefault_storage_engine=innodbinnodb_autoinc_lock_mode=2wsrep_node_address= OS6---221wsrep_sst_method=xtrabackup-v2wsrep_cluster_name=singulaxwsrep_sst_auth= "wsrep:wsrep"


Start the 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 copied automatically when the other server is started. Refer to PXC copy principle)

GRANT RELOAD, LOCK TABLES, REPLICATION CLIENT on *. * to [email protected] ' localhost ' identified by ' wsrep '; FLUSH privileges;


OS6---221 server

[mysqld] #wsrepwsrep_provider =/usr/lib64/libgalera_smm.sowsrep_cluster_address=gcomm://os6---221,os6-222, OS6---223binlog_format=rowdefault_storage_engine=innodbinnodb_autoinc_lock_mode=2wsrep_node_address= OS6---222wsrep_sst_method=xtrabackup-v2wsrep_cluster_name=singulaxwsrep_sst_auth= "wsrep:wsrep"


Start the os6-222 database

/etc/init.d/mysql Start | | Service MySQL Start

OS6---223 server

[mysqld] #wsrepwsrep_provider =/usr/lib64/libgalera_smm.sowsrep_cluster_address=gcomm://os6---221,os6-222, OS6---223binlog_format=rowdefault_storage_engine=innodbinnodb_autoinc_lock_mode=2wsrep_node_address= OS6---223wsrep_sst_method=xtrabackup-v2wsrep_cluster_name=singulaxwsrep_sst_auth= "wsrep:wsrep"


Start the os6-223 database

/etc/init.d/mysql Start | | Service MySQL Start

After the PXC is installed, the MySQL service is automatically checked for Clustercheck commands and 9200 ports.


Usage:

/usr/bin/clustercheck <user> <pass> <available_when_donor=0|1> <log_file> <available_ When_readonly=0|1> <defaults_extra_file>

To add a detection user:

Grant Process on * * to [e-mail protected] ' localhost ' identified by ' clustercheckuser ';

Test results returned: 200 or 503. For example

Clustercheck Clustercheckuser clustercheckuserhttp/1.1 Okcontent-type:text/plainconnection:closecontent-le Ngth:40percona XtraDB Cluster Node is synced.


9200 Port: Install the xinetd first and generate 9200 ports with xinetd.

Yum Install Xinetd-y


XINETD after the installation is complete, generate the Mysqlchk file and configure

# default: on# description: mysqlchkservice mysqlchk{# this is a  config for xinetd, place it in /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        #         # Passing arguments to clustercheck         # <user> <pass> <available_when_donor=0|1 > <log_file> <available_when_readonly=0|1> <defaults_extra_file> "         # recommended: server_args   = user  pass 1 /var/log/log-file 0 /etc/my.cnf.local "         # compatibilitY: server_args = user pass 1 /var/log/log-file 1 /etc/my.cnf.local "         # 55-to-56 upgrade: server_args =  User pass 1 /var/log/log-file 0 /etc/my.cnf.extra "         server_args = clustercheckuser  clustercheckuser         # recommended to put the IPs that need         # to connect exclusively  (security purposes)         per_source      = unlimited }

Then, add a new service to port 9200 on/etc/services

Mysqlchk 9200/tcp # Mysqlchk

Start xinetd

Service xinetd Startchkconfig xinetd on


Haproxy load Balancing and detection

Installing Haproxy

Yum install haproxy-y #centos6官方自带安装包, direct yum installation

Configuring firewalls

Iptables-a input-p TCP--dport 8080-m State--state new,established-j acceptiptables-a input-p TCP--DP ORT 3306-m State--state new,established-j acceptiptables-a input-p TCP--dport 3307-m State--state NEW, Established-j ACCEPT

Configuration file:

frontend stats-frontbind *:8080mode httpdefault_backend stats-backfrontend  pxc-frontbind *:3307mode tcpdefault_backend pxc-backfrontend pxc-onenode-frontbind * :3308mode tcpdefault_backend pxc-onenode-backbackend stats-backmode httpbalance  Roundrobinstats uri /haproxy/statsstats auth haproxy:haproxybackend pxc-backmode  tcpbalance leastconnoption httpchkserver c1 192.168.115.221:3306 check  port 9200 inter 12000 rise 3 fall 3server c2 192.168.115.222:3306  check port 9200 inter 12000 rise 3 fall 3server c3  192.168.115.223:3306 check port 9200 inter 12000 rise 3 fall  3backend pxc-onenode-backmode tcpbalance leastconnoption httpchkserver c1  192.168.115.221:3306 check port 9200 inter 12000 rise 3 fall 3server c2 192.168.115.222:3306  Check port 9200 inter 12000 rise 3 fall 3 backupserver c3  192.168.115.223:3306 check port 9200 inter 12000 rise 3 fall  3 backup

Start

Service Haproxy StartService Haproxy stop


Access:

Http://192.168.115.224:8080/haproxy/stats


This article from the "Do not ask for the best, only better" blog, please be sure to keep this source http://yujianglei.blog.51cto.com/7215578/1726409

Deployment of Percona XtraDB Cluster in CentOS6 environment

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.