Installing Percona XtraDB Cluster on CentOS
Posted 曹小贱
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Installing Percona XtraDB Cluster on CentOS相关的知识,希望对你有一定的参考价值。
PXC简介
原理描述
分布式系统的CAP理论:
C 一致性,所有的节点数据一致
A 可用性,一个或者多个节点失效,不影响服务请求
P 分区容忍性,节点间的连接失效,仍然可以处理请求
任何一个分布式系统,需要满足这三个中的两个
安装部署
环境描述
三个node节点
hostname: percona1
IP: 192.168.100.7
node #2
hostname: percona2
IP: 192.168.100.8
node #3
hostname: percona3
IP: 192.168.100.9
基础环境包
三个node节点都要执行以下操作。
基础环境
yum -y groupinstall Base Compatibility libraries Debugging Tools Dial-up Networking suppport Hardware monitoring utilities Performance Tools Development tools
yum install http://www.percona.com/downloads/percona-release/redhat/0.1-3/percona-release-0.1-3.noarch.rpm -y
yum install Percona-XtraDB-Cluster-55 -y
数据库配置
选择一个node作为名义上的master,咱们以node1为master,以下操作只在node1上执行。
只需要修改mysql的配置文件--/etc/my.cnf
说明:这里的IP地址是内网地址。
[[email protected]-kysyolko ~]# cat /etc/my.cnf
# Template my.cnf for PXC
# Edit to your requirements.
[mysqld]
datadir=/var/lib/mysql
user=mysql
# Path to Galera library
wsrep_provider=/usr/lib64/libgalera_smm.so
# Cluster connection URL contains the IPs of node#1, node#2 and node#3
wsrep_cluster_address=gcomm://192.168.100.7,192.168.100.8,192.168.100.9
# In order for Galera to work correctly binlog format should be ROW
binlog_format=ROW
# MyISAM storage engine has only experimental support
default_storage_engine=InnoDB
# This changes how InnoDB autoincrement locks are managed and is a requirement for Galera
innodb_autoinc_lock_mode=2
# Node #1 address
wsrep_node_address=192.168.100.7
# SST method
wsrep_sst_method=xtrabackup-v2
# Cluster name
wsrep_cluster_name=my_centos_cluster
# Authentication for SST method
wsrep_sst_auth="sstuser:s3cret"
[mysqld_safe]
pid-file = /run/mysqld/mysql.pid
syslog
!includedir /etc/my.cnf.d
启动数据库
CentOS6:/etc/init.d/mysql bootstrap-pxc
CentOS7:systemctl start [email protected]
配置数据库
mysql> show status like ‘wsrep%‘;
+----------------------------+--------------------------------------+
| Variable_name | Value |
+----------------------------+--------------------------------------+
| wsrep_local_state_uuid | c2883338-834d-11e2-0800-03c9c68e41ec |
...
| wsrep_local_state | 4 |
| wsrep_local_state_comment | Synced |
...
| wsrep_cluster_size | 1 #主要看这里 |
| wsrep_cluster_status | Primary |
| wsrep_connected | ON |
...
| wsrep_ready | ON |
+----------------------------+--------------------------------------+
40 rows in set (0.01 sec)
# 数据库用户名密码的设置
[email protected]> UPDATE mysql.user SET password=PASSWORD("Passw0rd") where user=‘root‘;
# 创建、授权、同步账号
[email protected]> CREATE USER ‘sstuser‘@‘localhost‘ IDENTIFIED BY ‘s3cret‘;
[email protected]> GRANT RELOAD, LOCK TABLES, REPLICATION CLIENT ON *.* TO ‘sstuser‘@‘localhost‘;
[email protected]> FLUSH PRIVILEGES;
node2、node3节点配置
只需要修改第26行,当前node的IP地址。两个node都是只是修改这个地址即可。
wsrep_node_address=192.168.100.8
[[email protected]-kysyolko ~]# cat /etc/my.cnf
# Template my.cnf for PXC
# Edit to your requirements.
[mysqld]
datadir=/var/lib/mysql
user=mysql
# Path to Galera library
wsrep_provider=/usr/lib64/libgalera_smm.so
# Cluster connection URL contains the IPs of node#1, node#2 and node#3
wsrep_cluster_address=gcomm://192.168.100.7,192.168.100.8,192.168.100.9
# In order for Galera to work correctly binlog format should be ROW
binlog_format=ROW
# MyISAM storage engine has only experimental support
default_storage_engine=InnoDB
# This changes how InnoDB autoincrement locks are managed and is a requirement for Galera
innodb_autoinc_lock_mode=2
# Node #1 address
wsrep_node_address=192.168.100.8
# SST method
wsrep_sst_method=xtrabackup-v2
# Cluster name
wsrep_cluster_name=my_centos_cluster
# Authentication for SST method
wsrep_sst_auth="sstuser:s3cret"
[mysqld_safe]
pid-file = /run/mysqld/mysql.pid
syslog
!includedir /etc/my.cnf.d
启动数据库
CentOS6:/etc/init.d/mysql start
CentOS7:systemctl start mysql.service
说明:
1、除了名义上的master之外,其它的node节点只需要启动mysql即可。
2、节点的数据库的登陆和master节点的用户名密码一致,自动同步。所以其它的节点数据库用户名密码无须重新设置。
测试
在任意一个node上,进行操作,然后去其它的节点上看是否取得相同的结果。
官方引用:
https://www.percona.com/doc/percona-xtradb-cluster/5.5/howtos/centos_howto.html
以上是关于Installing Percona XtraDB Cluster on CentOS的主要内容,如果未能解决你的问题,请参考以下文章