熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> MySQL >> 正文

MySQL群集雙機模擬方案

2022-06-13   來源: MySQL 

  硬件配置
  
  普通PC server * (最小集群環境需要台服務器)
  
  模擬環境
  
  red hat linux for x (or red hat AS 以上版本)glibc static gcc
  
  MySQL版本 binares
  
  mysqlmax binary版本目前只支持linuxmax os x和solaris
  
  本方案不涉及從源代碼編譯安裝
  
  主機 IP地址 用途
  
  ndb_mgmd_sqld Ndb node+mgmd node+sqld node
  ndb_sqld Ndb node+sqld node
  
  Mgmd:management server
  sqld:mysql server
  ndb:storaged node (sharenothingbase in memory)
  
  安裝
  
  從下載mysqlmaxpclinuxgnuitargz到/var/tmp
  Storage and SQL Node Installation
  
  在兩台主機上執行如下過程
  
  shell>groupadd mysql
  shell>useradd g mysql mysql
  shell>tar zxfv mysqlmaxpclinuxgnuitargz
  shell>cp vr mysqlmaxpclinuxgnui /usr/local/mysqlmaxpclinuxgnui
  shell>cd /usr/local
  shell>ln s mysqlmaxpclinuxgnui mysql
  shell>cd mysql;scripts/mysql_install_db –user=mysql
  shell>chown R root ;chown R mysql data;chgrp R mysql
  shell>cp supportfiles/mysqlserver /etc/rcd/initd/
  shell>chmod +x /etc/rcd/initd/mysqlserver
  shell>chkconfig add mysqlserver
  shell>chkconfig –level mysqlserver off
  Management Node Installation
  
  在主機ndb_mgmd_sqld上執行如下過程
  
  shell>cd /var/tmp
  shell>tar zxvf mysqlmaxapclinuxgnuitargz /usr/local/bin */bin/ndb_mgm*
  Configuration
  Configuring the Storage and SQL Nodes
  
  在兩台主機上執行如下過程
  
  shell>vi /etc/f
  [MYSQLD]             # Options for mysqld process:
  ndbcluster           # run NDB engine
  ndbconnectstring=  # location of MGM node
  
  [MYSQL_CLUSTER]         # Options for ndbd process:
  ndbconnectstring=  # location of MGM node
  
  Configuring the Management Node
  
  在主機ndb_mgmd_sqld上執行如下過程
  
  shell>mkdir /var/lib/mysqlcluster
  shell>cd /var/lib/mysqlcluster
  shell>vi configini
  [NDBD DEFAULT]   # Options affecting ndbd processes on all data nodes:
  NoOfReplicas=   # Number of replicas
  DataMemory=M   # How much memory to allocate for data storage
  IndexMemory=M  # 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 KB this should be more than enough for
  # this example Cluster setup
  [TCP DEFAULT]
  
  [NDB_MGMD]        # Management process options:
  hostname= # Hostname or IP address of MGM node
  datadir=/var/lib/mysqlcluster  # Directory for MGM node logfiles
  
  [NDBD]             # Options for data node A:
  # (one [NDBD] section per data node)
  HostName=      # Hostname or IP address
  DataDir=/usr/local/mysql/data  # Directory for this data nodes datafiles
  
  [NDBD]             # Options for data node B:
  hostname=      # Hostname or IP address
  datadir=/usr/local/mysql/data  # Directory for this data nodes datafiles
  
  [MYSQLD]             # SQL node options:
  hostname=     # Hostname or IP address
  # Directory for SQL nodes datafiles
  # (additional mysqld connections can be
  # specified for this node for various
  # purposes such as running ndb_restore)
  
  [MYSQLD] # SQL node options:
  hostname=     # Hostname or IP address
  # Directory for SQL nodes datafiles
  # (additional mysqld connections can be
  # specified for this node for various
  # purposes such as running ndb_restore)
  
  第一次啟動
  
  在主機ndb_mgmd_sqld上執行如下過程
  
  shell> ndb_mgmd f /var/lib/mysqlcluster/configini
  
  在兩台主機上執行如下過程
  
  shell>ndbd –initial (note:initial選項只能在第一次啟動的時候使用)
  shell>/etc/initd/mysqlserver start
  
  測試
  
  在主機ndb_mgmd_sqld上執行如下過程
  shell> ndb_mgm
   NDB Cluster Management Client
  ndb_mgm> show
  Connected to Management Server at: localhost:
  Cluster Configuration
  
  [ndbd(NDB)]   node(s)
  id=  @ (Version: Nodegroup: Master)
  id=  @ (Version: Nodegroup: )
  
  [ndb_mgmd(MGM)] node(s)
  id=  @ (Version: )
  
  [mysqld(SQL)]  node(s)
  id=  (Version: )
  
  出現如上信息則表示mysql群集安裝成功
  
  數據抽樣測試
  
  在主機ndb_mgmd_sqld上執行如下過程
  
  shell>/usr/local/mysql/bin/mysql u root test
  MySQL>DROP TABLE IF EXISTS City;
  CREATE TABLE City (
  ID int() NOT NULL auto_increment
  Name char() NOT NULL default
  CountryCode char() NOT NULL default
  District char() NOT NULL default
  Population int() NOT NULL default
  PRIMARY KEY (ID)
  ) ENGINE=NDBCLUSTER;
  
  MySQL>INSERT INTO City VALUES (KabulAFGKabol);
  INSERT INTO City VALUES (QandaharAFGQandahar);
  INSERT INTO City VALUES (HeratAFGHerat);
  
  在主機ndb_sqld上執行如下過程
  
  shell>/usr/local/mysql/bin/mysql u root mysql
  MySQSL>select * from City;
  
  如果成功顯示數據信息則表示集群已經成功啟動
  
  Safe Shutdown and Restart
  
  在主機ndb_mgmd_sqld上執行如下過程
  
  shell>ndb_mgm e shutdown (關閉集群服務器storage node也會自動被關閉)
  
  在兩台主機上執行如下過程
  
  shell>/etc/initd/mysqlserver stop
  
  重新啟動集群(順序不能弄錯)
  
  在主機ndb_mgmd_sqld上執行如下過程
  
  shell> ndb_mgmd f /var/lib/mysqlcluster/configini
  
  在兩台主機上執行如下過程
  
  shell>/usr/local/mysql/bin/ndbd
  
  啟動完ndbd進程後啟動sqld進程
  
  shell>/etc/initd/mysqlserver start
  
  附
  
  configini中各部分解釋
  
  [COMPUTER]: 定義群集主機
  
  [NDBD]: 定義群集數據節點
  
  [MYSQLD]: 定義Sql server節點
  
  [MGM|NDB_MGMD]: Defines the management server node in the cluster
  [TCP]: Defines TCP/IP connections between nodes in the cluster with TCP/IP being the default connection protocol
  [SHM]: Defines sharedmemory connections between nodes 在MySQL 之前這個功能必須使用withndbshm option編譯進去 從MySQL max版本開始 it is enabled by default
From:http://tw.wingwit.com/Article/program/MySQL/201311/29444.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.