环境:
id | ip | 功能 | 操作系统 |
1 | 10.0.0.248 | 管理节点+数据节点 | ubuntu-18.04 |
2 | 10.0.0.128 | 数据节点+SQL节点 | ubuntu-18.04 |
集群版本:mysql-cluster-gpl-7.4.11-linux-glibc2.5-x86_64
下载位置:https://dev.mysql.com/downloads/cluster/
一号坑:注意你的机器是arm还是amd,这个包是x86,也就是amd的,我用的华为云鲲鹏处理器,结果它是继承的arm架构,结果根本没法用。我没有找到支持arm版本ubuntu18.04系统的cluster安装文件,所以把虚拟机换成了x86.
然后详细配置过程我就不写了,网上还挺多的,我参考的是下面这两个:
参考链接2:http://t.zoukankan.com/lianshuiwuyi-p-9181811.html
按照上面的流程走会有一些他们没提到的的问题,如下:
二号坑:https://zhuanlan.zhihu.com/p/302309647
不知道mysql cluster其他的版本怎么样,这个版本的确实会有上面这个帖子里的问题,第一次sql节点启动失败,它会一直占用着管理节点的端口,后面的连接怎么样也不可能连上。
![](https://img-blog.csdnimg.cn/img_convert/12b71a0c8128f690419c7b8b42d7e156.png)
![](https://img-blog.csdnimg.cn/img_convert/4a70a8f665d57a4406f74ecd116f87c5.png)
这个帖子写的是mysql连接,不知道和cluster是不是一个原理,但事实证明第一次产生的失败连接确实将后面的连接都阻塞了。帖子里的解决方法是设置等待时间,到时间后自动dang掉,我就不这么麻烦了,也不经常用,我就把服务都关掉,然后重启了一下,把所有可能的阻塞的连接都关掉,然后顺序启动,启动顺序如三号坑所述。
3号坑:集群启动顺序是管理节点->所有数据节点->SQL节点
https://blog.csdn.net/weixin_31591833/article/details/114340391
这个问题好多帖子都有提到,上面这个帖子最下面,博主把所有数据节点启动后,他的SQL节点自动启动了。我也是这样,根本没有执行 mysqld_safe的命令,所以一定要先把所有数据节点都启动起来。我就是只开了一个数据节点就去开SQL节点了,导致踩了上面的2号坑,卡了半天。
小号坑:
这里记一些乱七八糟的小坑
4号小坑:本来在数据节点上配置好my.cnf后,运行"ndbd"命令应该能直接连上管理节点,但是我确实连不上,解决方法是用命令:
ndbd --connect-string=123.45.6.78(管理节点ip)
就是告诉它管理节点的ip。
5号小坑:这个版本的mysqld是没有--initial命令的,不要执行不要执行!!执行了可能就会导致上面的二号坑,造成阻塞,万一不小心执行了,建议先关掉所有节点的cluster服务,然后重启一下,再说别的。
mysqld这个命令有两个功能(上连下开):
连接集群中的管理节点;
开启mysql服务,让用户可以接入集群;
那还有一个mysqld_safe命令的作用是什么呢?它就是一个mysqld的一种安全启动方式,是mysqld的守护进程,mysqld意外结束后,mysqld_safe可以再启动起来。两个命令的用法差不多,用他们任意一个连接管理节点都可以,不过它建议用mysqld_safe。
#这是mysqld和mysqld_safe的常见用法,两个命令很多option都是一样的
mysqld_safe --user=root --defaults-file=/user/local/mysql/my.cnf --ndb-connectstring=123.45.6.78 --ndb-nodeid=2;
mysqld --user=root --defaults-file=/user/local/mysql/my.cnf --ndb-connectstring=123.45.6.78 --ndb-nodeid=2;
#可以用下面的命令查看帮助
mysqld --verbose --help
不过根据上面3号坑的意思,如果一切顺利的话,根本不用运行这两个命令就可以连接成功。
另外不建议用mysql/support-files下面的mysql.server来启动SQL节点,很慢,它的作用和mysqld是一样的,停止SQL节点也不要用mysql.server stop,用ps -A 查看所有进程,找到mysqld和mysqld_safe两个进程的pid,然后kill -9 pid就ok了。
再有就是如果mysql_safe程序运行正确的话,程序会一直挂着,不要等它执行结束,直接再开一个命令行窗口就行了,可以查看/var/log/mysql.log文件
2023-01-06 14:47:38 1404 [Note] /usr/local/mysql/bin/mysqld: ready for connections.
Version: '5.6.29-ndb-7.4.11-cluster-gpl' socket: '/usr/local/mysql/sock/mysql.sock' port: 3306 MySQL Cluster Community Server (GPL)
如果日志文件显示执行到这里,说明本机的mysql服务已经开启了,但是不一定连接到管理节点上了。这个时候已经可以用mysql -u root -p -S /usr/local/mysql/sock/mysql.sock连接本地mysql服务了,但是连接到的服务仅支持本机数据存储,而不是集群数据存储,只有连接到管理节点上,才可以使用集群数据存储。
230106 14:47:06 mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data
2023-01-06 14:47:06 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2023-01-06 14:47:06 0 [Note] /usr/local/mysql/bin/mysqld (mysqld 5.6.29-ndb-7.4.11-cluster-gpl) starting as process 1404 ...
2023-01-06 14:47:06 1404 [Note] Plugin 'FEDERATED' is disabled.
2023-01-06 14:47:06 1404 [Note] InnoDB: Using atomics to ref count buffer pool pages
2023-01-06 14:47:06 1404 [Note] InnoDB: The InnoDB memory heap is disabled
2023-01-06 14:47:06 1404 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2023-01-06 14:47:06 1404 [Note] InnoDB: Memory barrier is not used
2023-01-06 14:47:06 1404 [Note] InnoDB: Compressed tables use zlib 1.2.3
2023-01-06 14:47:06 1404 [Note] InnoDB: Using Linux native AIO
2023-01-06 14:47:06 1404 [Note] InnoDB: Using CPU crc32 instructions
2023-01-06 14:47:06 1404 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2023-01-06 14:47:06 1404 [Note] InnoDB: Completed initialization of buffer pool
2023-01-06 14:47:06 1404 [Note] InnoDB: Highest supported file format is Barracuda.
2023-01-06 14:47:06 1404 [Note] InnoDB: The log sequence numbers 1626343 and 1626343 in ibdata files do not match the log sequence number 1626413 in the ib_logfiles!
2023-01-06 14:47:06 1404 [Note] InnoDB: Database was not shutdown normally!
2023-01-06 14:47:06 1404 [Note] InnoDB: Starting crash recovery.
2023-01-06 14:47:06 1404 [Note] InnoDB: Reading tablespace information from the .ibd files...
2023-01-06 14:47:06 1404 [Note] InnoDB: Restoring possible half-written data pages
2023-01-06 14:47:06 1404 [Note] InnoDB: from the doublewrite buffer...
2023-01-06 14:47:07 1404 [Note] InnoDB: 128 rollback segment(s) are active.
2023-01-06 14:47:07 1404 [Note] InnoDB: Waiting for purge to start
2023-01-06 14:47:07 1404 [Note] InnoDB: 5.6.29 started; log sequence number 1626413
2023-01-06 14:47:07 1404 [Note] NDB: Changed global value of binlog_format from STATEMENT to MIXED
2023-01-06 14:47:38 1404 [Warning] NDB: server id set to zero - changes logged to bin log with server id zero will be logged with another server id by slave mysqlds
2023-01-06 14:47:38 1404 [Note] NDB Binlog: Starting...
2023-01-06 14:47:38 1404 [Note] NDB Util: Starting...
2023-01-06 14:47:38 1404 [Note] NDB Util: Wait for server start completed
2023-01-06 14:47:38 1404 [Note] NDB Binlog: Started
2023-01-06 14:47:38 1404 [Note] NDB Binlog: Setting up
2023-01-06 14:47:38 1404 [Note] NDB Index Stat: Starting...
2023-01-06 14:47:38 1404 [Note] NDB Index Stat: Wait for server start completed
2023-01-06 14:47:38 1404 [Note] NDB Binlog: Started
2023-01-06 14:47:38 1404 [Note] NDB Binlog: Setting up
2023-01-06 14:47:38 1404 [Note] NDB Index Stat: Starting...
2023-01-06 14:47:38 1404 [Note] NDB Index Stat: Wait for server start completed
2023-01-06 14:47:38 1404 [Note] NDB Binlog: Created schema Ndb object, reference: 0x0, name: 'Ndb Binlog schema change monitoring'
2023-01-06 14:47:38 1404 [Note] NDB Binlog: Created injector Ndb object, reference: 0x0, name: 'Ndb Binlog data change monitoring'
2023-01-06 14:47:38 1404 [Note] NDB Binlog: Setup completed
2023-01-06 14:47:38 1404 [Note] NDB Binlog: Wait for server start completed
2023-01-06 14:47:38 1404 [Note] Server hostname (bind-address): '*'; port: 3306
2023-01-06 14:47:38 1404 [Note] IPv6 is available.
2023-01-06 14:47:38 1404 [Note] - '::' resolves to '::';
2023-01-06 14:47:38 1404 [Note] Server socket created on IP: '::'.
2023-01-06 14:47:38 1404 [Note] Event Scheduler: Loaded 0 events
2023-01-06 14:47:38 1404 [Note] /usr/local/mysql/bin/mysqld: ready for connections.
Version: '5.6.29-ndb-7.4.11-cluster-gpl' socket: '/usr/local/mysql/sock/mysql.sock' port: 3306 MySQL Cluster Community Server (GPL)
2023-01-06 14:47:38 1404 [Note] NDB Binlog: Check for incidents
2023-01-06 14:47:38 1404 [Note] NDB Util: Wait for cluster to start
2023-01-06 14:47:38 1404 [Note] NDB Binlog: Wait for cluster to start
2023-01-06 14:47:38 1404 [Note] NDB Index Stat: Wait for cluster to start
2023-01-06 14:48:08 1404 [Warning] NDB : Tables not available after 30 seconds. Consider increasing --ndb-wait-setup value
2023-01-06 14:48:08 1404 [Warning] IP address '61.142.103.97' could not be resolved: Name or service not known
2023-01-06 14:57:04 1404 [Note] NDB: NodeID is 4, management server '10.0.0.248:1186'
2023-01-06 14:57:04 1404 [Note] NDB Util: Started
2023-01-06 14:57:04 1404 [Note] NDB Index Stat: Started
2023-01-06 14:57:04 1404 [Note] created index stats Ndb object: reference 0x80070004, name: 'Ndb Index Statistics monitoring'
2023-01-06 14:57:05 1404 [Note] NDB: Creating mysql.ndb_schema
2023-01-06 14:57:05 1404 [Note] NDB Binlog: CREATE TABLE Event: REPL$mysql/ndb_schema
2023-01-06 14:57:05 1404 [Note] NDB Binlog: logging ./mysql/ndb_schema (UPDATED,USE_WRITE)
2023-01-06 14:57:05 1404 [Note] NDB: Creating mysql.ndb_apply_status
2023-01-06 14:57:05 1404 [Note] NDB Binlog: CREATE TABLE Event: REPL$mysql/ndb_apply_status
2023-01-06 14:57:05 1404 [Note] NDB Binlog: logging ./mysql/ndb_apply_status (UPDATED,USE_WRITE)
2023-01-06 14:57:05 1404 [Note] NDB: Cleaning stray tables from database 'ndb_2_fs'
2023-01-06 14:57:05 1404 [Note] NDB: Cleaning stray tables from database 'ndbinfo'
2023-01-06 14:57:05 1404 [Note] NDB: Cleaning stray tables from database 'performance_schema'
2023-01-06 14:57:05 1404 [Note] NDB: Cleaning stray tables from database 'test'
2023-01-06 14:57:05 1404 [Note] NDB: missing frm for mysql.ndb_index_stat_sample, discovering...
2023-01-06 14:57:05 1404 [Note] NDB: missing frm for mysql.ndb_index_stat_head, discovering...
2023-01-06 14:57:05 1404 [Note] NDB Binlog: Wait for first event
2023-01-06 14:57:05 [NdbApi] INFO -- Flushing incomplete GCI:s < 4/20
2023-01-06 14:57:05 [NdbApi] INFO -- Flushing incomplete GCI:s < 4/20
2023-01-06 14:57:05 1404 [Note] NDB Binlog: starting log at epoch 4/20
2023-01-06 14:57:05 1404 [Note] NDB Binlog: Got first event
2023-01-06 14:57:05 1404 [Note] NDB Binlog: ndb tables writable
2023-01-06 14:57:05 1404 [Note] NDB Binlog: Startup and setup completed
这是SQL节点上正确启动的完整日志记录。
下面贴上每个节点的配置文件
#2号节点-my.cnf
[client]
socket=/usr/local/mysql/sock/mysql.sock
[mysqld]
ndbcluster
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
socket=/usr/local/mysql/sock/mysql.sock
ndb-connectstring=10.0.0.248
user=root
symbolic-links=0
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
[mysql_cluster]
ndb-connectstring=10.0.0.248
[NDB_MGM]
Connect-string=10.0.0.248
default-storage-engine=ndbcluster
#1号节点-config.ini
[ndbd default]
NoOfReplicas=1
DataMemory=80M
IndexMemory=18M
[ndb_mgmd]
NodeID=1
hostname=10.0.0.248
datadir=/usr/local/mysql/data
[ndbd]
NodeID=2
hostname=10.0.0.128
datadir=/usr/local/mysql/data
[ndbd]
NodeID=3
hostname=10.0.0.248
datadir=/usr/local/mysql/data
[mysqld]
NodeId=4
hostname=10.0.0.128
#1号节点-my.cnf
[mysqld]
ndbcluster
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
socket=/usr/local/mysql/sock/mysql.sock
symbolic-links=0
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
[mysql_cluster]
ndb-connectstring=10.0.0.248
default-storage-engine=ndbcluster
在部署过程中还遇到了很多其它问题,不想回忆了,欢迎评论区交流。