PXC(Percona XtraDB Cluster)集群安装

Percona XtraDB Cluster是一个开源,免费的MySQL高可用工具.

General introduction

  1. 集群由节点组成.推荐三个以上的节点,不过两个节点也能运行.
  2. 每个节点正常安装MySQL或者Percona Server.可以使用已经存在的MySQL或者Percona Server数据库充当集群中的节点.另外,也可以把集群中的节点拆出来,当作普通的MySQL/Percona Server使用.
  3. 每个节点都包括一份完整的数据.That defines XtraDB Cluster behavior in many ways. And obviously there are benefits and drawbacks.

  1. Benefits of such approach:
    • 当你在本地节点执行一个查询的时候,不需要远程访问,本地节点所有数据是可用的.
    • 没有中心管理者.你可以在任意时间失去任何一个节点,并且集群还可以提供服务.
    • 对于读压力大的架构,是一个非常好的弹性方案.你能够在所有节点执行读操作.
  2. Drawbacks:
    • 加入新节点的开销比较大.它需要复制全部数据,如果有100G,那么就会复制100G.
    • 不能作为可扩展写入的方案.在任何一个节点写入,在集群中的其他节点都会写入.即,所有节点会写入相同的数据.
    • 会存在很多重复的数据.例如,3个节点,那么就会有3份数据.

What is core difference Percona XtraDB Cluster from MySQL Replication ?

分布式系统中的CAP理论,CAP理论指出,对一个分布式系统只能满足三个中的两个,不可能同时满足.
http://zh.wikipedia.org/wiki/CAP%E5%AE%9A%E7%90%86
一致性(Consistency) (所有节点在同一时间具有相同的数据)
可用性(Availability) (保证每个请求不管成功或者失败都有响应)
分隔容忍(Partition tolerance) (系统中任意信息的丢失或失败不会影响系统的继续运作)

MySQL replication has: Availability and Partitioning tolerance.
Percona XtraDB Cluster has: Consistency and Availability.

MySQL复制不能保证数据的一致性.Percona XtraDB Cluster保证数据的一致性.(失去了分区容忍度)

Components

Percona XtraDB Cluster 是基于Percona Server with XtraDB数据库并且包括Write Set Replication插件补丁.使用Galera library.版本2.x,一个通用的多主同步复制插件.
Galera library is developed by Codership Oy.
Galera 2.x supports such new features as:

  1. Incremental State Transfer (IST), especially useful for WAN deployments,
  2. RSU, Rolling Schema Update. Schema change does not block operations against table.

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

作者在2014Oracle数据库嘉年华中有幸听到了关于去哪网的MySQL数据库基于PXC的高可用架构设计主题。

MySQL和Oracle是完全不同的两种数据库,Oracle重于管理,而MySQL更重要的是架构设计。笔者对MySQL以及新技术也是充满了好奇,索性回来自己搭建一个测试环境。

 

操作系统:CentOS 6.6

软件版本:5.5.39-36.0-55 PerconaXtraDB Cluster (GPL)

 

节点信息:

pxc1192.168.0.200
pxc2192.168.0.201
pxc3192.168.0.202

安装过程

安装PXC,这里使用的是Percona以及EPEL的官方repositories :

http://www.percona.com/doc/percona-server/5.5/installation/yum_repo.html?id=repositories:yum 

http://fedoraproject.org/wiki/EPEL


  1. yum installhttp://www.percona.com/downloads/percona-release/redhat/0.1-3/percona-release-0.1-3.noarch.rpm  
  2. yum installhttp://mirrors.ustc.edu.cn/fedora/epel/6/i386/epel-release-6-8.noarch.rpm  
  3. yum -y install Percona-XtraDB-Cluster-serverPercona-XtraDB-Cluster-client Percona-Server-shared-compat percona-xtrabackup  



 

每台机器开启PXC,之后添加SST账户:

  1. DELETE FROM mysql.user WHERE user='';  
  2. GRANT RELOAD, LOCK TABLES, REPLICATION CLIENT ON *.* TO 'sstuser'@'localhost' IDENTIFIED BY 'sstuser';;  
  3. FLUSH PRIVILEGES;  


 

每个节点关闭PXC。编辑第一个节点的PXC设置。

 

  1. [mysqld]  
  2. server_id=1  
  3. wsrep_provider=/usr/lib64/libgalera_smm.so  
  4. wsrep_cluster_address="gcomm://192.168.0.200,192.168.0.201,192.168.0.202"  
  5. wsrep_sst_auth=sstuser:sstuser  
  6. wsrep_provider_options="gcache.size=4G"  
  7. wsrep_cluster_name=Percona  
  8. wsrep_sst_method=xtrabackup  
  9. wsrep_node_name=pxc1  
  10. wsrep_slave_threads=4  
  11. log_slave_updates  
  12. innodb_locks_unsafe_for_binlog=1  
  13. innodb_autoinc_lock_mode=2  


 

 

开启第一个节点(如果集群关闭,每次拥有正确信息的节点使用此命令开启集群)

 

  1. [root@pxc1 ~]# service mysql bootstrap-pxc  
  2. Bootstrapping PXC (Percona XtraDBCluster)Starting MySQL (Percona XtraDB Cluster)..[  OK  ]  
  3.    


 

编辑另外两个节点的my.cnf配置文件需要修改的内容:

  1. server_id=2  
  2. wsrep_node_name=pxc2  



将其他两个节点加入到集群中

  1. service mysql start  


至此,集群安装结束。


遇到的问题

以下是配置过程中的报错信息以及解决方法:

 

现象:

开启PXC节点的时候遇到

  1. Failed to read output of: 'ip addr show | grep -E '^[ ]*inet' | grep -m1global | awk '{ print $2 }' | sed -e 's/\/.*//''  
  2. ........  
  3. 141120 22:46:35 [ERROR] WSREP: Permission denied  
  4. 141120 22:46:35 [ERROR] WSREP: failed to open gcomm backend connection: 13:error while trying to listen 'tcp://0.0.0.0:4567?socket.non_blocking=1', asioerror 'Permission denied': 13 (Permission denied)  


原因:

由于开启了SELINUX。

解决方法:

编辑文件/etc/sysconfig/selinux

SELINUX设为disabled

重启后就会忽略selinux,或者直接执行命令

setenforce 0

立即生效。

 

现象:

添加节点到集群中的时候遇到

last inactive check morethan PT1.5S ago (PT3.50529S), skipping check

卡在这里

原因:

iptables

解决方法:

关闭iptables

 

chkconfig iptables off

service iptables stop

 


简单测试

  1. [root@pxc1 ~]# mysql  
  2.   
  3. Welcome to the MySQL monitor.  Commands end with ; or \g.  
  4.   
  5. Your MySQL connection id is 7  
  6.   
  7. Server version: 5.5.39-36.0-55 Percona XtraDB Cluster (GPL), Release rel36.0, Revision 824, WSREP version 25.11, wsrep_25.11.r4023  
  8.   
  9.   
  10. Copyright (c) 2009-2014 Percona LLC and/or its affiliates  
  11.   
  12. Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.  
  13.   
  14.   
  15. Oracle is a registered trademark of Oracle Corporation and/or its  
  16.   
  17. affiliates. Other names may be trademarks of their respective  
  18.   
  19. owners.  
  20.   
  21.   
  22. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.  
  23.   
  24.   
  25. mysql> show global status like 'wsrep_cluster_size';  
  26.   
  27. +--------------------+-------+  
  28.   
  29. | Variable_name      | Value |  
  30.   
  31. +--------------------+-------+  
  32.   
  33. | wsrep_cluster_size | 2     |  
  34.   
  35. +--------------------+-------+  
  36.   
  37. 1 row in set (0.00 sec)  
  38.   
  39.   
  40. mysql> show global status like 'wsrep_cluster_size';  
  41.   
  42. +--------------------+-------+  
  43.   
  44. | Variable_name      | Value |  
  45.   
  46. +--------------------+-------+  
  47.   
  48. | wsrep_cluster_size | 3     |  
  49.   
  50. +--------------------+-------+  
  51.   
  52. 1 row in set (0.00 sec)  
  53.   
  54.   
  55. mysql> create database dexdb ;  
  56.   
  57. Query OK, 1 row affected (0.01 sec)  
  58.   
  59.   
  60. mysql> use dexdb  
  61.   
  62. Database changed  
  63.   
  64. mysql> create table dextb (id int ,name char(10))  engine=innodb ;  
  65.   
  66. Query OK, 0 rows affected (0.03 sec)  
  67.   
  68.   
  69. mysql> insert into dextb values (1,'22') ;  
  70.   
  71. Query OK, 1 row affected (0.01 sec)  
  72.   
  73.   
  74. mysql> insert into dextb values (1,'22') ;  
  75.   
  76. Query OK, 1 row affected (0.00 sec)  
  77.   
  78.   
  79. mysql> commit ;  
  80.   
  81. Query OK, 0 rows affected (0.00 sec)  
  82.   
  83.   
  84. mysql> select * from dextb ;  
  85.   
  86. +------+------+  
  87.   
  88. | id   | name |  
  89.   
  90. +------+------+  
  91.   
  92. |    1 | 22   |  
  93.   
  94. |    1 | 22   |  
  95.   
  96. +------+------+  
  97.   
  98. rows in set (0.00 sec)  
  99.   
  100.   
  101.   
  102.   
  103.   
  104. [root@pxc2 ~]# mysql  
  105.   
  106. Welcome to the MySQL monitor.  Commands end with ; or \g.  
  107.   
  108. Your MySQL connection id is 6  
  109.   
  110. Server version: 5.5.39-36.0-55 Percona XtraDB Cluster (GPL), Release rel36.0, Revision 824, WSREP version 25.11, wsrep_25.11.r4023  
  111.   
  112.   
  113. Copyright (c) 2009-2014 Percona LLC and/or its affiliates  
  114.   
  115. Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.  
  116.   
  117.   
  118. Oracle is a registered trademark of Oracle Corporation and/or its  
  119.   
  120. affiliates. Other names may be trademarks of their respective  
  121.   
  122. owners.  
  123.   
  124.   
  125. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.  
  126.   
  127.   
  128. mysql> show database ;  
  129.   
  130. ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'database' at line 1  
  131.   
  132. mysql> show databases ;  
  133.   
  134. +--------------------+  
  135.   
  136. Database           |  
  137.   
  138. +--------------------+  
  139.   
  140. | information_schema |  
  141.   
  142. | dexdb              |  
  143.   
  144. | mysql              |  
  145.   
  146. | performance_schema |  
  147.   
  148. | test               |  
  149.   
  150. +--------------------+  
  151.   
  152. rows in set (0.01 sec)  
  153.   
  154.   
  155. mysql> use dexdb  
  156.   
  157. Reading table information for completion of table and column names  
  158.   
  159. You can turn off this feature to get a quicker startup with -A  
  160.   
  161.   
  162. Database changed  
  163.   
  164. mysql> select * from dextb ;  
  165.   
  166. +------+------+  
  167.   
  168. | id   | name |  
  169.   
  170. +------+------+  
  171.   
  172. |    1 | 22   |  
  173.   
  174. |    1 | 22   |  
  175.   
  176. +------+------+  
  177.   
  178. rows in set (0.00 sec)  
  179.   
  180.   
  181.   
  182.   
  183.   
  184. [root@pxc3 ~]# service mysql start  
  185.   
  186. MySQL (Percona XtraDB Cluster) is not running, but lock file (/var/lock/subsys/mysql) exists[FAILED]  
  187.   
  188. Starting MySQL (Percona XtraDB Cluster).....[  OK  ]  
  189.   
  190. [root@pxc3 ~]# mysql  
  191.   
  192. Welcome to the MySQL monitor.  Commands end with ; or \g.  
  193.   
  194. Your MySQL connection id is 6  
  195.   
  196. Server version: 5.5.39-36.0-55 Percona XtraDB Cluster (GPL), Release rel36.0, Revision 824, WSREP version 25.11, wsrep_25.11.r4023  
  197.   
  198.   
  199. Copyright (c) 2009-2014 Percona LLC and/or its affiliates  
  200.   
  201. Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.  
  202.   
  203.   
  204. Oracle is a registered trademark of Oracle Corporation and/or its  
  205.   
  206. affiliates. Other names may be trademarks of their respective  
  207.   
  208. owners.  
  209.   
  210.   
  211. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.  
  212.   
  213.   
  214. mysql> use dexdb  
  215.   
  216. Reading table information for completion of table and column names  
  217.   
  218. You can turn off this feature to get a quicker startup with -A  
  219.   
  220.   
  221. Database changed  
  222.   
  223. mysql> select * from dextb ;  
  224.   
  225. +------+------+  
  226.   
  227. | id   | name |  
  228.   
  229. +------+------+  
  230.   
  231. |    1 | 22   |  
  232.   
  233. |    1 | 22   |  
  234.   
  235. +------+------+  
  236.   
  237. rows in set (0.00 sec)  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值