1. 程式人生 > >CentOS下 MySQL Cluster NDB 7.2 部署實踐

CentOS下 MySQL Cluster NDB 7.2 部署實踐

實驗需要,OneCoder打算親自部署一下MySQL Cluster環境。VMware環境中,虛擬化三臺CentOS5.4 x64虛擬機器。

10.4.44.201 SQL
10.4.44.202 Data
10.4.44.203 Manager

用於部署。

官方文件自然是最好的部署手冊,先簡單瞭解一下。

MySQL Cluster構成

Each MySQL Cluster host computer must have the correct executable programs installed. A host running an SQL node must have installed on it a MySQL Server binary (mysqld). Management nodes require the management server daemon (ndb_mgmd); data nodes require the data node daemon (ndbd or ndbmtd). It is not necessary to install the MySQL Server binary on management node hosts and data node hosts. It is recommended that you also install the management client (ndb_mgm) on the management server host.

SQL節點,必須部署MySQL Server binary(mysqld);管理(Management) 節點,需要部署management server daemon(ndb_mgmd);資料(data)節點,需要部署data node daemon(ndbd 或者 ndbmtd)。無需在管理和資料節點上部署MySQL Server binary。推薦在管理節點上,也部署management client(ndb_mgm)。

MySQL Cluster配置(翻譯自官方文件)

每個data和SQL節點都需要一個my.cnf檔案,其中包含了兩條重要的資訊:一個連結串指明management節點位置,一條針對data節點,告訴MySQL伺服器開啟NDBCLUSTER儲存引擎。
management節點需要config.ini配置檔案,裡面儲存著它需要管理的叢集節點的資訊、儲存資料和各data節點資料索引所需的記憶體資訊,data節點的位置資訊,
有了這些理論基礎,下面我們來動手操作一下

先部署data和SQL節點, 下載MysQL Cluster壓縮包 ,通過putty自帶的pscp工具,拷貝到各個節點linux虛擬機器中。

解壓。

先配置SQL和Data節點。在/etc下放置my.cnf配置檔案。內容如下:

[ndbcluster]
ndb-connectstring=10.4.44.203
[mysql_cluster]
ndb-connectstring=10.4.44.203

再配置Manager

同樣先將壓縮包拷貝,然後在/var/lib/mysql-cluster/config.ini 配置:[ndbd default]

# Options affecting ndbd processes on all data nodes:
NoOfReplicas=1    # Number of replicas
DataMemory=80M    # How much memory to allocate for data storage
IndexMemory=18M   # How much memory to allocate for index storage
                  # For DataMemory and IndexMemory, we have used the
                  # default values. Since the "world" database takes up
                  # only about 500KB, this should be more than enough for
                  # this example Cluster setup.

[ndb_mgmd]
# Management process options:
hostname=10.4.44.203           # Hostname or IP address of MGM node
datadir=/var/lib/mysql-cluster  # Directory for MGM node log files

[ndbd]
# Options for data node "A":
                                # (one [ndbd] section per data node)
hostname=10.4.44.202          # Hostname or IP address
datadir=/usr/local/mysql/data   # Directory for this data node's data files

[mysqld]
# SQL node options:
hostname=10.4.44.201          # Hostname or IP address
                                            # (additional mysqld connections can be
                                        # specified for this node for various
                                                # purposes such as running ndb_restore)

啟動MySQL Cluster:

先啟動Management節點:

shell> ndb_mgmd -f /var/lib/mysql-cluster/config.ini

再啟動data

shell>ndbd

和SQL節點shell> groupadd mysql

shell> useradd -r -g mysql mysql
shell> cd /usr/local
shell> tar zxvf /path/to/mysql-VERSION-OS.tar.gz
shell> ln -s full-path-to-mysql-VERSION-OS mysql
shell> cd mysql
shell> chown -R mysql .
shell> chgrp -R mysql .
shell> scripts/mysql_install_db
shell> bin>mysqld

成功。在management節點,利用./ndb_mgm檢視狀態。

ndb_mgm>show.

部署成功。

OneCoder注:這裡一開始有一個誤區,就是我根據文件誤以為SQL節點部署的MySQL Server版本而不是Cluster版本,導致耽誤了很多時間。今天看一個錯誤出神的時候,才突然醒悟,我是不是搞錯了。連忙替換了版本,這才成功。