ubuntu 搭建mysql cluster

開(kāi)始前介紹

docker ubuntu 版本:latest (20.04)
mysql-cluster 版本 :mysql-cluster-8.0.28-linux-glibc2.12-x86_64.tar.gz
ubuntu 地址172.17.0.2(msg);172.17.0.3,172.17.0.4(node)
本次集群是通過(guò)docker 模擬搭建出來(lái)的蠢古。這里默認(rèn)系統(tǒng)已經(jīng)搭建好了docker
主要節(jié)點(diǎn)有cluster-msg,cluster-node-1,cluster-node2
三個(gè)服務(wù)。
將mysql-cluster 上傳到服務(wù)器里路徑:/usr/local/

開(kāi)始前準(zhǔn)備

準(zhǔn)備 config.ini (msg 管理需要)

mkdir -p /usr/local/mysql-cluster/msg
vim /usr/local/mysql-cluster/msg/config.ini
#將一下配置拷進(jìn)去
[NDBD DEFAULT]
NoOfReplicas =2
DataMemory = 512M
IndexMemory = 64M
[NDB_MGMD]
NodeId=1
hostname =172.17.0.2
datadir =/var/lib/mysql-cluster
[NDBD]
NodeId =2
hostname =172.17.0.4
datadir =/usr/local/mysql-cluster/data
[NDBD]
NodeId =3
hostname =172.17.0.3
datadir =/usr/local/mysql-cluster/data
[mysqld]
NodeId =4
hostname =172.17.0.4
[mysqld]
NodeId =5
hostname =172.17.0.3

準(zhǔn)備配置my.cnf (node 節(jié)點(diǎn)需要)

mkdir -p /usr/local/mysql-cluster/node
vim /usr/local/mysql-cluster/node/my.cnf
[mysqld]
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
socket=/usr/local/mysql/sock/mysql.sock
symbolic-links=0
ndbcluster
ndb-connectstring=172.17.0.2
[mysql_cluster]
ndb-connectstring=172.17.0.2
[mysqld_safe]
log-error=/usr/local/mysql/logs/mysql.pid
pid-file=/usr/local/mysql/logs/error.log
[mysql]
socket=/usr/local/mysql/sock/mysql.sock
開(kāi)始配置msg (172.17.0.2)
#解壓縮
tar vxf mysql-cluster-8.0.28-linux-glibc2.12-x86_64.tar.gz
#重命名
mv mysql-cluster-8.0.28-linux-glibc2.12-x86_64
mysql-cluster
#啟動(dòng)docker
docker run -it -d -v /usr/local/mysql-cluster/msg:/usr/local/mysql-cluster -v /usr/local/mysql:/usr/local/mysql --name mysql-cluster-msg ubuntu
#進(jìn)入 msg容器
docker exec -it mysql-cluster-msg /bin/bash
#確認(rèn)當(dāng)前容器得ip 是172.17.0.2
root@cdcb6a1a12bf:/usr/local/mysql-cluster# hostname -i  
172.17.0.2
cd /usr/local/mysql/bin
#確認(rèn) ndb_mgmd 文件在這里
root@cdcb6a1a12bf:/usr/local/mysql/bin# ls
ibd2sdi                    mysqladmin      ndb_desc               ndb_restore
innochecksum               mysqlbinlog     ndb_drop_index         ndb_select_all
lz4_decompress             mysqlcheck      ndb_drop_table         ndb_select_count
my_print_defaults          mysqld          ndb_error_reporter     ndb_show_tables
myisam_ftdump              mysqld-debug    ndb_import             ndb_size.pl
myisamchk                  mysqld_multi    ndb_index_stat         ndb_top
myisamlog                  mysqld_safe     ndb_mgm                ndb_waiter
myisampack                 mysqldump       ndb_mgmd               ndbd
mysql                      mysqldumpslow   ndb_move_data          ndbinfo_select_all
mysql_config               mysqlimport     ndb_perror             ndbmtd
mysql_config_editor        mysqlpump       ndb_print_backup_file  ndbxfrm
mysql_migrate_keyring      mysqlshow       ndb_print_file         perror
mysql_secure_installation  mysqlslap       ndb_print_frag_file    zlib_decompress
mysql_ssl_rsa_setup        ndb_blob_tool   ndb_print_schema_file
mysql_tzinfo_to_sql        ndb_config      ndb_print_sys_file
mysql_upgrade              ndb_delete_all  ndb_redo_log_reader
#開(kāi)始初始化
./ndb_mgmd -f /usr/local/mysql-cluster/config.ini --initial
#結(jié)果現(xiàn)實(shí)
root@cdcb6a1a12bf:/usr/local/mysql/bin# ./ndb_mgmd -f /usr/local/mysql-cluster/config.ini --initial
./ndb_mgmd: error while loading shared libraries: libtinfo.so.5: cannot open shared object file: No such file or directory
#執(zhí)行如下命令
apt update && apt install -y libtinfo5 --allow-remove-essential
#再次執(zhí)行命令
ntialcdcb6a1a12bf:/usr/local/mysql/bin# ./ndb_mgmd -f /usr/local/mysql-cluster/config.ini --initial
MySQL Cluster Management Server mysql-8.0.28 ndb-8.0.28
2023-01-04 07:12:22 [MgmtSrvr] INFO     -- The default config directory '/usr/local/mysql/mysql-cluster' does not exist. Trying to create it...
2023-01-04 07:12:22 [MgmtSrvr] INFO     -- Sucessfully created config directory
2023-01-04 07:12:22 [MgmtSrvr] WARNING  -- at line 4: [DB] IndexMemory is deprecated, will use Number bytes on each ndbd(DB) node allocated for storing indexes instead
2023-01-04 07:12:22 [MgmtSrvr] WARNING  -- at line 4: [DB] IndexMemory is deprecated, will use Number bytes on each ndbd(DB) node allocated for storing indexes instead - Repeated 2 times
2023-01-04 07:12:22 [MgmtSrvr] ERROR    -- Directory '/var/lib/mysql-cluster' specified with DataDir in configuration does not exist.
#失敗 缺少/var/lib/mysql-cluster 執(zhí)行命令
mkdir -p /var/lib/mysql-cluster
重新執(zhí)行命令
./ndb_mgmd -f /usr/local/mysql-cluster/config.ini --initial
MySQL Cluster Management Server mysql-8.0.28 ndb-8.0.28
2023-01-04 07:22:48 [MgmtSrvr] WARNING  -- at line 4: [DB] IndexMemory is deprecated, will use Number bytes on each ndbd(DB) node allocated for storing indexes instead
#執(zhí)行成功
#執(zhí)行命令 
root@cdcb6a1a12bf:/usr/local/mysql/bin# ./ndb_mgm
-- NDB Cluster -- Management Client --
ndb_mgm> show
Connected to Management Server at: localhost:1186
Cluster Configuration
---------------------
[ndbd(NDB)]     2 node(s)
id=2 (not connected, accepting connect from 172.17.0.4)
id=3 (not connected, accepting connect from 172.17.0.3)

[ndb_mgmd(MGM)] 1 node(s)
id=1    @172.17.0.2  (mysql-8.0.28 ndb-8.0.28)

[mysqld(API)]   2 node(s)
id=4 (not connected, accepting connect from 172.17.0.4)
id=5 (not connected, accepting connect from 172.17.0.3)

ndb_mgm> 
mgm 執(zhí)行完成
開(kāi)始搭建node-1
docker run -it -d -v /usr/local/mysql-cluster/node:/usr/local/mysql-cluster -v /usr/local/mysql:/usr/local/mysql -p 3307:3306 --name mysql-cluster-node-1 ubuntu
root@hecs-337478:/usr/local/mysql-cluster/node# docker exec -it mysql-cluster-node-1 /bin/bash
root@c75ec054d646:/# hostname -i
172.17.0.3
#將my.cnf 拷貝到 /etc/my.cnf
cp /usr/local/mysql-cluster/my.cnf /etc/my.cnf
#進(jìn)入執(zhí)行文件
cd /usr/local/mysql/bin
root@c75ec054d646:/usr/local/mysql/bin# ./ndbd --initial   
2023-01-04 07:34:52 [ndbd] INFO     -- Angel connected to '172.17.0.2:1186'
2023-01-04 07:34:52 [ndbd] INFO     -- Angel allocated nodeid: 3
2023-01-04 07:34:52 [ndbd] WARNING  -- Cannot change directory to '/usr/local/mysql-cluster/data', error: 2
2023-01-04 07:34:52 [ndbd] ERROR    -- Couldn't start as daemon, error: 'Failed to open logfile '/usr/local/mysql-cluster/data/ndb_3_out.log' for write, errno: 2
#執(zhí)行失敗 文件
#執(zhí)行如下命令
mkdir /usr/local/mysql-cluster/data
#重新執(zhí)行命令
./ndbd --initial
root@c75ec054d646:/usr/local/mysql/bin# ./ndbd --initial
2023-01-04 07:36:05 [ndbd] INFO     -- Angel connected to '172.17.0.2:1186'
2023-01-04 07:36:05 [ndbd] INFO     -- Angel allocated nodeid: 3
#執(zhí)行成功
開(kāi)始搭建node-2
docker run -it -d -v /usr/local/mysql-cluster/node:/usr/local/mysql-cluster -v /usr/local/mysql:/usr/local/mysql -p 3306:3306 --name mysql-cluster-node-2 ubuntu
root@hecs-337478:/usr/local/mysql-cluster/node# docker exec -it mysql-cluster-node-1 /bin/bash
root@c75ec054d646:/# hostname -i
172.17.0.3
#將my.cnf 拷貝到 /etc/my.cnf
cp /usr/local/mysql-cluster/my.cnf /etc/my.cnf
#進(jìn)入執(zhí)行文件
cd /usr/local/mysql/bin
root@c75ec054d646:/usr/local/mysql/bin# ./ndbd --initial   
2023-01-04 07:34:52 [ndbd] INFO     -- Angel connected to '172.17.0.2:1186'
2023-01-04 07:34:52 [ndbd] INFO     -- Angel allocated nodeid: 3
2023-01-04 07:34:52 [ndbd] WARNING  -- Cannot change directory to '/usr/local/mysql-cluster/data', error: 2
2023-01-04 07:34:52 [ndbd] ERROR    -- Couldn't start as daemon, error: 'Failed to open logfile '/usr/local/mysql-cluster/data/ndb_3_out.log' for write, errno: 2
#執(zhí)行失敗 文件
#執(zhí)行如下命令
mkdir /usr/local/mysql-cluster/data
#重新執(zhí)行命令
./ndbd --initial
root@c75ec054d646:/usr/local/mysql/bin# ./ndbd --initial
2023-01-04 07:36:05 [ndbd] INFO     -- Angel connected to '172.17.0.2:1186'
2023-01-04 07:36:05 [ndbd] INFO     -- Angel allocated nodeid: 3
#執(zhí)行成功

查看mgm 節(jié)點(diǎn)連上了

ndb_mgm> show
Cluster Configuration
---------------------
[ndbd(NDB)]     2 node(s)
id=2 (not connected, accepting connect from 172.17.0.4)
id=3    @172.17.0.3  (mysql-8.0.28 ndb-8.0.28, starting, Nodegroup: 0)

[ndb_mgmd(MGM)] 1 node(s)
id=1    @172.17.0.2  (mysql-8.0.28 ndb-8.0.28)

[mysqld(API)]   2 node(s)
id=4 (not connected, accepting connect from 172.17.0.4)
id=5 (not connected, accepting connect from 172.17.0.3)
#連接所有節(jié)點(diǎn)之后 再次執(zhí)行
ndb_mgm> show
Cluster Configuration
---------------------
[ndbd(NDB)]     2 node(s)
id=2    @172.17.0.4  (mysql-8.0.28 ndb-8.0.28, Nodegroup: 0, *)
id=3    @172.17.0.3  (mysql-8.0.28 ndb-8.0.28, Nodegroup: 0)

[ndb_mgmd(MGM)] 1 node(s)
id=1    @172.17.0.2  (mysql-8.0.28 ndb-8.0.28)

[mysqld(API)]   2 node(s)
id=4 (not connected, accepting connect from 172.17.0.4)
id=5    @172.17.0.3  (mysql-8.0.28 ndb-8.0.28)

這里需要注意得是,需要鏈接所有的節(jié)點(diǎn)才能繼續(xù)安裝mysql 否者得話 會(huì)導(dǎo)致mysql 鏈接不上集群

會(huì)報(bào)如下錯(cuò)誤

 0 [ERROR] [MY-010865] [Server] NDB: Tables not available after 120 seconds. Consider increasing --ndb-wait-setup value

重要得事情說(shuō)三遍 保證所有節(jié)點(diǎn)(ndbd)都連接上mgm 津畸!保證所有的節(jié)點(diǎn)(ndbd)都連接上mgm!保證所有得節(jié)點(diǎn)(ndbd)都連接上mgm ! 才可以安裝mysql不然會(huì)報(bào)錯(cuò)的狂秦。

開(kāi)始安裝mysql

#執(zhí)行命令
root@c75ec054d646:/usr/local/mysql/bin# ./mysqld --initialize --user=root
./mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
root@c75ec054d646:/usr/local/mysql/bin# 
#執(zhí)行
apt-get update & apt-get install libaio-dev
再次執(zhí)行
root@c75ec054d646:/usr/local/mysql/bin# ./mysqld --initialize --user=root
./mysqld: error while loading shared libraries: libnuma.so.1: cannot open shared object file: No such file or directory
#執(zhí)行
apt-get install numactl
再次執(zhí)行
root@c75ec054d646:/usr/local/mysql/bin# ./mysqld --initialize --user=root
2023-01-04T07:46:09.014641Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release.
2023-01-04T07:46:09.019801Z 0 [System] [MY-013169] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.28-cluster) initializing of server in progress as process 570
2023-01-04T07:46:09.078046Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2023-01-04T07:46:10.299762Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2023-01-04T07:46:12.249271Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: :EY9G=a2Akby
保存好初始密碼  EY9G=a2Akby

啟動(dòng) mysql

root@c75ec054d646:/usr/local/mysql/bin# ./mysqld --user=root
2023-01-04T07:48:05.896979Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release.
2023-01-04T07:48:05.897101Z 0 [System] [MY-010116] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.28-cluster) starting as process 615
2023-01-04T07:48:05.913412Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2023-01-04T07:48:06.087261Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
#這里你以為啟動(dòng)成功了 但是并沒(méi)有 這里其實(shí)啟動(dòng)失敗了 因?yàn)?我沒(méi)有啟動(dòng)全部的node 就直接啟動(dòng)mysql過(guò)一段時(shí)間會(huì)報(bào)出如下異常
 0 [ERROR] [MY-010865] [Server] NDB: Tables not available after 120 seconds. Consider increasing --ndb-wait-setup value
#如何解決: 啟動(dòng)所有得節(jié)點(diǎn)

保證所有得節(jié)點(diǎn)都連接上mgm 后再次啟動(dòng)mysql

root@be35e378176d:/usr/local/mysql/bin# ./mysqld --user=root
2023-01-04T08:47:51.512841Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release.
2023-01-04T08:47:51.512971Z 0 [System] [MY-010116] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.28-cluster) starting as process 424
2023-01-04T08:47:51.526725Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2023-01-04T08:47:51.883664Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2023-01-04T08:47:53.512744Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2023-01-04T08:47:53.512787Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
2023-01-04T08:47:53.560897Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 33060, socket: /tmp/mysqlx.sock
2023-01-04T08:47:53.560938Z 0 [System] [MY-010931] [Server] /usr/local/mysql/bin/mysqld: ready for connections. Version: '8.0.28-cluster'  socket: '/usr/local/mysql/sock/mysql.sock'  port: 3306  MySQL Cluster Community Server - GPL.
2023-01-04 08:47:54 [NdbApi] INFO     -- Flushing incomplete GCI:s < 251/7
2023-01-04 08:47:54 [NdbApi] INFO     -- Flushing incomplete GCI:s < 251/7

查看msg 鏈接狀態(tài)

ndb_mgm> show
Cluster Configuration
---------------------
[ndbd(NDB)]     2 node(s)
id=2    @172.17.0.4  (mysql-8.0.28 ndb-8.0.28, Nodegroup: 0, *)
id=3    @172.17.0.3  (mysql-8.0.28 ndb-8.0.28, Nodegroup: 0)

[ndb_mgmd(MGM)] 1 node(s)
id=1    @172.17.0.2  (mysql-8.0.28 ndb-8.0.28)

[mysqld(API)]   2 node(s)
id=4    @172.17.0.4  (mysql-8.0.28 ndb-8.0.28)
id=5    @172.17.0.3  (mysql-8.0.28 ndb-8.0.28)

ndb_mgm> 

開(kāi)始驗(yàn)證

ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
update user set host = '%' where user = 'root';

ALTER USER 'root'@'%' IDENTIFIED WITH 'hou123456.' BY '123456';

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市推捐,隨后出現(xiàn)的幾起案子裂问,更是在濱河造成了極大的恐慌,老刑警劉巖牛柒,帶你破解...
    沈念sama閱讀 211,265評(píng)論 6 490
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件堪簿,死亡現(xiàn)場(chǎng)離奇詭異,居然都是意外死亡皮壁,警方通過(guò)查閱死者的電腦和手機(jī)椭更,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 90,078評(píng)論 2 385
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái)蛾魄,“玉大人虑瀑,你說(shuō)我怎么就攤上這事∥吠螅” “怎么了缴川?”我有些...
    開(kāi)封第一講書(shū)人閱讀 156,852評(píng)論 0 347
  • 文/不壞的土叔 我叫張陵,是天一觀的道長(zhǎng)描馅。 經(jīng)常有香客問(wèn)我把夸,道長(zhǎng),這世上最難降的妖魔是什么铭污? 我笑而不...
    開(kāi)封第一講書(shū)人閱讀 56,408評(píng)論 1 283
  • 正文 為了忘掉前任恋日,我火速辦了婚禮,結(jié)果婚禮上嘹狞,老公的妹妹穿的比我還像新娘岂膳。我一直安慰自己,他們只是感情好磅网,可當(dāng)我...
    茶點(diǎn)故事閱讀 65,445評(píng)論 5 384
  • 文/花漫 我一把揭開(kāi)白布谈截。 她就那樣靜靜地躺著,像睡著了一般涧偷。 火紅的嫁衣襯著肌膚如雪簸喂。 梳的紋絲不亂的頭發(fā)上,一...
    開(kāi)封第一講書(shū)人閱讀 49,772評(píng)論 1 290
  • 那天燎潮,我揣著相機(jī)與錄音喻鳄,去河邊找鬼。 笑死确封,一個(gè)胖子當(dāng)著我的面吹牛除呵,可吹牛的內(nèi)容都是我干的再菊。 我是一名探鬼主播,決...
    沈念sama閱讀 38,921評(píng)論 3 406
  • 文/蒼蘭香墨 我猛地睜開(kāi)眼颜曾,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼纠拔!你這毒婦竟也來(lái)了?” 一聲冷哼從身側(cè)響起泛啸,我...
    開(kāi)封第一講書(shū)人閱讀 37,688評(píng)論 0 266
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤绿语,失蹤者是張志新(化名)和其女友劉穎,沒(méi)想到半個(gè)月后候址,有當(dāng)?shù)厝嗽跇?shù)林里發(fā)現(xiàn)了一具尸體吕粹,經(jīng)...
    沈念sama閱讀 44,130評(píng)論 1 303
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 36,467評(píng)論 2 325
  • 正文 我和宋清朗相戀三年岗仑,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了匹耕。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 38,617評(píng)論 1 340
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出留攒,到底是詐尸還是另有隱情拳芙,我是刑警寧澤晨雳,帶...
    沈念sama閱讀 34,276評(píng)論 4 329
  • 正文 年R本政府宣布,位于F島的核電站,受9級(jí)特大地震影響,放射性物質(zhì)發(fā)生泄漏嘱蛋。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 39,882評(píng)論 3 312
  • 文/蒙蒙 一五续、第九天 我趴在偏房一處隱蔽的房頂上張望洒敏。 院中可真熱鬧,春花似錦疙驾、人聲如沸凶伙。這莊子的主人今日做“春日...
    開(kāi)封第一講書(shū)人閱讀 30,740評(píng)論 0 21
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)函荣。三九已至,卻和暖如春扳肛,著一層夾襖步出監(jiān)牢的瞬間傻挂,已是汗流浹背。 一陣腳步聲響...
    開(kāi)封第一講書(shū)人閱讀 31,967評(píng)論 1 265
  • 我被黑心中介騙來(lái)泰國(guó)打工敞峭, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人蝉仇。 一個(gè)月前我還...
    沈念sama閱讀 46,315評(píng)論 2 360
  • 正文 我出身青樓旋讹,卻偏偏與公主長(zhǎng)得像殖蚕,于是被迫代替她去往敵國(guó)和親。 傳聞我的和親對(duì)象是個(gè)殘疾皇子沉迹,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 43,486評(píng)論 2 348

推薦閱讀更多精彩內(nèi)容