MySQL InnoDB Cluster环境搭建和简单测试
yuyutoo 2024-11-08 15:40 3 浏览 0 评论
InnoDB Cluster初印象
记得MySQL Group Replicatioin 刚开始的时候,MySQL界很是轰动,等待了多年,终于有了官方的这个高可用解决方案。你要说还有一些方案补充,比如MySQL Cluster,MySQL Proxy,这些的使用率个人感觉还是不高,也就是经受的考验还不够,原因有很多,就不赘述了。
不久,我和一个MySQL DBA有了下面的一个基本对话。
我: MySQL GR GA之后,里面的自动切换功能确实很赞,能够做到读写分离,原本MHA的方案现在MGR也可以做了。
MySQL DBA:如果数据库发生了故障,这个自动切换的过程,其实对于应用不是透明的,因为读写节点相当于漂移到了另外一台服务器上,除非再做个中间件。
我:单纯MGR目前还做不了这个,它目前只是保证数据库层面的这种切换和高可用。
MySQL DBA:所以说MGR的企业级应用还是需要一些辅助,这样才算是一个完整的解决方案。
不久,MySQL InnoDB Cluster推出,我觉得这个方案想比原来的MGR更进一步,说实话,我很看好这个方案,尽管目前愿意真正去用的用户确实不多。
如果你看一下官方的这个架构图,就会发现,MGR本身就是Innodb Cluster的一部分,还有两个组件,MySQL Shell,MySQL Router,这三板斧就是InnoDB Cluster的一个核心组件,而正如我之前所说,可以看到MySQL的一个格局和定位,他正在很努力去解决以前诟病的问题。
安装前先保证Python满足要求
要安装InnoDB Cluster,环境的一个基本要求就是Python,我看了下,很多默认的系统版本是2.6,而它的最低要求是2.7及以上,所以还是需要提前准备下这个部分。
如果你的系统是Python 2.6版本的,可以考虑升级到2.7,参考如下的方法。
下载安装包,部署
wget http://python.org/ftp/python/2.7/Python-2.7.tar.bz2 --no-check-certificate
./configure
make all
make install
make clean
make distclean
查看Python的版本
# /usr/local/bin/python2.7 -V
Python 2.7
做基本的环境设置,替换旧的Python
mv /usr/bin/python /usr/bin/python2.6
ln -s /usr/local/bin/python2.7 /usr/bin/python
sandbox安装部署InnoDB Cluster
搭建InnoDB Cluster显而易见需要多台服务器,而如果在一台服务器上练习测试,也是全然没有问题,如果想更快更方便的测试模拟,还可以使用sandbox来做,首先你得有sandbox,接着InnoDB Cluster的三大组件是MGR,MySQL Shell,MySQL Router,所以你可以从官网直接下载下来。
然后我们开启安装之旅。
使用MySQL Shell的命令mysqlsh开始部署,创建一个端口为3310的实例
mysql-js> dba.deploySandboxInstance(3310)
A new MySQL sandbox instance will be created on this host in
/root/mysql-sandboxes/3310
输入密码之后,一个3310端口的MySQL服务就启动了。
Please enter a MySQL root password for the new instance:
Deploying new MySQL instance...
Instance localhost:3310 successfully deployed and started.
Use shell.connect('root@localhost:3310'); to connect to the instance.
接着创建另外两个节点 3320,3330
dba.deploySandboxInstance(3320)
dba.deploySandboxInstance(3330)
我们切换到3310的MySQL实例,准备开始创建Cluster
mysql-js> \connect root@localhost:3310
Creating a Session to 'root@localhost:3310'
Enter password:
Closing old connection...
Classic Session successfully established. No default schema selected.
定义一个Cluster变量,节点1就开启了Cluster创建之旅,可以从下面的信息看出,至少需要3个节点
mysql-js> var cluster = dba.createCluster('testCluster')
A new InnoDB cluster will be created on instance 'root@localhost:3310'.
Creating InnoDB cluster 'testCluster' on 'root@localhost:3310'...
Adding Seed Instance...
Cluster successfully created. Use Cluster.addInstance() to add MySQL instances.
At least 3 instances are needed for the cluster to be able to withstand up to one server failure.
接着把另外两个节点加入进来,先加入端口为3320的节点
mysql-js> cluster.addInstance('root@localhost:3320')
A new instance will be added to the InnoDB cluster. Depending on the amount of
data on the cluster this might take from a few seconds to several hours.
Please provide the password for 'root@localhost:3320':
Adding instance to the cluster ...
加入端口为3330的节点,日志和节点2相似。
mysql-js> cluster.addInstance('root@localhost:3330')
这个时候Cluster就创建好了。
这个时候,我们再配置一下MySQL Router,创建个软链接,保证能够正常调用。
# ln -s /home/innodb_cluster/mysql-router-2.1.3-linux-glibc2.12-x86-64bit/bin/mysqlrouter /usr/bin/mysqlroute
# which mysqlroute
/usr/bin/mysqlroute
配置MySQL Router的启动节点为端口3310的实例
# mysqlrouter --bootstrap root@localhost:3310 --user=mysql
这个时候还是要输入密码,成功之后,这个绑定就打通了。
Please enter MySQL password for root:
Bootstrapping system MySQL Router instance...
MySQL Router has now been configured for the InnoDB cluster 'testCluster'.
The following connection information can be used to connect to the cluster.
Classic MySQL protocol connections to cluster 'testCluster':
- Read/Write Connections: localhost:6446
- Read/Only Connections: localhost:6447
X protocol connections to cluster 'testCluster':
- Read/Write Connections: localhost:64460
- Read/Only Connections: localhost:64470
可以从上面的日志看出来,分配的读写端口是6446,只读端口是6447,还有x协议连接的端口为64460,64470
启动MySQL Router
# mysqlrouter &
[1] 2913
如果对MySQL Router还有些疑问,可以看看安装目录下,会生成下面的配置文件,我们就看里面的.conf文件,里面的一部分内容如下:
[routing:testCluster_default_rw]
bind_address=0.0.0.0
bind_port=6446
destinations=metadata-cache://testCluster/default?role=PRIMARY
mode=read-write
protocol=classic
验证测试
我们尝试使用6446来连接登录,这个时候就通过MySQL Shell开启了连接入口,MySQL Router做了转接,连接到了里面的读写节点3310
# mysqlsh --uri root@localhost:6446
Creating a Session to 'root@localhost:6446'
Enter password:
Classic Session successfully established. No default schema selected.
Welcome to MySQL Shell 1.0.9
切换到sql模式,查看端口就知道是哪个节点了。
mysql-js> \sql
Switching to SQL mode... Commands end with ;
mysql-sql> select @@port;
+--------+
| @@port |
+--------+
| 3310 |
+--------+
1 row in set (0.00 sec)
如果切换为脚本模式查看实例的状态,可以使用里面定义的API来做,输出都是JSON串。
mysql-js> dba.configureLocalInstance('root@127.0.0.1:3310')
Please provide the password for 'root@127.0.0.1:3310':
Detected as sandbox instance.
Validating MySQL configuration file at: /root/mysql-sandboxes/3310/my.cnf
Validating instance...
The instance '127.0.0.1:3310' is valid for Cluster usage
You can now use it in an InnoDB Cluster.
{
"status": "ok"
}
如果查看Cluster的信息,可以看到下面的读写节点,只读节点的状态信息
mysql-js> dba.getCluster()
<Cluster:testCluster>
var cluster = dba.getCluster()
得到Cluster的信息
mysql-js> cluster.status()
{
"clusterName": "testCluster",
"defaultReplicaSet": {
"name": "default",
"primary": "localhost:3310",
"status": "OK",
"statusText": "Cluster is ONLINE and can tolerate up to ONE failure.",
"topology": {
"localhost:3310": {
"address": "localhost:3310",
"mode": "R/W",
"readReplicas": {},
"role": "HA",
"status": "ONLINE"
},
"localhost:3320": {
"address": "localhost:3320",
"mode": "R/O",
"readReplicas": {},
"role": "HA",
"status": "ONLINE"
},
"localhost:3330": {
"address": "localhost:3330",
"mode": "R/O",
"readReplicas": {},
"role": "HA",
"status": "ONLINE"
}
}
}
}
也可以使用describe得到一些基本的信息
mysql-js> cluster.describe();
{
"clusterName": "testCluster",
"defaultReplicaSet": {
"instances": [
{
"host": "localhost:3310",
"label": "localhost:3310",
"role": "HA"
},
{
"host": "localhost:3320",
"label": "localhost:3320",
"role": "HA"
},
{
"host": "localhost:3330",
"label": "localhost:3330",
"role": "HA"
}
],
"name": "default"
}
}
切换测试
当然光看不练还是假把式,我们切换一下,看看好使不?
模拟一个节点出现问题,可以使用killSandboxInstance方法。
mysql-js> dba.killSandboxInstance(3310)
The MySQL sandbox instance on this host in
/root/mysql-sandboxes/3310 will be killed
Killing MySQL instance...
Instance localhost:3310 successfully killed.
节点被清理了,没有任何进程存在。
# ps -ef|grep mysql|grep 3310
#
我们还是使用6446的端口来统一连接,这个时候就切换到了端口3320的MySQL服务
# mysqlsh --uri root@localhost:6446
Creating a Session to 'root@localhost:6446'
Enter password:
Classic Session successfully established. No default schema selected.
Welcome to MySQL Shell 1.0.9
mysql-js> \sql
Switching to SQL mode... Commands end with ;
mysql-sql> select @@port;
+--------+
| @@port |
+--------+
| 3320 |
+--------+
1 row in set (0.00 sec)
所以切换的部分没有问题,我们再次把“迷失”的节点启动起来。
# mysqlsh --uri root@localhost:6446
mysql-js> dba.startSandboxInstance(3310)
The MySQL sandbox instance on this host in
/root/mysql-sandboxes/3310 will be started
Starting MySQL instance...
Instance localhost:3310 successfully started.
这个时候再次查看Cluster的状态,3320就是主了,3310就是只读节点了。
mysql-js> dba.getCluster()
<Cluster:testCluster>
把节点2纳入到Cluster中
mysql-js> cluster.rejoinInstance('root@localhost:3310')
Rejoining the instance to the InnoDB cluster. Depending on the original
problem that made the instance unavailable, the rejoin operation might not be
successful and further manual steps will be needed to fix the underlying
problem.
Please monitor the output of the rejoin operation and take necessary action if
the instance cannot rejoin.
Please provide the password for 'root@localhost:3310':
Rejoining instance to the cluster ...
The instance 'root@localhost:3310' was successfully rejoined on the cluster.
The instance 'localhost:3310' was successfully added to the MySQL Cluster.
mysql-js>
可以想象如果是一个生产系统,这么多的日志,这个过程真是让人纠结。
最后来一个切换后的Cluster状态
mysql-js> cluster.status()
{
"clusterName": "testCluster",
"defaultReplicaSet": {
"name": "default",
"primary": "localhost:3320",
"status": "OK",
"statusText": "Cluster is ONLINE and can tolerate up to ONE failure.",
"topology": {
"localhost:3310": {
"address": "localhost:3310",
"mode": "R/O",
"readReplicas": {},
"role": "HA",
"status": "ONLINE"
},
"localhost:3320": {
"address": "localhost:3320",
"mode": "R/W",
"readReplicas": {},
"role": "HA",
"status": "ONLINE"
},
"localhost:3330": {
"address": "localhost:3330",
"mode": "R/O",
"readReplicas": {},
"role": "HA",
"status": "ONLINE"
}
}
}
}
相关推荐
- 从头再来,再见了我曾奋斗的地方
-
今天,我告别了奋斗二十年的地,就现在也不敢相信曾经是那么的辉煌那么让我骄傲的厂子今天确是也要告别了,我们不知道该怨谁该谁买单可苦的是我们还得从头再来...
- 《万古神帝》第4202章(评)咬定神树不放松,第二儒祖仍在破局中
-
各位老铁,酒窝突然有了一个匪夷所思的猜想,从突袭天庭,再到夺取世界树,到天姥和若尘打上天界对战第二儒祖和慕容主宰。这一切会不会只是时空人祖一开始就谋划好的,引蛇出洞之计?第二儒祖乃至整个神界也只不过是...
- 香皂和透明皂可以混用吗?
-
香皂和透明皂是家庭常用物品,使用频率比较高。但是,有些市民认为香皂比较柔和,香味也比较好,因此喜欢用香皂给孩子洗衣服。而有些成年人,特别是男性,觉得透明皂的去污能力强,有时候会使用透明皂洗手或洗澡。那...
- 批评别人的技巧
-
批评和赞美是一对反义词,但在说话这门艺术里,两者不过是两种与人交流沟通的不同方式而已,赞美侧重于一个人的优点和长处,批评侧重于一个人的缺点和不足。赞美人需要讲究方式和技巧,批评人同样不能草率从事。批评...
- 山东2020春季高考技能考试主考学校及考试安排来了
-
山东2020年春季高考技能考试安排在7月14日—20日进行,各类别具体考试时间由主考学校自主确定。考生请于7月11日起登录山东省教育招生考试院招生考试信息平台(http://wsbm.sdzk.cn)...
- 石河子大学2019-2020学年第二学期选课通知
-
它来了,它来了小石带着秘籍来了!又快到了每学期的选课时间内心是不是既兴奋又紧张敲黑板,划重点!为保证选课工作的顺利进行现将选课事宜安排如下你想要的课程安排选课时间及其相关要求...
- “奋进新时代”主题成就展线上开展!一起为山西单元云端打call
-
登录网址,点击按钮,“祝融号”火星车模型、天问一号着陆器模型、东风-17高超音速导弹等实物展品立刻呈现;跟随着语音讲解,奋进山西单元的精彩内容就跃然眼前……近日,“奋进新时代”主题成就展网上展馆上线。...
- 延边大学关于2021年秋季学期本(专)科教学运行工作安排的通知
-
关于2021年秋季学期本(专)科教学运行工作安排的通知根据学校《关于2021年秋季学期师生返校安排的通知》和《关于2021级新生报到相关事宜的通知》,为做好2021年秋季学期开学期间的本(专)科教学相...
- 阿里巴巴Yun OS智能手表Pay Watch亮相:深度整合支付宝
-
IT之家讯9月22日消息,刚刚我们报道了阿里巴巴智能手表亮相YunOS官网,本来以为阿里巴巴会重点介绍一下这款产品。没想到这款智能手表已经悄悄的登录淘宝众筹了。与此同时,它的名字也正式揭晓:Pay...
- 内网本机IP怎么查?外网本机IP地址查询方法
-
在工作中,我们或许要查看本机的ip地址,不是很懂电脑的人,对此可能会无从下手,今天飞飞就给你们分享外网/内网本机IP地址查询方法,感兴趣的往下看,非常简单,肯定可以学会...
- 查完成绩,你是不是还需要了解一下这个「奸笑脸」
-
各位假期生活过得如何?不管你是在各个城市享受旅行,或是已经摊在家里过着肥宅的快乐生活。都醒一醒吧!这一次不同于各种校园推送里的假消息是真的可以查成绩了!成绩已于今日上午...
- 「鼠标」垂直鼠标再体验:多彩DELUX 90度垂直鼠 M618与M618PLUS
-
我因为用原来的鼠标时间比较久了,想换个姿势用鼠标。我仔细搜了一下,垂直鼠标,只找到罗技的MXVERTICAL和多彩的M618系列产品。因为我的初体验是罗技的MXVERTICAL,所以这篇叫“垂直...
- 说一个目前最让你焦虑的事?
-
来说说那些让你感到非常焦虑但是不被生活中你的亲人朋友所知道的吧,在这里说一下,写下来,聊一聊,互相温暖鼓励一下吧!...
你 发表评论:
欢迎- 一周热门
- 最近发表
- 标签列表
-
- mybatis plus (70)
- scheduledtask (71)
- css滚动条 (60)
- java学生成绩管理系统 (59)
- 结构体数组 (69)
- databasemetadata (64)
- javastatic (68)
- jsp实用教程 (53)
- fontawesome (57)
- widget开发 (57)
- vb net教程 (62)
- hibernate 教程 (63)
- case语句 (57)
- svn连接 (74)
- directoryindex (69)
- session timeout (58)
- textbox换行 (67)
- extension_dir (64)
- linearlayout (58)
- vba高级教程 (75)
- iframe用法 (58)
- sqlparameter (59)
- trim函数 (59)
- flex布局 (63)
- contextloaderlistener (56)