Percona XtraDB Cluster提供的特性有:
1.同步复制,事务要么在所有节点提交或不提交。
2.多主复制,可以在任意节点进行写操作。
3.在从服务器上并行应用事件,真正意义上的并行复制。
4.节点自动配置。
5.数据一致性,不再是异步复制。
开始搭建:
三台服务器:先设置hosts 10.0.0.231 node1 10.0.0.232 node2 10.0.0.233 node3
1:下载安装文件
官网:https://www.percona.com
下载地址:https://www.percona.com/downloads/Percona-XtraDB-Cluster-LATEST/Percona-XtraDB-Cluster-5.7.18-29.20/binary/tarball/Percona-XtraDB-Cluster-5.7.18-rel15-29.20.1.Linux.x86_64.ssl100.tar.gz
2:解压到指定目录
tar -zxvf Percona-XtraDB-Cluster-5.7.18-rel15-29.20.1.Linux.x86_64.ssl101.tar.gz -C /usr/local ln -s Percona-XtraDB-Cluster-5.7.18-rel15-29.20.1.Linux.x86_64.ssl101 mysql5.7
3:创建目录
mkdir -p /usr/local/mysql5.7/data mkdir -p /usr/local/mysql5.7/tmp
4:创建用户
useradd -d /usr/local/mysql5.7 -m mysql chown -R /usr/local/mysql5.7 chmod 600 /usr/local/mysql5.7
5:配制/etc/my.cnf
note1:
[mysqld] server_id=231 datadir=/usr/local/mysql5.7/data user=mysql basedir=/usr/local/mysql5.7 default_storage_engine=Innodb innodb_buffer_pool_size=1610612736 innodb_log_file_size=104857600 wsrep_provider=/usr/local/mysql5.7/lib/libgalera_smm.so wsrep_cluster_address=gcomm://10.0.0.231,10.0.0.232,10.0.0.233 wsrep_node_name=node1 wsrep_node_address=10.0.0.231 wsrep_cluster_name=pxc_sampson wsrep_sst_auth=sst:sampson wsrep_sst_method=rsync wsrep_slave_threads=2 pxc_strict_mode=ENFORCING innodb_autoinc_lock_mode=2 wsrep_provider_options="debug=1;gcache.size=1G"
note2:
[mysqld] server_id=232 datadir=/usr/local/mysql5.7/data user=mysql basedir=/usr/local/mysql5.7 default_storage_engine=Innodb innodb_buffer_pool_size=1610612736 innodb_log_file_size=104857600 wsrep_provider=/usr/local/mysql5.7/lib/libgalera_smm.so wsrep_cluster_address=gcomm://10.0.0.231,10.0.0.232,10.0.0.233 wsrep_node_name=node2 wsrep_node_address=10.0.0.232 wsrep_cluster_name=pxc_sampson wsrep_sst_auth=sst:sampson wsrep_sst_method=rsync wsrep_slave_threads=2 pxc_strict_mode=ENFORCING innodb_autoinc_lock_mode=2 wsrep_provider_options="debug=1;gcache.size=1G"
note3:
[mysqld] server_id=233 datadir=/usr/local/mysql5.7/data user=mysql basedir=/usr/local/mysql5.7 default_storage_engine=Innodb innodb_buffer_pool_size=1610612736 innodb_log_file_size=104857600 wsrep_provider=/usr/local/mysql5.7/lib/libgalera_smm.so wsrep_cluster_address=gcomm://10.0.0.231,10.0.0.232,10.0.0.233 wsrep_node_name=node3 wsrep_node_address=10.0.0.233 wsrep_cluster_name=pxc_sampson wsrep_sst_auth=sst:sampson wsrep_sst_method=rsync wsrep_slave_threads=2 pxc_strict_mode=ENFORCING innodb_autoinc_lock_mode=2 wsrep_provider_options="debug=1;gcache.size=1G"
6:初始化mysql
note1,note2,note3
/usr/local/mysql5.7/bin/mysql_install_db --defaults-file=/etc/my.cnf --user=mysql --basedir=/usr/local/mysql5.7/ --datadir=/usr/local/mysql5.7/data/
7:启动第一个节点
node1:
/usr/local/mysql5.7/bin/mysqld_safe --ledir=/usr/local/mysql5.7/bin --wsrep-new-cluster &
完成后Ctrl+C
8:修改mysql密码
查看初使密码 cat /root/.mysql_secret 假设初始密码为abcde 修改初始密码 先进入mysql命令行:mysql -u root -p 输入初始密码abcde 修改初始密码:SET PASSWORD = PASSWORD('123456');
9:启动第二,三个节点
node2,node3
/usr/local/mysql5.7/bin/mysqld_safe --ledir=/usr/local/mysql5.7/bin &
10:查看
登录mysql
mysql>show global status like 'wsrep_cluster_size'; mysql>show global status like 'wsrep%';
11:设置开机启动
cp /usr/local/mysql5.7/support-files/mysql.server /etc/init.d/mysql …复制启动文件 chmod 755 /etc/init.d/mysql …增加执行权限 chkconfig --add mysql …加入自动启动项 chkconfig --level 2345 mysql on …设置MySQL 在345 等级自动启动
12:环境变量
export PATH=/usr/local/mysq5.7l/bin:$PATH