知道相关概念后,实际上手搭建一把。因为现在有Docker
这个工具,吃螃蟹现在也方便多了,感谢无私的程序员,下面是基于Docker
+docker-compose
这两个工具搭建的环境
部署运行
管理节点
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
mysql-ndb-mgm:
image: mysql/mysql-cluster:8.0
container_name: mysql-ndb-mgm
hostname: mgm
net: host
restart: always
environment:
- TZ=Asia/Shanghai
volumes:
- ./hosts:/etc/hosts
- ./mgm_data:/var/lib/mysql
- ./mysql-cluster.cnf:/etc/mysql-cluster.cnf
- ./my.cnf:/etc/my.cnf
command:
ndb_mgmd --ndb-nodeid=1 --initial
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
[tcp default]
SendBufferMemory=2M
ReceiveBufferMemory=2M
[ndbd default]
NoOfReplicas=2
LockPagesInMainMemory=1
DataMemory=3456M
NoOfFragmentLogFiles=300
MaxNoOfConcurrentOperations=100000
SchedulerSpinTimer=400
SchedulerExecutionTimer=100
RealTimeScheduler=1
TimeBetweenGlobalCheckpoints=1000
TimeBetweenEpochs=200
RedoBuffer=32M
MaxNoOfTables=1024
MaxNoOfOrderedIndexes=256
Datadir=/var/lib/mysql
[ndb_mgmd]
NodeId=1
Hostname=mgm
Datadir=/var/lib/mysql
[ndbd]
NodeId=2
Hostname=128.0.100.174
LockExecuteThreadToCPU=1
LockMaintThreadsToCPU=0
[ndbd]
NodeId=3
Hostname=ndb1
LockExecuteThreadToCPU=1
LockMaintThreadsToCPU=0
[mysqld]
NodeId=4
Hostname=mysql1
|
my.cnf
1
2
3
4
5
6
7
8
9
10
11
12
|
[mysqld]
ndbcluster
ndb-use-exact-count=0
ndb-index-stat-enable=0
ndb-force-send=1
optimizer-switch=engine_condition_pushdown=on
ndb-connectstring=mgm
user=mysql
[mysql_cluster]
ndb-connectstring=mgm
|
数据节点
1
2
3
4
5
6
7
8
9
10
11
12
13
|
mysql-ndb-mgm:
image: mysql/mysql-cluster:8.0
container_name: mysql-ndb-ndbd
net: host
restart: always
environment:
- TZ=Asia/Shanghai
volumes:
- ./ndbd_data:/var/lib/mysql
- ./my.cnf:/etc/my.cnf
- ./hosts:/etc/hosts
command:
ndbd --ndb-nodeid=2
|
SQL
节点
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
mysql-ndb-mysql:
image: mysql/mysql-cluster:8.0
container_name: mysql-ndb-mysql
net: host
restart: always
environment:
- TZ=Asia/Shanghai
- MYSQL_ROOT_PASSWORD=1234qwer
volumes:
- ./hosts:/etc/hosts
- ./mysql_data:/var/lib/mysql
- ./my.cnf:/etc/my.cnf
command:
mysqld --ndb-nodeid=4
|
将相关容器启动起来就可以了。启动顺序为管理节点—>数据节点—>MySQL
节点
后续操作
-
创建SQL
用户
1
2
3
|
CREATE USER admin@'%' IDENTIFIED WITH mysql_native_password BY 'admin';
GRANT ALL PRIVILEGES ON *.* TO 'admin'@'%';
FLUSH PRIVILEGES;
|
-
查看分区情况
1
2
3
4
5
6
7
|
SELECT
partition_name part,
partition_expression expr,
partition_description descr,
table_rows
FROM information_schema.partitions
WHERE table_schema = schema() AND table_name='test';
|
增加节点
增加SQL
节点很简单。
第一步 要修改管理节点的mysql-cluster.conf
文件
第二步 是要重启数据节点,所有的数据节点都要重启
第三步 启动新的MySQL
节点即可。新节点会连接至集群,同步数据至本地