1. 程式人生 > >Install Percona XtraDb Cluster 5.6.20 on CentOS 6.5

Install Percona XtraDb Cluster 5.6.20 on CentOS 6.5

ots mysql- mkdir binlog rdf bootstra cfg mysql sql

http://blog.51cto.com/hj192837/1546149

You should have odd number of real nodes.

node #1
hostname: percona1
IP: 192.168.70.71

node #2
hostname: percona2
IP: 192.168.70.72

node #3
hostname: percona3
IP: 192.168.70.73

1. disable selinux and iptables

service iptables stop
chkconfig iptables off; chkconfig ip6tables off

setenforce 0
vi /etc/selinux/config
SELINUX=disabled

2. cat << EOF > /etc/yum.repos.d/iso.repo
[iso]
name=iso
baseurl=http://mirrors.sohu.com/centos/6.5/os/x86_64
enable=1
gpgcheck=0
EOF

cat << EOF > /etc/yum.repos.d/epel.repo
[epel]
name=epel
baseurl=http://mirrors.sohu.com/fedora-epel/6Server/x86_64
enable=1
gpgcheck=0
EOF

( or rpm -ivh http://www.percona.com/redir/downloads/percona-release/percona-release-0.0-1.x86_64.rpm )

cat << EOF > /etc/yum.repos.d/percona.repo
[percona]
name=percona
baseurl=file:///percona (http://repo.percona.com/centos/6Server/os/x86_64/)
enable=1
gpgcheck=0
EOF

3. yum -y install Percona-XtraDB-Cluster-56

on node 1:
vi /etc/my.cnf
[mysqld]
wsrep_provider=/usr/lib64/libgalera_smm.so
wsrep_cluster_address=gcomm://192.168.70.71,192.168.70.72,192.168.70.73
binlog_format=ROW
default_storage_engine=InnoDB
innodb_autoinc_lock_mode=2
wsrep_node_address=192.168.70.71
wsrep_sst_method=xtrabackup-v2
wsrep_cluster_name=my_centos_cluster
wsrep_sst_auth="sstuser:s3cret"

expire_logs_days=10
max_binlog_size=100M

# just for creating a NEW cluster

service mysql bootstrap-pxc

or
service mysql start --wsrep_new_cluster
or
service mysql start --wsrep-cluster-address="gcomm://"

or for CentOS 7
systemctl start [email protected]

mysql -uroot
mysql> show status like ‘wsrep%‘;

技術分享圖片

mysql> UPDATE mysql.user SET password=PASSWORD("Passw0rd") where user=‘root‘;
mysql> CREATE USER ‘sstuser‘@‘localhost‘ IDENTIFIED BY ‘s3cret‘;
mysql> GRANT RELOAD, LOCK TABLES, REPLICATION CLIENT ON *.* TO ‘sstuser‘@‘localhost‘;
mysql> FLUSH PRIVILEGES;

on node 2:
vi /etc/my.cnf
[mysqld]
wsrep_provider=/usr/lib64/libgalera_smm.so
wsrep_cluster_address=gcomm://192.168.70.71,192.168.70.72,192.168.70.73
binlog_format=ROW
default_storage_engine=InnoDB
innodb_autoinc_lock_mode=2
wsrep_node_address=192.168.70.72
wsrep_sst_method=xtrabackup-v2
wsrep_cluster_name=my_centos_cluster
wsrep_sst_auth="sstuser:s3cret"

expire_logs_days=10
max_binlog_size=100M


service mysql start

技術分享圖片

on node 3:
vi /etc/my.cnf
[mysqld]
wsrep_provider=/usr/lib64/libgalera_smm.so
wsrep_cluster_address=gcomm://192.168.70.71,192.168.70.72,192.168.70.73
binlog_format=ROW
default_storage_engine=InnoDB
innodb_autoinc_lock_mode=2
wsrep_node_address=192.168.70.73
wsrep_sst_method=xtrabackup-v2
wsrep_cluster_name=my_centos_cluster
wsrep_sst_auth="sstuser:s3cret"

expire_logs_days=10
max_binlog_size=100M


service mysql start

技術分享圖片

Ports:

Galera: 4567
SST: 4444
SST incremental port: 4568
MySQL: 3306

Notes: http://www.percona.com/blog/2014/09/01/galera-replication-how-to-recover-a-pxc-cluster/

在vmware workstation測試環境中,不可能mysql一直開機

1. on three nodes:

chkconfig mysql off

2. poweroff sequence: node3 > node2 > node1

3. poweron sequence: node1 > node2 > node3

4. on node1: service mysql bootstrap-pxc

on node2 and node3: service mysql start

HAproxy配置:

percona node1: 192.168.70.71
percona node2: 192.168.70.72
percona node3: 192.168.70.73
haproxy server 1: 192.168.70.12
haproxy server 2: 192.168.70.13
haproxy VIP: 192.168.70.10

on three percona nodes:
yum -y install xinetd

vi /etc/services
mysqlchk 6033/tcp # mysqlchk

vi /etc/xinetd.d/mysqlchk
# port = 9200
port = 6033

service xinetd start

If you want to use a different username or password for clustercheck, vi /usr/bin/clustercheck

On one percona node:
mysql -uroot -p
mysql> CREATE USER ‘haproxy‘@‘192.168.70.12‘;
mysql> CREATE USER ‘haproxy‘@‘192.168.70.13‘;
mysql> grant process on *.* to ‘clustercheckuser‘@‘localhost‘ identified by ‘clustercheckpassword!‘;
mysql> flush privileges;

On two haproxy server:
yum -y install mysql

vi /etc/haproxy/haproxy.cfg
defaults
# option httplog
# option http-server-close
# option forwardfor except 127.0.0.0/8

listen mysqld-status 192.168.70.10:3306
balance source
mode tcp
option tcpka
option mysql-check user haproxy
server MySQL1 192.168.70.71:3306 check weight 1
server MySQL2 192.168.70.72:3306 check weight 1
server MySQL2 192.168.70.73:3306 check weight 1

listen mysql-cluster 192.168.70.10:3306
mode tcp
balance source
option httpchk
server MySQL1 192.168.70.71:3306 check port 6033 inter 12000 rise 3 fall 3
server MySQL1 192.168.70.72:3306 check port 6033 inter 12000 rise 3 fall 3
server MySQL1 192.168.70.73:3306 check port 6033 inter 12000 rise 3 fall 3

service haproxy reload

Testing:

On one percona server:
mysql -uroot -p
mysql> grant all on *.* to root@‘%‘ identified by ‘password‘ with grant option;

from mysql client:

mysql -h 192.168.70.10 -uroot -p

使用innobackupex備份數據庫:

mkdir -p /data/backups

full backup:
1. innobackupex --user=sstuser --password=s3cret /data/backups

restore full backup:
1. innobackupex --apply-log /data/backups/2014-09-08_11-03-56
2. service mysql stop; rm -rf /var/lib/mysql/*
3. innobackupex --copy-back /data/backups/2014-09-08_11-03-56
4. chown -R mysql:mysql /var/lib/mysql
5. service mysql start


Incremental backup:
1. full backup
innobackupex --user=sstuser --password=s3cret /data/backups
2. incremental one, based on full backup
innobackupex --user=sstuser --password=s3cret --incremental /data/backups --incremental-basedir=/data/backups/2014-09-08_11-20-51
3. incremental two, based on incremental one
innobackupex --user=sstuser --password=s3cret --incremental /data/backups --incremental-basedir=/data/backups/2014-09-08_11-28-56

技術分享圖片

restore incremental backup:
1. innobackupex --apply-log --redo-only /data/backups/2014-09-08_11-20-51
2. innobackupex --apply-log --redo-only /data/backups/2014-09-08_11-20-51 --incremental-dir=/data/backups/2014-09-08_11-28-56
3. innobackupex --apply-log /data/backups/2014-09-08_11-20-51 --incremental-dir=/data/backups/2014-09-08_11-31-53
Notes: --redo-only should be used when merging all incrementals except the last one.
4. innobackupex --apply-log /data/backups/2014-09-08_11-20-51
5. service mysql stop; rm -rf /var/lib/mysql/*
6. innobackupex --copy-back /data/backups/2014-09-08_11-20-51
7. chown -R mysql:mysql /var/lib/mysql
8. service mysql start

Install Percona XtraDb Cluster 5.6.20 on CentOS 6.5