(MySQL 叢集) MySQL Cluster在Linux上的安裝(RedHat 5.6)

來源:互聯網
上載者:User

一、環境介紹

IP_Address

Port_No

Node_name

Service_name

Desc

192.168.56.101

  3306

SQL node(API Node)

mysqld

SQL節點(API節點)

192.168.56.101

 2202

Data Node

ndbd

資料節點

192.168.56.102

 3306

SQL node(API Node)

mysqld

SQL節點(API節點)

192.168.56.102

 2202

Data Node

ndbd

資料節點

192.168.56.103

1186

Mgmt Node

ndb_mgmd

管理節點

二、準備工作

1)關閉防火牆(在三台伺服器上操作)

[root@localhost ~]# service iptables stop

Flushing firewall rules:                                   [  OK  ]

Setting chains to policy ACCEPT: filter                    [  OK  ]

Unloading iptables modules:                                [  OK  ]

[root@localhost local]# chkconfig iptables off

2)預設不啟動防火牆(在三台伺服器上操作)

 [root@localhost ~]# chkconfig iptables off

3)添加mysql使用者和組(在三台伺服器上操作)

[root@localhost ~]# groupadd mysql

[root@localhost ~]# useradd -g mysql mysql

4)上傳安裝檔案(只需要在192.168.56.101上操作即可)

可以使用FileZilla軟體來上傳安裝檔案,比如上傳到Linux 上的/tmp目錄。我使用的安裝檔案是:mysql-cluster-gpl-7.1.10-linux-i686-glibc23.tar.gz

 三、安裝Mysql Cluster

1.安裝資料節點和SQL節點(只需要在192.168.56.101上操作即可)

1)安裝tar包

[root@localhost ~]# cd /tmp

[root@localhost tmp]# tar -C /usr/local -zxvf mysql-cluster-gpl-7.1.10-linux-i686-glibc23.tar.gz

[root@localhost tmp]# ln -s /usr/local/mysql-cluster-gpl-7.1.10-linux-i686-glibc23/ /usr/local/mysql

[root@localhost tmp]# cd /usr/local/mysql

[root@localhost mysql]# scripts/mysql_install_db --usr=mysql

 2)授權

[root@localhost mysql]# cd ..

[root@localhost local]# chown -R mysql mysql

[root@localhost local]# chgrp -R mysql mysql

 3)建立編輯my.cnf,鍵入下面內容

 [mysqld]

ndbcluster

ndb-connectstring=192.168.56.103

[mysql_cluster]

ndb-connectstring=192.168.56.103

 2.將/usr/local/mysql檔案夾和/etc/my.cnf拷貝到192.168.56.102上

[root@localhost local]# scp -r ./mysql/* root@192.168.56.102:/usr/local/mysql

The authenticity of host '192.168.56.102 (192.168.56.102)' can't be established.

RSA key fingerprint is 1f:26:d9:20:d1:77:47:bf:3c:7b:64:6d:68:0f:bb:76.

Are you sure you want to continue connecting (yes/no)? yes

Warning: Permanently added '192.168.56.102' (RSA) to the list of known hosts.

root@192.168.56.102's password:

...........

[root@localhost local]# scp -r /etc/my.cnf root@192.168.56.102:/etc/

 3.將/usr/local/mysql檔案夾Copy到192.168.56.103(使用scp命令)

[root@localhost local]# scp -r ./mysql/* root@192.168.56.103:/usr/local/mysql

The authenticity of host '192.168.56.103 (192.168.56.103)' can't be established.

RSA key fingerprint is 1f:26:d9:20:d1:77:47:bf:3c:7b:64:6d:68:0f:bb:76.

Are you sure you want to continue connecting (yes/no)? yes

Warning: Permanently added '192.168.56.103' (RSA) to the list of known hosts.

root@192.168.56.103's password:

 4.在102 & 103授權

[root@localhost ~]# cd /usr/local

[root@localhost local]# chown -R mysql mysql

[root@localhost local]# chgrp -R mysql mysql

 5.組態管理節點(在192.168.56.103上操作)

[root@localhost mysql]# mkdir /var/lib/mysql-cluster

[root@localhost mysql]# chown -R mysql /var/lib/mysql-cluster

[root@localhost mysql]# chgrp -R mysql /var/lib/mysql-cluster

[root@localhost mysql]# cd /usr/local/mysql/

[root@localhost mysql]# vim config.ini

 鍵入下面內容到config.ini中

[ndbd default]

NoOfReplicas=2 # Number of replicas

DataMemory=80M # How much memory to allocate for data storage

IndexMemory=18M # How much memory to allocate for index storage

[tcp default]

portnumber=2202 # This the default; however, you can use any

[ndb_mgmd]

hostname=192.168.56.103 # Hostname or IP address of MGM node

datadir=/var/lib/mysql-cluster # Directory for MGM node log files

[ndbd]

hostname=192.168.56.101 # Hostname or IP address

datadir=/usr/local/mysql/data # Directory for this data node's data files

[ndbd]

hostname=192.168.56.102 # Hostname or IP address

datadir=/usr/local/mysql/data # Directory for this data node's data files

[mysqld]

hostname=192.168.56.101 # Hostname or IP address

[mysqld]

hostname=192.168.56.102 # Hostname or IP address

 四、啟動Mysql Cluster

1.啟動管理節點後台服務(在192.168.56.103上操作)

[root@localhost mysql]# /usr/local/mysql/bin/ndb_mgmd -f /usr/local/mysql/config.ini

 2.啟動管理節點管理服務(在192.168.56.103上操作)

[root@localhost mysql]# /usr/local/mysql/bin/ndb_mgm

 3.查看Mysql Cluster配置資訊(在192.168.56.103上操作)

ndb_mgm> show

Connected to Management Server at: localhost:1186

Cluster Configuration

---------------------

[ndbd(NDB)]     2 node(s)

id=2 (not connected, accepting connect from 192.168.56.101)

id=3 (not connected, accepting connect from 192.168.56.102)

[ndb_mgmd(MGM)] 1 node(s)

id=1    @192.168.56.103  (mysql-5.1.51 ndb-7.1.10)

[mysqld(API)]   2 node(s)

id=4 (not connected, accepting connect from 192.168.56.101)

id=5 (not connected, accepting connect from 192.168.56.102)

 4.啟動資料節點(101 & 102上操作)

[root@localhost local]# /usr/local/mysql/bin/ndbd --initial

 5.啟動SQL節點(101 & 102上操作)

[root@localhost local]# /usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf &

 6.再次查看Mysql Cluster配置資訊(在192.168.56.103上操作)

ndb_mgm> show

Cluster Configuration

---------------------

[ndbd(NDB)]     2 node(s)

id=2    @192.168.56.101  (mysql-5.1.51 ndb-7.1.10, Nodegroup: 0, Master)

id=3    @192.168.56.102  (mysql-5.1.51 ndb-7.1.10, Nodegroup: 0)

[ndb_mgmd(MGM)] 1 node(s)

id=1    @192.168.56.103  (mysql-5.1.51 ndb-7.1.10)

[mysqld(API)]   2 node(s)

id=4    @192.168.56.101  (mysql-5.1.51 ndb-7.1.10)

id=5    @192.168.56.102  (mysql-5.1.51 ndb-7.1.10)

 五、Mysql Cluster測試

1.在101(102)上建立資料庫、表並插入資料

[root@localhost ~]# mysql

…

mysql> show databases;

+--------------------+

| Database           |

+--------------------+

| information_schema |

| mysql              |

| ndb_2_fs           |

| ndbinfo            |

| test               |

+--------------------+

5 rows in set (0.00 sec)

mysql> create database test1;

Query OK, 1 row affected (0.06 sec)

mysql> show databases;

+--------------------+

| Database           |

+--------------------+

| information_schema |

| mysql              |

| ndb_2_fs           |

| ndbinfo            |

| test               |

| test1              |

+--------------------+

6 rows in set (0.00 sec)

mysql> use test1;

Database changed

mysql> create table tb_test(id int) engine=ndb;

Query OK, 0 rows affected (0.36 sec)

mysql> insert into tb_test select 1;

Query OK, 1 row affected (0.06 sec)

Records: 1  Duplicates: 0  Warnings: 0

mysql> select * from tb_test;

+------+

| id   |

+------+

|    1 |

+------+

1 row in set (0.00 sec)

2.在102(101)上查看已有的資料庫、表和表資料

[root@localhost ~]# mysql

…

mysql> show databases;

+--------------------+

| Database           |

+--------------------+

| information_schema |

| mysql              |

| ndb_3_fs           |

| ndbinfo            |

| test               |

| test1              |

+--------------------+

6 rows in set (0.01 sec)

mysql> use test1;

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> select * from tb_test;

+------+

| id   |

+------+

|    1 |

+------+

1 row in set (0.00 sec)

通過測試,至此Mysql Cluster配置成功。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.