mysql-cluster 安裝配置

來源:互聯網
上載者:User

標籤:mysql cluster

mysql-cluster免編譯包下載:https://dev.mysql.com/downloads/file/?id=469881


wget https://cdn.mysql.com//Downloads/MySQL-Cluster-7.5/mysql-cluster-gpl-7.5.6-linux-glibc2.5-x86_64.tar.gz


解壓:

# tar xvf mysql-cluster-gpl-7.5.6-linux-glibc2.5-x86_64.tar.gz

# mv xvf mysql-cluster-gpl-7.5.6-linux-glibc2.5-x86_64 /soft/mysql


給mysql-cluster目錄授權

#useradd -s mysql /sbin/nologin

# mkdir /soft/mysql/data

# chown -R mysql:mysql /soft/mysql/*

# chmod +x /soft/mysql/bin/ndb_mem*

# cd /soft/mysql/

# ln -s /soft/mysql/bin/ndb_mgmd   /sbin/ndb_mgmd     #方便在shell直接調用ndb_mgmd命令

# ln -s /soft/mysql/bin/ndb_mgm   /sbin/ndb_mgm      #方便在shell直接調用ndb_mgm命令      

建立config.ini檔案

# vim config.ini                     #內容如下,一定要注意格式。從windows複製過來的話記得用uft8編碼


[NDBD DEFAULT]


NoOfReplicas=2                      #每個資料節點的鏡像數量


DataMemory=500M                 #每個資料節點中給資料分配的記憶體


IndexMemory=300M                 #每個資料節點中給索引分配的記憶體


[NDB_MGMD]                     #組態管理節點,[]後面不能有空格,也不能有注釋


hostname=192.168.240.130

datadir=/soft/mysql/data           #管理節點資料(日誌)目錄


[NDBD]                       #資料節點配置,[]後面不能有空格,也不能有注釋


hostname=192.168.240.129

datadir=/soft/mysql/data 


[NDBD]


hostname=192.168.240.127

datadir=/soft/mysql/data


[MYSQLD]                     #SQL節點目錄,[]後面不能有空格,也不能有注釋


hostname=192.168.240.129


[MYSQLD]


hostname=192.168.240.128

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

[[email protected] mysql]# ./bin/ndb_mgmd -f config.ini      #啟動服務

MySQL Cluster Management Server mysql-5.7.18 ndb-7.5.6   #啟動成功


[[email protected] mysql]# ./bin/ndb_mgm                #進入管理程式,可以看到設定檔生效了,但因為沒配置節點上的mysql,所以這裡顯示未串連

-- 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.240.129)

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


[ndb_mgmd(MGM)]1 node(s)

id=1@192.168.240.130  (mysql-5.7.18 ndb-7.5.6)


[mysqld(API)]2 node(s)

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

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


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

配置節點: 192.168.240.128/192.168.240.129


[[email protected]]# useradd -s /sbin/nologin mysql

[[email protected]]# mkdir /soft/mysql

[[email protected]]# tar xf mysql-cluster-gpl-7.5.6-linux-glibc2.5-x86_64.tar.gz 

[[email protected]]# mkdir /soft/mysql/data

[[email protected]]# chown -R mysql:mysql /soft/mysql

[[email protected]]# cd /soft/mysql

[[email protected] mysql]# yum install -y libaio*

vim support-files/mysql.server    #修改服務檔案

basedir=/soft/mysql

datadir=/soft/mysql/data


[[email protected] mysql]# bin/mysqld  --initialize --user=mysql --basedir=/soft/mysql --datadir=/soft/mysql/data

./bin/mysqld --initialize --user=mysql --datadir=/soft/mysql/data      --注意自動產生的臨時密碼


[Note] A temporary password is generated for [email protected]: pByj>rz95OhV

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

先更改密碼:


[[email protected] mysql]# bin/mysql -u root -p‘pByj>rz95OhV‘        --登入mysql,有特殊符號,要用‘‘括起來,在這裡踏坑了

mysql> use mysql;                                --必須先更改密碼才可以操作

ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

mysql> alter user ‘root‘@‘localhost‘ identified by ‘123456‘;

Query OK, 0 rows affected (0.00 sec)


[[email protected]]# vim /etc/my.cnf

[mysqld]

datadir=/soft/mysql/data

user=mysql

ndbcluster

lc_messages-dir=/soft/mysql/share/

ndb-connectstring=192.168.240.130

 

[mysql_cluster]

ndb-connectstring=192.168.240.130

 

[[email protected]]# bin/ndbd --initial      #第一次使用要初始化資料,下次不能加--initial,否則會清空資料庫

[[email protected]]# ln -s /soft/mysql/bin /sbin/mysql

[[email protected]]# ln -s /soft/mysql/support-files/mysql.server  /sbin/mysqld


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

回到130控制台:


ndb_mgm> show

Cluster Configuration

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

[ndbd(NDB)]2 node(s)

id=2@192.168.61.128  (mysql-5.7.18 ndb-7.5.6, starting, Nodegroup: 0)  --節點ndbd已串連

id=3@192.168.61.129  (mysql-5.7.18 ndb-7.5.6, starting, Nodegroup: 0) --節點ndbd已串連


[ndb_mgmd(MGM)]1 node(s)

id=1@192.168.61.130  (mysql-5.7.18 ndb-7.5.6)


[mysqld(API)]2 node(s)

[mysqld(API)]2 node(s)

id=4@192.168.61.128  (mysql-5.7.18 ndb-7.5.6)                  #小心防火牆

id=5@192.168.61.129  (mysql-5.7.18 ndb-7.5.6)                  #小心防火牆


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

測試:

建庫/建表

在192.168.61.128上登入mysql:

mysql>create databases abc charset=gbk;

Query OK, 0 rows affected (0.72 sec)

mysql>create table name(id int(5) not null primary key auto_increment,name varchar(10) not null ) engine=ndb;

Query OK, 0 rows affected (0.72 sec)

mysql>insert into name(name) values (‘張三‘),(‘李四‘);


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

在192.168.240.128/192.168.240.129 進行查詢

mysql>select * from tp.name;

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

| id | name   |

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

|  1 | 張三   |

|  2 | 李四   |

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


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

類比192.168.240.128/192.168.240.129故障之一失效,再查詢

mysql>select * from tp.name;


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

| id | name   |

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

|  1 | 張三   |

|  2 | 李四   |

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

mysql>insert into name(name) values (‘長江‘),(‘黃河‘);

Query OK, 0 rows affected (0.72 sec)

mysql> select * from tp.name group by id;

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

| id | name   |

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

|  1 | 長江   |

|  2 | 黃河   |

|  3 | 張三   |

|  4 | 李四   |

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

4 rows in set (0.01 sec)


經過測試總結幾點:

  1. 當cluster掛了後,兩個資料節點的mysql都不能訪問資料庫;

  2. 當cluster掛了時,兩個mysql還是可以正常工作的,更新資料也會同步,但不能重啟mysql服務;

2.只要不是兩個mysql服務同時掛了,資料還是安全的。

3.當cluster掛掉,節點A掛掉,這時往節點B上更新資料;cluster和節點A恢複上線後會造成節點A和節點B的資料不一致。

4.當兩個mysql資料不一致時,先啟動cluster,再啟動資料更新的資料節點和SQL節點,確保已經成功連上cluster,最後再啟動另一個節點,後一個節點會自動更新最新的資料。!!啟動順序很重要!!!


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


啟動順序:

管理節點 ndb_megd -> 資料節點 ndbd -> SQL節點 指定ndbcluster 參數的專用mysqld

     ndb_mgmd -f config.ini -> ndbd -> mysqld start 


關閉順序:

SQL節點 指定ndbcluster 參數的專用mysqld ->  管理節點 ndb_mem

      mysqld stop --> ndb_mgm -e shutdown --> 完成



附:


1. mysqld --initialize-insecure自動產生無密碼的root使用者,mysqld --initialize自動產生帶隨機密碼的root使用者


2.用mysql帳號設定的話需要在 /etc/security/limits.conf 中追加下面資訊,不然會提示limite限制錯誤:

mysql   hard   nofile   65535


3.[ERROR] Can‘t find error-message file ‘/usr/local/mysql/share/zh-cn/errmsg.sys‘. Check error-message file location and ‘lc-messages-dir‘ configuration directive.

在my.cnf裡添加行:

lc_messages-dir=/soft/mysql/share/


4.啟動mysql時,可能會提示:ERROR 2002 (HY000): Can‘t connect to local MySQL server through socket ‘/tmp/mysql.sock‘ (111)


ln -s /soft/mysql/mysql.sock  /tmp/mysql.sock             #要用絕對路徑



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.