码迷,mamicode.com
首页 > 数据库 > 详细

Build MySQL Cluster Environment

时间:2014-12-26 16:32:01      阅读:254      评论:0      收藏:0      [点我收藏+]

标签:

This post documents how build MySQL cluster environment with 4 machines. Their IP addresses and roles are listed below.

  • Host #1: 192.168.1.100, management node
  • Host #2: 192.168.1.101, SQL node
  • Host #3: 192.168.1.102, data node #1
  • Host #4: 192.168.1.103, data node #2 

 

Download MySQL Cluster on each host

wget http://dev.mysql.com/get/Downloads/MySQL-Cluster-7.3/mysql-cluster-gpl-7.3.7-linux-glibc2.5-x86_64.tar.gz
tar zxvf mysql-cluster-gpl-7.3.7-linux-glibc2.5-x86_64.tar.gz
cd mysql-cluster-gpl-7.3.7-linux-glibc2.5-x86_64/

 

Setup the cluster

On Management Node, run the following commands to copy ndb_mgm and ndb_mgmd to /usr/local/bin/.

cp bin/ndb_mgm /usr/local/bin/
cp bin/ndb_mgmd /usr/local/bin/

On Data Node, run the following commands to copy ndbd and ndbmtd to /usr/local/bin/.

cp bin/ndbd /usr/local/bin/
cp bin/ndbmtd /usr/local/bin/

On SQL Node

Check if the library libaio1 installed on the host, if not, execute the following command to install the library.

apt-get install libaio1

If the library can‘t be installed by running apt-get, you can download this package first, and then install it with dpkg -i like below.

wget http://archive.ubuntu.com/ubuntu/pool/main/liba/libaio/libaio1_0.3.109-4_amd64.deb
dpkg -i libaio1_0.3.109-4_amd64.deb

Run the following commands to install MySQL.

#
groupadd mysql
useradd -g mysql mysql
 
#
tar zxvf mysql-cluster-gpl-7.3.7-linux-glibc2.5-x86_64.tar.gz -C /usr/local/
ln -s /usr/local/mysql-cluster-gpl-7.3.7-linux-glibc2.5-x86_64 /usr/local/mysql

#
cd /usr/loca/mysql
scripts/mysql_install_db --user=mysql

#
chown -R root .
chown -R mysql data
chgrp -R mysql .
 
#
cp support-files/mysql.server /etc/init.d/
update-rc.d mysql.server defaults

 

Configure the Cluster

On the SQL and data nodes, type the following lines in /etc/my.cnf.

[mysqld]
ndbcluster

[mysql_cluster]
ndb-connectstring=1092.168.1.100

On the management node, type the following lines in /etc/mysql/config.ini.

[ndbd default]
NoOfReplicas=2    # Number of replicas
DataMemory=80M    # How much memory to allocate for data storage
IndexMemory=18M   # How much memory to allocate for index storage
                 

[tcp default]
# TCP/IP options:
portnumber=2202
                 

[ndb_mgmd]
# Management process options:
hostname=192.168.1.100
datadir=/var/lib/mysql-cluster  # Directory for MGM node log files


[ndbd]
# Options for data node #1:                                
hostname=192.168.1.102
datadir=/usr/local/mysql/data   # Directory for this data nodes data files


[ndbd]
# Options for data node #2:
hostname=192.168.1.103
datadir=/usr/local/mysql/data   # Directory for this data nodes data files


[mysqld]
# SQL node #1:
hostname=192.168.1.101

 

Start the cluster

Start the management node first.

ndb_mgmd -f /var/lib/mysql-cluster/config.ini

Start the data nodes.

ndbd

Start the SQL node.

service mysql.server start

On the management node, run the following command to see if the cluster goes well.

ndb_mgm
ndb_mgm> show

On the SQL node, set password for root.

mysqladmin -u root password your password

Finally, try to create a database to test.

 

Build MySQL Cluster Environment

标签:

原文地址:http://www.cnblogs.com/jeffreyf/p/build-mysql-cluster-environment.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!