mysql bootstrap pxc_Mysql高可用之PXC

article/2025/9/14 18:50:35

一。PXC简介

Percona XtraDB Cluster简称PXC。是一套开源mysql高可用解决方案(XtraDb是mysql被oracle收购之前 开源一个分支 其他分支还有mariadb),Percona Xtradb Cluster的实现是在原mysql代码上通过Galera包将不同的mysql实例(新名称 Percona Server)连接起来,实现了multi-master(多个主都可以同时写入)的集群架构。pxc包含 Percona XtraBackup 组件用于提供Percone Server所有版本

在线备份解决方案

一个集群包含多个节点 每个节点互相同步包含相同的数据集 ,至少应该包含3个节点 每个节点都可以拥有读写的能力

fa486b0470c6de48ce6003ad62bdee72.png

Percona XtraDB Cluster特点

(1)同步复制,事务在所有集群节点要么同时提交,要么不提交。

(2)多主复制,可以在任意一个节点写入。

(3)从服务器上的并行应用事件,真正的“并行复制”。

(4)自动配置节点。

(5)数据一致性,没有不同步的从服务器。

Percona XtraDB Cluster与MySQL Replication区别在于:

分布式系统的CAP理论:

C—一致性,所有节点的数据一致;

A—可用性,一个或多个节点失效,不影响服务请求;

P—分区容忍性,节点间的连接失效,仍然可以处理请求;

任何一个分布式系统,需要满足这三个中的两个。

MySQLReplication: 可用性和分区容忍性;

Percona XtraDBCluster: 一致性和可用性。

因此MySQL Replication并不保证数据的一致性,而Percona XtraDB Cluster提供数据一致性。

官方文档参考 (https://www.percona.com/doc/percona-xtradb-cluster/LATEST/index.html)

二。PXC安装

1》安装

安装参考(https://www.percona.com/doc/percona-xtradb-cluster/LATEST/overview.html)

模拟环境(centos7)

ode

主机名

IP地址Node 1

node1

192.168.58.147

Node 2

node2

192.168.58.149

Node 3

node3

192.168.58.150

三台机器同时安装 PXC(centos安装参考https://www.percona.com/doc/percona-xtradb-cluster/LATEST/install/yum.html#yum)

配置yum的peronna仓库(https://www.percona.com/doc/percona-repo-config/yum-repo.html)

yum install http://www.percona.com/downloads/percona-release/redhat/0.1-4/percona-release-0.1-4.noarch.rpm

关闭selinux

setenforce 0

或者修改 /etc/selinux/config 永久关闭SELINUX=disabled

安装

yum install Percona-XtraDB-Cluster-57 -y

重置xtradb默认密码 root默认密码是个临时密码 需要在启动后 读取/var/log/mysqld.log获取 得到后修改即可

启动xtradb

service mysql start

查看临时密码

grep 'temporary password' /var/log/mysqld.log

[root@node1 log]#  grep 'temporary password' /var/log/mysqld.log

2018-02-05T08:34:23.628185Z 1 [Note] A temporary password is generated for root@localhost: O9Y-Ji8#>)u_

如果之前安装过mysql 卸载过 就会发现没有查看到  后来用root作为密码登录测试能成功 默认临时密码就是root

这样是安装失败的

登录测试

mysql -uroot -p

输入密码O9Y-Ji8#>)u_ 登录后修改密码

set password=password('root')

如果不小心删了日志或者查找不到临时密码 可以修改/etc/my.cnf最上面加入

[mysqld]

skip-grant-tables

重启mysql服务  直接使用 mysql -uroot -p 不输入密码直接回车进入 修改密码

update user set authentication_string=password('root');

重启 即可

得到控制台结果(日志中打印了 5.7.20 PXC)

碰到错误

错误1:WSREP: wsrep_load(): dlopen(): /usr/lib64/galera3/libgalera_smm.so: symbol SSL_COMP_free_compression_methods, version libssl.so.10 not defined in file libssl.so.10

with link time reference

解决方案: 升级openssl  (yum update openssl)

成功效果 :

[root@node2 ~]#

[root@node2 ~]# mysql -uroot -proot

mysql: [Warning] Using a password on the command line interface can be insecure.

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 8

Server version: 5.7.20-18-57 Percona XtraDB Cluster (GPL), Release rel18, Revision 4a4da7e, WSREP version 29.24, wsrep_29.24

2》配置pxc(参考https://www.percona.com/doc/percona-xtradb-cluster/LATEST/configure.html)

关闭三台mysql

service stop mysql

默认配置文件位于 /etc/my.cnf

[root@node2 ~]# more /etc/my.cnf

#

# The Percona XtraDB Cluster 5.7 configuration file.

#

#

# * IMPORTANT: Additional settings that can override those from this file!

# The files must end with '.cnf', otherwise they'll be ignored.

# Please make any edits and changes to the appropriate sectional files

# included below.

#

!includedir /etc/my.cnf.d/

!includedir /etc/percona-xtradb-cluster.conf.d/

147配置如下(注意 要加[mysqld啊])

[mysqld]

wsrep_provider=/usr/lib64/galera3/libgalera_smm.so

wsrep_cluster_name=pxc-cluster

wsrep_cluster_address=gcomm://192.168.58.147,192.168.58.149,192.168.58.150

wsrep_node_name=node1

wsrep_node_address=192.168.58.147

wsrep_sst_method=xtrabackup-v2

wsrep_sst_auth=sstuser:passw0rd

pxc_strict_mode=ENFORCING

binlog_format=ROW

default_storage_engine=InnoDB

innodb_autoinc_lock_mode=2

149所有配置和147相同 除了

wsrep_node_name=node2

wsrep_node_address=192.168.58.149

150所有配置和147相同 除了wsrep_node_name=node3

wsrep_node_address=192.168.58.150

3》启动第一个节点pxc

》》启动第一个节点147 (确保该节点上拥有所有的数据 数据会被同步到其他节点)参考https://www.percona.com/doc/percona-xtradb-cluster/LATEST/bootstrap.html#bootstrap

执行启动单台节点初始化

systemctl start mysql@bootstrap.service

登录确实是否成功

mysql> show status like 'wsrep%';

+----------------------------------+----------------------------------------------+

| Variable_name | Value |

+----------------------------------+----------------------------------------------+

| wsrep_local_state_uuid | 640a6119-0a4f-11e8-a74b-bbd28c7ed16f |

| wsrep_protocol_version | 7 |

| wsrep_last_applied | 1 |

| wsrep_last_committed | 1 |

| wsrep_replicated | 0 |

| wsrep_replicated_bytes | 0 |

| wsrep_repl_keys | 0

| wsrep_cluster_conf_id            | 1                                            |

| wsrep_cluster_size               | 1                                            |

| wsrep_cluster_state_uuid         | 640a6119-0a4f-11e8-a74b-bbd28c7ed16f         |

| wsrep_cluster_status             | Primary                                      |

| wsrep_connected                  | ON

wsrep_cluster_size=1表示集群中只有一个节点 已经连接 并且状态时 primary 随时写入数据到集群 再加入其他两个节点

之前 需要创建一个SST( State Snapshot Transfer)账号 用于集群间通信  必须和主机my.cnf配置的参数一致

wsrep_sst_auth=sstuser:passw0rd

添加用户并赋予权限

mysql> CREATE USER 'sstuser'@'localhost' IDENTIFIED BY 'passw0rd';

Query OK, 0 rows affected (0.01 sec)

mysql> GRANT RELOAD, LOCK TABLES, PROCESS, REPLICATION CLIENT ON *.* TO

-> 'sstuser'@'localhost';

Query OK, 0 rows affected (0.01 sec)

mysql> FLUSH PRIVILEGES;

Query OK, 0 rows affected (0.00 sec)

4》添加其他节点到集群

其他机器 启动即可

service mysql start

再次到147登录显示状态(表示集群中有三个元素了)

wsrep_cluster_size | 3

5》测试

149创建数据库tt和表aa

mysql> create database tt;

Query OK, 1 row affected (0.01 sec)

mysql> use tt;

Database changed

mysql> create table aa(id int auto_increment primary key,uname varchar(20));

Query OK, 0 rows affected (0.16 sec)

150 查看是会否自动同步表 并插入数据

mysql> use tt

Reading table information for completion of table and column names

You can turn off this feature to get a quicker startup with -A

Database changed

mysql> desc aa;

+-------+-------------+------+-----+---------+----------------+

| Field | Type | Null | Key | Default | Extra |

+-------+-------------+------+-----+---------+----------------+

| id | int(11) | NO | PRI | NULL | auto_increment |

| uname | varchar(20) | YES | | NULL | |

+-------+-------------+------+-----+---------+----------------+

2 rows in set (0.00 sec)

mysql> insert into aa(uname) values('hello');

Query OK, 1 row affected (0.06 sec)

147上查看是否存在数据并删除数据

mysql> select * from tt.aa;

+----+-------+

| id | uname |

+----+-------+

| 3 | hello |

+----+-------+

1 row in set (0.00 sec)

mysql> delete from tt.aa;

Query OK, 1 row affected (0.15 sec)

PXC的缺点非常明显是 操作表数据库会锁定整个集群的所有数据库 等待写入 资源竞争压力大

三。使用ProxySql负载均衡

ProxySql是一款高性能 Sql代理  ProxySql作为后台服务运行,会被后台进程监控 后台进程在Proxy当掉后 短时间内快速重启,

接受来自mysql客户端的请求 将请求转发后实际的后台mysql服务器

ProxySql同时支持PXC的状态检查

1》安装ProxySql(https://www.percona.com/doc/percona-xtradb-cluster/LATEST/howtos/proxysql.html#load-balancing-with-proxysql)

centos使用yum安装(先安装之前的pxc的yum源) 机器ip 192.168.58.151yum -y install proxysql proxysql提供了proxysql-admin 工具配置 pxc 查看该工具命令选项

[root@node4 ~]# proxysql-admin

Usage: [ options ]

Options:

--config-file Read login credentials from a configuration file (overrides any login credentials specified on the command line)

--quick-demo Setup a quick demo with no authentication

--proxysql-username=user_name Username for connecting to the ProxySQL service

--proxysql-password[=password] Password for connecting to the ProxySQL service

--proxysql-port=port_num Port Nr. for connecting to the ProxySQL service

--proxysql-hostname=host_name Hostname for connecting to the ProxySQL service

--cluster-username=user_name Username for connecting to the Percona XtraDB Cluster node

--cluster-password[=password] Password for connecting to the Percona XtraDB Cluster node

--cluster-port=port_num Port Nr. for connecting to the Percona XtraDB Cluster node

--cluster-hostname=host_name Hostname for connecting to the Percona XtraDB Cluster node

--cluster-app-username=user_name Application username for connecting to the Percona XtraDB Cluster node

--cluster-app-password[=password] Application password for connecting to the Percona XtraDB Cluster node

--without-cluster-app-user Configure Percona XtraDB Cluster without application user

--monitor-username=user_name Username for monitoring Percona XtraDB Cluster nodes through ProxySQL

--monitor-password[=password] Password for monitoring Percona XtraDB Cluster nodes through ProxySQL

--enable, -e Auto-configure Percona XtraDB Cluster nodes into ProxySQL

--disable, -d Remove any Percona XtraDB Cluster configurations from ProxySQL

--node-check-interval=3000 Interval for monitoring node checker script (in milliseconds)

--mode=[loadbal|singlewrite] ProxySQL read/write configuration mode, currently supporting: 'loadbal' and 'singlewrite' (the default) modes

--write-node=host_name:port Writer node to accept write statments. This option is supported only when using --mode=singlewrite

Can accept comma delimited list with the first listed being the highest priority.

--include-slaves=host_name:port Add specified slave node(s) to ProxySQL, these nodes will go into the reader hostgroup and will only be put into

the writer hostgroup if all cluster nodes are down. Slaves must be read only. Can accept comma delimited list.

If this is used make sure 'read_only=1' is in the slave's my.cnf

--adduser Adds the Percona XtraDB Cluster application user to the ProxySQL database

--syncusers Sync user accounts currently configured in MySQL to ProxySQL (deletes ProxySQL users not in MySQL)

--version, -v Print version info我这里使用手动的方式配置 当前命令行的方式更好 无需重启

启动proxysql

service proxysql start必须在151主机上 安装pxc客户端 其他机器有客户端的是无法连接的

yum install Percona-XtraDB-Cluster-client-57登录管理接口

[root@node4 ~]# mysql -u admin -padmin -h 127.0.0.1 -P 6032查看所有数据库、

mysql> show databases;

+-----+---------------+-------------------------------------+

| seq | name | file |

+-----+---------------+-------------------------------------+

| 0 | main | |

| 2 | disk | /var/lib/proxysql/proxysql.db |

| 3 | stats | |

| 4 | monitor | |

| 5 | stats_history | /var/lib/proxysql/proxysql_stats.db |

+-----+---------------+-------------------------------------+

5 rows in set (0.00 sec)2》添加集群到ProxySql

只需要插入对应的pxc后端数据库服务器的信息到main数据库下的mysql_servers表即可

INSERT INTO mysql_servers(hostgroup_id, hostname, port) VALUES (0,'192.168.58.147',3306);

INSERT INTO mysql_servers(hostgroup_id, hostname, port) VALUES (0,'192.168.58.149',3306);

INSERT INTO mysql_servers(hostgroup_id, hostname, port) VALUES (0,'192.168.58.150',3306);

加载服务器到实时内存中LOAD MYSQL SERVERS TO RUNTIME;

SAVE MYSQL SERVERS TO DISK;

配置访问后端数据库服务器的用户名和密码

INSERT INTO mysql_users (username,password) VALUES ('root','root');加载用户名和密码到实时内存 并写入磁盘

LOAD MYSQL USERS TO RUNTIME;

SAVE MYSQL USERS TO DISK;确保 proxysql安装机器(151)有访问集群的root用户权限 登录147插入root账号

CREATE USER root@'%' IDENTIFIED BY 'root';

grant all on *.* to root@'%';注意管理接口是6032 代理后端mysql是 6033 测试登录

[root@node4 ~]# mysql -u root -proot -h 127.0.0.1 -P 6033

mysql: [Warning] Using a password on the command line interface can be insecure.

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 7

Server version: 5.5.30 (ProxySQL)

Copyright (c) 2009-2017 Percona LLC and/or its affiliates

Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.测试之前集群中创建的表是否创建 其他关于监控相关的 参考(https://www.percona.com/doc/percona-xtradb-cluster/LATEST/howtos/proxysql.html#load-balancing-with-proxysql)


http://chatgpt.dhexx.cn/article/8KKdppAZ.shtml

相关文章

mysql pxc 安装_MYSQL PXC 集群安装

名词介绍: WS:write set写数据集 IST: Incremental State Transfer增量同步 SST:State Snapshot Transfer全量同步 1.准备环境 1.1 centos 7系统,三台主机 IP分别为:192.168.80.163;192.168.80.167;192.168…

kubernetes mysql pxc_PXC快速入门

C C语言开发 PXC快速入门 1.快速入门 实验环境: Node Host IPNode1 pxc1 192.168.70.61 Node2 pxc2 192.168.70.62 Node3 pxc3 192.168.70.63 1.1 安装Percona-XtraDb-Cluster yum源: [percona] namepercona_repo baseurl https://mirrors.tuna.tsinghu…

mysql pxc

一、PXC介绍 Percona Server由领先的MySQL咨询公司Percona发布。 Percona Server是一款独立的数据库产品,其可以完全与MySQL兼容,可以在不更改代码的情况了下将存储引擎更换成XtraDB 。XtraDB可以看做是InnoDB存储引擎的增强版本,它完全兼容InnoDB,且提供了很多InnoDB不具…

mysql pxc集群 原理 (图解+秒懂+史上最全)

文章很长,而且持续更新,建议收藏起来,慢慢读! Java 高并发 发烧友社群:疯狂创客圈(总入口) 奉上以下珍贵的学习资源: 免费赠送 经典图书 : 极致经典 社群大片好评 《 …

什么是PXC?

目录 什么是PXC PXC的作用 PXC集群的注意事项 比较PXC模式和Replication(传统主从) 什么是PXC PXC是针对MySQL用户的高可用性和扩展性解决方案,基于Percona Server 。 Percona Server 是MySQL的改进版本,使用 XtraDB 存储引擎,在功能和性…

MySQL高可用之PXC详解

PXC 一、PXC相关简介二、部署PXC 一、PXC相关简介 1.pxc简介 PXC(Percona XtraDB Cluster)是一个开源的MySQL高可用解决方案。它将Percona server和XtraBackup与galera库集成,以实现同步多主复制。基于galera的高可用方案主要有MariaDB gale…

小马激活工具拒绝访问cannot open file c:\oemsf解决方法

第一步、激活本机的管理员帐号(administrator),进入命令行窗口(WinKeyR 出现运行窗口,输入“cmd”,按确定),输入以下命令:net user administrator /active:yes。 第二步、使用管理员帐号(administrator)登录系统&am…

小马激活工具对比暴风激活工具

提到win7激活工具,人气最旺的就是:小马激活工具和暴风激活工具。那么,这两款win7激活工具哪个好呢?在今天的教程中,小编就给大家分享一下win7激活工具:小马激活工具和暴风激活工具的使用过程对比&#xff0…

使用小马哥win10 激活工具激活后, 桌面上经常出现一个广告快捷方式的 解决方法...

【本文首发在 梦溪笔记 http://www.mengxi.me 】 小马哥的win10 激活工具 可以一键激活win10, 使用方便,还有效, 但是也存在个人很讨厌的打广告行为, 每次电脑启动时, 会在桌面上创建一个垃圾网站的快捷方式, 图标长的…

小马激活工具出现Cannot open file k:\OEMSF 的解决方法

遇到“此windows副本不是正版7601”,我们一般用小马激活软件激活一下就可以了。但是有时候可能不管用,会显示“Cannot open file OEMSF”的错误,那么我们该怎么解决呢?不用担心,下面就为大家介绍一下,一起来…

很抱歉 程序无法在非mbr引导的分区上激活

很抱歉 程序无法在非mbr引导的分区上激活 [Windows] 神器。完美解决非MBR引导下的WIN7激活问题。你会用的到的 才帮同事装了个系统,发现有100M的隐藏分区。 小马等其他激活工具都激活不了。提示非MBR引导无法激活。 找到了这个激活工具,完美解决。 链…

小马激活手动分配磁盘_不要成为“单把小马”手动测试仪

小马激活手动分配磁盘 我记得我父母带我去马戏团时见过小马。 它们是节目的重要组成部分,以敏捷,跳过障碍物和用两只脚走路给观众留下了深刻的印象。 小马的表演是如此多样,即使您连续几天参加演出,也很难对此感到无聊。 但是让…

使用小马激活工具激活Windows后,浏览器的首页被篡改,如何改回去?

方法一 直接修改浏览器的名字,这种事最简单的方法,KMS(小马激活工具)通过搜索相关的关键字。比如chrome、google、360等一些主流浏览器,对其进行动态代码注入。 方法二 通过WMI(Windows Management Inst…

小马激活软件下载,当心伪小马,有病毒

官方的小马激活软件已经停止更新了,下文是官方停更公告。 http://www.pccppc.com/xiaomajihuo-html 所以小马oem7以后的都不是官方的,包含病毒。重装系统后,一般是先激活系统,再安装杀毒软件,这就给“伪小马激活工具”…

电脑系统或者office系列使用小马激活工具,电脑开机桌面出现假的Edge浏览器

步骤: 首先,在电脑搜索栏里搜索“计划任务” 然后,点击计划任务,打开 最后,关掉有关KMS的计划,右侧的禁用

激活工具也带毒,一批携带病毒的“小马激活工具”被火绒拦截

关于部分网站发布带有木马 KMS 激活工具,一般来说,除非追根溯源将根源清理干净,否则这种现象基本会长期存在,即使短暂性被网络公开,不法分子仍会通过转移的方式多次实施犯罪。 近期,火绒安全实验室又拦截到…

Notes Twelfth Day-渗透攻击-红队-命令与控制

** Notes Twelfth Day-渗透攻击-红队-打入内网(dayu) ** 作者:大余 时间:2020-09-28 请注意:对于所有笔记中复现的这些终端或者服务器,都是自行搭建的环境进行渗透的。我将使用Kali Linux作为此次学习的攻击者机器。这里使用的…

Maven的基础知识详细解析

1 简介 Maven是Apache软件基金会唯一维护的一款自动化构建工具,专注于服务Java平台的项目构建和依赖管理。 Maven是基于项目对象模型(POM),可以通过一小段描述信息来管理项目的构建、报告和文档的软件项目管理工具。 在有多个开…

docker基础命令/dockerfile制作镜像/docker-compose编排容器

参考文章: docker-compose.yml详解 http://www.imooc.com/article/278410 docker-compose官网 https://docs.docker.com/compose/compose-file/#command 什么是docker 我们在理解 docker 之前,我们首先要了解一下虚拟化技术. 百度百科定义: 在计算机中&#xff0…

Maven介绍,包括作用、核心概念、用法、常用命令、扩展及配置

由浅入深,主要介绍maven的用途、核心概念(Pom、Repositories、Artifact、Build Lifecycle、Goal)、用法(Archetype意义及创建各种项目)、maven常用参数和命令以及简单故障排除、maven扩展(eclipse、cobertura、findbugs、插件开发…