mysql cluster 安裝配置

Mysql Cluster安裝:

 

軟件版本:mysql-cluster-gpl-7.2.19-linux2.6-x86_64.tar.gz

mysql官方下載頁面中會訪問google的js,google不能訪問的話,選擇平臺的下拉框就會失效。需要代理服務器下載。

安裝環境:

Centos5.8  Linux 2.6.18-308.el5 x86_64  內存4G  非常消耗內存

 

10.0.12.150:管理節點

10.0.12.151SQL節點

10.0.12.152SQL節點

10.0.12.153DATA節點

10.0.12.154DATA節點

 

 

  • 管理節點安裝:

  • :管理節點


[root@localhost ~]# groupadd mysql
[root@localhost ~]# useradd mysql-g mysql
[root@localhost ~]# cd /usr/local
[root@localhost ~]# tar –xf mysql-cluster-gpl-7.2.19-linux2.6-x86_64.tar.gz
[root@localhost ~]# mv mysql-cluster-gpl-7.2.19-linux2.6-x86_64  mysql
[root@localhost ~]# chown -R mysql:mysql mysql
[root@localhost ~]# mkdir /usr/local/mysql/data
[root@localhost ~]# mkdir /usr/local/mysql/logs
[root@localhost ~]# mkdir/var/lib/mysql-cluster
[root@localhost ~]# cd mysql
[root@localhost ~]# scripts/mysql_install_db  --user=mysql --basedir=/usr/local/mysql  --datadir=/usr/local/mysql/data
[root@localhost ~]#vi /var/lib/mysql-cluster/config.ini


寫入以下內容:

[NDBD DEFAULT]
NoOfReplicas=2
DataMemory=1024MB
IndexMemory=1024MB
MaxNoOfTables=300
MaxNoOfOrderedIndexes=500
MaxNoOfUniqueHashIndexes=500
MaxNoOfAttributes=20000
[TCP DEFAULT]
portnumber=3306
[NDB_MGMD]
hostname=10.0.12.150
datadir=/usr/local/mysql/data/
[NDBD]
hostname=10.0.12.153
datadir=/usr/local/mysql/data/
[NDBD]
hostname=10.0.12.154
datadir=/usr/local/mysql/data/
[MYSQLD]
hostname=10.0.12.151
[MYSQLD]
hostname=10.0.12.152


[root@localhost ~]#



 

  • DATA節點安裝

  • 10.0.12.153 Data節點

  • 10.0.12.154 Data節點


[root@localhost ~]# groupadd mysql
[root@localhost ~]# useradd mysql-g mysql
[root@localhost ~]# cd /usr/local
[root@localhost ~]# tar –xf mysql-cluster-gpl-7.2.19-linux2.6-x86_64.tar.gz
[root@localhost ~]# mv mysql-cluster-gpl-7.2.19-linux2.6-x86_64  mysql
[root@localhost ~]# chown -R mysql:mysql mysql
[root@localhost ~]# mkdir /usr/local/mysql/data
[root@localhost ~]# mkdir /usr/local/mysql/logs
[root@localhost ~]# mkdir /var/lib/mysql-cluster
[root@localhost ~]# cd mysql
[root@localhost ~]# scripts/mysql_install_db  --user=mysql --basedir=/usr/local/mysql  --datadir=/usr/local/mysql/data
[root@localhost ~]# cpsupport-files/mysql.server /etc/init.d/mysqld
[root@localhost ~]# vi /etc/my.cnf


寫入以下內容:

[mysqld]
basedir         = /usr/local/mysql
datadir         = /usr/local/mysql/data
user            = mysql
port            = 3306
socket          = /var/lib/mysql/mysql.sock
ndbcluster
ndb-connectstring=10.0.12.150
[mysql_cluster]
ndb-connectstring=10.0.12.150
[NDB_MGM]
connect-string=10.0.12.150


[root@localhost ~]# chown -Rmysql:mysql /var/lib/mysql
[root@localhost ~]#
[root@localhost ~]#




  • SQL節點安裝

同Data節點安裝

  1. 10.0.12.151 sql節點

  2. 10.0.12.152 sql節點

 

  • Cluster啓動

1、    啓動管理節點

/usr/local/mysql/bin/ndb_mgmd -f/var/lib/mysql-cluster/config.ini --initial

首次啓動後面加 –initial

關閉:/usr/local/mysql/bin/ndb_mgm -e shutdown

2、    啓動data節點

/usr/local/mysql/bin/ndbd --initial

首次啓動或者修改參數後啓動需要加--initial

3、    啓動sql節點

service mysqld start

關閉:service mysqld stop

 

 

啓動完成後在管理節點執行/usr/local/mysql/bin/ndb_mgm

ndb_mgm>show
Connected toManagement Server at: localhost:1186
ClusterConfiguration
---------------------
[ndbd(NDB)]     2 node(s)
id=2    @10.0.12.153  (mysql-5.5.41 ndb-7.2.19, Nodegroup: 0, *)
id=3    @10.0.12.154  (mysql-5.5.41 ndb-7.2.19, Nodegroup: 0)
 
[ndb_mgmd(MGM)] 1node(s)
id=1    @10.0.12.150  (mysql-5.5.41 ndb-7.2.19)
 
[mysqld(API)]   2 node(s)
id=4    @10.0.12.151  (mysql-5.5.41 ndb-7.2.19)
id=5    @10.0.12.152  (mysql-5.5.41 ndb-7.2.19)
 
ndb_mgm>


 

 

測試:在sql節點10.0.12.151進入mysql創建庫testcluster,創建測試table,在10.0.12.152可以看見新建的表,mysqlcluster創建成功。


mysql cluster節點,分組, 複製和分片詳見以下文檔

MySQL Cluster Nodes, Node Groups, Replicas, and Partitions

http://dev.mysql.com/doc/refman/5.5/en/mysql-cluster-nodes-groups.html


*********************************************************


Replica.  This is a copy of a cluster partition. Each node in a node group stores a replica. Also sometimes known as a partition replica. The number of replicas is equal to the number of nodes per node group.

The following diagram illustrates a MySQL Cluster with four data nodes, arranged in two node groups of two nodes each; nodes 1 and 2 belong to node group 0, and nodes 3 and 4 belong to node group 1.

Note

Only data (ndbd) nodes are shown here; although a working cluster requires an ndb_mgm process for cluster management and at least one SQL node to access the data stored by the cluster, these have been omitted in the figure for clarity.

A MySQL Cluster, with 2 node groups having 2 nodes each

The data stored by the cluster is divided into four partitions, numbered 0, 1, 2, and 3. Each partition is stored—in multiple copies—on the same node group. Partitions are stored on alternate node groups as follows:

  • Partition 0 is stored on node group 0; a primary replica (primary copy) is stored on node 1, and a backup replica (backup copy of the partition) is stored on node 2.

  • Partition 1 is stored on the other node group (node group 1); this partition's primary replica is on node 3, and its backup replica is on node 4.

  • Partition 2 is stored on node group 0. However, the placing of its two replicas is reversed from that of Partition 0; for Partition 2, the primary replica is stored on node 2, and the backup on node 1.

  • Partition 3 is stored on node group 1, and the placement of its two replicas are reversed from those of partition 1. That is, its primary replica is located on node 4, with the backup on node 3.

What this means regarding the continued operation of a MySQL Cluster is this: so long as each node group participating in the cluster has at least one node operating, the cluster has a complete copy of all data and remains viable. This is illustrated in the next diagram.

Nodes required to keep a 2x2 cluster viable

In this example, where the cluster consists of two node groups of two nodes each, any combination of at least one node in node group 0 and at least one node in node group 1 is sufficient to keep the cluster alive (indicated by arrows in the diagram). However, if both nodes from either node group fail, the remaining two nodes are not sufficient (shown by the arrows marked out with an X); in either case, the cluster has lost an entire partition and so can no longer provide access to a complete set of all cluster data.


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章