码迷,mamicode.com
首页 > 数据库 > 详细

Percona XtraDB Cluster 5.6安装配置

时间:2015-04-22 02:10:55      阅读:1353      评论:0      收藏:0      [点我收藏+]

标签:percona xtradb cluster 5.6安装配置

Percona XtraDB Cluster 5.6安装配置

环境介绍:

操作系统版本:CentOS-6.5-x86_64-minimal.iso 

数据库版本:Percona-Server-5.6.15-rel63.0.tar

192.168.3.81           node1  (1核1G)

192.168.3.82           node2  (1核1G)

192.168.3.83           node3  (1核1G)

1.安装 Percona mysql(所有节点安装)

//源

rpm -ivh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
wget http://www.percona.com/downloads/percona-release/percona-release-0.0-1.x86_64.rpm && rpm -ivh percona-release-0.0-1.x86_64.rpm

//基础包

yum install socat -y
//Percona mysql软件包
yum install Percona-Server-shared-56 Percona-Server-client-56 Percona-Server-server-56  -y

2.Percona mysql配置文件修改

2.1配置 /etc/my.cnf,(所有节点安装):

vim /etc/my.cnf
[mysqld]
innodb_buffer_pool_size = 1024M      //innodb_buffer_pool_size内存的80%
datadir = /data/mysql
port = 3306
server_id = 81                        //server_id必须要不一样
socket = /tmp/mysql.sock
log-bin=mysql-bin
expire_logs_days = 10
sort_buffer_size = 1M
join_buffer_size = 1M
query_cache_size = 512M
query_cache_limit = 2M
query_cache_min_res_unit = 2k
thread_stack = 192K
tmp_table_size = 246M
max_heap_table_size = 246M
key_buffer_size = 300M
read_buffer_size = 1M
read_rnd_buffer_size = 16M
bulk_insert_buffer_size = 64M
slow_query_log = 1
log-error = /data/mysql/log/error.log
long_query_time = 2
log-queries-not-using-indexes = ON
slow_query_log_file = /data/mysql/log/slowquery.log
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
general_log                    = 1                                    //数据库执行日志开关,一般不打开
general_log_file               = /data/mysql/log/mysql-general.log //数据库执行日志文件,一般不打开

2.2创建所需目录,(所有节点安装):

mkdir -p /data/mysql/log
chown mysql:mysql /data/mysql/log

2.3 初始化数据库,(所有节点安装):

mysql_install_db --user=mysql --datadir=/data/mysql
/etc/init.d/mysql start
mysqladmin -u root password ‘123456‘ -S  /tmp/mysql.sock  //首次修改mysql密码

2.4. 删除原有软件包,(所有节点安装):

因为XtraDB Cluster的软件包与原有软件包冲突:

Error: Percona-XtraDB-Cluster-shared-56 conflicts with Percona-Server-shared-56-5.6.23-rel72.1.el6.x86_64
Error: Percona-XtraDB-Cluster-server-56 conflicts with Percona-Server-server-56-5.6.23-rel72.1.el6.x86_64
/etc/init.d/mysql stop

//解决方法:

rpm -qa | grep Percona-Server | grep -v compat |xargs  rpm -e --nodeps

3.安装Percona XtraDB Cluster 5.6 (所有节点安装)

//Percona cluster软件包
yum install Percona-XtraDB-Cluster-server-56 Percona-XtraDB-Cluster-client-56 Percona-XtraDB-Cluster-galera-3 -y

4. XtraDB Cluster配置文件修改

4.1添加 XtraDB Cluster 的支持,(所有节点安装)

vim /etc/my.cnf
在[mysqld]模块下面增加下面内容:

# xtradb cluster settings
binlog_format = ROW
wsrep_cluster_name = PXC
wsrep_cluster_address = gcomm://192.168.3.81,192.168.3.82,192.168.3.83
wsrep_node_address = 192.168.3.81  //注意,每台服务器需要将 wsrep_node_address 设置为本机的IP地址或主机名。
wsrep_provider = /usr/lib64/libgalera_smm.so
wsrep_sst_method = rsync
innodb_locks_unsafe_for_binlog = 1
innodb_autoinc_lock_mode = 2
default_storage_engine=InnoDB

5. 初始化第一个Node:

service mysql bootstrap-pxc //第一个节点才使用
mysql> show global status like ‘wsrep%‘;
+------------------------------+--------------------------------------+
| Variable_name                | Value                                |
+------------------------------+--------------------------------------+
| wsrep_local_state_uuid       | fdfec3ab-d9e8-11e4-94aa-ae45256a81fb |
| wsrep_protocol_version       | 7                                    |
| wsrep_last_committed         | 2                                    |
| wsrep_replicated             | 0                                    |
| wsrep_replicated_bytes       | 0                                    |
| wsrep_repl_keys              | 0                                    |
| wsrep_repl_keys_bytes        | 0                                    |
| wsrep_repl_data_bytes        | 0                                    |
| wsrep_repl_other_bytes       | 0                                    |
| wsrep_received               | 2                                    |
| wsrep_received_bytes         | 141                                  |
| wsrep_local_commits          | 0                                    |
| wsrep_local_cert_failures    | 0                                    |
| wsrep_local_replays          | 0                                    |
| wsrep_local_send_queue       | 0                                    |
| wsrep_local_send_queue_max   | 1                                    |
| wsrep_local_send_queue_min   | 0                                    |
| wsrep_local_send_queue_avg   | 0.000000                             |
| wsrep_local_recv_queue       | 0                                    |
| wsrep_local_recv_queue_max   | 1                                    |
| wsrep_local_recv_queue_min   | 0                                    |
| wsrep_local_recv_queue_avg   | 0.000000                             |
| wsrep_local_cached_downto    | 0                                    |
| wsrep_flow_control_paused_ns | 0                                    |
| wsrep_flow_control_paused    | 0.000000                             |
| wsrep_flow_control_sent      | 0                                    |
| wsrep_flow_control_recv      | 0                                    |
| wsrep_cert_deps_distance     | 0.000000                             |
| wsrep_apply_oooe             | 0.000000                             |
| wsrep_apply_oool             | 0.000000                             |
| wsrep_apply_window           | 0.000000                             |
| wsrep_commit_oooe            | 0.000000                             |
| wsrep_commit_oool            | 0.000000                             |
| wsrep_commit_window          | 0.000000                             |
| wsrep_local_state            | 4                                    |
| wsrep_local_state_comment    | Synced                               |
| wsrep_cert_index_size        | 0                                    |
| wsrep_causal_reads           | 0                                    |
| wsrep_cert_interval          | 0.000000                             |
| wsrep_incoming_addresses     | 192.168.3.81:3306                    |
| wsrep_evs_delayed            |                                      |
| wsrep_evs_evict_list         |                                      |
| wsrep_evs_repl_latency       | 0/0/0/0/0                            |
| wsrep_evs_state              | OPERATIONAL                          |
| wsrep_gcomm_uuid             | 597ae492-dcc6-11e4-ba30-e6dfd92be1c6 |
| wsrep_cluster_conf_id        | 1                                    |
| wsrep_cluster_size           | 1                                    |
| wsrep_cluster_state_uuid     | fdfec3ab-d9e8-11e4-94aa-ae45256a81fb |
| wsrep_cluster_status         | Primary                              |
| wsrep_connected              | ON                                   |
| wsrep_local_bf_aborts        | 0                                    |
| wsrep_local_index            | 0                                    |
| wsrep_provider_name          | Galera                               |
| wsrep_provider_vendor        | Codership Oy <info@codership.com>    |
| wsrep_provider_version       | 3.9(r93aca2d)                        |
| wsrep_ready                  | ON                                   |
+------------------------------+--------------------------------------+
56 rows in set (0.00 sec)
参数 "wsrep_cluster_size" 为 1,因为目前Cluster中只有一个Node。
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| log                |
| mysql              |
| performance_schema |
| test               |
+--------------------+
5 rows in set (0.00 sec)

mysql> create database liu;
Query OK, 1 row affected (0.00 sec)

mysql> use liu
Database changed
mysql> create table liu01 (id int,name char(4));
Query OK, 0 rows affected (0.05 sec)

mysql> show tables;
+---------------+
| Tables_in_liu |
+---------------+
| liu01         |
+---------------+
1 row in set (0.01 sec)

6.添加新的 Node 到Cluster中:

service mysql start
[root@M1905 mysql]# mysql -u root -p123456 -S /tmp/mysql.sock 
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| liu                |
| log                |
| mysql              |
| performance_schema |
| test               |
+--------------------+
6 rows in set (0.00 sec)

mysql> use liu
Database changed
mysql> show tables;
+---------------+
| Tables_in_liu |
+---------------+
| liu01         |
+---------------+
1 row in set (0.00 sec)
查看Cluster的状态:
mysql> show global status like ‘wsrep%‘;
+------------------------------+--------------------------------------+
| Variable_name                | Value                                |
+------------------------------+--------------------------------------+
| wsrep_local_state_uuid       | fdfec3ab-d9e8-11e4-94aa-ae45256a81fb |
| wsrep_protocol_version       | 7                                    |
| wsrep_last_committed         | 7                                    |
| wsrep_replicated             | 0                                    |
| wsrep_replicated_bytes       | 0                                    |
| wsrep_repl_keys              | 0                                    |
| wsrep_repl_keys_bytes        | 0                                    |
| wsrep_repl_data_bytes        | 0                                    |
| wsrep_repl_other_bytes       | 0                                    |
| wsrep_received               | 4                                    |
| wsrep_received_bytes         | 510                                  |
| wsrep_local_commits          | 0                                    |
| wsrep_local_cert_failures    | 0                                    |
| wsrep_local_replays          | 0                                    |
| wsrep_local_send_queue       | 0                                    |
| wsrep_local_send_queue_max   | 1                                    |
| wsrep_local_send_queue_min   | 0                                    |
| wsrep_local_send_queue_avg   | 0.000000                             |
| wsrep_local_recv_queue       | 0                                    |
| wsrep_local_recv_queue_max   | 1                                    |
| wsrep_local_recv_queue_min   | 0                                    |
| wsrep_local_recv_queue_avg   | 0.000000                             |
| wsrep_local_cached_downto    | 7                                    |
| wsrep_flow_control_paused_ns | 0                                    |
| wsrep_flow_control_paused    | 0.000000                             |
| wsrep_flow_control_sent      | 0                                    |
| wsrep_flow_control_recv      | 0                                    |
| wsrep_cert_deps_distance     | 1.000000                             |
| wsrep_apply_oooe             | 0.000000                             |
| wsrep_apply_oool             | 0.000000                             |
| wsrep_apply_window           | 1.000000                             |
| wsrep_commit_oooe            | 0.000000                             |
| wsrep_commit_oool            | 0.000000                             |
| wsrep_commit_window          | 1.000000                             |
| wsrep_local_state            | 4                                    |
| wsrep_local_state_comment    | Synced                               |
| wsrep_cert_index_size        | 3                                    |
| wsrep_causal_reads           | 0                                    |
| wsrep_cert_interval          | 0.000000                             |
| wsrep_incoming_addresses     | 192.168.3.82:3306,192.168.3.81:3306  |
| wsrep_evs_delayed            |                                      |
| wsrep_evs_evict_list         |                                      |
| wsrep_evs_repl_latency       | 0/0/0/0/0                            |
| wsrep_evs_state              | OPERATIONAL                          |
| wsrep_gcomm_uuid             | 16e598fb-dccb-11e4-9ca9-cb37e03eb618 |
| wsrep_cluster_conf_id        | 2                                    |
| wsrep_cluster_size           | 2                                    |
| wsrep_cluster_state_uuid     | fdfec3ab-d9e8-11e4-94aa-ae45256a81fb |
| wsrep_cluster_status         | Primary                              |
| wsrep_connected              | ON                                   |
| wsrep_local_bf_aborts        | 0                                    |
| wsrep_local_index            | 0                                    |
| wsrep_provider_name          | Galera                               |
| wsrep_provider_vendor        | Codership Oy <info@codership.com>    |
| wsrep_provider_version       | 3.9(r93aca2d)                        |
| wsrep_ready                  | ON                                   |
+------------------------------+--------------------------------------+
56 rows in set (0.00 sec)
参数 "wsrep_cluster_size" 变为了 2。
下面,就可以按照同样的步骤,添加更多的节点到Cluster中了,在这个测试环境中,我们一共有3个Node。

7.测试Cluster功能

7.1模拟192.168.3.81节点1宕机

[root@M1905 ~]# service mysql stop
Shutting down MySQL (Percona XtraDB Cluster).... SUCCESS! 
[root@M1905 ~]# netstat -tunlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name   
tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN      809/sshd            
tcp        0      0 127.0.0.1:25                0.0.0.0:*                   LISTEN      898/master    
mysql> show global status like ‘wsrep%‘;  //在任意其它节的查看cluster状态
+------------------------------+---------------------------------------------------+
| Variable_name                | Value                                             |
+------------------------------+---------------------------------------------------+
| wsrep_local_state_uuid       | fdfec3ab-d9e8-11e4-94aa-ae45256a81fb              |
| wsrep_protocol_version       | 7                                                 |
| wsrep_last_committed         | 7                                                 |
| wsrep_replicated             | 0                                                 |
| wsrep_replicated_bytes       | 0                                                 |
| wsrep_repl_keys              | 0                                                 |
| wsrep_repl_keys_bytes        | 0                                                 |
| wsrep_repl_data_bytes        | 0                                                 |
| wsrep_repl_other_bytes       | 0                                                 |
| wsrep_received               | 4                                                 |
| wsrep_received_bytes         | 489                                               |
| wsrep_local_commits          | 0                                                 |
| wsrep_local_cert_failures    | 0                                                 |
| wsrep_local_replays          | 0                                                 |
| wsrep_local_send_queue       | 0                                                 |
| wsrep_local_send_queue_max   | 1                                                 |
| wsrep_local_send_queue_min   | 0                                                 |
| wsrep_local_send_queue_avg   | 0.000000                                          |
| wsrep_local_recv_queue       | 0                                                 |
| wsrep_local_recv_queue_max   | 1                                                 |
| wsrep_local_recv_queue_min   | 0                                                 |
| wsrep_local_recv_queue_avg   | 0.000000                                          |
| wsrep_local_cached_downto    | 0                                                 |
| wsrep_flow_control_paused_ns | 0                                                 |
| wsrep_flow_control_paused    | 0.000000                                          |
| wsrep_flow_control_sent      | 0                                                 |
| wsrep_flow_control_recv      | 0                                                 |
| wsrep_cert_deps_distance     | 0.000000                                          |
| wsrep_apply_oooe             | 0.000000                                          |
| wsrep_apply_oool             | 0.000000                                          |
| wsrep_apply_window           | 0.000000                                          |
| wsrep_commit_oooe            | 0.000000                                          |
| wsrep_commit_oool            | 0.000000                                          |
| wsrep_commit_window          | 0.000000                                          |
| wsrep_local_state            | 4                                                 |
| wsrep_local_state_comment    | Synced                                            |
| wsrep_cert_index_size        | 0                                                 |
| wsrep_causal_reads           | 0                                                 |
| wsrep_cert_interval          | 0.000000                                          |
| wsrep_incoming_addresses     | 192.168.3.82:3306,192.168.3.83:3306               |
| wsrep_evs_delayed            |                                                   |
| wsrep_evs_evict_list         |                                                   |
| wsrep_evs_repl_latency       | 0.000483336/0.000670287/0.000857238/0.000186951/2 |
| wsrep_evs_state              | OPERATIONAL                                       |
| wsrep_gcomm_uuid             | 6c70c34d-dccd-11e4-a9fd-a30f91414348              |
| wsrep_cluster_conf_id        | 4                                                 |
| wsrep_cluster_size           | 2                                                 |
| wsrep_cluster_state_uuid     | fdfec3ab-d9e8-11e4-94aa-ae45256a81fb              |
| wsrep_cluster_status         | Primary                                           |
| wsrep_connected              | ON                                                |
| wsrep_local_bf_aborts        | 0                                                 |
| wsrep_local_index            | 1                                                 |
| wsrep_provider_name          | Galera                                            |
| wsrep_provider_vendor        | Codership Oy <info@codership.com>                 |
| wsrep_provider_version       | 3.9(r93aca2d)                                     |
| wsrep_ready                  | ON                                                |
+------------------------------+---------------------------------------------------+
56 rows in set (0.00 sec)
#发现wsrep_incoming_addresses的192.168.3.81:3306不存在,并且wsrep_cluster_size 可用节点为2.

7.2在192.168.3.83节点3上面插入新数据

mysql> select * from liu01;
+------+------+
| id   | name |
+------+------+
|    1 | aa   |
+------+------+
1 row in set (0.00 sec)

mysql> insert into liu01 values(2,‘bb‘);
Query OK, 1 row affected (0.02 sec)

mysql> select * from liu01;
+------+------+
| id   | name |
+------+------+
|    1 | aa   |
|    2 | bb   |
+------+------+
2 rows in set (0.00 sec)

7.3恢复192.168.3.81节点1mysql服务,及查询节点3数据是否正常。

[root@M1905 ~]# service mysql start
Starting MySQL (Percona XtraDB Cluster)...State transfer in progress, setting sleep higher
. SUCCESS! 
[root@M1905 ~]# mysql -u root -p123456 -S /tmp/mysql.sock 

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| liu                |
| log                |
| mysql              |
| performance_schema |
| test               |
+--------------------+
6 rows in set (0.00 sec)

mysql> use liu

Database changed
mysql> select * from liu01;
+------+------+
| id   | name |
+------+------+
|    1 | aa   |
|    2 | bb   |
+------+------+
2 rows in set (0.00 sec)
mysql> show global status like ‘wsrep%‘;
+------------------------------+-------------------------------------------------------+
| Variable_name                | Value                                                 |
+------------------------------+-------------------------------------------------------+
| wsrep_local_state_uuid       | fdfec3ab-d9e8-11e4-94aa-ae45256a81fb                  |
| wsrep_protocol_version       | 7                                                     |
| wsrep_last_committed         | 8                                                     |
| wsrep_replicated             | 0                                                     |
| wsrep_replicated_bytes       | 0                                                     |
| wsrep_repl_keys              | 0                                                     |
| wsrep_repl_keys_bytes        | 0                                                     |
| wsrep_repl_data_bytes        | 0                                                     |
| wsrep_repl_other_bytes       | 0                                                     |
| wsrep_received               | 3                                                     |
| wsrep_received_bytes         | 287                                                   |
| wsrep_local_commits          | 0                                                     |
| wsrep_local_cert_failures    | 0                                                     |
| wsrep_local_replays          | 0                                                     |
| wsrep_local_send_queue       | 0                                                     |
| wsrep_local_send_queue_max   | 1                                                     |
| wsrep_local_send_queue_min   | 0                                                     |
| wsrep_local_send_queue_avg   | 0.000000                                              |
| wsrep_local_recv_queue       | 0                                                     |
| wsrep_local_recv_queue_max   | 1                                                     |
| wsrep_local_recv_queue_min   | 0                                                     |
| wsrep_local_recv_queue_avg   | 0.000000                                              |
| wsrep_local_cached_downto    | 0                                                     |
| wsrep_flow_control_paused_ns | 0                                                     |
| wsrep_flow_control_paused    | 0.000000                                              |
| wsrep_flow_control_sent      | 0                                                     |
| wsrep_flow_control_recv      | 0                                                     |
| wsrep_cert_deps_distance     | 0.000000                                              |
| wsrep_apply_oooe             | 0.000000                                              |
| wsrep_apply_oool             | 0.000000                                              |
| wsrep_apply_window           | 1.000000                                              |
| wsrep_commit_oooe            | 0.000000                                              |
| wsrep_commit_oool            | 0.000000                                              |
| wsrep_commit_window          | 1.000000                                              |
| wsrep_local_state            | 4                                                     |
| wsrep_local_state_comment    | Synced                                                |
| wsrep_cert_index_size        | 0                                                     |
| wsrep_causal_reads           | 0                                                     |
| wsrep_cert_interval          | 0.000000                                              |
| wsrep_incoming_addresses     | 192.168.3.82:3306,192.168.3.81:3306,192.168.3.83:3306 |
| wsrep_evs_delayed            |                                                       |
| wsrep_evs_evict_list         |                                                       |
| wsrep_evs_repl_latency       | 0/0/0/0/0                                             |
| wsrep_evs_state              | OPERATIONAL                                           |
| wsrep_gcomm_uuid             | 4be90b42-dccf-11e4-83f4-5238aff4e818                  |
| wsrep_cluster_conf_id        | 5                                                     |
| wsrep_cluster_size           | 3                                                     |
| wsrep_cluster_state_uuid     | fdfec3ab-d9e8-11e4-94aa-ae45256a81fb                  |
| wsrep_cluster_status         | Primary                                               |
| wsrep_connected              | ON                                                    |
| wsrep_local_bf_aborts        | 0                                                     |
| wsrep_local_index            | 1                                                     |
| wsrep_provider_name          | Galera                                                |
| wsrep_provider_vendor        | Codership Oy <info@codership.com>                     |
| wsrep_provider_version       | 3.9(r93aca2d)                                         |
| wsrep_ready                  | ON                                                    |
+------------------------------+-------------------------------------------------------+
56 rows in set (0.00 sec)
#发现wsrep_incoming_addresses的192.168.3.81:3306已经存在,并且wsrep_cluster_size 可用节点为3.

8.以下是对 "Percona XtraDB Cluster" 功能测试的总结:

 //感觉cluster的高可用增加删除节点很方便,自动切换故障,如果能配合atlas做读写分离就完美了,但是经过测试,cluster写性能真的不咋的,如果对写要求不高,还是不错的选择。

最后还是要感谢群里老郭写的博客,让我从开始不熟悉cluster,然后后面完整地搭建出来,并进行性能测试。

本文出自 “成都@阿状” 博客,请务必保留此出处http://azhuang.blog.51cto.com/9176790/1636684

Percona XtraDB Cluster 5.6安装配置

标签:percona xtradb cluster 5.6安装配置

原文地址:http://azhuang.blog.51cto.com/9176790/1636684

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!