安裝配置PXC(Percona XtraDB Cluster)叢集

db_wjw發表於2015-07-01
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/,如需轉載,請註明出處,否則將追究法律責任。

相關文章