From: http://www.cnblogs.com/StanBlogs/archive/2011/06/14/2080986.html
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 or omissions, please send me an email:
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: need to use cluster version, can be downloaded on the official website
Http://dev.mysql.com/downloads/cluster/#downloads)
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) Management node MGM
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 Node ndbd and SQL Node
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. Cluster Environment 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
1. General test:
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. Simulate NDB node crash:
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. Simulate SQL node crash:
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.