wget https://www.percona.com/downloads/XtraBackup/Percona-XtraBackup-2.2.11/binary/RedHat/6/x86_64/percona-xtrabackup-2.2.11-1.el6.x86_64.rpm
rpm -ivh percona-xtrabackup-2.2.11-1.el6.x86_64.rpm
3.下载安装Percona-XtraDB-Cluster
wget https://www.percona.com/downloads/Percona-XtraDB-Cluster-56/Percona-XtraDB-Cluster-5.6.24-25.11/binary/tarball/Percona-XtraDB-Cluster-5.6.24-rel72.2-25.11..Linux.x86_64.tar.gz
无法下载软件包的请先FQ或者去官方网站查找最新版本
tar xf Percona-XtraDB-Cluster-5.6.24-rel72.2-25.11..Linux.x86_64.tar.gz -C /usr/local/services/
cd /usr/local/services/
ln -s Percona-XtraDB-Cluster-5.6.24-rel72.2-25.11..Linux.x86_64/ mysql
cd mysql
groupadd mysql
useradd -r -g mysql mysql
chown -R mysql .
chgrp -R mysql .
cp support-files/my-default.cnf /etc/my.cnf
mkdir -p /data/mysql/data
chown -R mysql.mysql /data/mysql/data
./scripts/mysql_install_db --user=mysql --basedir=/usr/local/services/mysql --datadir=/data/mysql/data/
chown -R root .
cp support-files/mysql.server /etc/init.d/mysqld
chmod 755 /etc/init.d/mysqld
以上安装步骤三个节点都安装,如果在初始化的时候报libssl.so.6和libcrypto.so.6两个动态库文件不存在的,就做下链接:
ln -s /usr/lib64/libssl.so /usr/lib64/libssl.so.6
ln -s /usr/lib64/libcrypto.so /usr/lib64/libcrypto.so.6
node1的配置和启动如下:
修改my.cnf配置文件如下:
/etc/my.cnf添加如下内容:
[mysqld]
basedir = /usr/local/services/mysql
datadir = /data/mysql/data
并在[mysqld]段落添如下参数:
wsrep_provider=/usr/local/services/mysql/lib/libgalera_smm.so #库文件
wsrep_cluster_address=gcomm://192.168.0.100,192.168.0.101,192.168.0.102 #节点中所有ip
wsrep_node_address=192.168.0.100 #节点的ip
wsrep_slave_threads=2 #开启的复制线程数,cpu核数*2
binlog_format=ROW #binlog格式必须为row
default_storage_engine=InnoDB #暂时不支持其他存储引擎,只支持innodb,当然可以支持myisam,需要另外参数打开
innodb_autoinc_lock_mode=2 #自增锁的优化
wsrep_cluster_name=pxc-linuxidc #集群名字
wsrep_sst_auth=sst:linuxidc #sst模式需要的用户名和密码
wsrep_sst_method=xtrabackup-v2 #采用什么方式复制数据。还支持mysqldump,rsync
启动,进行授权操作,对于第一个节点必须以特殊方式启动,如下:
查看启动选项:/etc/init.d/mysqld --help
Usage: mysql {start|stop|restart|restart-bootstrap|reload|force-reload|status|bootstrap-pxc} [ MySQL (Percona XtraDB Cluster) options ]
启动:
[root@node1 mysql]# /etc/init.d/mysqld bootstrap-pxc
Bootstrapping PXC (Percona XtraDB Cluster)Starting MySQL (P[ OK ]traDB Cluster).........
[root@node1 mysql]#
进行查看,可以发现启动两个端口
[root@node1 ~]# netstat -nltp | grep mysqld
tcp 0 00.0.0.0:4567 0.0.0.0:* LISTEN 2964/mysqld
tcp 0 00.0.0.0:3306 0.0.0.0:* LISTEN 2964/mysqld
[root@node1 ~]#
进行授权,推荐使用grant方式
mysql登录:
mysql> GRANT RELOAD, LOCK TABLES, REPLICATION CLIENT ON * . * TO 'sst'@'localhost' IDENTIFIED BY 'linuxidc';
Query OK, 0 rows affected (0.03 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.03 sec)
mysql>
到这里我们的第一个节点就搞定了,剩下的两个节点配置稍微不同,安装方式都是一样的,不再重复。
node2的配置如下:
[mysqld]
basedir = /usr/local/services/mysql
datadir = /data/mysql/data
wsrep_provider=/usr/local/services/mysql/lib/libgalera_smm.so
wsrep_cluster_address=gcomm://192.168.0.100,192.168.0.101,192.168.0.102
wsrep_node_address=192.168.0.101