1笔喉、構(gòu)建安裝環(huán)境
1.1猖凛、獲取 Percona XtraDB Cluster
瀏覽器訪(fǎng)問(wèn):
在 【Percona XtraDB Cluster】選中【Download 5.6 Now】
在新頁(yè)面選擇:
- 【Version】:Percona XtraDB Cluster 5.6.35-26.20
- 【Software】:Linux-Generic
- 【Hardware】:x86_64
- Percona-XtraDB-Cluster-5.6.35-rel80.0-26.20.2.Linux.x86_64.ssl101.tar.gz
1.2挽拂、獲取 Percona XtraBackup
瀏覽器訪(fǎng)問(wèn):
在 【Percona XtraBackup】選中【Download Latest】
在新頁(yè)面選擇:
- 【Version】:Percona-XtraBackup-2.4.6
- 【Software】:Linux-Generic
- 【Hardware】:x86_64
- percona-xtrabackup-2.4.6-Linux-x86_64.tar.gz
1.3枪蘑、實(shí)驗(yàn)機(jī)的準(zhǔn)備
實(shí)驗(yàn)用虛擬機(jī)的安裝請(qǐng)參見(jiàn):
《VMware --- CentOS6.x 實(shí)驗(yàn)機(jī)安裝配置的簡(jiǎn)單說(shuō)明》
鏈接如下:
本次實(shí)驗(yàn)使用的系統(tǒng)版本為:
CentOS release 6.8 (Final)
實(shí)驗(yàn)用網(wǎng)絡(luò)規(guī)劃:
IP | 用途 |
---|---|
192.168.135.11 | node1 |
192.168.135.12 | node2 |
192.168.135.13 | node3 |
1.4慨灭、軟件環(huán)境的準(zhǔn)備
安裝依賴(lài)軟件
]# yum install git scons gcc gcc-c++ openssl check cmake bison boost-devel asio-devel libaio-devel ncurses-devel readline-devel pam-devel -y
]# yum install socat -y
刪除沖突軟件
]# rpm -qa |grep -i mysql |xargs rpm -e --nodeps
注:
需安裝 EPEL 源
2唱歧、Percona XtraDB Cluster 的安裝宪摧、配置
將下載的安裝文件,上傳到 /apps01/src 中
]# mkdir /apps01/src
]# cd /apps01/src/
]# tar -xzf Percona-XtraDB-Cluster-5.6.35-rel80.0-26.20.2.Linux.x86_64.ssl101.tar.gz
]# mv Percona-XtraDB-Cluster-5.6.35-rel80.0-26.20.2.Linux.x86_64.ssl101 mysql
]# tar -xzf percona-xtrabackup-2.4.6-Linux-x86_64.tar.gz
]# mv percona-xtrabackup-2.4.6-Linux-x86_64/bin/* mysql/bin/
]# mv percona-xtrabackup-2.4.6-Linux-x86_64/man/man1/* mysql/man/man1/
]# mv percona-xtrabackup-2.4.6-Linux-x86_64/percona-xtrabackup-2.4-test/ mysql/
安裝
]# mkdir -p /apps01/local/
]# mv mysql/ /apps01/local/
]# cd /apps01/local/mysql/
]# mkdir -p {log/{binlog,relaylog,slowlog},tmp}
新建 mysql 用戶(hù)颅崩,并更改權(quán)限
]# useradd -r mysql
]# chown -R mysql:mysql /apps01/local/mysql/
初始化 MySQL
]# ./scripts/mysql_install_db --user=mysql --basedir=/apps01/local/mysql --datadir=/apps01/local/mysql/data --explicit_defaults_for_timestamp
新建并編輯配置文件
]# sudo -u mysql touch my.cnf
]# vim my.cnf
[mysqld]
###### basic settings ######
port = 3306
bind-address = 0.0.0.0
basedir = /apps01/local/mysql
datadir = /apps01/local/mysql/data
tmpdir = /apps01/local/mysql/tmp
socket = /tmp/mysql.sock
pid-file = /apps01/local/mysql/mysql.pid
server-id = 11
user = mysql
###### Percona XtraDB Cluster ######
# Specify the path to the Galera library.
wsrep_provider = /apps01/local/mysql/lib/libgalera_smm.so
# Specify the logical name for your cluster. It must be the same for all nodes in your cluster.
wsrep_cluster_name = bind
# Specify the IP addresses of nodes in your cluster. At least one is required for a node to join the cluster, but it is recommended to list addresses of all nodes. This way if the first node in the list is not available, the joining node can use other addresses.
wsrep_cluster_address = gcomm://192.168.135.11,192.168.135.12,192.168.135.13
# Specify the logical name for each individual node. If this variable is not specified, the host name will be used.
wsrep_node_name = node1
# Specify the IP address of this particular node.
wsrep_node_address = 192.168.135.11
# By default, Percona XtraDB Cluster uses Percona XtraBackup for State Snapshot Transfer (SST). Setting wsrep_sst_method=xtrabackup-v2 is highly recommended. This method requires a user for SST to be set up on the initial node. Provide SST user credentials with the wsrep_sst_auth variable.
wsrep_sst_method = xtrabackup-v2
# Specify authentication credentials for SST as <sst_user>:<sst_pass>. You must create this user when Bootstrapping the First Node and provide necessary privileges for it:
wsrep_sst_auth = sstuser:sstuserPass
# Galera supports only interleaved (2) lock mode for InnoDB. Setting the traditional (0) or consecutive (1) lock mode can cause replication to fail due to unresolved deadlocks. Set this variable to innodb_autoinc_lock_mode=2.
innodb_autoinc_lock_mode = 2
# Galera supports only row-level replication, so set binlog_format=ROW.
binlog_format = ROW
# Galera fully supports only the InnoDB storage engine. It will not work correctly with MyISAM or any other non-transactional storage engines. Set this variable to default_storage_engine=InnoDB.
default_storage_engine = InnoDB
注:
其它兩個(gè)節(jié)點(diǎn)的配置文件几于,主要需要修改以下幾項(xiàng),其余可以保持不變:
server-id =
wsrep_node_name =
wsrep_node_address =
復(fù)制 mysql 啟動(dòng)腳本
]# cp support-files/mysql.server /etc/init.d/mysql
修改啟動(dòng)腳本
]# vim /etc/init.d/mysql
basedir=/apps01/local/mysql
datadir=/apps01/local/mysql/data
修改 mysqld_safe 文件
]# sed -i 's#/mnt/workspace/percona-xtradb-cluster-5.6-binary-new/label_exp/centos6-64/Percona-XtraDB-Cluster-5.6.35-80.0/110/usr/local/Percona-XtraDB-Cluster-5.6.35-rel80.0-26.20.2.Linux.x86_64.ssl101/#/apps01/local/mysql/#g' /apps01/local/mysql/bin/mysqld_safe
鏈接配置文件到 /etc 目錄
]# ln -s /apps01/local/mysql/my.cnf /etc/my.cnf
配置環(huán)境變量
]# vim /etc/profile
export PATH=$PATH:/apps01/local/mysql/bin
]# source /etc/profile
重復(fù)以步驟沿后,完成剩余兩個(gè)節(jié)點(diǎn)的安裝
3沿彭、Percona XtraDB Cluster 的啟動(dòng)
3.1、啟動(dòng)第一個(gè)節(jié)點(diǎn)
]# /etc/init.d/mysql bootstrap-pxc
添加同步用戶(hù)
]# mysql -u root -p
Enter password:
> grant all on *.* to 'sstuser'@'localhost' identified by 'sstuserPass';
Query OK, 0 rows affected (0.00 sec)
> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.01 sec)
檢查集群狀態(tài):
> show status like 'wsrep%';
> show status like 'wsrep%';
+------------------------------+--------------------------------------+
| Variable_name | Value |
+------------------------------+--------------------------------------+
| wsrep_incoming_addresses | 192.168.135.11:3306 |
| wsrep_evs_state | OPERATIONAL |
| wsrep_gcomm_uuid | 5480f3f7-112a-11e7-975a-e7e64467f6d3 |
| wsrep_cluster_conf_id | 1 |
| wsrep_cluster_size | 1 |
| wsrep_cluster_state_uuid | 54819951-112a-11e7-9630-4e25ee000443 |
| wsrep_cluster_status | Primary |
| wsrep_connected | ON |
| wsrep_ready | ON |
+------------------------------+--------------------------------------+
59 rows in set (0.00 sec)
注:
為節(jié)省篇幅尖滚,以上命令輸出只保留了需要重點(diǎn)關(guān)的幾個(gè)參數(shù)喉刘,其它的都刪除了
3.2瞧柔、啟動(dòng)第二、第三個(gè)節(jié)點(diǎn)
第一個(gè)節(jié)點(diǎn)啟動(dòng)完成睦裳,檢查狀態(tài)正常后造锅,就可以通過(guò)依次啟動(dòng)第二,第三個(gè)節(jié)點(diǎn)
]# /etc/init.d/mysql start
注:
節(jié)點(diǎn)必須逐個(gè)啟動(dòng)廉邑,也就是說(shuō)哥蔚,一個(gè)啟動(dòng)完成后,檢查狀態(tài)正常后鬓催,再啟動(dòng)下一個(gè)