程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> MYSQL數據庫 >> MySQL綜合教程 >> MySQL的集群設置裝備擺設的根本敕令應用及一次操作進程實錄

MySQL的集群設置裝備擺設的根本敕令應用及一次操作進程實錄

編輯:MySQL綜合教程

MySQL的集群設置裝備擺設的根本敕令應用及一次操作進程實錄。本站提示廣大學習愛好者:(MySQL的集群設置裝備擺設的根本敕令應用及一次操作進程實錄)文章只能為提供參考,不一定能成為您想要的結果。以下是MySQL的集群設置裝備擺設的根本敕令應用及一次操作進程實錄正文


1. 先懂得一下你能否應當用MySQL集群。

削減數據中間結點壓力和年夜數據量處置,采取把MySQL散布,一個或多個application對應一個MySQL數據庫。把幾個MySQL數據庫公用的數據做出同享數據,例如購物車,用戶對象等等,存在數據結點外面。其他不同享的數據還保持在各自散布的MySQL數據庫自己中。

2015113094520716.png (583×372)

2. 集群MySQL中稱號概念.(如上圖)

1)Sql結點(SQL node--上圖對應為MySQLd):散布式數據庫。包含本身數據和查詢中間結點數據.

2)數據結點(Data node -- ndbd):集群同享數據(內存中).

3)治理辦事器(Management Server – ndb_mgmd):集群治理SQL node,Data node.

3.設置裝備擺設

MySQL-max版本,固然如今MySQL集群體系windonws平台下面不被支撐.

裝置MySQL就不多說了,網上一年夜堆,長篇大論。

  • A:192.168.1.251 – Data node和Management Server.
  • B:192.168.1.254 – SQL node.

固然,你也能夠讓一個機械同時為3者。

A,B my.inf加上:

[MySQLD]             
ndbcluster           # run NDB engine 
ndb-connectstring=192.168.1.251 # location of MGM node 
  
# Options for ndbd process: 
[MySQL_CLUSTER]         
ndb-connectstring=192.168.1.251 # location of MGM node 
  
A: /var/lib/MySQL-cluster/config.ini 
[NDBD DEFAULT]   
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. 
# TCP/IP options: 
[TCP DEFAULT]   
portnumber=2202 # This the default; however, you can use any 
         # port that is free for all the hosts in cluster 
         # Note: It is recommended beginning with MySQL 5.0 that 
         # you do not specify the portnumber at all and simply allow 
         # the default value to be used instead 
# Management process options: 
[NDB_MGMD]            
hostname=192.168.1.251     # Hostname or IP address of MGM node 
datadir=/var/lib/MySQL-cluster # Directory for MGM node logfiles 
# Options for data node "A": 
[NDBD]              
# (one [NDBD] section per data node) 
hostname=192.168.1.251     # Hostname or IP address 
datadir=/usr/local/MySQL/data # Directory for this data node's datafiles 
# SQL node options: 
[MySQLD] 
hostname=192.168.1.254 
#[MySQLD] #這個相當於192.168.1.251 

 
4. 啟動測試

在治理辦事器下面(這裡是192.168.1.251):

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

在數據結點辦事器下面(仍然是192.168.1.251and more):

shell>ndbd--initial 

 (第一次時加--initial參數)
SQL結點辦事器下面(192.168.1.254):

shell>MySQLd & 

在251下面觀察

./ndb_mgm 

 

-- NDB Cluster -- Management Client -- 
ndb_mgm> show 
Connected to Management Server at: 192.168.1.251:1186 
Cluster Configuration 
--------------------- 
[ndbd(NDB)]  1 node(s) 
id=2  @192.168.1.251 (Version:5.0.22, Nodegroup: 0, Master) 
  
[ndb_mgmd(MGM)] 1 node(s) 
id=1  @192.168.1.251 (Version:5.0.22) 
  
[MySQLd(API)] 1 node(s) 
id=3  @192.168.1.254 (Version:5.0.22) 
ok

封閉集群:

shell>ndb_mgm -e shutdown 

5.根本的集群解釋

1)在MySQL集群中.當table引擎為NDBCLUSTER時才做集群,其他非NDBCLUSTER表和普通MySQL數據庫表一樣,不會同享數據. NDBCLUSTER表數據存儲在Data node辦事器內存中,Data Node可認為1台或多台辦事器,它們之間寄存同享數據。Data Node辦事器可以分組數據copy。

例如:2,3,4,5為四台Data Node辦事器ID. 2,3為組0。 4,5為組1。 2,3保持數據雷同,4,5保持數據雷同。 組0和組1保持數據分歧。

2)sql node辦事器中,非NDBCLUSTER數據存在自己數據庫中,table引擎為NDBCLUSTER時,數據存儲在Data Node中。當查詢NDBCLUSTER表時,它會從Data node集群中提起數據.

3)Manager server

治理SQl node和Data node狀況。

附:MySQL集群設置裝備擺設具體進程錄制
1、預備三台linux辦事器(三台機械停止以下設置裝備擺設)
--hostname設置裝備擺設
192.168.9.241    sqltest01   (mysqld及存儲節點)
192.168.9.242    sqltest02   (mysqld及存儲節點)
192.168.9.243    sqltest03
個中,sqltest01、sqltest02分離是mysql節點及存儲節點,sqltest03為治理節點
--同時,把防火牆停止封閉或許把相干的端口翻開,如3306,治理節點的1186等

[root@sqltest01 u01]# service iptables status
iptables: Firewall is not running.

假如開啟的,請應用service iptables stop
--創立響應的用戶及目次

[root@sqltest01 u01]# groupadd mysql
[root@sqltest01 u01]# useradd -r -g mysql mysql
[root@sqltest01 u01]# mkdir -p /usr/local/mysql
[root@sqltest01 u01]# chown -R mysql.mysql

2、mysql cluster
下載網址:dev.mysql.com,然後選擇cluster,然後在網頁中湧現的選擇平台中,選擇linux generic!在這裡選擇所須要tar包,我這裡用的是mysql-cluster-gpl-7.3.7-linux-glibc2.5-x86_64.tar.gz
下載完成後,應用ftp傳送到辦事器下面,然後分離在三台機械上解壓

[root@sqltest01 u01]# tar -zxvf mysql-cluster-gpl-7.3.7-linux-glibc2.5-x86_64.tar.gz
mysql-cluster-gpl-7.3.7-linux-glibc2.5-x86_64/mysql-test/include/have_plugin_auth.inc
mysql-cluster-gpl-7.3.7-linux-glibc2.5-x86_64/mysql-test/include/kill_query.inc
mysql-cluster-gpl-7.3.7-linux-glibc2.5-x86_64/mysql-test/include/unsafe_binlog.inc
mysql-cluster-gpl-7.3.7-linux-glibc2.5-x86_64/mysql-test/include/have_multi_ndb.inc
mysql-cluster-gpl-7.3.7-linux-glibc2.5-x86_64/mysql-test/include/ipv6_clients.inc
mysql-cluster-gpl-7.3.7-linux-glibc2.5-x86_64/mysql-test/include/setup_fake_relay_log.inc
mysql-cluster-gpl-7.3.7-linux-glibc2.5-x86_64/mysql-test/include/wait_for_slave_sql_error_and_skip.inc
......................................................................................................

解壓後,外面包含了數據庫文件和集群軟件
3、設置裝備擺設治理節點(sqltest03)
--將適才解壓的軟件拷貝到指定地位/usr/local/mysql

[root@sqltest03 mysql-cluster-gpl-7.3.7-linux-glibc2.5-x86_64]# pwd
/u01/mysql-cluster-gpl-7.3.7-linux-glibc2.5-x86_64
[root@sqltest03 mysql-cluster-gpl-7.3.7-linux-glibc2.5-x86_64]# mv * /usr/local/mysql/

--創立集群目次

[root@sqltest03 u01]# cd /usr/local/mysql
[root@sqltest03 mysql]# mkdir mysql-cluster
[root@sqltest03 mysql]# pwd
/usr/local/mysql
[root@sqltest03 mysql]# cp bin/ndb_mgm* /usr/local/bin/
[root@sqltest03 mysql]# cd /var/lib
[root@sqltest03 mysql]# mkdir mysql-cluster
[root@sqltest03 mysql]# cd mysql-cluster
[root@sqltest03 mysql]# vi config.ini

設置裝備擺設內容以下:

[root@sqltest03 mysql-cluster]# cat config.ini 
[ndbd default]
NoOfReplicas=1
DataMemory=2048M
IndexMemory=512M
[tcp default]
[ndb_mgmd]
hostname=192.168.9.243
datadir=/var/lib/mysql-cluster
NodeId=1
[ndbd]
hostname=192.168.9.241
datadir=/u01/mysql/data
NodeId=2
[ndbd]
hostname=192.168.9.242
datadir=/u01/mysql/data
NodeId=3
[mysqld]
hostname=192.168.9.241
NodeId=4
[mysqld]
hostname=192.168.9.242
NodeId=5

設置裝備擺設解釋:
[ndbd default]
這部門是公共部門,關於每個數據節點都有用,只須要設置裝備擺設一份
NoOfReplicas=1
數據鏡像幾份(各數據節點之間互相備份)
[tcp default]
針對每一個數據節點及治理節點之間應用哪一個端口停止通信,在舊版本的NDB集群軟件設置裝備擺設時,這個處所平日設置裝備擺設portnumber=2202但新版的NDB軟件這裡不須要設置裝備擺設,而且MySQL官方也激烈建議不要設置裝備擺設
[ndb_mgmd]
治理節點的設置裝備擺設部門(平日只要一個)。留意NodeId=1指明治理節點的節點ID為1,假如不指定,在啟動集群時,會報錯
hostname=192.168.9.243
指明治理節點的IP地址
datadir=/var/lib/mysql-cluster
指明集群治理日記寄存的地位
[ndbd]
數據節點設置裝備擺設部門,有幾個數據節點就設置裝備擺設幾個[ndbd]
hostname=192.168.1.111
指明數據節點的IP地址
datadir=/u01/app/mysql/data
指明數據節點上的數據庫文件寄存的地位
NodeId=2
指明該數據節點在全部集群中的nodeid號(很主要)
[mysqld]
SQL節點設置裝備擺設部門,有幾個SQL節點,就設置裝備擺設幾個[mysqld]
到這裡,便可以啟動集群了

[root@sqltest03 bin]# pwd
/usr/local/bin
[root@sqltest03 bin]# ./ndb_mgmd -f /var/lib/mysql-cluster/config.ini
MySQL Cluster Management Server mysql-5.6.21 ndb-7.3.7

進入履行檢查

[root@sqltest03 bin]# 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.9.241)
id=3 (not connected, accepting connect from 192.168.9.242)
[ndb_mgmd(MGM)] 1 node(s)
id=1  @192.168.9.243 (mysql-5.6.21 ndb-7.3.7)
[mysqld(API)]  2 node(s)
id=4 (not connected, accepting connect from 192.168.9.241)
id=5 (not connected, accepting connect from 192.168.9.242)

可以看到有兩個節點,節點沒有銜接上
4、設置裝備擺設mysqld節點及存儲節點(sqltest01,sqltest02)
--樹立響應目次

[root@sqltest01 mysql]# mkdir -p /usr/local/mysql  --用於寄存適才解壓的文件,如mysql的bin目次等
[root@sqltest01 mysql]# mkdir -p /u01/mysql/data --用於存儲數據文件(innodb)
[root@sqltest01 mysql]# chown -R mysql.mysql /u01

--將先前解壓的文件拷貝

[root@sqltest01 mysql-cluster-gpl-7.3.7-linux-glibc2.5-x86_64]# pwd
/u01/mysql-cluster-gpl-7.3.7-linux-glibc2.5-x86_64
[root@sqltest01 mysql-cluster-gpl-7.3.7-linux-glibc2.5-x86_64]# mv * /usr/local/mysql/
[root@sqltest01 mysql]# chown -R mysql.mysql /usr/local/mysql/

--拷貝mysql.server

[root@sqltest01 support-files]# pwd
/usr/local/mysql/support-files
[root@sqltest01 support-files]# ls -lrt
total 32
-rw-r--r--. 1 mysql mysql  773 Oct 9 21:46 magic
-rwxr-xr-x. 1 mysql mysql 10880 Oct 9 22:42 mysql.server
-rwxr-xr-x. 1 mysql mysql  894 Oct 9 22:42 mysql-log-rotate
-rwxr-xr-x. 1 mysql mysql 1061 Oct 9 22:42 mysqld_multi.server
-rw-r--r--. 1 mysql mysql 1126 Oct 9 22:42 my-default.cnf
-rwxr-xr-x. 1 mysql mysql 1153 Oct 9 22:42 binary-configure
[root@sqltest01 support-files]# cp mysql.server /etc/rc.d/init.d/mysqld

--編纂情況變量

[root@sqltest01 tmp]# vi /etc/profile

添加以下:

PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH
export PATH
[root@sqltest01 tmp]# source /etc/profile 

   --使修正失效
--設置裝備擺設my.cnf

[root@sqltest01 support-files]# cp my-default.cnf /etc/my.cnf

並對my.cnf停止設置裝備擺設,詳細設置裝備擺設以下

[mysqld]
ndbcluster
basedir=/usr/local/mysql
datadir=/u01/mysql/data
port=3306
[mysql_cluster]
ndb-connectstring=192.168.9.243

--初始化節點數據庫

[root@sqltest01 mysql]# scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/u01/mysql/data

履行完這條敕令今後,數據庫的數據文件(包含mysql,test , performance_schema等數據庫),就裝置到響應的地位了,可使用了
在兩個節點都履行下面的步調便可
5、在兩個點啟動

[root@sqltest01 mysql]# ndbd --initial
2014-12-24 17:55:57 [ndbd] INFO   -- Angel connected to '192.168.9.243:1186'
2014-12-24 17:55:57 [ndbd] INFO   -- Angel allocated nodeid: 2

第一次啟動時,須要加--initial來初始化數據節點,第二次啟動時,就不須要這個參數了
在治理節點檢查,可以看到第一個節點曾經銜接

ndb_mgm> show
Cluster Configuration
---------------------
[ndbd(NDB)]   2 node(s)
id=2  @192.168.9.241 (mysql-5.6.21 ndb-7.3.7, starting, Nodegroup: 0)  --注解曾經銜接上了
id=3 (not connected, accepting connect from 192.168.9.242)
[ndb_mgmd(MGM)] 1 node(s)
id=1  @192.168.9.243 (mysql-5.6.21 ndb-7.3.7)
[mysqld(API)]  2 node(s)
id=4 (not connected, accepting connect from 192.168.9.241)
id=5 (not connected, accepting connect from 192.168.9.242)

啟動mysqld

[root@sqltest01 mysql]# cd /usr/local/mysql/bin
[root@sqltest01 bin]# ./mysqld_safe --user=mysql
141224 17:59:50 mysqld_safe Logging to '/u01/mysql/data/sqltest01.err'.
141224 17:59:51 mysqld_safe Starting mysqld daemon with databases from /u01/mysql/data

啟動數據庫時,第一次初始化應用的root,而此次應用mysql,須要對/u01/mysql/data權限停止設置裝備擺設,不然報弗成讀寫
再次在治理節點檢查

ndb_mgm> show
Cluster Configuration
---------------------
[ndbd(NDB)]   2 node(s)
id=2  @192.168.9.241 (mysql-5.6.21 ndb-7.3.7, Nodegroup: 0, *)
id=3 (not connected, accepting connect from 192.168.9.242)
[ndb_mgmd(MGM)] 1 node(s)
id=1  @192.168.9.243 (mysql-5.6.21 ndb-7.3.7)
[mysqld(API)]  2 node(s)
id=4  @192.168.9.241 (mysql-5.6.21 ndb-7.3.7)   

                  --注解曾經銜接上了
最初把第二節點也啟動,再次從治理節點檢討

ndb_mgm> show
Cluster Configuration
---------------------
[ndbd(NDB)]   2 node(s)
id=2  @192.168.9.241 (mysql-5.6.21 ndb-7.3.7, Nodegroup: 0, *)
id=3  @192.168.9.242 (mysql-5.6.21 ndb-7.3.7, Nodegroup: 1)
[ndb_mgmd(MGM)] 1 node(s)
id=1  @192.168.9.243 (mysql-5.6.21 ndb-7.3.7)
[mysqld(API)]  2 node(s)
id=4  @192.168.9.241 (mysql-5.6.21 ndb-7.3.7)
id=5  @192.168.9.242 (mysql-5.6.21 ndb-7.3.7)

6、在兩個節點測試

[root@sqltest01 ~]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.21-ndb-7.3.7-cluster-gpl MySQL Cluster Community Server (GPL)
Copyright (c) 2000, 2014, 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> create database mydb1;
Query OK, 1 row affected (0.07 sec)
mysql> use mydb1;
Database changed
mysql> create table mytb1(id int,birthdate datetime,pername char(10)) engine=ndbcluster;
Query OK, 0 rows affected (0.19 sec)

mysql> insert into mytb1(id,birthdate,pername) values(1,'2013-01-23 09:45:10','pengzitong');
Query OK, 1 row affected (0.00 sec)
mysql> commit;
Query OK, 0 rows affected (0.00 sec)
mysql> insert into mytb1(id,birthdate,pername) values(2,'2007-07-09 09:45:10','pengzixin');
Query OK, 1 row affected (0.00 sec)
mysql> commit;
Query OK, 0 rows affected (0.00 sec)

在第二節點檢討

[root@sqltest02 ~]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.21-ndb-7.3.7-cluster-gpl MySQL Cluster Community Server (GPL)
Copyright (c) 2000, 2014, 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> use mydb1
mysql> select * from mytb1;
+------+---------------------+------------+
| id  | birthdate      | pername  |
+------+---------------------+------------+
|  1 | 2013-01-23 09:45:10 | pengzitong |
|  2 | 2007-07-09 09:45:10 | pengzixin |
+------+---------------------+------------+

7、集群停滯
要想封閉 Cluster,可在MGM節點地點的機械上,在Shell中簡略地輸出下述敕令:

[root@sqltest03 bin]# /usr/local/mysql/ndb_mgm -e shutdown

運轉以下敕令封閉SQL節點的mysqld辦事:

[root@sqltest01 bin]# /usr/local/mysql/bin/mysqladmin -uroot shutdown

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved