Percona 介绍

Percona Server由领先的MySQL咨询公司Percona发布。Percona Server是一款独立的数据库产品,其可以完全与MySQL兼容,可以在不更改代码的情况了下将存储引擎更换成XtraDB 。

Percona团队的最终声明是“Percona Server是由Oracle发布的最接近官方MySQL Enterprise发行版的版本”,因此与其他更改了大量基本核心MySQL代码的分支有所区别。Percona Server的一个缺点是他们自己管理代码,不接受外部开发人员的贡献,以这种方式确保他们对产品中所包含功能的控制。

Percona提供了高性能XtraDB引擎,还提供PXC高可用解决方案,并且附带了percona-toolkit等DBA管理工具箱。

官方给出了MySQL5.6.14和Percona Server 5.6.13的性能对比结果:

.Percona在高负载压力情况下的稳定性要高于MySQL

.Percona在高负载压力情况下的性能要高于MySQL

一 安装 percona server

yum install -y http://www.percona.com/downloads/percona-release/redhat/0.1-4/percona-release-0.1-4.noarch.rpm

yum install -y Percona-Server-server-57

查看/etc/my.cnf的配置信息:

!includedir /etc/my.cnf.d/

!includedir /etc/percona-server.conf.d/

datadir=/var/lib/mysql

socket=/var/lib/mysql/mysql.sock

# Disabling symbolic-links is recommended to prevent assorted security risks

symbolic-links=0

log-error=/var/log/mysqld.log

pid-file=/var/run/mysqld/mysqld.pid

初始化数据库:

[root@percona percona-server.conf.d]# mysqld --initialize --user=mysql

启动数据库:

Service mysqld start

查看mysql进程:

ps –ef|grep mysql

获取root初始化密码: 在/var/log/mysqld.log中所有password关键词,获取初始化密码 2017-08-03T12

二 Percona XtraDB Cluster 介绍

Percona XtraDB Cluster是MySQL高可用性和可扩展性的解决方案.

Percona XtraDB Cluster提供的特性有:

1.同步复制,事务要么在所有节点提交或不提交。

2.多主复制,可以在任意节点进行写操作。

3.在从服务器上并行应用事件,真正意义上的并行复制。

4.节点自动配置。

5.数据一致性,不再是异步复制。

Percona XtraDB Cluster完全兼容MySQL和Percona Server,表现在:

1.数据的兼容性

2.应用程序的兼容性:无需更改应用程序

1.集群是有节点组成的,推荐配置至少3个节点,但是也可以运行在2个节点上。

2.每个节点都是普通的mysql/percona服务器,可以将现有的数据库服务器组成集群,反之,也可以将集群拆分成单独的服务器。

3.每个节点都包含完整的数据副本。

优点如下:

1.当执行一个查询时,在本地节点上执行。因为所有数据都在本地,无需远程访问。

2.无需集中管理。可以在任何时间点失去任何节点,但是集群将照常工作。

3.良好的读负载扩展,任意节点都可以查询。

缺点如下:

1.加入新节点,开销大。需要复制完整的数据。

2.不能有效的解决写缩放问题,所有的写操作都将发生在所有节点上。

3.有多少个节点就有多少重复的数据

Percona XtraDB Cluster基于XtraDB的Percona Server以及包含写复制集补丁。使用Galera 2.x library,事务型应用下的通用的多主同步复制插件。

三 Percona XtraDB Cluster安装

删除原本安装的percona server软件:

yum erase -y Percona-Server-server-57

yum erase -y Percona-Server-client-57

安装软件:

yum install -y Percona-XtraDB-Cluster-57

启动mysql服务:

[root@percona mysql]# service mysql start

在log文件中找到root的临时密码:

Vi /var/log/mysql.log

2017-08-03T14:13:02.319082Z 1 [Note] A temporary password is generated for root@localhost: aNIjY*p=Z9>N

修改root密码:

[root@percona mysql]# mysql -u root -p

Enter password:

mysql>

mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'mysql';

配置各个节点的/etc/percona-xtradb-cluster.conf.d/wsrep.cnf文件: 

[root@percona percona-xtradb-cluster.conf.d]# vi wsrep.cnf 

[mysqld] 

# Path to Galera library

 wsrep_provider=/usr/lib64/galera3/libgalera_smm.so 

# Cluster connection URL contains IPs of nodes 

#If no IP is found, this implies that a new cluster needs to be created, 

#in order to do that you need to bootstrap this node wsrep_cluster_address=gcomm://192.168.237.135, 192.168.237.136

 # 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 

# Slave thread to use 

wsrep_slave_threads= 8 

wsrep_log_conflicts

 # This changes how InnoDB autoincrement locks are managed and is a requirement for Galera innodb_autoinc_lock_mode=2 

# Node IP address 

wsrep_node_address=192.168.237.135 

# Cluster name 

wsrep_cluster_name=pxc-cluster 

#If wsrep_node_name is not specified, then system hostname will be used wsrep_node_name=percona 

#pxc_strict_mode allowed values: DISABLED,PERMISSIVE,ENFORCING,MASTER pxc_strict_mode=ENFORCING 

# SST method 

wsrep_sst_method=rsync 

#Authentication for SST method

 #wsrep_sst_auth="sstuser:mysql"

配置第二个节点的/etc/percona-xtradb-cluster.conf.d/wsrep.cnf文件:

 [mysqld]

 # Path to Galera library 

wsrep_provider=/usr/lib64/galera3/libgalera_smm.so

 # Cluster connection URL contains IPs of nodes #If no IP is found, this implies that a new cluster needs to be created, 

#in order to do that you need to bootstrap this node wsrep_cluster_address=gcomm://192.168.237.135, 192.168.237.136 

# 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 

# Slave thread to use

 wsrep_slave_threads= 8 

wsrep_log_conflicts

 # This changes how InnoDB autoincrement locks are managed and is a requirement for Galera innodb_autoinc_lock_mode=2 

# Node IP address 

wsrep_node_address=192.168.237.136 

# Cluster name 

wsrep_cluster_name=pxc-cluster 

#If wsrep_node_name is not specified, then system hostname will be used 

wsrep_node_name=percona2 

#pxc_strict_mode allowed values: DISABLED,PERMISSIVE,ENFORCING,MASTER pxc_strict_mode=ENFORCING 

# SST method wsrep_sst_method=rsync 

#Authentication for SST method 

#wsrep_sst_auth="sstuser:mysql"

启动第一个节点:

[root@percona percona-xtradb-cluster.conf.d]# systemctl start mysql@bootstrap.service

mysql> show status like 'wsrep_%';

启动第二个节点:

Service mysql start

查看集群状态:

mysql> show status like 'wsrep_cluster_size';

+--------------------+-------+

| Variable_name | Value |

+--------------------+-------+

| wsrep_cluster_size | 2 |