mysql8.0使用pxc实现高可用
环境准备
准备三台虚拟机,其对应的主机名和IP地址为
pxc-1 | 192.168.190.129 |
pxc-2 | 192.168.190.133 |
pxc-3 | 192.168.190.134 |
解析,都要做解析
测试
下载pxc的安装包,
官网:https://www.percona.com/downloads
选择8.0的版本并下载,之后上传到虚拟机
下载 qpress-11-1.el8.x86_64.rpm
https://repo.percona.com/yum/release/8/RPMS/x86_64/z
之后同样上传到虚拟机
解压
部署
在虚拟机安装
[root@pxc-2 ~]# yum install *.rpm /root -y
初始化数据库,在pxc-2和pxc-3修改server-id为2和3就可以了
[root@pxc-1 ~]# vim /etc/my.cnf
启动数据库
[root@pxc-1 ~]# systemctl start mysqld
登陆数据库后修改密码
授权用户
创建集群
修改配置参数
[root@pxc-1 ~]# vim /etc/my.cnf
pxc-2和pxc-3同理,但只修改 wsrep_node_name(为本主机名),wsrep_node_address(为本主机IP)
将引导服务mysql目录下的*.pem拷贝给其他服务器
关闭数据库,都关
[root@pxc-1 ~]# systemctl stop mysql.service
第一个节点需要以引导模式启动:
接着在第二和第三个节点上正常启动数据库服务
查看
mysql> SHOW STATUS LIKE 'wsrep%';
+----------------------------------+------------------------------------------- ------------------------------------------------------------------------------- ----------------------+
| Variable_name | Value |
+----------------------------------+------------------------------------------- ------------------------------------------------------------------------------- ----------------------+
| wsrep_local_state_uuid | 7b513b9c-e6cb-11ef-acb6-f2f80e7c1599 |
| wsrep_protocol_version | 10 |
| wsrep_last_applied | 16 |
| wsrep_last_committed | 16 |
| wsrep_monitor_status (L/A/C) | [ (2, 2), (16, 16), (16, 16) ] |
| wsrep_replicated | 0 |
| wsrep_replicated_bytes | 0 |
| wsrep_repl_keys | 0 |
| wsrep_repl_keys_bytes | 0 |
| wsrep_repl_data_bytes | 0 |
| wsrep_repl_other_bytes | 0 |
| wsrep_received | 2 |
| wsrep_received_bytes | 152 |
| wsrep_local_commits | 0 |
| wsrep_local_cert_failures | 0 |
| wsrep_local_replays | 0 |
| wsrep_local_send_queue | 0 |
| wsrep_local_send_queue_max | 1 |
| wsrep_local_send_queue_min | 0 |
| wsrep_local_send_queue_avg | 0 |
| wsrep_local_recv_queue | 0 |
| wsrep_local_recv_queue_max | 2 |
| wsrep_local_recv_queue_min | 0 |
| wsrep_local_recv_queue_avg | 0.5 |
| wsrep_local_cached_downto | 1 |
| wsrep_flow_control_paused_ns | 0 |
| wsrep_flow_control_paused | 0 |
| wsrep_flow_control_sent | 0 |
| wsrep_flow_control_recv | 0 |
| wsrep_flow_control_active | false |
| wsrep_flow_control_requested | false |
| wsrep_flow_control_interval | [ 100, 100 ] |
| wsrep_flow_control_interval_low | 100 |
| wsrep_flow_control_interval_high | 100 |
| wsrep_flow_control_status | OFF |
| wsrep_cert_deps_distance | 0 |
| wsrep_apply_oooe | 0 |
| wsrep_apply_oool | 0 |
| wsrep_apply_window | 0 |
| wsrep_apply_waits | 0 |
| wsrep_commit_oooe | 0 |
| wsrep_commit_oool | 0 |
| wsrep_commit_window | 0 |
| wsrep_local_state | 4 |
| wsrep_local_state_comment | Synced |
| wsrep_cert_index_size | 0 |
| wsrep_cert_bucket_count | 1 |
| wsrep_gcache_pool_size | 4432 |
| wsrep_causal_reads | 0 |
| wsrep_cert_interval | 0 |
| wsrep_open_transactions | 0 |
| wsrep_open_connections | 0 |
| wsrep_ist_receive_status | |
| wsrep_ist_receive_seqno_start | 0 |
| wsrep_ist_receive_seqno_current | 0 |
| wsrep_ist_receive_seqno_end | 0 |
| wsrep_incoming_addresses | 192.168.190.129:3306 |
| wsrep_cluster_weight | 1 |
| wsrep_desync_count | 0 |
| wsrep_evs_delayed | |
| wsrep_evs_evict_list | |
| wsrep_evs_repl_latency | 2.485e-06/4.641e-06/7.737e-06/1.77919e-06/ 5 |
| wsrep_evs_state | OPERATIONAL |
| wsrep_gcomm_uuid | c7343249-e6d8-11ef-816f-5b945b7c8cd0 |
| wsrep_gmcast_segment | 0 |
| wsrep_cluster_capabilities | |
| wsrep_cluster_conf_id | 1 |
| wsrep_cluster_size | 1 |
| wsrep_cluster_state_uuid | 7b513b9c-e6cb-11ef-acb6-f2f80e7c1599 |
| wsrep_cluster_status | Primary |
| wsrep_connected | ON |
| wsrep_local_bf_aborts | 0 |
| wsrep_local_index | 0 |
| wsrep_provider_capabilities | :MULTI_MASTER:CERTIFICATION:PARALLEL_APPLY ING:TRX_REPLAY:ISOLATION:PAUSE:CAUSAL_READS:INCREMENTAL_WRITESET:UNORDERED:PREO RDERED:STREAMING:NBO: |
| wsrep_provider_name | Galera |
| wsrep_provider_vendor | Codership Oy <info@codership.com> (modifie d by Percona <https://percona.com/>) |
| wsrep_provider_version | 4.14(779b689) |
| wsrep_ready | ON |
| wsrep_thread_count | 9 |
+----------------------------------+------------------------------------------- ------------------------------------------------------------------------------- ----------------------+
79 rows in set (0.01 sec)
第一个节点
以引导模式来进行关闭:
systemctl stop mysql@bootstrap.service
其他节点正常下线
systemctl stop mysqld