MySQL-Cluster architecture graphic description _ MySQL

Source: Internet
Author: User
Tags localhost mysql mysql view
MySQL-Cluster architecture

MySQL-ClusterArchitecture graphic explanation

Stan, June 1/6/7

Preface:

This is my first time in contact with Linux, CentOS, and MySQL. after five days, I finally succeeded in the MySQL-Cluster architecture based on CentOS5.0. I will share my experiences with you. If you find any errors and negligence, please mail me: stan_home@qq.com.

(PDF text version please download, address: http://download.csdn.net/source/3365704)

Before configuration, add some common Linux commands:

Ls browsing

Ls-l permission to view folders and files

Vi text editor (search and edit)

I status is modified

Exit: "Esc", enter ":", and then enter "wq" to write and exit

: Q! Force exit

Vim-f [file name] Force file recovery

Cp file copy command

Rm delete File

Create a folder using mkdir

Ln connection price or directory

Man [command] view command parameters

Ifconfig Nic Information Command

Dig (domain information searcher)

Df View system files

Vmstat system status

Ps to view the process (-e to show all,-f to output in full format)

Ps-ef | grep mysql view all mysql processes

Tips: enter a file or file name. press the Tab key to automatically change the file name (provided that the file or folder must exist );

For example:

Input

[Root @ localhost tmp] # tar-xzvf mysql-c

Press the Tab key to automatically complete the operation:

[Root @ localhost tmp] # tar-xzvf mysql-cluster-gpl-7.1.13-linux-i686-glibc23.tar.gz

Let's build the architecture together!

1. configure the environment:

OS: Linux CentOS 5.0

MySQL: mysql-cluster-gpl-7.1.13-linux-i686-glibc23.tar.gz (note: Cluster version is required, you can download the http://dev.mysql.com/downloads/cluster/#downloads on the official website)

Node configuration:

MGM: 192.168.20.231

NDBD1: 192.168.20.133

NDBD2: 192.168.20.233

SQL1: 192.168.0000234

SQL2: 192.168.20.235

Modify CentOS IP address

(1) open the/etc/sysconfig/network-scripts/ifcfg-eth0 file and make the following changes

# Intel Corporation 82545EM Gigabit Ethernet Controller (Copper)

DEVICE = eth0

BOOTPROTO = static

ONBOOT = yes

HWADDR = 00: 0c: 29: be: b3: 53

IPADDR = 192.168.20.231

NETMASK = 255.255.255.0

GATEWAY = 192.168.20.1

(2) modify the/etc/resolv. conf file as follows (modify DNS service)

Nameserver 202.101.172.35

Search localdomain

(3) restart the network service

[Root @ localhost ~] # Service network restart

II. software installation:

(1) manage nodesMGM

Configuration management node

First, create a configuration file for the management node at an appropriate location. The steps are as follows:

[Root @ localhost ~] # Mkdir/var/lib/mysql-cluster

[Root @ localhost ~] # Cd/var/lib/mysql-cluster

[Root @ localhost mysql-cluster] # vi config. ini

The configuration file config. ini contains the following content:

[Ndbd default]

NoOfReplicas = 2

DataMemory = 80 M

IndexMemory = 18 M

[Tcp default]

Portnumber = 2202

[Ndb_mgmd]

Hostname = 192.168.20.231

Datadir =/var/lib/mysql-cluster

[Ndbd]

Hostname = 192.168.20.133

Datadir =/usr/local/mysql/data

[Ndbd]

Hostname = 192.168.20.233

Datadir =/usr/local/mysql/data

[Mysqld]

Hostname = 192.168.255.234

[Mysqld]

Hostname = 192.168.20.235

Install the management node without the mysqld binary file. you only need the MySQL Cluster Server Program (ndb_mgmd) and the listener client program (ndb_mgm ). Both files are in the bin folder after the MySQL-cluster File is decompressed. Perform the following steps to install ndb_mgmd and ndb_mgm on the management node of the cluster.

1. change the address to the/var/tmp Directory, decompress the MySQL-Cluster compressed file, and copy ndb_mgm and ndb_mgmd to the/usr/local/bin directory.

[Root @ localhost ~] # Cd/var/tmp

[Root @ localhost tmp] # tar-xzvf mysql-cluster-gpl-7.1.13-linux-i686-glibc23.tar.gz

[Root @ localhost tmp] # mysql-cluster-gpl-7.1.13-linux-i686-glibc23 cd

[Root @ localhost tmp] # cp bin/ndb_mgm */usr/local/bin

2. change the path to the copied directory and make sure the two files are executable.

[Root @ localhost tmp] # cd/usr/local/bin

[Root @ localhost bin] # chmod + x ndb_mgm *

3. create a mysql folder under/usr/local.

[Root @ localhost ~] # Cd/usr/local

[Root @ localhost local] # mkdir mysql

(2) data nodesNDBDAndSQLNode

Configure Data nodes NDBD and SQL nodes

Find the my. cnf file in the/etc directory of each SQL node and configure it as follows:

[Client]

Socket =/usr/local/mysql/sock/mysql. sock

[Mysqld]

Ndbcluster

Datadir =/usr/local/mysql

Socket =/usr/local/mysql/sock/mysql. sock

Ndb-connectstring = 192.168.20.231

Old_passwords = 1

[Mysql_cluster]

Ndb-connectstring = 192.168.20.231

Run the following steps with the root user on the machine of each data node NDBD and SQL node.

1. check the/etc/passwd and/etc/group files for the existence of mysql groups and mysql Users. if not, use the following command to create a mysql group, add the mysql user in the reorganization.

[Root @ localhost ~] # Groupadd mysql

[Root @ localhost ~] # Useradd-g mysql

2. change the folder location to the storage location of the mysql compressed package, decompress the file, and prepare for installation. The steps are as follows:

(The download file can be mapped from other computers. create a download folder under/home/. if the file is downloaded from Linux on the local computer, this ing step is not required .)

[Root @ localhost ~] # Mount-t cifs-o username = "name", password = "password" // 192.168.20.210/MySQL/home/download

[Root @ localhost ~] Cp/home/download/mysql-cluster-gpl-7.1.13-linux-i686-glibc23.tar.gz/var/tmp

[Root @ localhost ~] # Cd/var/tmp

[Root @ localhost tmp] # tar-C/usr/local-xzvf mysql-cluster-gpl-7.1.13-linux-i686-glibc23.tar.gz

3. change the location to the local folder, change the mysql decompressed folder name to mysql, and then execute the provided script to create the system database.

[Root @ localhost tmp] # cd/usr/local

[Root @ localhost local] # music mysql-cluster-gpl-7.1.13-linux-i686-glibc23/mysql/

[Root @ localhost local] # cd mysql

[Root @ localhost mysql] # mkdir sock

[Root @ localhost mysql] # scripts/mysql_install_db -- user = mysql -- basedir =/usr/local/mysql -- datadir =/usr/local/mysql

4. set necessary services for MySQL services and data directories.

[Root @ localhost mysql] # chown-R root.

[Root @ localhost mysql] # chown-R mysql. mysql/usr/local/mysql/data

[Root @ localhost mysql] # chown-R mysql. mysql/usr/local/mysql/sock

[Root @ localhost mysql] # chgrp-R mysql.

[Root @ localhost mysql] # ls-l

5. copy the MySQL startup script to the following folder to make sure it can be executed. And set it to start MySQL at the same time when the system starts.

[Root @ localhost mysql] # cp support-files/mysql. server/etc/rc. d/init. d/

[Root @ localhost mysql] # chmod + x/etc/rc. d/init. d/mysql. server

[Root @ localhost mysql] # chkconfig -- add mysql. server

III,ClusterEnvironment startup

Note the startup sequence: first, the management node, then the NDBD node, and finally the SQL node.

1,[MGM]

[Root @ localhost ~] # Ndb_mgmd-f/var/lib/mysql-cluster/config. ini

Use ndb_mgm to listen to the client, as shown below:

[Root @ localhost ~] # Ndb_mgm

2,[NDBD]

For the first time, you need to add the -- initial parameter for NDB node initialization. This parameter cannot be added during subsequent startup. Otherwise, the ndbd program will clear all data files and log files created previously for restoration.

[Root @ localhost ~] #/Usr/local/mysql/bin/ndbd -- initial

If it is not the first time, run the following command.

[Root @ localhost ~] #/Usr/local/mysql/bin/ndbd

3,[SQLD]

/Usr/local/mysql/bin/mysqld_safe -- user = mysql &

The system database creation problem may occur. you only need to create a system database again by using the following method:

[Root @ localhost mysql] # scripts/mysql_install_db -- user = mysql -- basedir =/usr/local/mysql -- datadir =/usr/local/mysql

Start again

/Usr/local/mysql/bin/mysqld_safe -- user = mysql &

View the management node. started successfully:

IV. test

1General testing:

On node 4:

To make the table copy in the cluster normally, you must use the ndbcluster engine (engine = ndb Or engine = ndbcluster) to create a table as follows:

Mysql> use test

Mysql> create table teacher (t_id int) engine = ndb;

If an existing table exists, use alter table to modify the engine of the table.

Mysql> alter table student engine = ndb;

Insert a data entry:

Mysql> insert into teacher value (133 );

Then on node 5:

Mysql> select * from teacher;

The data on the two nodes is consistent. Congratulations! the test is successful!

2, SimulationNDBNodeCrash:

Terminate the NDB process on Node 2, and then access the teacher table through the two SQL nodes to check whether the access is normal and whether the data is consistent. As follows:

View processes

[Root @ localhost ~] # Ps-ef

[Root @ localhost ~] # Killed 3344

[Root @ localhost ~] # Ps-ef

View the management node. it is displayed that node 2 is closed.

Node 4:

On node 5:

Return to Node 4:

The test is successful. when there is an NDB node Crash, the entire MySQL Cluster environment can still serve normally.

3, SimulationSQLNodeCrash:

Kill the mysqld process of node 4 and access it through node 5 as follows:

After node 4 Crash is displayed, node 5 can continue to work normally and the test is successful.

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.