ubuntu mysql集群搭建_ubuntu server部署mysql集群
簡介
[說明本次部署的內容,目的等等]
本部署文檔的目的是如何在ubuntu server上進行mysql的群集部署。
前期準備
在進行本文檔操作前,需要完成如下前期步驟:
1.安裝3臺ubuntu server服務器;
Server1: ndbd 192.168.68.5
Server2: ndbd 192.168.68.6
Server3: mysqld –ndb-cluster 192.168.68.8
ndbd(192.168.68.5\192.168.68.6): 數據庫節點,存放數據。
mysqld –ndb-cluster(192.168.68.8): MySQL服務器節點,管理節點,管理群集。
注:
本實驗在ubuntu server(8.04)實現
管理節點:server3(192.168.68.8)存儲節點:server1(192.168.68.5),server2(192.168.68.6)
2.3臺server均安裝mysql - server數據庫。
部署概要
1.安裝ubuntu服務器(本實驗使用為8.04);
2.安裝mysql – server數據庫;
3.這三臺服務器上配置my.cnf;
4.管理節點(192.168.68.8)上配置ndb_mgmd.cnf;
5.管理節點服務器上啟動mysql-ndb-mgm;
6.存儲節點上(192.168.68.5\6)啟動mysql-ndb;
7.3臺服務器分別啟動mysql-ndb服務;
8.測試管理節點。
部署步驟
安裝Ubuntu服務器
1.安裝ubuntu服務器,安裝過程中安裝msyql(也可單獨安裝)、openssh服務。
群集配置
ndbcluster
ndb-connectstring=192.168.68.8
[mysqldump]
quick
quote-names
max_allowed_packet = 16M
[mysql]
#no-auto-rehash # faster start of mysql but no tab completition
[isamchk]
key_buffer = 16M
#
# * NDB Cluster
#
# See /usr/share/doc/mysql-server-*/README.Debian for more information.
#
# The following configuration is read by the NDB Data Nodes (ndbd processes)
# not from the NDB Management Nodes (ndb_mgmd processes).
#
[MYSQL_CLUSTER]
ndb-connectstring=192.168.68.8
#
# * IMPORTANT: Additional settings that can override those from this file!
# The files must end with ‘.cnf’, otherwise they’ll be ignored.
#
!includedir /etc/mysql/conf.d/
ubuntu@ubuntu:~$
提示
/etc/mysql/my.cnf主要配置如下內容:
ndbcluster
ndb-connectstring=192.168.68.13
和添加
[MYSQL_CLUSTER]
ndb-connectstring=192.168.68.13
三臺服務器都需要配置
2.管理節點服務器中配置(192.168.68.8)中配置ndb_mgmd.cnf。
復制:
/usr/share/doc/mysql-server-5.0/examples/ndb_mgmd.cnf?至/etc/mysql/ndb_mgmd.cnf
3.管理節點服務器中配置(192.168.68.8)中編輯ndb_mgmd.cnf。
ubuntu@ubuntu:~$ sudo vim /etc/mysql/ndb_mgmd.cnf
[NDBD DEFAULT]
NoOfReplicas=2
DataMemory=10MB
IndexMemory=25MB
MaxNoOfTables=256
MaxNoOfOrderedIndexes=256
MaxNoOfUniqueHashIndexes=128
[MYSQLD DEFAULT]
[NDB_MGMD DEFAULT]
[TCP DEFAULT]
[NDB_MGMD]
Id=1 # the NDB Management Node (this one)HostName=192.168.68.8
DataDir= /var/lib/mysql-cluster
[NDBD]
Id=2 # the first NDB Data Node
HostName=192.168.68.5
DataDir= /var/lib/mysql-cluster
[NDBD]
Id=3 # the second NDB Data Node
HostName=192.168.68.6DataDir=/var/lib/mysql-cluster
[MYSQLD]
Id=4 # the first SQL node
HostName=192.168.68.5
[MYSQLD]
Id=5 # the first SQL node
HostName=192.168.68.6
4.服務器管理節點服務器(192.168.68.8)中的mysql-ndb-mgm服務。
sudo /etc/init.d/mysql-ndb-mgm start
5.啟動數據存儲服務器(192.168.68.5\6)中服務mysql-ndb。
sudo /etc/init.d/mysql-ndb start
6.最后啟動,3臺服務器中(192.168.68.5\6\8)啟動mysql服務。
sudo /etc/init.d/mysql start
群集測試
1.節點管理服務器運行ndb_mgm(192.168.68.8)。
ubuntu@ubuntu:~$ 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 @192.168.68.5(Version: 5.0.51, Nodegroup: 0)
id=3 @192.168. 68.6 (Version: 5.0.51, Nodegroup: 0, Master)
[ndb_mgmd(MGM)] 1 node(s)
id=1 @192.168. 68.8 (Version: 5.0.51)
[mysqld(API)] 2 node(s)
id=4 @192.168. 68.5 (Version: 5.0.51)
id=5 @192.168. 68.6 (Version: 5.0.51)
ndb_mgm>
提示
1.表必須用ENGINE=NDB或ENGINE=NDBCLUSTER選項創建,或用ALTER TABLE選項更改,以使用NDB Cluster存儲引擎在 Cluster內復制它們。如果使用mysqldump的輸出從已有數據庫導入表,可在文本編輯器中打開SQL腳本,并將該選項添加到任何表創建語句,或用這類選項之一替換任何已有的ENGINE(或TYPE)選項。
2.另外還請記住,每個NDB表必須有一個主鍵。如果在創建表時用戶未定義主鍵,NDB Cluster存儲引擎將自動生成隱含的主鍵。(注釋:該隱含 鍵也將占用空間,就像任何其他的表。
3.索引一樣。由于沒有足夠的內存來容納這些自動創建的鍵,出現問題并不罕見)。
4.當你在一個節點上運行create database mydb;你去其他sql node上執行show databases;將不能看到mydb,你需要創建它,然后use mydb; show tables;你將看到同步的表。
2.存儲節點1 (192.168.68.5)中創建數據庫(test)與表(table1)。
ubuntu@ubuntu:~$ mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 7
Server version: 5.0.51a-3ubuntu5.1 (Ubuntu)
Type ‘help;’ or ‘h’ for help. Type ‘c’ to clear the buffer.
mysql> create database test;
Query OK, 1 row affected (0.00 sec)
mysql> use cluster
Database changed
mysql> create table table1(nub int(10),primary key(nub),) engine = ndbcluster;
charset utf8;
Query OK, 0 rows affected (1.07 sec)
mysql>insert into table1 values(1);
Query OK, 1 row affected (0.12 sec)
3.存儲節點2(192.168.68.6)中創建數據庫(test)。
注:節點2中不需要創建table1表,
ubuntu@ubuntu:~$ mysql –u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 7
Server version: 5.0.51a-3ubuntu5.1 (Ubuntu)
Type ‘help;’ or ‘h’ for help. Type ‘c’ to clear the buffer.
mysql> show databases;
+——————–+
| Database |
+——————–+
| information_schema |
| mysql |
+——————–+
2 rows in set (0.13 sec)
mysql>create database test;
Query OK, 1 row affected (0.00 sec)
mysql> show databases;
+——————–+
| Database |
+——————–+
| information_schema |
| test|
| mysql |
+——————–+
3 rows in set (0.13 sec)
mysql> use test;
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
mysql> show tables;
+——————-+
| Tables_in_cluster |
+——————-+
| table1 |
+——————-+
1 row in set (0.01 sec)
mysql> select * from table1;
+—-+———–+
| nub |
+—-+———–+
| 1 |
+—-+———–+
1 rows in set (0.03 sec)
提示
在節點2(192.168.68.6)中,可觀察到,雖未創建table1表,但是能夠查看到該表,并能夠看到表中的數據,驗證結果mysql群集實現。
4.將管理節點(192.168.68.8)停掉,在存儲節點1服務器(192.168.68.5)中創建table2(使用ENGINE=NDBCLUSTER),在存儲節點2服務器(192.168.68.6)上“show tables”也可以看到新創建的表table2。
提示
群集實現后,管理節點服務器可以停掉,群集仍然可以實現。
總結:如創建表時,未在創建表語句后添加ENGINE=NDB或ENGINE=NDBCLUSTER,則該表不會在群集server中同步。
管理節點、存儲節點,也可以同在一臺機器上,或兩臺msyql數據庫server服務器,其中一臺同時為管理節點與存儲節點,而另一臺僅為存儲節點,這樣的設計均是可以的。
在實際過程中可以根據實際需要而部署。
總結
以上是生活随笔為你收集整理的ubuntu mysql集群搭建_ubuntu server部署mysql集群的全部內容,希望文章能夠幫你解決所遇到的問題。
 
                            
                        - 上一篇: 女生什么时候减肥效果最快最好
- 下一篇: 甩脂机能减肥吗,对身体有什么伤害
