mysqlpxcmysql5.7_PXC5.7(PerconaXtraDBCluster)集
部署
PXC三节点安装:
node1:10.157.26.132
node2:10.157.26.133
node3:10.157.26.134
配置服务器ssh登录⽆密码验证
ssh-keygen实现三台主机之间相互免密钥登录,保证三台主机之间能ping通
1)在所有的主机上执⾏:
# ssh-keygen -t rsa
2)将所有机⼦上公钥(id_rsa.pub)导到⼀个主机的/root/.ssh/authorized_keys⽂件中,然后将authorized_keys分别拷贝到所有主机上
cat /root/.ssh/id_rsa.pub >> /root/.ssh/authorized_keys
ssh 10.157.26.133 cat /root/.ssh/id_rsa.pub >> /root/.ssh/authorized_keys
ssh 10.157.26.134 cat /root/.ssh/id_rsa.pub >> /root/.ssh/authorized_keys
scp /root/.ssh/authorized_keys 10.157.26.133:/root/.ssh/authorized_keys
scp /root/.ssh/authorized_keys 10.157.26.134:/root/.ssh/authorized_keys
测试:ssh 10.157.26.133/10.157.26.134
安装依赖包:
yum install -y git scons gcc gcc-c++ openssl check cmake bison boost-devel asio-devel libaio-devel ncurses-devel readline-devel pam-devel socat
若socat⽆法⽤yum安装,可下载源码包安装
tar zxvf socat-1.7.3.
cd socat-1.7.3.2
./configure
make && make install
1、将⼆进制包解压,添加mysql账号,做软连接【三个节点都要操作】:
mkdir /opt/mysql
cd /opt/mysql
tar zxvf /data/src/Percona-XtraDB-Cluster-5.7.17-rel13-29.20.3.Linux.x86_64.
cd /usr/local
ln -s /opt/mysql/Percona-XtraDB-Cluster-5.7.17-rel13-29.20.3.Linux.x86_64.ssl101/ mysql
groupadd mysql
mkdir -p /data/mysql/mysql_3306/{data,logs,tmp}
mkdir -p /data/mysql/mysql_3306/logs/binlog
chown -R mysql:mysql /data/mysql/
chown -R mysql:mysql /usr/local/mysql
3、配置⽂件myf
132的配置⽂件:
default_storage_engine=Innodb
#pxc
wsrep_provider = /usr/local/mysql/lib/libgalera_smm.so #库⽂件位置
wsrep_cluster_address = gcomm://10.157.26.132,10.157.26.133,10.157.26.134 #集中所有节点的ip wsrep_node_name = node132 #本节点的名字
wsrep_node_address = 10.157.26.132 #本节点的ip
wsrep_cluster_name = pxc_sampson #集名字
wsrep_sst_auth = sst:sampson #sst模式需要的⽤户名和密码
wsrep_sst_method = xtrabackup-v2 #采⽤什么⽅式复制数据。还⽀持mysqldump,rsync
wsrep_slave_threads = 2 # 开启的复制线程数,建议cpu核数*2 ,解决apply_cb跟不上问题
pxc_strict_mode = ENFORCING #pxc严厉模式,还有DISABLED、PERMISSIVE、MASTER可选
innodb_autoinc_lock_mode = 2 #⾃增锁的优化
wsrep_provider_options = "debug=1;gcache.size=1G" #打开调试模式
133的配置⽂件:
default_storage_engine=Innodb
#pxc
wsrep_provider = /usr/local/mysql/lib/libgalera_smm.so
wsrep_cluster_address = gcomm://10.157.26.132,10.157.26.133,10.157.26.134
wsrep_node_name = node133
wsrep_node_address = 10.157.26.133
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
default_storage_engine=Innodb
#pxc
wsrep_provider = /usr/local/mysql/lib/libgalera_smm.so
wsrep_cluster_address = gcomm://10.157.26.132,10.157.26.133,10.157.26.134
wsrep_node_name = node134
wsrep_node_address = 10.157.26.134
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"
【注:本来所有节点的wsrep_sst_method均配置为xtrabackup-v2,但是添加第⼆个节点时报错:WSREP_SST: [ERROR] Error while getting data from donor node: exit codes: 137 0,换成了rsync后,就没有问题了,待验证是否是xtrabackup的版本问题,我之前⽤的是2.4.7】
4、启动节点1【132上执⾏】:
/usr/local/mysql/bin/mysqld --defaults-file=/data/mysql/mysql_3306/my_3306f --wsrep-new-cluster
【注:当node1启动的时候,它会先尝试加⼊⼀个已存在的集,但是现在集并不存在,pxc必须从0开始,所以node1的启动必须加上命令--wsrep-new-cluster,⽤于新建⼀个新的集。node1正常启动之后,其他的node就可以使⽤平时的启动⽅式,它们都会⾃动连接上primary node】
在error.log⾥看到
[Note] WSREP: Shifting JOINED -> SYNCED (TO: 7)
[Note] WSREP: Waiting for SST/IST to complete.
[Note] WSREP: New cluster view: global state: f71affa6-2b55-11e7-b8db-6afbe908670d:7, view# 1: Primary, number of nodes: 1, my index: 0, protocol version 3
则启动成功,登录mysql -S /tmp/mysql_3306.sock -p
节点⼀密码在error.log中:
mysql下载之后是个文件夹
[root@dpstcmsweb00 ~]# cat /data/mysql/mysql_3306/logs/error.log |grep password
2017-05-09T02:46:25.724852Z 1 [Note] A temporary password is generated for root@localhost: worQi;aYF9eQ
登录进去后修改root密码:mysql>set password=password('mysql');
主节点添加账号:
grant usage on *.* to 'pxc-monitor'@'%' identified by 'pxc-monitor';
grant all privileges on *.* to 'sst'@'%' identified by 'sampson';
查看对应的error.log,能看到
[Note] WSREP: Shifting JOINER -> JOINED (TO: 7)
[Note] WSREP: Member 1.0 (node3307) synced with group.
[Note] WSREP: Shifting JOINED -> SYNCED (TO: 7)
[Note] WSREP: Synchronized with group, ready for connections
则表⽰node启动并加⼊cluster集成功。
启动成功后,直接使⽤节点1上的账号密码登录即可,这⾥是mysql -uroot -pmysql
6、查看节点个数:
"root@localhost:mysql_3306.sock [(none)]>show global status like 'wsrep_cluster_size'; +--------------------+-------+
| Variable_name | Value |
+--------------------+-------+
| wsrep_cluster_size | 3 |
+--------------------+-------+
1 row in set (0.00 sec)
7、查看集状态
"root@localhost:mysql_3306.sock [(none)]>show global status like 'wsrep%';
+------------------------------+----------------------------------------------------------+
| Variable_name | Value |
+------------------------------+----------------------------------------------------------+
| wsrep_local_state_uuid | bed19806-3465-11e7-85af-731d83552ec6 | | wsrep_protocol_version | 7 |
| wsrep_last_committed | 4 |
| wsrep_replicated | 3 |
| wsrep_replicated_bytes | 732 |
| wsrep_repl_keys | 3 |
| wsrep_repl_keys_bytes | 93 |
| wsrep_repl_data_bytes | 447 |
| wsrep_repl_other_bytes | 0 |
| wsrep_received | 36 |
| wsrep_received_bytes | 3494 |
| wsrep_local_commits | 0 |
| wsrep_local_send_queue | 0 |
| wsrep_local_send_queue_max | 1 |
| wsrep_local_send_queue_min | 0 |
| wsrep_local_send_queue_avg | 0.000000 |
| wsrep_local_recv_queue | 0 |
| wsrep_local_recv_queue_max | 2 |
| wsrep_local_recv_queue_min | 0 |
| wsrep_local_recv_queue_avg | 0.027778 |
| wsrep_local_cached_downto | 2 |
| wsrep_flow_control_paused_ns | 0 |
| wsrep_flow_control_paused | 0.000000 |
| wsrep_flow_control_sent | 0 |
| wsrep_flow_control_recv | 0 |
| wsrep_flow_control_interval | [ 173, 173 ] |
| wsrep_flow_control_status | OFF |
| wsrep_cert_deps_distance | 1.000000 |
| wsrep_apply_oooe | 0.000000 |
| wsrep_apply_oool | 0.000000 |
| wsrep_apply_window | 1.000000 |
| wsrep_commit_oooe | 0.000000 |
| wsrep_commit_oool | 0.000000 |
| wsrep_commit_window | 1.000000 |
| wsrep_local_state | 4 |
| wsrep_local_state_comment | Synced |
| wsrep_cert_index_size | 1 |
| wsrep_cert_bucket_count | 22 |
| wsrep_gcache_pool_size | 2932 |
| wsrep_causal_reads | 0 |
| wsrep_cert_interval | 0.000000 |
| wsrep_ist_receive_status | |
| wsrep_incoming_addresses | 10.157.26.134:3306,10.157.26.132:3306,10.157.26.133:3306 | | wsrep_desync_count | 0 |
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论