1、环境描述
mysql manager 节点:192.168.0.1
mysqlserver节点:192.168.0.100
mysql 节点:192.168.0.160
mysql 节点:192.168.0.161
说明:至少需要四台服务器才可以做mysql的集群。建议5台,再增加一台mysqlserver。
2安装mysql二进制包
2.1 安装之前的准备工作
下载mysql-max-4.1.13-pc-linux-gnu-i686.tar.gz包
(注意:可以做集群的mysql都是mysql-max的,下载地点)
#groupadd mysql
#useradd -g mysql mysql
#cd /usr/local
#tar xfz mysql-max-4.1.13-pc-linux-gnu-i686.tar.gz
#ln -s /usr/local/mysql-max-4.1.13-pc-linux-gnu-i686 /opt/mysql4.1.13
2.2 分别在manager,server,,node节点上安装二进制的mysql包
#cd mysql4.1.13
#scripts/mysql_install_db --user=mysql (必须带目录执行,否则出错)
#chown -r root /opt/mysql4.1.13
#chgrp -r mysql /opt/mysql4.1.13
#chown -r mysql.mysql /opt/mysql4.1.13/data
#cp support-files/mysql.server /etc/rc.d/init.d/ 配置mysql启动设置
#chmod +x /etc/rc.d/init.d/mysql.server
#chkconfig --add mysql.server
3配置server,note节点
在192.168.0.160和192.168.0.161机器上
# ./mysql –help 该命令可以查看mysql启动时是怎么寻找my.cnf文件的顺序。
default options are read from the following files in the given order:
/etc/my.cnf /usr/local/mysql-max-4.1.13/data/my.cnf ~/.my.cnf
# cp support-files/my-medium.cnf data/my.cnf 将mysql的配置文件考到data下
vi /usr/local/mysql-max-4.1.13-pc-linux-gnu-i686/data/my.cnf
[mysqld]
ndbcluster
ndb-connectstring=192.168.0.1
[mysql_cluster]
ndb-connectstring=192.168.0.1
4配置management管理节点
在192.168.0.1机器上
#mkdir /var/lib/mysql-cluster
#cd /var/lib/mysql-cluster
#vi config.ini
[ndbd default] # options affecting ndbd processes on all data nodes:
noofreplicas=2 # number of replicas
datamemory=80m # how much memory to allocate for data storage
indexmemory=52m # 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 500kb, this should be more than enough for
# this example cluster setup.
[tcp default] # tcp/ip options:
portnumber=2202 # this the default; however, you can use any
# port that is free for all the hosts in cluster
# note: it is recommended beginning with mysql 5.0 that
# you do not specify the portnumber at all and simply allow
# the default value to be used instead
# management process options(定义管理节点.)
[ndb_mgmd]
hostname=192.168.0.1 # 管理节点hostname or ip address of mgm node
datadir=/var/lib/mysql-cluster # directory for mgm node logfiles
# options for data node a(定义群集数据节点.)
# (one [ndbd] section per data node)
[ndbd]
hostname=192.168.0.160 # 节点hostname or ip address
datadir=/usr/local/mysql/data # directory for this data node's datafiles
# options for data node b(定义群集数据节点.)
[ndbd]
hostname=192.168.0.161 # 节点hostname or ip address
datadir=/usr/local/mysql/data # directory for this data node's datafiles
# sql node options(定义sql server节点.)
[mysqld]
hostname=192.168.0.100 # sql节点hostname or ip address
#datadir=/usr/local/mysql/data # directory for sql node's datafiles
# (additional mysqld connections can be
# specified for this node for various
# purposes such as running ndb_restore)
[ndb_mgmd]:后面不能有任何注释信息,否则提示:
error line 17: [tcp] unknown parameter: [ndb_mgmd] # management process options
error line 17: could not parse name-value pair in config file.
[shm]: defines shared-memory connections between nodes. 在mysql 4.1.9之前,这个功能必须使用--with-ndb-shm option编译进去, 从mysql 4.1.9-max版本开始, it is enabled by default
