MySQL Cluster dual-host simulation solution _ MySQL

Source: Internet
Author: User
Hardware configuration common PCserver * 2 (minimum cluster environment requires 4 servers) simulation environment redhatlinux9forx86 (orredhatAS2 or later), glibc-2.2, static, gccMySQL version 4.1.12binaresmysql-maxbinary currently only supports linux, maxosx, and solaris. this solution does not involve compiling and installing host hardware configurations from source code.
  
Common PC server x 2 (the minimum cluster environment requires four servers)
  
Simulated Environment
  
Red hat linux9 for x86 (or red hat AS 2 or later), glibc-2.2, static, gcc
  
MySQL 4.1.12 binares
  
Mysql-max binary currently only supports linux, max OS x, and solaris
  
This solution does not involve compilation and installation from source code.
  
Host IP address usage
  
Ndb1_mgmd_sqld 1194251.100 Ndb node1 + mgmd node1 + sqld node1
Ndb2_sqld2 192.168.1.200 Ndb node2 + sqld node2
  
Mgmd: management server
Sqld: mysql server
Ndb: storaged node (share-nothing, base in memory)
  
Install
  
Slave
Storage and SQL Node Installation
  
Execute the following process on the two hosts:
  
Shell> groupadd mysql
Shell> useradd-g mysql
Shell> tar zxfv mysql-max-4.1.12-pc-linux-gnu-i686.tar.gz.
Shell> cp-vr mysql-max-4.1.12-pc-linux-gnu-i686/usr/local/mysql-max-4.1.12-pc-linux-gnu-i686
Shell> cd/usr/local
Shell> ln-s mysql-max-4.1.12-pc-linux-gnu-i686 mysql
Shell> cd mysql; scripts/mysql_install_db-user = mysql
Shell> chown-R root.; chown-R mysql data; chgrp-R mysql.
Shell> cp support-files/mysql. server/etc/rc. d/init. d/
Shell> chmod + x/etc/rc. d/init. d/mysql. server
Shell> chkconfig -- add mysql. server
Shell> chkconfig-level 3 mysql. server off
Management Node Installation
  
Run the following procedure on the ndb1_mgmd_sqld1 host:
  
Shell> cd/var/tmp
Shell> tar-zxvf mysql-max-4.1.12a-pc-linux-gnu-i686.tar.gz/usr/local/bin '*/bin/ndb_mgm *'
Configuration
Refreshing the Storage and SQL Nodes
  
Execute the following process on the two hosts:
  
Shell> vi/etc/my. cnf
[MYSQLD] # Options for mysqld process:
Ndbcluster # run NDB engine
Ndb-connectstring = 192.168.1.100 # location of MGM node
  
[MYSQL_CLUSTER] # Options for ndbd process:
Ndb-connectstring = 192.168.1.100 # location of MGM node
  
Processing the Management Node
  
Run the following procedure on the ndb1_mgmd_sqld1 host:
  
Shell> mkdir/var/lib/mysql-cluster
Shell> cd/var/lib/mysql-cluster
Shell> vi config. ini
[Ndbd default] # Options affecting ndbd processes on all data nodes:
NoOfReplicas = 2 # Number of replicas
DataMemory = 80 M # How much memory to allocate for data storage
IndexMemory = 52 M # How much memory to allocate for index storage
# For DataMemory and IndexMemory, we have used
# Default values. Since the "world" database takes up
# Only about 500KB, this shoshould be more than enough
# This example Cluster setup.
[Tcp default]
  
[NDB_MGMD] # Management process options:
Hostname = 192.168.1.100 # Hostname or IP address of MGM node
Datadir =/var/lib/mysql-cluster # Directory for MGM node logfiles
  
[NDBD] # Options for data node "":
# (One [NDBD] section per data node)
HostName = 192.168.1.100 # Hostname or IP address
DataDir =/usr/local/mysql/data # Directory for this data node's datafiles
  
[NDBD] # Options for data node "B ":
Hostname = 192.168.1.200 # Hostname or IP address
Datadir =/usr/local/mysql/data # Directory for this data node's datafiles
  
[MYSQLD] # SQL node options:
Hostname = 192.168.1.100 # Hostname or IP address
# Directory for SQL node's datafiles
# (Additional mysqld connections can be
# Specified for this node for various
# Purposes such as running ndb_restore)
  
[MYSQLD] # SQL node options:
Hostname = 192.168.1.200 # Hostname or IP address
# Directory for SQL node's datafiles
# (Additional mysqld connections can be
# Specified for this node for various
# Purposes such as running ndb_restore)
  
Start for the first time
  
Run the following procedure on the ndb1_mgmd_sqld1 host:
  
Shell> ndb_mgmd-f/var/lib/mysql-cluster/config. ini
  
Execute the following process on the two hosts:
  
Shell> ndbd-initial (note: -- initial option can only be used at the first startup)
Shell>/etc/init. d/mysql. server start
  
Test
  
Run the following procedure on the ndb1_mgmd_sqld1 host:
Shell> 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 @ 192.168.0.100 (Version: 4.1.12, Nodegroup: 0, Master)
Id = 3 @ 192.168.0.200 (Version: 4.1.12, Nodegroup: 0)
  
[Ndb_mgmd (MGM)] 1 node (s)
Id = 1 @ 192.168.0.100 (Version: 4.1.12)
  
[Mysqld (SQL)] 1 node (s)
Id = 4 (Version: 4.1.12)
  
If the preceding information is displayed, the mysql Cluster is successfully installed.
  
Data sampling test
  
Run the following procedure on the ndb1_mgmd_sqld1 host:
  
Shell>/usr/local/mysql/bin/mysql-u root test
MySQL> drop table if exists City;
Create table City (
ID int (11) not null auto_increment,
Name char (35) not null default '',
CountryCode char (3) not null default '',
District char (20) not null default '',
Population int (11) not null default '0 ',
Primary key (ID)
) ENGINE = NDBCLUSTER;
  
MySQL> insert into City VALUES (1, 'Kabul ', 'afg', 'kabol', 1780000 );
Insert into City VALUES (2, 'qandahar ', 'afg', 'qandahar', 237500 );
Insert into City VALUES (3, 'hat', 'afg', 'hat', 186800 );
  
Run the following procedure on ndb2_sqld2
  
Shell>/usr/local/mysql/bin/mysql-u root mysql
MySQSL> select * from City;
  
If data is successfully displayed, the cluster is successfully started.
  
Safe Shutdown and Restart
  
Run the following procedure on the ndb1_mgmd_sqld1 host:
  
Shell> ndb_mgm-e shutdown (shut down the cluster server, and the storage node is also automatically disabled)
  
Execute the following process on the two hosts:
  
Shell>/etc/init. d/mysql. server stop
  
Restart the cluster (the order cannot be wrong)
  
Run the following procedure on the ndb1_mgmd_sqld1 host:
  
Shell> ndb_mgmd-f/var/lib/mysql-cluster/config. ini
  
Execute the following process on the two hosts:
  
Shell>/usr/local/mysql/bin/ndbd
  
Start the sqld process after the ndbd process is started
  
Shell>/etc/init. d/mysql. server start
  
Appendix:
  
Description of each part in config. ini
  
[COMPUTER]: defines the cluster host.
  
[NDBD]: defines the cluster data node.
  
[MYSQLD]: defines SQL server nodes.
  
[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 shared-memory connections between nodes. before MySQL 4.1.9, this function must be compiled using -- with-ndb-shm option. from MySQL 4.1.9-max, it is enabled by default.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.