mysql叢集的配置

來源:互聯網
上載者:User

標籤:mysql

       最近在 學習MYSQL叢集的配置,首先要瞭解什麼叢集,為什麼要使用叢集,以及安裝叢集的軟體是什麼和叢集中的進程有哪些。

      1.什麼是叢集?

         叢集是一組伺服器提供相同的服務。

        2.為什麼要使用叢集?

         解決單點故障和資料的備份問題。

        作業系統以及mysql設定檔的說明。

            Linux系統:redhat6.5

       安裝叢集軟體: MySQL-Cluster-gpl-7.3.3-1.el6.x86_64.rpm-bundle.tar

       伺服器的角色:

 

        實驗要求:5台伺服器,分別ip地址192.168.1.10做管理節點,192.168.1.20/192.168.1.30做資料節點使資料能夠同時備份當其中任意一台伺服器宕機後,對資料庫進行操作,當宕機的伺服器恢複後自動同步資料,192.168.1.40/192.168.1.50做sql節點當任意一台mysql節點故障後,都可以登陸資料庫。  

         192.168.1.10(mgmd)

               192.168.1.20(ndbd)

         192.168.1.30 (ndbd)

         192.168.1.40 (sql)

         192.168.1.50 (sql)
一。在所有伺服器上安裝提供叢集服務的軟體 mysql-cluster (.rpm  源碼)

最簡單是的PRM包,下面採用二進位包的方法進行安裝

1.解壓軟體包。

 [[email protected] opt]# tar -xvf MySQL-Cluster-gpl-7.3.3-1.el6.x86_64.rpm-bundle.tar
2.安裝軟體包,tar解壓出來的是rpm包,直接安裝就可以。

 [[email protected] opt]# rpm  -Uvh  MySQL-Cluster-*.rpm

3.查看軟體包是否已安裝。

[[email protected] opt]# rpm -qa | grep -i mysql

MySQL-Cluster-shared-compat-gpl-7.3.3-1.el6.x86_64
MySQL-Cluster-devel-gpl-7.3.3-1.el6.x86_64
MySQL-Cluster-embedded-gpl-7.3.3-1.el6.x86_64
perl-DBD-MySQL-4.013-3.el6.x86_64
MySQL-Cluster-test-gpl-7.3.3-1.el6.x86_64
MySQL-Cluster-server-gpl-7.3.3-1.el6.x86_64
MySQL-Cluster-client-gpl-7.3.3-1.el6.x86_64
MySQL-Cluster-shared-gpl-7.3.3-1.el6.x86_64

4.在192.168.1.10上組態管理節點。

    管理節點啟動並執行是管理進程,運行時載入自己的主設定檔,主設定檔需要自己寫。

例如:設定檔為config.ini   設定檔的內容包括:

  1 資料節點的公用配置[ndbd  default]
  2 指定管理節點[ndb_mgmd]
  3 指定資料節點 [ndbd]
  4 指定sql節點  [mysqld]

[[email protected] ~]# vim /etc/config.ini

[ndbd  default]
NoOfReplicas=2 (表示資料節點的份數,有幾個資料節點就寫幾)
DataMemory=80M  (表示資料緩衝的大小)
IndexMemory=18M  (表示索引緩衝的大小)
[ndb_mgmd]
nodeid=1  ( 用來設定當前主機在叢集中的編號)
hostname=192.168.1.10  (指定管理節點的IP地址)
datadir=/var/log/mysql-cluster (指定把運行中的資訊放在/var/log/mysql-cluster,這個檔案夾   必須在系統中存在,如果沒有建立該檔案夾。)
[ndbd]
nodeid=2  (資料節點的編號)
hostname=192.168.1.20 (資料節點的IP地址)
datadir=/var/log/mysql-cluster/data  (儲存資料的位置)
[ndbd]
nodeid=3
hostname=192.168.1.30
datadir=/var/log/mysql-cluster/data
[mysqld]
nodeid=4
hostname=192.168.1.40
[mysqld]
nodeid=5
hostname=192.168.1.50


在192.168.1.10建立/var/log/mysql-cluster檔案夾

[[email protected] ~]# mkdir -p /var/log/mysql-cluster/

5.在192.168.1.20/192.168.1.30上配置資料節點

  在192.168.1.20和192.168.1.30上 分別建立/var/log/mysql-cluster檔案夾用來儲存資料的位置

  [[email protected] ~]# mkdir -p /var/log/mysql-cluster/
建立主設定檔。
 [[email protected] ~]# vim /etc/my.cnf
 [mysqld]
 datadir=/var/log/mysql-cluster/data   (指定資料庫目錄)
 ndb-connectstring=192.168.1.10   (指定串連管理叢集的伺服器IP)
 ndbcluster        (表的儲存引擎必須是ndbcluster)
 [mysql_cluster]   ( 指定管理叢集的機器)
 ndb-connectstring=192.168.1.10(指定誰來管理叢集的伺服器IP)

6.在192.168.1.40/192.168.1.50上配置sql節點
[[email protected] ~]# vim /etc/my.cnf
[mysqld]
ndbcluster
default-storage-engine=ndbcluster     (指定預設的儲存引擎)
ndb-connectstring=192.168.1.10 (指定串連管理叢集的伺服器IP)
[mysql_cluster]
ndb-connectstring=192.168.1.10 (指定誰來管理叢集的伺服器IP)

7.啟動不同角色服務對應進程(有啟動順序,按照以下順序進行啟動)。
    1  啟動管理進程在192.168.1.10上。
[[email protected] ~]# ndb_mgmd -f /etc/config/init        啟動mysql cluster服務
MySQL Cluster Management Server mysql-5.6.14 ndb-7.3.3
  

[[email protected] ~]# netstat -anuptl | grep :1186       查看叢集連接埠是否開啟

tcp        0      0 0.0.0.0:1186                0.0.0.0:*                   LISTEN      4341/ndb_mgmd
tcp        0      0 127.0.0.1:38177             127.0.0.1:1186              ESTABLISHED 4341/ndb_mgmd
tcp        0      0 127.0.0.1:1186              127.0.0.1:38177             ESTABLISHED 4341/ndb_mgmd
tcp        0      0 192.168.1.10:1186           192.168.1.50:43075          ESTABLISHED 4341/ndb_mgmd
tcp        0      0 192.168.1.10:1186           192.168.1.40:37459          ESTABLISHED 4341/ndb_mgmd
  

[[email protected] ~]# 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 (not connected, accepting connect from 192.168.1.20)
id=3 (not connected, accepting connect from 192.168.1.30)

[ndb_mgmd(MGM)] 1 node(s)
id=1    @192.168.1.10  (mysql-5.6.14 ndb-7.3.3)

[mysqld(API)]   2 node(s)
id=4 (not connected, accepting connect from 192.168.1.40)
id=5 (not connected, accepting connect from 192.168.1.50)
   2  啟動192.168.1.20/192.168.1.30上的資料進程
   [[email protected] ~]# ndbd           在192.168.1.20啟動資料進程的命令

2015-07-21 15:49:24 [ndbd] INFO     -- Angel connected to ‘192.168.1.10:1186‘
2015-07-21 15:49:24 [ndbd] INFO     -- Angel allocated nodeid: 2  3 
[[email protected] ~]# ndbd        在192.168.1.30啟動資料進程的命令
2015-07-21 10:16:16 [ndbd] INFO     -- Angel connected to ‘192.168.1.10:1186‘
2015-07-21 10:16:16 [ndbd] INFO     -- Angel allocated nodeid: 3   service mysql start    

  3.啟動完資料進程後在管理節點192.168.1.10上查看資料進程是否已經啟動。

ndb_mgm> show
Cluster Configuration
---------------------
[ndbd(NDB)]     2 node(s)
id=2    @192.168.1.20  (mysql-5.6.14 ndb-7.3.3, starting, Nodegroup: 0, *)
id=3    @192.168.1.30  (mysql-5.6.14 ndb-7.3.3, starting, Nodegroup: 0)

[ndb_mgmd(MGM)] 1 node(s)
id=1    @192.168.1.10  (mysql-5.6.14 ndb-7.3.3)

[mysqld(API)]   2 node(s)
id=4 (not connected, accepting connect from 192.168.1.40)
id=5 (not connected, accepting connect from 192.168.1.50)

ndb_mgm> Node 2: Started (version 7.3.3)
Node 3: Started (version 7.3.3)
  4.在192.168.1.40/192.168.1.50啟動mysql資料庫服務。

[[email protected] ~]# service mysql start
Starting MySQL SUCCESS!

5.啟動完mysql資料庫服務後在管理節點192.168.1.10上查看mysql進程是否已經啟動。

ndb_mgm> show
Cluster Configuration
---------------------
[ndbd(NDB)]     2 node(s)
id=2    @192.168.1.20  (mysql-5.6.14 ndb-7.3.3, Nodegroup: 0, *)
id=3    @192.168.1.30  (mysql-5.6.14 ndb-7.3.3, Nodegroup: 0)

[ndb_mgmd(MGM)] 1 node(s)
id=1    @192.168.1.10  (mysql-5.6.14 ndb-7.3.3)

[mysqld(API)]   2 node(s)
id=4    @192.168.1.40  (mysql-5.6.14 ndb-7.3.3)
id=5    @192.168.1.50  (mysql-5.6.14 ndb-7.3.3)

8.用戶端測試
1.訪問節點的單點故障。
在mysql 資料庫服務上建表建庫,進行查看。

登陸mysql伺服器192.168.1.40/192.168.1.50

[[email protected]~]# cat /root/.mysql_secret
# The random password set for the root user at Mon Jul  6 04:54:27 2015 (local time): umdVqWxz
[[email protected] ~]# mysql -hlocalhost -uroot -pumdVqWxz

mysql>set password for [email protected]=password("123")

mysql>quit

[[email protected] ~]# mysql -hlocalhost -uroot -p123
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.6.14-ndb-7.3.3-cluster-gpl MySQL Cluster Community Server                                                (GPL)

Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved                                               .

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input stateme                                               nt.


 查看儲存引擎預設是不是dbcluster

mysql> show engines;
+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+
| Engine             | Support | Comment                                                        | Transactions | XA   | Savepoints |
+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+
| ndbcluster         | DEFAULT | Clustered, fault-tolerant tables                               | YES          | NO   | NO         |

關閉192.168.1.50上的 mysql服務

  [[email protected] ~]# service mysql stop
查看192.168.1.10上的資訊

ndb_mgm> show
Cluster Configuration
---------------------
[ndbd(NDB)]     2 node(s)
id=2    @192.168.1.20  (mysql-5.6.14 ndb-7.3.3, Nodegroup: 0, *)
id=3    @192.168.1.30  (mysql-5.6.14 ndb-7.3.3, Nodegroup: 0)

[ndb_mgmd(MGM)] 1 node(s)
id=1    @192.168.1.10  (mysql-5.6.14 ndb-7.3.3)

[mysqld(API)]   2 node(s)
id=4    @192.168.1.40  (mysql-5.6.14 ndb-7.3.3)
id=5 (not connected, accepting connect from 192.168.1.50)

用192.168.1.40查看是否可以登陸資料庫,如果可以登陸說明解決單點故障。

[[email protected] ~]# mysql -hlocalhost -uroot -p123
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.14-ndb-7.3.3-cluster-gpl MySQL Cluster Community Server (GPL)

Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.

mysql>

2.資料節點單點故障。(關閉1個資料服務,在表中進行插入,查看等一些操作,當另外一個恢複服務後,看能不能進行同步資料,如果可以說明就解決單點故障)
驗證資料節點單點故障的步驟:

   1.關閉192.168.1.20的資料節點的服務。

[[email protected] ~]# pkill -9 ndbd

   2. 查看管理節點的192.168.1.20的狀態。

 ndb_mgm> show
Cluster Configuration
---------------------
[ndbd(NDB)]     2 node(s)
id=2 (not connected, accepting connect from 192.168.1.20)
id=3    @192.168.1.30  (mysql-5.6.14 ndb-7.3.3, Nodegroup: 0, *)

[ndb_mgmd(MGM)] 1 node(s)
id=1    @192.168.1.10  (mysql-5.6.14 ndb-7.3.3)

[mysqld(API)]   2 node(s)
id=4    @192.168.1.40  (mysql-5.6.14 ndb-7.3.3)
id=5    @192.168.1.50  (mysql-5.6.14 ndb-7.3.3)

     3.在sql節點上查看資料庫的資訊,當192.168.1.20宕機後查看的資訊是192.168.1.30的資訊。

在資料庫上對錶進行select ,insert into 等資訊後,當192.168.1.30恢複後能不能同步資料,如果可以說明可以解決單點故障。

本文出自 “腳踏實地向前行” 部落格,請務必保留此出處http://343614597.blog.51cto.com/7056394/1676946

mysql叢集的配置

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.