本文我們主要介紹了MySQL數據庫集群實現負載均衡的安裝配置工作,接下來我們就讓我們一起來了解一下這部分內容。
MySQL數據庫集群關系如下圖:
ndbd:數據庫節點,物理數據實際存放位置。
mysqld:MySQL服務器節點。
ndbd_mgmd:管理節點。管理/查看各庫節點和服務器節點的狀態。程序直接訪問的是這台機器的IP。默認端口仍是3306。
1.在ndb_mgmd、mysqld、Node A、Node B上安裝MySQL5.0
安裝目錄:/usr/local/mysql
2.配置 Node A、Node B、mysqld:
- # cp /usr/local/mysql/support-files/my-medium.cnf /etc/my.cnf
- # vi /etc/my.cnf 在文件尾加入 # my.cnf
- # example additions to my.cnf for MySQL Cluster
- # (valid in MySQL 5.0) # enable ndbcluster storage engine, and provide connectstring for
- # management Server host (default port is 1186)
- [mysqld]
- ndbcluster
- ndb-connectstring=192.168.56.30 # provide connectstring for management Server host (default port: 1186)
- [ndbd]
- connect-string=192.168.56.30 # provide connectstring for management Server host (default port: 1186)
- [ndb_mgm]
- connect-string=192.168.56.30 # provide location of cluster configuration file
- [ndb_mgmd]
- config-file=/var/lib/mysql-cluster
在Node A、Node B上創建日志文件夾
- # mkdir /var/lib/mysql-cluster
3.配置ndb_mgmd:
- # mkdir /var/lib/mysql-cluster
- # cd /var/lib/mysql-cluster
- # vi config.ini # file "config.ini" - 2 data nodes and 2 SQL nodes
- # This file is placed in the startup directory of ndb_mgmd (the
- # management server)
- # The first MySQL Server can be started from any host. The second
- # can be started only on the host mysqld_5.mysql.com [NDBD DEFAULT]
- NoOfReplicas= 2
- DataDir= /var/lib/mysql-cluster [NDB_MGMD]
- Hostname= 192.168.56.30
- DataDir= /var/lib/mysql-cluster [NDBD]
- HostName= 192.168.56.11 [NDBD]
- HostName= 192.168.56.12[MYSQLD]
- [MYSQLD]
- [MYSQLD]
4. 啟動服務
- ndb_mgmd /usr/local/mysql/bin/ndb_mgmd -f /var/lib/mysql-cluster/config.ini
- Node A /usr/local/mysql/bin/ndbd --initial #只在第一次啟動ndbd時使用--initial參數
- Node B /usr/local/mysql/bin/ndbd --initial
- mysqld /usr/local/mysql/support-files/mysql.server start檢查工作狀態
回到管理節點服務器Ndb_mgmd上,並啟動管理終端:# /usr/bin/ndb_mgm
- ndb_mgm> show
- Cluster Configuration [ndbd(NDB)] 2 node(s)
- id=2 (not connected, accepting connect from 192.168.56.11)
- id=3 @192.168.56.12 (Version: 5.0.22, Nodegroup: 0, Master) [ndb_mgmd(MGM)] 1 node(s)
- id=1 @192.168.56.30 (Version: 5.0.22) [mysqld(API)] 3 node(s)
- id=4 @192.168.56.20 (Version: 5.0.22)
- id=5 (not connected, accepting connect from any host)
- id=6 (not connected, accepting connect from any host) mysqld(API)即mysqld --ndb-cluster,MySQL服務器節點,應該程序訪問的IP。創建數據庫mysqld):
- # /usr/local/mysql/bin/mysql
- > use test;
- > CREATE TABLE ctest (i INT) ENGINE=NDBCLUSTER;
- > INSERT INTO ctest () VALUES (1);
關於MySQL數據庫集群負載均衡的配置就介紹到這裡了,希望本次的介紹能夠對您有所收獲!