ITPub博客

首页 > 数据库 > MySQL > 安装配置PXC(Percona XtraDB Cluster)集群

安装配置PXC(Percona XtraDB Cluster)集群

原创 MySQL 作者:db_wjw 时间:2015-07-01 16:57:46 0 删除 编辑
1、安装percona-release包
下面操作在三台服务器上都执行:
创建用户:
# groupadd mysql
# useradd -g mysql mysql
# passwd mysql
安装数据源:
# rpm -ivh percona-release-0.0-1.x86_64.rpm
# rpm -ivh epel-release-6-8.noarch.rpm
装软件:
# yum install Percona-XtraDB-Cluster-56


2、pxc01配置:
# vi /etc/my.cnf
内容如下:
[mysqld]

# GENERAL
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
pid_file=/var/lib/mysql/mysql.pid
user=mysql
port=3306
default_storage_engine=InnoDB
character_set_server=utf8

# INNODB/XtraDB
innodb_buffer_pool_size=1610612736
innodb_log_file_size=104857600

#PXC
wsrep_provider=/usr/lib64/libgalera_smm.so
wsrep_cluster_address=gcomm://10.0.2.155,10.0.2.156,10.0.2.157
binlog_format=ROW
innodb_autoinc_lock_mode=2
wsrep_node_address=10.0.2.155
wsrep_sst_method=xtrabackup-v2
wsrep_cluster_name=my_mysql_cluster
wsrep_sst_auth="sstuser:s3cret"

# LOGGING
log-error=/var/lib/mysql/mysql-error.log
slow_query_log=1
slow_query_log_file=/var/lib/mysql/mysql-slow.log

# OTHER

[client]
socket=/var/lib/mysql/mysql.sock
port=3306
# END

启动PXC01服务器
# su - mysql
$ /etc/init.d/mysql bootstrap-pxc
Bootstrapping PXC (Percona XtraDB Cluster)Starting MySQL (Percona XtraDB Cluster).. SUCCESS!

检查状态:
mysql> show status like 'wsrep%';
+------------------------------+--------------------------------------+
| Variable_name                | Value                                |
+------------------------------+--------------------------------------+
| wsrep_local_state_uuid       | 7123acbc-0ab4-11e5-b639-82c550f88127 |
| wsrep_protocol_version       | 7                                    |
...
| 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     |
| wsrep_provider_version       | 3.9(r93aca2d)                        |
| wsrep_ready                  | ON                                   |
+------------------------------+--------------------------------------+
修改root密码:
mysql> UPDATE mysql.user SET password=PASSWORD("Passw0rd") where user=’root’;
mysql> FLUSH PRIVILEGES;
创建SST用户:
mysql> CREATE USER 'sstuser'@'localhost' IDENTIFIED BY 'sstuser';
mysql> GRANT RELOAD,LOCK TABLES,REPLICATION CLIENT ON *.* TO 'sstuser'@'localhost';
mysql> FLUSH PRIVILEGES;


2、pxc02配置:
# vi /etc/my.cnf
内容如下:
[mysqld]

# GENERAL
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
pid_file=/var/lib/mysql/mysql.pid
user=mysql
port=3306
default_storage_engine=InnoDB
character_set_server=utf8

# INNODB/XtraDB
innodb_buffer_pool_size=1610612736
innodb_log_file_size=104857600

#PXC
wsrep_provider=/usr/lib64/libgalera_smm.so
wsrep_cluster_address=gcomm://10.0.2.155,10.0.2.156,10.0.2.157
binlog_format=ROW
innodb_autoinc_lock_mode=2
wsrep_node_address=10.0.2.156
wsrep_sst_method=xtrabackup-v2
wsrep_cluster_name=my_mysql_cluster
wsrep_sst_auth="sstuser:sstuser"

# LOGGING
log-error=/var/lib/mysql/mysql-error.log
slow_query_log=1
slow_query_log_file=/var/lib/mysql/mysql-slow.log

# OTHER

[client]
socket=/var/lib/mysql/mysql.sock
port=3306

启动pxc02服务器:
# su - mysql
$ /etc/init.d/mysql start
Stale sst_in_progress file in datadir
Starting MySQL (Percona XtraDB Cluster)State transfer in progress, setting sleep higher
... SUCCESS!

检查状态:
$ mysql -u root -p
mysql> show status like 'wsrep%';
+------------------------------+--------------------------------------+
| Variable_name                | Value                                |
+------------------------------+--------------------------------------+
| wsrep_local_state_uuid       | 7123acbc-0ab4-11e5-b639-82c550f88127 |
...
| wsrep_local_state_comment    | Synced                               |
...
| wsrep_cluster_conf_id        | 2                                    |
| wsrep_cluster_size           | 2                                    |
| wsrep_cluster_state_uuid     | 7123acbc-0ab4-11e5-b639-82c550f88127 |
| 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     |
| wsrep_provider_version       | 3.11(ra0189ab)                       |
| wsrep_ready                  | ON                                   |
+------------------------------+--------------------------------------+



3、PXC03服务器配置:
# vi /etc/my.cnf
内容如下:
[mysqld]

# GENERAL
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
pid_file=/var/lib/mysql/mysql.pid
user=mysql
port=3306
default_storage_engine=InnoDB
character_set_server=utf8

# INNODB/XtraDB
innodb_buffer_pool_size=1610612736
innodb_log_file_size=104857600

#PXC
wsrep_provider=/usr/lib64/libgalera_smm.so
wsrep_cluster_address=gcomm://10.0.2.155,10.0.2.156,10.0.2.157
binlog_format=ROW
innodb_autoinc_lock_mode=2
wsrep_node_address=10.0.2.157
wsrep_sst_method=xtrabackup-v2
wsrep_cluster_name=my_mysql_cluster
wsrep_sst_auth="sstuser:sstuser"

# LOGGING
log-error=/var/lib/mysql/mysql-error.log
slow_query_log=1
slow_query_log_file=/var/lib/mysql/mysql-slow.log

# OTHER

[client]
socket=/var/lib/mysql/mysql.sock
port=3306

启动pxc03服务器:
# su - mysql
$ /etc/init.d/mysql start
Stale sst_in_progress file in datadir
Starting MySQL (Percona XtraDB Cluster)State transfer in progress, setting sleep higher
... SUCCESS!

检查状态:
$ mysql -u root -p
mysql> show status like 'wsrep%';
+------------------------------+-------------------------------------------------+
| Variable_name                | Value                                           |
+------------------------------+-------------------------------------------------+
| wsrep_local_state_uuid       | 7123acbc-0ab4-11e5-b639-82c550f88127            |
...
| wsrep_local_state_comment    | Synced                                          |
...
| wsrep_cluster_conf_id        | 3                                               |
| wsrep_cluster_size           | 3                                               |
| wsrep_cluster_status         | Primary                                         |
| wsrep_connected              | ON                                              |
| wsrep_local_bf_aborts        | 0                                               |
| wsrep_local_index            | 2                                               |
| wsrep_provider_name          | Galera                                          |
| wsrep_provider_vendor        | Codership Oy                |
| wsrep_provider_version       | 3.11(ra0189ab)                                  |
| wsrep_ready                  | ON                                              |
+------------------------------+-------------------------------------------------+

4、测试配置结果:
在pxc02创建database
mysql> create database wjw;
在pxc03创建表
mysql> use wjw;
mysql> create table t (id int);
在pxc01插入数据:
mysql> use wjw;
mysql> insert into t values(1);
mysql> commit;

随后在三个节点上都能查到刚创建的数据库、表和数据。


来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/26194851/viewspace-1719252/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2011-08-21

  • 博文量
    96
  • 访问量
    452142