如果您对为什么与MariaDB10.2RAND感兴趣,那么本文将是一篇不错的选择,我们将为您详在本文中,您将会了解到关于为什么与MariaDB10.2RAND的详细内容,我们还将为您解答函数发生如此多
如果您对为什么与MariaDB 10.2 RAND感兴趣,那么本文将是一篇不错的选择,我们将为您详在本文中,您将会了解到关于为什么与MariaDB 10.2 RAND的详细内容,我们还将为您解答函数发生如此多的冲突?的相关问题,并且为您提供关于c – 为什么这个非常简单的Makefile产生如此多的调试日志记录?、CentOS 7.2部署MariaDB Galera Cluster(10.1.21-MariaDB) 3主集群环境、CentOS 7下安装MySQL与mariadb冲突的解决办法、centos7 Mariadb5.5 升级到 Mariadb10.2的有价值信息。
本文目录一览:- 为什么与MariaDB 10.2 RAND()函数发生如此多的冲突?
- c – 为什么这个非常简单的Makefile产生如此多的调试日志记录?
- CentOS 7.2部署MariaDB Galera Cluster(10.1.21-MariaDB) 3主集群环境
- CentOS 7下安装MySQL与mariadb冲突的解决办法
- centos7 Mariadb5.5 升级到 Mariadb10.2
为什么与MariaDB 10.2 RAND()函数发生如此多的冲突?
注意:在Windows Server 2012 R2 Standard上运行MariaDB 10.2.27。
我想生成用于MariaDB的随机整数,因此我一直在尝试使用MariaDB RAND()函数。我的期望和理解都偏离了基础(绝对有可能!),或者MariaDB
RAND()函数不是非常随机的。
使用BIGINT(20)专栏中,我想生成随机整数最大长度为16位,所以我用这个SQL:FLOOR(RAND()*9999999999999999)+1)
。我在循环中使用的确切SQL是:
INSERT INTO rnd_test VALUES (FLOOR(RAND()*9999999999999999)+1);
表rnd_test具有单个列,该列是BIGINT(20)并且是主要ID。
在有10 ^ 16个数字的池中,考虑到生日悖论,我希望在生成10 ^
8个数字后发生碰撞的几率约为50%。显然这会有一些差异,但是每次我运行插入循环时,我几乎都立即看到冲突,然后每2000或3000个生成的数字(有时更频繁)重复一次。生成约50,000个随机数后,我发现每隔几百个数字就会发生冲突。
考虑到我的理解可能是完全错误的,我调整了循环vb.net代码以在本地生成随机数,然后将其插入到MariaDB表中。我在例程的顶部定义了一个新的System.Random,然后使用它来生成随机数:
Dim r As Long = CLng(Math.Floor(rNum.NextDouble() * 9999999999999999)) + 1
通常,此方法效果更好,但仍不如我预期的好。在发生碰撞之前,它通常会运行约100,000次迭代,然后在此之后,每生成10,000个随机变量,似乎就会发生一两次碰撞。有时,将有10,000个批次完全没有碰撞。
那么,为什么与vb.net函数相比,MariaDB RAND()函数的性能如此差?
答案1
小编典典5.6的RAND的进一步实验表明,只有30位是好的。也就是说,它只有大约十亿个不同的值。
使用bugs.mysql.com和/或MariaDB提交错误。
30位足以满足大多数应用的需求。在那些它还不够好的应用程序中,大多数人不会注意到它的缺点。
FLOAT
具有24位精度;DOUBLE
有53。因此有30个需求DOUBLE
,但无法满足需求。
c – 为什么这个非常简单的Makefile产生如此多的调试日志记录?
Makefile makefile.cpp
这是makefile.cpp(惊喜!):
#include <iostream> int main() { std::cout << "Hello World!\n"; return 0; }
这是Makefile:
CC = g++ FILES = makefile.cpp OUT_EXE = makefileout build: $(FILES) $(CC) -o $(OUT_EXE) $(FILES)
然后我运行make -d并得到一个很长的日志:
$make -d GNU Make 3.81 copyright (C) 2006 Free Software Foundation,Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or fitness FOR A PARTIculaR PURPOSE. This program built for x86_64-pc-linux-gnu Reading makefiles... Reading makefile `Makefile'... Updating makefiles.... Considering target file `Makefile'. Looking for an implicit rule for `Makefile'. Trying pattern rule with stem `Makefile'. Trying implicit prerequisite `Makefile.o'. Trying pattern rule with stem `Makefile'. Trying implicit prerequisite `Makefile.c'. Trying pattern rule with stem `Makefile'. Trying implicit prerequisite `Makefile.cc'. Trying pattern rule with stem `Makefile'. Trying implicit prerequisite `Makefile.C'. Trying pattern rule with stem `Makefile'. Trying implicit prerequisite `Makefile.cpp'. Trying pattern rule with stem `Makefile'. Trying implicit prerequisite `Makefile.p'. Trying pattern rule with stem `Makefile'. Trying implicit prerequisite `Makefile.f'. Trying pattern rule with stem `Makefile'. Trying implicit prerequisite `Makefile.F'. Trying pattern rule with stem `Makefile'. Trying implicit prerequisite `Makefile.r'. Trying pattern rule with stem `Makefile'. Trying implicit prerequisite `Makefile.s'. Trying pattern rule with stem `Makefile'. Trying implicit prerequisite `Makefile.S'. Trying pattern rule with stem `Makefile'. Trying implicit prerequisite `Makefile.mod'. Trying pattern rule with stem `Makefile'. Trying implicit prerequisite `Makefile.sh'. Trying pattern rule with stem `Makefile'. Trying implicit prerequisite `Makefile,v'. Trying pattern rule with stem `Makefile'. Trying implicit prerequisite `RCS/Makefile,v'. Trying pattern rule with stem `Makefile'. Trying implicit prerequisite `RCS/Makefile'. Trying pattern rule with stem `Makefile'. Trying implicit prerequisite `s.Makefile'. Trying pattern rule with stem `Makefile'. Trying implicit prerequisite `SCCS/s.Makefile'. Trying pattern rule with stem `Makefile'. Trying implicit prerequisite `Makefile.o'. Looking for a rule with intermediate file `Makefile.o'. Avoiding implicit rule recursion. Trying pattern rule with stem `Makefile'. Trying implicit prerequisite `Makefile.c'. Trying pattern rule with stem `Makefile'. Trying implicit prerequisite `Makefile.cc'. Trying pattern rule with stem `Makefile'. Trying implicit prerequisite `Makefile.C'. Trying pattern rule with stem `Makefile'. Trying implicit prerequisite `Makefile.cpp'. Trying pattern rule with stem `Makefile'. Trying implicit prerequisite `Makefile.p'. Trying pattern rule with stem `Makefile'. Trying implicit prerequisite `Makefile.f'. Trying pattern rule with stem `Makefile'. Trying implicit prerequisite `Makefile.F'. Trying pattern rule with stem `Makefile'. Trying implicit prerequisite `Makefile.r'. Trying pattern rule with stem `Makefile'. Trying implicit prerequisite `Makefile.s'. Trying pattern rule with stem `Makefile'. Trying implicit prerequisite `Makefile.S'. Trying pattern rule with stem `Makefile'. Trying implicit prerequisite `Makefile.mod'. Trying pattern rule with stem `Makefile.o'. Trying implicit prerequisite `Makefile.o,v'. Trying pattern rule with stem `Makefile.o'. Trying implicit prerequisite `RCS/Makefile.o,v'. Trying pattern rule with stem `Makefile.o'. Trying implicit prerequisite `RCS/Makefile.o'. Trying pattern rule with stem `Makefile.o'. Trying implicit prerequisite `s.Makefile.o'. Trying pattern rule with stem `Makefile.o'. Trying implicit prerequisite `SCCS/s.Makefile.o'. Trying pattern rule with stem `Makefile'. Trying implicit prerequisite `Makefile.c'. Looking for a rule with intermediate file `Makefile.c'. Avoiding implicit rule recursion. Avoiding implicit rule recursion. Trying pattern rule with stem `Makefile'. Trying implicit prerequisite `Makefile.y'. Trying pattern rule with stem `Makefile'. Trying implicit prerequisite `Makefile.l'. Trying pattern rule with stem `Makefile'. Trying implicit prerequisite `Makefile.w'. Trying pattern rule with stem `Makefile'. Trying implicit prerequisite `Makefile.w'. Trying pattern rule with stem `Makefile.c'. Trying implicit prerequisite `Makefile.c,v'. Trying pattern rule with stem `Makefile.c'. Trying implicit prerequisite `RCS/Makefile.c,v'. Trying pattern rule with stem `Makefile.c'. Trying implicit prerequisite `RCS/Makefile.c'. Trying pattern rule with stem `Makefile.c'. Trying implicit prerequisite `s.Makefile.c'. Trying pattern rule with stem `Makefile.c'. Trying implicit prerequisite `SCCS/s.Makefile.c'. Trying pattern rule with stem `Makefile'. Trying implicit prerequisite `Makefile.y'. Looking for a rule with intermediate file `Makefile.y'. Avoiding implicit rule recursion. Avoiding implicit rule recursion. Avoiding implicit rule recursion. Trying pattern rule with stem `Makefile.y'. Trying implicit prerequisite `Makefile.y,v'. Trying pattern rule with stem `Makefile.y'. Trying implicit prerequisite `RCS/Makefile.y,v'. Trying pattern rule with stem `Makefile.y'. Trying implicit prerequisite `RCS/Makefile.y'. Trying pattern rule with stem `Makefile.y'. Trying implicit prerequisite `s.Makefile.y'. Trying pattern rule with stem `Makefile.y'. Trying implicit prerequisite `SCCS/s.Makefile.y'. Trying pattern rule with stem `Makefile'. Trying implicit prerequisite `Makefile.l'. Looking for a rule with intermediate file `Makefile.l'. Avoiding implicit rule recursion. Avoiding implicit rule recursion. Avoiding implicit rule recursion. Trying pattern rule with stem `Makefile.l'. Trying implicit prerequisite `Makefile.l,v'. Trying pattern rule with stem `Makefile.l'. Trying implicit prerequisite `RCS/Makefile.l,v'. Trying pattern rule with stem `Makefile.l'. Trying implicit prerequisite `RCS/Makefile.l'. Trying pattern rule with stem `Makefile.l'. Trying implicit prerequisite `s.Makefile.l'. Trying pattern rule with stem `Makefile.l'. Trying implicit prerequisite `SCCS/s.Makefile.l'. Trying pattern rule with stem `Makefile'. Trying implicit prerequisite `Makefile.w'. Looking for a rule with intermediate file `Makefile.w'. Avoiding implicit rule recursion. Avoiding implicit rule recursion. Avoiding implicit rule recursion. Trying pattern rule with stem `Makefile.w'. Trying implicit prerequisite `Makefile.w,v'. Trying pattern rule with stem `Makefile.w'. Trying implicit prerequisite `RCS/Makefile.w,v'. Trying pattern rule with stem `Makefile.w'. Trying implicit prerequisite `RCS/Makefile.w'. Trying pattern rule with stem `Makefile.w'. Trying implicit prerequisite `s.Makefile.w'. Trying pattern rule with stem `Makefile.w'. Trying implicit prerequisite `SCCS/s.Makefile.w'. Trying pattern rule with stem `Makefile'. Rejecting impossible implicit prerequisite `Makefile.w'. Trying pattern rule with stem `Makefile'. Trying implicit prerequisite `Makefile.cc'. Looking for a rule with intermediate file `Makefile.cc'. Avoiding implicit rule recursion. Avoiding implicit rule recursion. Trying pattern rule with stem `Makefile.cc'. Trying implicit prerequisite `Makefile.cc,v'. Trying pattern rule with stem `Makefile.cc'. Trying implicit prerequisite `RCS/Makefile.cc,v'. Trying pattern rule with stem `Makefile.cc'. Trying implicit prerequisite `RCS/Makefile.cc'. Trying pattern rule with stem `Makefile.cc'. Trying implicit prerequisite `s.Makefile.cc'. Trying pattern rule with stem `Makefile.cc'. Trying implicit prerequisite `SCCS/s.Makefile.cc'. Trying pattern rule with stem `Makefile'. Trying implicit prerequisite `Makefile.C'. Looking for a rule with intermediate file `Makefile.C'. Avoiding implicit rule recursion. Avoiding implicit rule recursion. Trying pattern rule with stem `Makefile.C'. Trying implicit prerequisite `Makefile.C,v'. Trying pattern rule with stem `Makefile.C'. Trying implicit prerequisite `RCS/Makefile.C,v'. Trying pattern rule with stem `Makefile.C'. Trying implicit prerequisite `RCS/Makefile.C'. Trying pattern rule with stem `Makefile.C'. Trying implicit prerequisite `s.Makefile.C'. Trying pattern rule with stem `Makefile.C'. Trying implicit prerequisite `SCCS/s.Makefile.C'. Trying pattern rule with stem `Makefile'. Trying implicit prerequisite `Makefile.cpp'. Looking for a rule with intermediate file `Makefile.cpp'. Avoiding implicit rule recursion. Avoiding implicit rule recursion. Trying pattern rule with stem `Makefile.cpp'. Trying implicit prerequisite `Makefile.cpp,v'. Trying pattern rule with stem `Makefile.cpp'. Trying implicit prerequisite `RCS/Makefile.cpp,v'. Trying pattern rule with stem `Makefile.cpp'. Trying implicit prerequisite `RCS/Makefile.cpp'. Trying pattern rule with stem `Makefile.cpp'. Trying implicit prerequisite `s.Makefile.cpp'. Trying pattern rule with stem `Makefile.cpp'. Trying implicit prerequisite `SCCS/s.Makefile.cpp'. Trying pattern rule with stem `Makefile'. Trying implicit prerequisite `Makefile.p'. Looking for a rule with intermediate file `Makefile.p'. Avoiding implicit rule recursion. Avoiding implicit rule recursion. Trying pattern rule with stem `Makefile'. Trying implicit prerequisite `Makefile.web'. Trying pattern rule with stem `Makefile.p'. Trying implicit prerequisite `Makefile.p,v'. Trying pattern rule with stem `Makefile.p'. Trying implicit prerequisite `RCS/Makefile.p,v'. Trying pattern rule with stem `Makefile.p'. Trying implicit prerequisite `RCS/Makefile.p'. Trying pattern rule with stem `Makefile.p'. Trying implicit prerequisite `s.Makefile.p'. Trying pattern rule with stem `Makefile.p'. Trying implicit prerequisite `SCCS/s.Makefile.p'. Trying pattern rule with stem `Makefile'. Trying implicit prerequisite `Makefile.web'. Looking for a rule with intermediate file `Makefile.web'. Avoiding implicit rule recursion. Avoiding implicit rule recursion. Avoiding implicit rule recursion. Trying pattern rule with stem `Makefile.web'. Trying implicit prerequisite `Makefile.web,v'. Trying pattern rule with stem `Makefile.web'. Trying implicit prerequisite `RCS/Makefile.web,v'. Trying pattern rule with stem `Makefile.web'. Trying implicit prerequisite `RCS/Makefile.web'. Trying pattern rule with stem `Makefile.web'. Trying implicit prerequisite `s.Makefile.web'. Trying pattern rule with stem `Makefile.web'. Trying implicit prerequisite `SCCS/s.Makefile.web'. Trying pattern rule with stem `Makefile'. Trying implicit prerequisite `Makefile.f'. Looking for a rule with intermediate file `Makefile.f'. Avoiding implicit rule recursion. Avoiding implicit rule recursion. Trying pattern rule with stem `Makefile'. Trying implicit prerequisite `Makefile.F'. Trying pattern rule with stem `Makefile'. Trying implicit prerequisite `Makefile.r'. Trying pattern rule with stem `Makefile.f'. Trying implicit prerequisite `Makefile.f,v'. Trying pattern rule with stem `Makefile.f'. Trying implicit prerequisite `RCS/Makefile.f,v'. Trying pattern rule with stem `Makefile.f'. Trying implicit prerequisite `RCS/Makefile.f'. Trying pattern rule with stem `Makefile.f'. Trying implicit prerequisite `s.Makefile.f'. Trying pattern rule with stem `Makefile.f'. Trying implicit prerequisite `SCCS/s.Makefile.f'. Trying pattern rule with stem `Makefile'. Trying implicit prerequisite `Makefile.F'. Looking for a rule with intermediate file `Makefile.F'. Avoiding implicit rule recursion. Avoiding implicit rule recursion. Avoiding implicit rule recursion. Trying pattern rule with stem `Makefile.F'. Trying implicit prerequisite `Makefile.F,v'. Trying pattern rule with stem `Makefile.F'. Trying implicit prerequisite `RCS/Makefile.F,v'. Trying pattern rule with stem `Makefile.F'. Trying implicit prerequisite `RCS/Makefile.F'. Trying pattern rule with stem `Makefile.F'. Trying implicit prerequisite `s.Makefile.F'. Trying pattern rule with stem `Makefile.F'. Trying implicit prerequisite `SCCS/s.Makefile.F'. Trying pattern rule with stem `Makefile'. Trying implicit prerequisite `Makefile.r'. Looking for a rule with intermediate file `Makefile.r'. Avoiding implicit rule recursion. Avoiding implicit rule recursion. Avoiding implicit rule recursion. Trying pattern rule with stem `Makefile'. Rejecting impossible implicit prerequisite `Makefile.l'. Trying pattern rule with stem `Makefile.r'. Trying implicit prerequisite `Makefile.r,v'. Trying pattern rule with stem `Makefile.r'. Trying implicit prerequisite `RCS/Makefile.r,v'. Trying pattern rule with stem `Makefile.r'. Trying implicit prerequisite `RCS/Makefile.r'. Trying pattern rule with stem `Makefile.r'. Trying implicit prerequisite `s.Makefile.r'. Trying pattern rule with stem `Makefile.r'. Trying implicit prerequisite `SCCS/s.Makefile.r'. Trying pattern rule with stem `Makefile'. Rejecting impossible implicit prerequisite `Makefile.F'. Trying pattern rule with stem `Makefile'. Rejecting impossible implicit prerequisite `Makefile.r'. Trying pattern rule with stem `Makefile'. Trying implicit prerequisite `Makefile.s'. Looking for a rule with intermediate file `Makefile.s'. Avoiding implicit rule recursion. Avoiding implicit rule recursion. Trying pattern rule with stem `Makefile'. Trying implicit prerequisite `Makefile.S'. Trying pattern rule with stem `Makefile.s'. Trying implicit prerequisite `Makefile.s,v'. Trying pattern rule with stem `Makefile.s'. Trying implicit prerequisite `RCS/Makefile.s,v'. Trying pattern rule with stem `Makefile.s'. Trying implicit prerequisite `RCS/Makefile.s'. Trying pattern rule with stem `Makefile.s'. Trying implicit prerequisite `s.Makefile.s'. Trying pattern rule with stem `Makefile.s'. Trying implicit prerequisite `SCCS/s.Makefile.s'. Trying pattern rule with stem `Makefile'. Trying implicit prerequisite `Makefile.S'. Looking for a rule with intermediate file `Makefile.S'. Avoiding implicit rule recursion. Avoiding implicit rule recursion. Avoiding implicit rule recursion. Trying pattern rule with stem `Makefile.S'. Trying implicit prerequisite `Makefile.S,v'. Trying pattern rule with stem `Makefile.S'. Trying implicit prerequisite `RCS/Makefile.S,v'. Trying pattern rule with stem `Makefile.S'. Trying implicit prerequisite `RCS/Makefile.S'. Trying pattern rule with stem `Makefile.S'. Trying implicit prerequisite `s.Makefile.S'. Trying pattern rule with stem `Makefile.S'. Trying implicit prerequisite `SCCS/s.Makefile.S'. Trying pattern rule with stem `Makefile'. Rejecting impossible implicit prerequisite `Makefile.S'. Trying pattern rule with stem `Makefile'. Trying implicit prerequisite `Makefile.mod'. Looking for a rule with intermediate file `Makefile.mod'. Avoiding implicit rule recursion. Avoiding implicit rule recursion. Trying pattern rule with stem `Makefile.mod'. Trying implicit prerequisite `Makefile.mod,v'. Trying pattern rule with stem `Makefile.mod'. Trying implicit prerequisite `RCS/Makefile.mod,v'. Trying pattern rule with stem `Makefile.mod'. Trying implicit prerequisite `RCS/Makefile.mod'. Trying pattern rule with stem `Makefile.mod'. Trying implicit prerequisite `s.Makefile.mod'. Trying pattern rule with stem `Makefile.mod'. Trying implicit prerequisite `SCCS/s.Makefile.mod'. Trying pattern rule with stem `Makefile'. Rejecting impossible implicit prerequisite `Makefile.c'. Trying pattern rule with stem `Makefile'. Rejecting impossible implicit prerequisite `Makefile.cc'. Trying pattern rule with stem `Makefile'. Rejecting impossible implicit prerequisite `Makefile.C'. Trying pattern rule with stem `Makefile'. Rejecting impossible implicit prerequisite `Makefile.cpp'. Trying pattern rule with stem `Makefile'. Rejecting impossible implicit prerequisite `Makefile.p'. Trying pattern rule with stem `Makefile'. Rejecting impossible implicit prerequisite `Makefile.f'. Trying pattern rule with stem `Makefile'. Rejecting impossible implicit prerequisite `Makefile.F'. Trying pattern rule with stem `Makefile'. Rejecting impossible implicit prerequisite `Makefile.r'. Trying pattern rule with stem `Makefile'. Rejecting impossible implicit prerequisite `Makefile.s'. Trying pattern rule with stem `Makefile'. Rejecting impossible implicit prerequisite `Makefile.S'. Trying pattern rule with stem `Makefile'. Rejecting impossible implicit prerequisite `Makefile.mod'. Trying pattern rule with stem `Makefile'. Trying implicit prerequisite `Makefile.sh'. Looking for a rule with intermediate file `Makefile.sh'. Avoiding implicit rule recursion. Trying pattern rule with stem `Makefile.sh'. Trying implicit prerequisite `Makefile.sh,v'. Trying pattern rule with stem `Makefile.sh'. Trying implicit prerequisite `RCS/Makefile.sh,v'. Trying pattern rule with stem `Makefile.sh'. Trying implicit prerequisite `RCS/Makefile.sh'. Trying pattern rule with stem `Makefile.sh'. Trying implicit prerequisite `s.Makefile.sh'. Trying pattern rule with stem `Makefile.sh'. Trying implicit prerequisite `SCCS/s.Makefile.sh'. No implicit rule found for `Makefile'. Finished prerequisites of target file `Makefile'. No need to remake target `Makefile'. Updating goal targets.... Considering target file `build'. File `build' does not exist. Considering target file `makefile.cpp'. Looking for an implicit rule for `makefile.cpp'. Trying pattern rule with stem `makefile.cpp'. Trying implicit prerequisite `makefile.cpp,v'. Trying pattern rule with stem `makefile.cpp'. Trying implicit prerequisite `RCS/makefile.cpp,v'. Trying pattern rule with stem `makefile.cpp'. Trying implicit prerequisite `RCS/makefile.cpp'. Trying pattern rule with stem `makefile.cpp'. Trying implicit prerequisite `s.makefile.cpp'. Trying pattern rule with stem `makefile.cpp'. Trying implicit prerequisite `SCCS/s.makefile.cpp'. No implicit rule found for `makefile.cpp'. Finished prerequisites of target file `makefile.cpp'. No need to remake target `makefile.cpp'. Finished prerequisites of target file `build'. Must remake target `build'. g++ -o makefileout makefile.cpp Putting child 0x01a6de60 (build) PID 6157 on the chain. Live child 0x01a6de60 (build) PID 6157 Reaping winning child 0x01a6de60 PID 6157 Removing child 0x01a6de60 PID 6157 from chain. Successfully remade target file `build'.
我的问题是:我做错了吗?为什么这么简单的例子会产生如此多的日志?
此外,即使源代码早于最新的make,我的Makefile似乎总是重新编译对象代码.换句话说,我从未见过这样的信息:“没有什么可做的.”
解决方法
my Makefile always seems to recompile the object code even if the
source code is older than the latest make
在这个答案.
考虑你的Makefile:
CC = g++ FILES = makefile.cpp OUT_EXE = makefileout build: $(FILES) $(CC) -o $(OUT_EXE) $(FILES)
这里唯一的目标是构建,这是永远不会构造的东西(这就是为什么你每次都看到编译的原因).对此最简单的解决方法应该是:
CC = g++ FILES = makefile.cpp OUT_EXE = makefileout ${OUT_EXE}: $(FILES) $(CC) -o $(OUT_EXE) $(FILES)
使用新规则make将检查makefileout而不是build,从而提供预期的行为.
如果您想进行更多实验,可以使用Makefile发出以下命令:
rm -f makefileout touch build make
你会发现即使可执行文件不存在,make也不会编译它.我告诉你为什么(一个简单的)练习的问题.
CentOS 7.2部署MariaDB Galera Cluster(10.1.21-MariaDB) 3主集群环境
MariaDB galera Cluster 介绍
galera Cluster是由第三方公司Codership所研发的一套免费开源的集群高可用方案,实现了数据零丢失,官网地址为http://galeracluster.com/。其在MysqLInnoDB存储引擎基础上打了wrep(虚拟全同步复制),Percona/MariaDB已捆绑在各自的发行版本中。
MariaDB galera Cluster是MariaDB同步多主机集群。它仅支持XTradB/InnoDB存储引擎(虽然有对MyISAM实验支持,具体看wsrep_replicate_myisam系统变量)。
MariaDB galera Cluster主要功能:
l 同步复制
l 真正的multi-master,即所有节点可以同时读写数据库
l 自动的节点成员控制,失效节点自动被清除
l 新节点加入数据自动复制
l 真正的并行复制,行级
l 用户可以直接连接集群,使用感受上与MysqL完全一致
优势:
l 因为是多主,所以不存在Slavelag(延迟)
l 不存在丢失事务的情况
l 同时具有读和写的扩展能力
l 更小的客户端延迟
l 节点间数据是同步的,而Master/Slave模式是异步的,不同slave上的binlog可能是不同的
缺点:
l 加入新节点时开销大,需要复制完整的数据
l 不能有效地解决写扩展的问题,所有的写操作都发生在所有的节点
l 有多少个节点,就有多少份重复的数据
l 由于事务提交需要跨节点通信,即涉及分布式事务操作,因此写入会比主从复制慢很多,节点越多,写入越慢,死锁和回滚也会更加频繁
l 对网络要求比较高,如果网络出现波动不稳定,则可能会造成两个节点失联,galera Cluster集群会发生脑裂,服务将不可用
还有一些地方存在局限:
l 仅支持InnoDB/XTradB存储引擎,任何写入其他引擎的表,包括MysqL.*表都不会被复制。但是DDL语句可以复制,但是insert into MysqL.user(MyISAM存储引擎)之类的插入数据不会被复制
l Delete操作不支持没有主键的表,因为没有主键的表在不同的节点上的顺序不同,如果执行select … limit …将出现不同的结果集
l LOCK/UNLOCK TABLES/FLUSH TABLES WITH READ LOCKS不支持单表所锁,以及锁函数GET_LOCK()、RELEASE_LOCK(),但FLUSH TABLES WITH READ LOCK支持全局表锁
l General Query Log日志不能保存在表中,如果开始查询日志,则只能保存到文件中
l 不能有大事务写入,不能操作wsrep_max_ws_rows=131072(行),且写入集不能超过wsrep_max_ws_size=1073741824(1GB),否则客户端直接报错
l 由于集群是乐观锁并发控制,因此,在commit阶段会有事务冲突发生。如果两个事务在集群中的不同节点上对同一行写入并提交,则失败的节点将回滚,客户端返回死锁报错
l XA分布式事务不支持Codership galera Cluster,在提交时可能会回滚
l 整个集群的写入吞吐量取决于最弱的节点限制,集群要使用同一的配置
技术:
galera集群的复制功能是基于认证的复制,其流程如下:
当客户端发出一个commit的指令,在事务被提交之前,所有对数据库的更改都会被write-set收集起来,并且将write-set记录的内容发送给其他节点。
write-set将在每个节点上使用搜索到的主键进行确认性认证测试,测试结果决定着节点是否应用write-set更改数据。如果认证测试失败,节点将丢弃 write-set ;如果认证测试成功,则事务提交,工作原理如下图:
关于新节点的加入,流程如下:
新加入的节点叫做Joiner,给Joiner提供复制的节点叫Donor。在该过程中首先会检查本地grastate.dat文件的seqno事务号是否在远端donor节点galera.cache文件里,如果存在,那么进行Incremental State Transfer(IST)增量同步复制,将剩余的事务发送过去;如果不存在那么进行State Snapshot Transfer(sst)全量同步复制。sst有三种全量拷贝方式:MysqLdump、rsync和xtrabackup。sst的方法可以通过wsrep_sst_method这个参数来设置。
备注:
sst是指从donor到joiner的数据全量拷贝,它通常使用在一个新的节点加入时,为了与集群同步,新的节点不得不去一个已经在集群中的节点上拷贝数据,在PXC(Percona XTradb Cluster)中,有三种sst的方法,MysqLdump,rsync,Xtrabackup。
建议使用XtraBackup,另外对XtraBackup补充说明:
在XtraBackup 2.1.x版本里,使用innobackupex备份时,备份流程如下:
1.备份InnoDB表数据
2.执行全局表读锁FLUSH TABLES WITH READ LOCKS
3.拷贝.frm和MyISAM表数据
4.得到当前的binlog文件名和position点
5.完成redo log事务日志的后台复制
6.解锁UNLOCK TABLES
由上面可以看出如果备份好几张MyISAM存储的大表时,将会进行锁表。
环境信息
MariaDB Server:10.1.21-MariaDB
CentOS:CentOS Linux release7.2.1511 (Core)
MariaDB galera Cluster 三个集群节点主机名和IP地址信息:
192.168.1.104 mariadb-a03
192.168.1.105 mariadb-a04
192.168.1.106 mariadb-a05
环境准备
1.配置hosts文件
# cat /etc/hosts 127.0.0.1 localhost.localdomain localhost 192.168.1.104 mariadb-a03 192.168.1.105 mariadb-a04 192.168.1.106 mariadb-a05
2./etc/security/limits.conf
* soft nofile 65536 * hard nofile 65536
3./etc/sysctl.conf
fs.file-max=655350 net.ipv4.ip_local_port_range = 1025 65000 net.ipv4.tcp_tw_recycle = 1
最后执行:
# sysctl -p
4.安装Percona XtraBackup热备份工具
下载地址:
https://www.percona.com/downloads/XtraBackup/Percona-XtraBackup-2.4.6/binary/tarball/percona-xtrabackup-2.4.6-Linux-x86_64.tar.gz
解压缩:
# tar -zxvf percona-xtrabackup-2.4.6-Linux-x86_64.tar.gz
拷贝脚本到指定位置:
# cd percona-xtrabackup-2.4.6-Linux-x86_64/bin/ # cp -a * /usr/bin/
安装依赖的一些包,比如lsof,socat,openssl,tar等
创建XtraBackup备份时用的用户名和密码:
MariaDB [(none)]> grant all on *.* to 'galera'@'localhost' identified by '123456';
部署MariaDB
从MariaDB 10.1版本开始,galera Cluster就已经包含在MariaDB包里面了,不需要单独部署MariaDB-galera-server 和galera 包。
这里演示使用YUM方式部署MariaDB galera Cluster。
步骤一:配置Yum源(192.168.1.104,192.168.1.105,192.168.1.106)
# touch /etc/yum.repos.d/MariaDB-IDC.repo 添加如下内容: [mariadb] name = MariaDB baseurl =http://yum.mariadb.org/10.1/centos7-amd64 gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB gpgcheck=1
由于我们的环境无法访问外网,单独部署一个MariaDB的Yum源:
# cat /etc/yum.repos.d/MariaDB-IDC.repo [MariaDB-10.1-IDC] name=MariaDB-10.1-IDC baseurl=http://192.168.1.100/repo/yum.mariadb.org/10.1/centos7-amd64 gpgcheck=0 enabled=1
步骤二:安装MariaDB(192.168.1.104,192.168.1.106)
# yum install MariaDB-server MariaDB-clientgalera -y
配置 MariaDB galera Cluster
下面我们开始配置MariaDB galera Cluster,分别修改MariaDB galera集群的每个节点上的/etc/my.cnf.d/server.cnf文件,具体每个节点的内容如下:
1.192.168.1.104节点的/etc/my.cnf.d/server.cnf文件内容:
[root@mariadb-a03 ~]# cat /etc/my.cnf.d/server.cnf | grep -v "#" | grep -v "^$" [server] [MysqLd] server_id=128 datadir=/app/galera user=MysqL skip-external-locking skip-name-resolve character-set-server=utf8 [galera] wsrep_causal_reads=ON #节点应用完事务才返回查询请求 wsrep_provider_options="gcache.size=4G"#同步复制缓冲池 wsrep_certify_nonPK=ON #为没有显式申明主键的表生成一个用于certificationtest的主键,默认为ON #log-bin=/app/galera/MysqL-bin #如果不接从库,注释掉 #log_slave_updates=1 #如果不接从库,注释掉 query_cache_size=0 #关闭查询缓存 wsrep_on=ON #开启全同步复制模式 wsrep_provider=/usr/lib64/galera/libgalera_smm.so#galera library wsrep_cluster_name=MariaDB-galera-Cluster wsrep_cluster_address="gcomm://192.168.1.104,192.168.1.106" #galera cluster URL wsrep_node_name=mariadb-a03 wsrep_node_address=192.168.1.104 binlog_format=row default_storage_engine=InnoDB innodb_autoinc_lock_mode=2 #主键自增模式修改为交叉模式 wsrep_slave_threads=8 #开启并行复制线程,根据cpu核数设置 innodb_flush_log_at_trx_commit=0 #事务提交每隔1秒刷盘 innodb_buffer_pool_size=2G wsrep_sst_method=rsync [embedded] [mariadb] [mariadb-10.1]
# 上面配置使用的是rsync方式同步数据,如果要使用xtrabackup方式(建议使用),需要设置:
wsrep_sst_auth=galera:123456
wsrep_sst_method=xtrabackup-v2 #默认是rsync全量拷贝,但是需要在donor节点上执行全局读锁(flushtables with read lock),建议采用xtrabackup热备份方式,只有在备份.frm表结构文件才会锁表
2.192.168.1.105节点的/etc/my.cnf.d/server.cnf文件内容:
[root@mariadb-a04 ~]# cat /etc/my.cnf.d/server.cnf | grep -v "#" | grep -v "^$" [server] [MysqLd] server_id=129 datadir=/app/galera user=MysqL skip-external-locking skip-name-resolve character-set-server=utf8 [galera] wsrep_causal_reads=ON wsrep_provider_options="gcache.size=4G" wsrep_certify_nonPK=ON query_cache_size=0 wsrep_on=ON wsrep_provider=/usr/lib64/galera/libgalera_smm.so wsrep_cluster_name=MariaDB-galera-Cluster wsrep_cluster_address="gcomm://192.168.1.104,192.168.1.106" wsrep_node_name=mariadb-a04 wsrep_node_address=192.168.1.105 binlog_format=row default_storage_engine=InnoDB innodb_autoinc_lock_mode=2 wsrep_slave_threads=8 innodb_flush_log_at_trx_commit=0 innodb_buffer_pool_size=2G wsrep_sst_method=rsync [embedded] [mariadb] [mariadb-10.1]
3.192.168.1.106节点的/etc/my.cnf.d/server.cnf文件内容:
[root@mariadb-a05 yum.repos.d]# cat /etc/my.cnf.d/server.cnf | grep -v "#" | grep -v "^$" [server] [MysqLd] server_id=130 datadir=/app/galera user=MysqL skip-external-locking skip-name-resolve character-set-server=utf8 [galera] wsrep_causal_reads=ON wsrep_provider_options="gcache.size=4G" wsrep_certify_nonPK=ON query_cache_size=0 wsrep_on=ON wsrep_provider=/usr/lib64/galera/libgalera_smm.so wsrep_cluster_name=MariaDB-galera-Cluster wsrep_cluster_address="gcomm://192.168.1.104,192.168.1.106" wsrep_node_name=mariadb-a05 wsrep_node_address=192.168.1.106 binlog_format=row default_storage_engine=InnoDB innodb_autoinc_lock_mode=2 wsrep_slave_threads=8 innodb_flush_log_at_trx_commit=0 innodb_buffer_pool_size=2G wsrep_sst_method=rsync [embedded] [mariadb] [mariadb-10.1]
MariaDB一个节点初始化安装(192.168.1.104):
# MysqL_install_db --defaults-file=/etc/my.cnf.d/server.cnf --user=MysqL
在192.168.1.104节点上通过bootstrap启动(第一次启动一定要使用--wsrep-new-cluster,再次启动就不需要)
MysqLd_safe --defaults-file=/etc/my.cnf.d/server.cnf --user=MysqL --wsrep-new-cluster &
在192.168.1.104节点上设置root密码以及安全设置(192.168.1.104,192.168.1.106)
/usr/bin/MysqL_secure_installation 或 MysqL_secure_installation
在192.168.1.105,192.168.1.106节点启动MariaDB:
MysqLd_safe --defaults-file=/etc/my.cnf.d/server.cnf --user=MysqL &
验证操作
登录三个节点查看
192.168.1.104节点: MariaDB [(none)]> SHOW STATUS LIKE 'wsrep_cluster_size'; +--------------------+-------+ | Variable_name | Value | +--------------------+-------+ | wsrep_cluster_size | 3 | +--------------------+-------+ 1 row in set (0.00 sec) MariaDB [(none)]> show global status like 'ws%'; +------------------------------+-------------------------------------------------------------+ | Variable_name | Value | +------------------------------+-------------------------------------------------------------+ | wsrep_apply_oooe | 0.000000 | | wsrep_apply_oool | 0.000000 | | wsrep_apply_window | 1.000000 | | wsrep_causal_reads | 11 | | wsrep_cert_deps_distance | 1.000000 | | wsrep_cert_index_size | 2 | | wsrep_cert_interval | 0.000000 | | wsrep_cluster_conf_id | 3 | | wsrep_cluster_size | 3 | | wsrep_cluster_state_uuid |3108c722-ff29-11e6-a31f-bb500598d033 | | wsrep_cluster_status | Primary | | wsrep_commit_oooe | 0.000000 | | wsrep_commit_oool | 0.000000 | | wsrep_commit_window | 1.000000 | | wsrep_connected | ON | | wsrep_desync_count | 0 | | wsrep_evs_delayed | | | wsrep_evs_evict_list | | | wsrep_evs_repl_latency | 0/0/0/0/0 | | wsrep_evs_state | OPERATIONAL | | wsrep_flow_control_paused | 0.000000 | | wsrep_flow_control_paused_ns | 0 | | wsrep_flow_control_recv | 0 | | wsrep_flow_control_sent | 0 | | wsrep_gcomm_uuid |3107a278-ff29-11e6-96d3-374133af7e21 | | wsrep_incoming_addresses | 192.168.1.105:3306,192.168.1.106:3306,192.168.1.104:3306| | wsrep_last_committed | 3 | | wsrep_local_bf_aborts | 0 | | wsrep_local_cached_downto | 1 | | wsrep_local_cert_failures | 0 | | wsrep_local_commits | 0 | | wsrep_local_index | 2 | | wsrep_local_recv_queue | 0 | | wsrep_local_recv_queue_avg | 0.000000 | | wsrep_local_recv_queue_max | 1 | | wsrep_local_recv_queue_min | 0 | | wsrep_local_replays | 0 | | wsrep_local_send_queue | 0 | | wsrep_local_send_queue_avg | 0.000000 | | wsrep_local_send_queue_max | 1 | | wsrep_local_send_queue_min | 0 | | wsrep_local_state | 4 | | wsrep_local_state_comment | Synced | | wsrep_local_state_uuid |3108c722-ff29-11e6-a31f-bb500598d033 | | wsrep_protocol_version | 7 | | wsrep_provider_name | galera | | wsrep_provider_vendor | Codership Oy<info@codership.com> | | wsrep_provider_version | 25.3.19(r3667) | | wsrep_ready | ON | | wsrep_received | 10 | | wsrep_received_bytes | 806 | | wsrep_repl_data_bytes | 1044 | | wsrep_repl_keys | 3 | | wsrep_repl_keys_bytes | 93 | | wsrep_repl_other_bytes | 0 | | wsrep_replicated | 3 | | wsrep_replicated_bytes | 1329 | | wsrep_thread_count | 9 | +------------------------------+-------------------------------------------------------------+ 58 rows in set (0.00 sec)
注释:
wsrep_cluster_status为Primary,表示节点为主节点,正常读写。
wsrep_ready为ON,表示集群正常运行。
wsrep_cluster_size为3,表示集群有三个节点。
创建数据库测试
192.168.1.104节点: [root@mariadb-a03 my.cnf.d]# MysqL -uroot –pxxxxxx MariaDB [(none)]> create databasetest_db; Query OK,1 row affected (0.01 sec)
192.168.1.105节点查看: [root@mariadb-a04 my.cnf.d]# MysqL -uroot -pxxxxxx MariaDB [(none)]> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | MysqL | | performance_schema | | test_db | +--------------------+
192.168.1.106节点查看: [root@mariadb-a05 my.cnf.d]# MysqL -uroot -pxxxxxx MariaDB [(none)]> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | MysqL | | performance_schema | | test_db | +--------------------+ 4 rows in set (0.00 sec)
可以看到集群正常使用。
创建MyISAM表测试
[root@mariadb-a03 my.cnf.d]# MysqL -uroot –pxxxxxx MariaDB [(none)]> use test_db; Database changed MariaDB [test_db]> create table myisam_tbl (id int,name text) ENGINE MyISAM; Query OK,0 rows affected (0.01 sec) MariaDB [test_db]> insert into myisam_tbl values(1,'hive'); Query OK,1 row affected (0.00 sec) MariaDB [test_db]> insert into myisam_tbl values(2,'hbase'); Query OK,1 row affected (0.00 sec)
其他节点查看:
[root@mariadb-a04 my.cnf.d]# MysqL -uroot -pxxxxxx MariaDB [(none)]> use test_db; 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 MariaDB [test_db]> select * from myisam_tbl; Empty set (0.00 sec) [root@mariadb-a05 my.cnf.d]# MysqL -uroot –pxxxxxx MariaDB [(none)]> use test_db; 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 MariaDB [test_db]> select * from myisam_tbl; Empty set (0.00 sec)
可以看到MyISAM存储的表,galera不支持同步。它仅支持XTradB/ InnoDB存储引擎(虽然有对MyISAM实验支持,具体看wsrep_replicate_myisam系统变量)。
验证InnoDB存储的表
[root@mariadb-a03 my.cnf.d]# MysqL -uroot –pxxxxxx MariaDB [test_db]> create table innodb_tbl(id int,name text) ENGINE InnoDB; Query OK,0 rows affected (0.04 sec) MariaDB [test_db]> insert into innodb_tbl values(1,1 row affected (0.00 sec) MariaDB [test_db]> insert into innodb_tbl values(2,1 row affected (0.00 sec) MariaDB [test_db]>
其他节点查看:
[root@mariadb-a04 my.cnf.d]# MysqL -uroot -pxxxxxx MariaDB [(none)]> use test_db; Reading table information for completion oftable and column names You can turn off this feature to get aquicker startup with -A Database changed MariaDB [test_db]> select * from innodb_tbl; +------+-------+ | id | name | +------+-------+ | 1 | hive | | 2 | hbase | +------+-------+ 2 rows in set (0.00 sec) [root@mariadb-a05 my.cnf.d]# MysqL -uroot –pxxxxxx MariaDB [(none)]> use test_db; 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 MariaDB [test_db]> select * from innodb_tbl; +------+-------+ | id | name | +------+-------+ | 1 | hive | | 2 | hbase | +------+-------+ 2 rows in set (0.00 sec)
模拟节点故障
将192.168.1.104数据库停止掉:
[root@mariadb-a03 system]# MysqLadmin -uroot -p "shutdown"
然后在其他节点192.168.1.105执行:
MariaDB [test_db]> show global status like 'wsrep%'; +------------------------------+-----------------------------------------------+ | Variable_name | Value | +------------------------------+-----------------------------------------------+ | wsrep_apply_oooe | 0.000000 | | wsrep_apply_oool | 0.000000 | | wsrep_apply_window | 1.000000 | | wsrep_causal_reads | 26 | | wsrep_cert_deps_distance | 1.142857 | | wsrep_cert_index_size |6 | | wsrep_cert_interval | 0.000000 | | wsrep_cluster_conf_id | 6 | | wsrep_cluster_size | 2 | | wsrep_cluster_state_uuid |3108c722-ff29-11e6-a31f-bb500598d033 | | wsrep_cluster_status | Primary | | wsrep_commit_oooe | 0.000000 | | wsrep_commit_oool | 0.000000 | | wsrep_commit_window | 1.000000 | | wsrep_connected | ON | | wsrep_desync_count | 0 | | wsrep_evs_delayed | | | wsrep_evs_evict_list | | | wsrep_evs_repl_latency |0.000403989/0.000656768/0.0012094/0.0003239/4 | | wsrep_evs_state | OPERATIONAL | | wsrep_flow_control_paused | 0.000000 | | wsrep_flow_control_paused_ns | 0 | | wsrep_flow_control_recv | 0 | | wsrep_flow_control_sent | 0 | | wsrep_gcomm_uuid | 0ce8537e-ff2a-11e6-b037-8a383b6a8db5 | | wsrep_incoming_addresses | 192.168.1.105:3306,192.168.1.106:3306 | | wsrep_last_committed | 10 | | wsrep_local_bf_aborts | 0 | | wsrep_local_cached_downto | 4 | | wsrep_local_cert_failures | 0 | | wsrep_local_commits | 0 | | wsrep_local_index | 0 | | wsrep_local_recv_queue | 0 | | wsrep_local_recv_queue_avg | 0.000000 | | wsrep_local_recv_queue_max | 1 | | wsrep_local_recv_queue_min | 0 | | wsrep_local_replays | 0 | | wsrep_local_send_queue | 0 | | wsrep_local_send_queue_avg | 0.000000 | | wsrep_local_send_queue_max | 1 | | wsrep_local_send_queue_min | 0 | | wsrep_local_state | 4 | | wsrep_local_state_comment | Synced | | wsrep_local_state_uuid |3108c722-ff29-11e6-a31f-bb500598d033 | | wsrep_protocol_version | 7 | | wsrep_provider_name | galera | | wsrep_provider_vendor | Codership Oy<info@codership.com> | | wsrep_provider_version | 25.3.19(r3667) | | wsrep_ready | ON | | wsrep_received | 14 | | wsrep_received_bytes | 3908 | | wsrep_repl_data_bytes | 0 | | wsrep_repl_keys | 0 | | wsrep_repl_keys_bytes | 0 | | wsrep_repl_other_bytes | 0 | | wsrep_replicated | 0 | | wsrep_replicated_bytes | 0 | | wsrep_thread_count | 9 | +------------------------------+-----------------------------------------------+
此时集群为自动将192.168.1.104故障节点剔除掉,并且正常提供服务。
最后我们恢复失败的节点:
[root@mariadb-a03 system]# MysqLd_safe --defaults-file=/etc/my.cnf.d/server.cnf --user=MysqL &
再次查看集群环境:
MariaDB [test_db]> SHOW STATUS LIKE 'wsrep_cluster_size'; +--------------------+-------+ | Variable_name | Value | +--------------------+-------+ | wsrep_cluster_size | 3 | +--------------------+-------+ 1 row in set (0.00 sec
模拟脑裂后的处理
下面模拟在网络抖动发生丢包的情况下,两个节点失联导致脑裂。首先,在192.168.1.105和192.168.1.106两个节点上分别执行:
iptables -A INPUT -p tcp --sport 4567 -j DROP
iptables -A INPUT -p tcp --dport 4567 -j DROP
以上命令用来禁止wsrep全同步复制4567端口通信。
然后我们在192.168.1.104节点查看:
MariaDB [(none)]> show global statuslike 'ws%'; 可以看到下面的几个值: wsrep_cluster_size 1 wsrep_cluster_status non-Primary wsrep_ready OFF MariaDB [(none)]> use test_db; ERROR 1047 (08S01): WSREP has not yetprepared node for application use MariaDB [(none)]> select@@wsrep_node_name; ERROR 1205 (HY000): Lock wait timeoutexceeded; try restarting transaction
现在已经出现脑裂的情况,并且集群无法执行任何命令。
为了解决这个问题,可以执行:
set global wsrep_provider_options="pc.bootstrap=true";
通过这个命令来强制恢复出现脑裂的节点。
下面我们来验证一下:
MariaDB [(none)]> select @@wsrep_node_name; ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transaction MariaDB [(none)]> set global wsrep_provider_options="pc.bootstrap=true"; Query OK,0 rows affected (0.00 sec) MariaDB [(none)]> select @@wsrep_node_name; +-------------------+ | @@wsrep_node_name | +-------------------+ | mariadb-a03 | +-------------------+ 1 row in set (0.27 sec) MariaDB [(none)]> use test_db; Reading table information for completion oft able and column names You can turn off this feature to get a quicker startup with -A Database changed MariaDB [test_db]> show tables; +-------------------+ | Tables_in_test_db | +-------------------+ | innodb_tbl | | myisam_tbl | +-------------------+
最后我们将节点192.168.1.105和192.168.1.106恢复一下,只要清理一下iptables表即可(因为我的是测试环境,生产环境需要删除上面的规则即可):
iptables –F
各个节点验证一下:
192.168.1.104: MariaDB [test_db]> SHOW STATUS LIKE 'wsrep_cluster_size'; +--------------------+-------+ | Variable_name | Value | +--------------------+-------+ | wsrep_cluster_size | 3 | +--------------------+-------+ 1 row in set (0.00 sec) 192.168.1.105: MariaDB [(none)]> select @@wsrep_node_name; +-------------------+ | @@wsrep_node_name | +-------------------+ | mariadb-a04 | +-------------------+
避免脏读
galera Cluster不是真正意义上的全同步复制,存在延迟。我们可以在一个节点上面执行FLUSH TABLES WITH READ LOCK;全局读锁。
然后在其他节点执行写操作,观察延迟情况。
比如我们在192.168.1.106节点执行全局读锁设置:
MariaDB [test_db]> flush tables with read lock; Query OK,0 rows affected (0.00 sec) MariaDB [test_db]> select * from innodb_tbl; +------+------+ | id | name | +------+------+ | 1 | hive | +------+------+ 1 row in set (0.00 sec) 然后在192.168.1.104节点插入操作: MariaDB [test_db]> select @@wsrep_node_name; +-------------------+ | @@wsrep_node_name | +-------------------+ | mariadb-a03 | +-------------------+ 1 row in set (0.00 sec) MariaDB [test_db]> insert into innodb_tbl values(2,1 row affected (0.00 sec) MariaDB [test_db]> select * from innodb_tbl; +------+-------+ | id | name | +------+-------+ | 1 | hive | | 2 | hbase | +------+-------+ 2 rows in set (0.00 sec) 在节点192.168.1.106上测试查询操作: MariaDB [test_db]> select * from innodb_tbl; ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transaction
这里之所以没有读取到脏数据,是因为我在MariaDB配置文件中设置了wsrep_causal_reads=ON;
我们将wsrep_causal_reads修改为0或OFF来看一下效果:
MariaDB [test_db]> set wsrep_causal_reads=0; Query OK,0 rows affected,1 warning (0.00sec) MariaDB [test_db]> select * from innodb_tbl; +------+------+ | id | name | +------+------+ | 1 | hive | +------+------+ 1 row in set (0.00 sec) MariaDB [test_db]>
总结
通过上面的一系列测试,最后总结一下:
1. 在生产环境下应该避免使用大事务,不建议在高并发写入场景下使用galera Cluster架构,会导致集群限流,从而引起整个集群hang住,出现生产故障。针对这种情况可以考虑主从,实现读写分离等手段。
2. 对数据一致性要求较高,并且数据写入不频繁,数据库容量也不大(50GB左右),网络状况良好的情况下,可以考虑使用galera方案
CentOS 7下安装MySQL与mariadb冲突的解决办法
首先centos7 已经不支持mysql,因为收费了你懂得,所以内部集成了mariadb,而安装mysql的话会和mariadb的文件冲突,所以需要先卸载掉mariadb,以下为卸载mariadb,安装mysql的步骤。
#列出所有被安装的rpm package
rpm -qa | grep mariadb
#卸载
rpm -e mariadb-libs-5.5.37-1.el7_0.x86_64
错误:依赖检测失败:
libmysqlclient.so.18()(64bit) 被 (已安裝) postfix-2:2.10.1-6.el7.x86_64 需要
libmysqlclient.so.18(libmysqlclient_18)(64bit) 被 (已安裝) postfix-2:2.10.1-6.el7.x86_64 需要
#强制卸载,因为没有--nodeps
rpm -e --nodeps mariadb-libs-5.5.37-1.el7_0.x86_64
#安装mysql依赖
yum install vim libaio net-tools
#安装mysql5.5.39的rpm包
rpm -ivh /home/liwei/MySQL-server-5.5.39-2.el6.x86_64.rpm
rpm -ivh /home/liwei/MySQL-client-5.5.39-2.el6.x86_64.rpm
#拷贝配置文件
cp /usr/share/mysql/my-medium.cnf /etc/my.cnf,改名为my.cnf作为mysql配置文件。
#修改响应的配置文件
vim /etc/my.cnf
#把mysql的data拷贝到制定的目录
mv /var/lib/mysql /home/mysql/data/
还要注意目录的属主和权限。
MYSQL启动后报:ERROR! The server quit without updating PID file错误的问题解决
MYSQL日志:Can''t find file: ''./mysql/plugin.frm'' (errno: 13 - Permission denied)
1、权限不够:chown -R mysql:mysql /home/mysql/data” “chmod -R 755 /home/mysql/data
2、centos7的selinux问题:打开/etc/selinux/config,把SELINUX=enforcing改为SELINUX=disabled后存盘退出重启机器。
下面看下其他网友的补充:
1、centos下yum暂时没有mysql-server直接安装包;
MariaDB是MySQL社区开发的分支,也是一个增强型的替代品;
2、安装MariaDB
yum -y install mariadb-server mariadb mariadb-devel
systemctl start mariadb
systemctl enable mariadb
mysql_secure_installation
firewall-cmd --permanent --add-service mysql
systemctl restart firewalld.service
iptables -L -n|grep 3306
3、登录数据库查看下是否有变好
msyql -uroot -p
show databases;
centos7 Mariadb5.5 升级到 Mariadb10.2
<div id="cnblogs_post_body"><p> </p> <p><strong><span> 一次升级过程,在此记录下。</span></strong></p> <p><span> 原因:新的项目需要新的数据库版本支持。</span></p> <p><span> 升级主要步骤:</span></p> <p><span><span> 备份原数据库 </span> ---<span>》卸载 </span><span>mariadb ---</span><span>》添加 </span><span>mariadb</span><span> 国内 </span><span>yum</span><span> 源 </span><span>---</span><span>》安装 </span><span>mariadb---</span><span>》初始化数据库 </span><span>---</span><span>》导入数据。</span></span></p> <p><span><strong>1. 备份原数据库 </strong></span></p> <p><span><strong> 由于是对测试环境的数据库进行升级,数据量不多,我直接导出需要迁移的数据库的数据到 sql 文件里。</strong></span></p> <div> <pre><span>mysqldump -uroot -p --database database_name >name.sql</span></pre> </div> <p><span><strong>2. <span> 卸载 < span>mariadb</span></span></strong></span></p> <p><span><strong><span><span> 由于是在同一台服务器进行安装新的 Mariadb10.2,所以我们需要将老的版本卸载。</span></span></strong></span></p> <p><span><span> 卸载 </span>mariadb<span>:</span> </span></p> <div> <pre><span><span>yum</span> remove mariadb</span></pre> </div> <p><span> 删除配置文件:</span></p> <div> <pre><span><span>rm</span> -f /etc/my.cnf</span></pre> </div> <p><span><span> 删除数据目录 </span>:</span></p> <div> <pre><span><span>rm</span> -rf /var/lib/mysql/</span></pre> </div> <p><span><strong>3. <span> 添加 </span>mariadb10.2<span> 的国内 </span><span>yum</span><span> 源 </span></strong></span></p> <p><span><span> 之前我添加的是国外的源,安装很耗时,所以我找到 < span><strong > 国内 </strong></span></span><span><strong>yum</strong></span><span><span><strong > 源 </strong></span>,通过这个源安装较快。</span></span></p> <div> <pre><span>vim /etc/<span>yum</span>.repos.d/Mariadb.repo</span></pre> </div> <p><span> 添加以下内容:</span></p> <div> <pre><span><span>[mariadb] name </span>=<span> MariaDB baseurl </span>= https:<span>//</span><span>mirrors.ustc.edu.cn/mariadb/yum/10.2/centos7-amd64</span> gpgkey=https:<span>//</span><span>mirrors.ustc.edu.cn/mariadb/yum/RPM-GPG-KEY-MariaDB</span> gpgcheck=<span>1</span></span></pre> </div> <p><span> 清除 yum 源缓存数据 </span></p> <div> <pre><span><span>yum</span> clean all</span></pre> </div> <p><span> 生成新的 yum 源数据缓存 </span></p> <div> <pre><span><span>yum</span> makecache all</span></pre> </div> <p><span><strong > 官方 yum 源(国内安装较慢)</strong></span></p> <div> <div><div id="highlighter_885383"><div><span><a href="#">?</a></span></div><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td><div>1</div><div>2</div><div>3</div><div>4</div><div>5</div><div>6</div><div>7</div></td><td><div><div><code># MariaDB 10.2 CentOS repository list - created 2018-06-06 03:42 UTC</code></div><div><code># http://downloads.mariadb.org/mariadb/repositories/</code></div><div><code>[mariadb]</code></div><div><code>name = MariaDB</code></div><div><code>baseurl = http:</code><code>//yum</code><code>.mariadb.org</code><code>/10</code><code>.2</code><code>/centos7-amd64</code></div><div><code>gpgkey=https:</code><code>//yum</code><code>.mariadb.org</code><code>/RPM-GPG-KEY-MariaDB</code></div><div><code>gpgcheck=1</code></div></div></td></tr></tbody></table></div></div> </div> <p><span><strong > 官方不同系统 yum 源网址:https://downloads.mariadb.org/mariadb/repositories/#mirror=tuna</strong></span></p> <p><span><strong>4. 安装 mariadb10.2</strong></span></p> <div> <pre><span><span>yum</span> <span>install</span> MariaDB-server MariaDB-client -y</span></pre> </div> <p><span> 启动并添加开机自启:</span></p> <div> <pre><span>systemctl start mariadb.service systemctl enable mariadb.service</span></pre> </div> <p><span><strong>5. mariadb 的初始化 </strong></span></p> <div> <pre><span>/usr/bin/mysql_secure_installation</span></pre> </div> <p><span> 一般建议按以下进行配置:</span></p> <div><div><span><a href="javascript:void (0);" onclick="copyCnblogsCode (this)" title="复制代码"><img src="//common.cnblogs.com/images/copycode.gif" alt="复制代码"></a></span></div> <pre><span>Enter current password <span>for</span> root (enter <span>for</span><span> none): Just press the Enter button Set root password</span>? [Y/<span>n]: <span>Y</span> New password: <span>your</span></span><span>-MariaDB-root-</span><span><span>password</span> Re</span>-enter new password: <span>your-MariaDB-root-</span><span><span>password</span> Remove anonymous users</span>? [Y/<span>n]: <span>Y</span> Disallow root </span><span>login</span> remotely? [Y/<span>n]: <span>n</span> Remove test database and access to it</span>? [Y/<span>n]: <span>Y</span> Reload privilege tables now</span>? [Y/n]: <span>Y</span></span></pre> <div><span><a href="javascript:void (0);" onclick="copyCnblogsCode (this)" title="复制代码"><img src="//common.cnblogs.com/images/copycode.gif" alt="复制代码"></a></span></div></div> <p><span><strong>6. 导入数据到新版本 mariadb</strong></span></p> <p><span><strong > 方法一:</strong></span></p> <p><span><strong > 登陆 mysql 后用 source 命令:(后面跟的是我们备份的 sql 文件的路径)</strong></span></p> <div> <pre><span>source /root/backup/java_api.sql</span></pre> </div> <p><span><strong > 方法二:</strong> </span></p> <p><span><strong > 在命令行直接导入 </strong></span></p> <div> <pre><span>mysql -uroot -p >/root/backup/java_api.sql</span></pre> </div> <p><span> 以上就是整个版本升级的过程了。</span></p></div>
今天关于为什么与MariaDB 10.2 RAND和函数发生如此多的冲突?的分享就到这里,希望大家有所收获,若想了解更多关于c – 为什么这个非常简单的Makefile产生如此多的调试日志记录?、CentOS 7.2部署MariaDB Galera Cluster(10.1.21-MariaDB) 3主集群环境、CentOS 7下安装MySQL与mariadb冲突的解决办法、centos7 Mariadb5.5 升级到 Mariadb10.2等相关知识,可以在本站进行查询。
本文标签: