Mysql环境搭建Centos5
[root@localhost ~]# uname -a
Linux localhost.localdomain 2.6.32-431.el6.x86_64 #1 SMP Fri Nov 22 03:15:09 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
root@localhost ~]# mkdir soft
[root@localhost ~]# cd soft
[root@localhost soft]# wget http://cdn.mysql.com//Downloads/MySQL-Cluster-7.4/mysql-cluster-gpl-7.4.10-linux-glibc2.5-x86_64.tar.gz
节点规划:
MGM:192.168.88.199
NDBD1:192.168.88.200
NDBD2:192.168.88.201
SQL1: 192.168.88.202
SQL2: 192.168.88.203
软件安装:
配置管理节点
首先在合适的位置,创建一个管理节点的配置文件,步骤如下:
[root@localhost ~]# mkdir /var/lib/mysql-cluster
[root@localhost ~]# cd /var/lib/mysql-cluster
[root@localhost mysql-cluster]# vi config.ini
[ndbd default]
NoOfReplicas=2
DataMemory=80M
IndexMemory=18M
[tcp default]
portnumber=2202
[ndb_mgmd]
hostname=192.168.88.199
datadir=/var/lib/mysql-cluster
[ndbd]
hostname=192.168.88.200
datadir=/usr/local/mysql/data
[ndbd]
hostname=192.168.88.201
datadir=/usr/local/mysql/data
[mysqld]
hostname=192.168.88.202
[mysqld]
hostname=192.168.88.203
安装管理节点,不需要mysqld二进制文件[数据库],只需要MySQL Cluster服务端程序(ndb_mgmd)和监听客户端程序(ndb_mgm)。这两个文件都在下载的MySQL-cluster文件解压后的bin 文件夹中。执行如下步骤,在集群的管理节点上安装ndb_mgmd 和 ndb_mgm。
1、改变地址到/var/tmp目录下,解压MySQL-Cluster压缩文件,取出ndb_mgm和ndb_mgmd复制到/usr/local/bin 目录下
2、[root@localhost soft]# tar -zxf mysql-cluster-gpl-7.4.10-linux-glibc2.5-i686.tar.gz
3、[root@localhost soft]# ls
4、mysql-cluster-gpl-7.4.10-linux-glibc2.5-i686
5、mysql-cluster-gpl-7.4.10-linux-glibc2.5-i686.tar.gz
6、[root@localhost soft]# cd mysql-cluster-gpl-7.4.10-linux-glibc2.5-i686
7、[root@localhost mysql-cluster-gpl-7.4.10-linux-glibc2.5-i686]#
8、[root@localhost mysql-cluster-gpl-7.4.10-linux-glibc2.5-i686]# ls bin/ndb_mgm*
9、bin/ndb_mgm bin/ndb_mgmd
[root@localhost mysql-cluster-gpl-7.4.10-linux-glibc2.5-i686]# cp bin/ndb_mgm* /usr/local/bin
2、改变路径为拷贝到的目录下,并确保这两个文件可执行。
[root@localhost tmp]# cd /usr/local/bin
[root@localhost bin]# chmod +x ndb_mgm*
3、在/usr/local下创建mysql文件夹。
[root@localhost ~]# cd /usr/local
[root@localhost local]# mkdir mysql
配置数据节点NDBD和SQL节点
在每一个SQL节点中的/etc目录下找到my.cnf文件,并做如下配置:
[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.88.199
old_passwords=1
[mysql_cluster]
ndb-connectstring=192.168.88.199
在每一个数据节点NDBD和SQL节点的机器上,用root用户执行下面的步骤。
1、检查/etc/passwd 和 /etc/group 文件,是否存在mysql组和mysql用户,如果没有,用下面的命令创建一个mysql组,并在改组中添加mysql用户。
[root@localhost ~]# groupadd mysql
[root@localhost ~]# useradd -r -g mysql mysql
2、在每一个数据节点NDBD和SQL节点的机器上同步文件,解压文件,准备安装,步骤如下:
[root@localhost soft]#scp mysql-cluster-gpl-7.4.10-linux-glibc2.5-i686.tar.gz [email protected]:~/soft
[root@localhost soft]# tar -xzf mysql-cluster-gpl-7.4.10-linux-glibc2.5-i686.tar.gz -C /usr/local
3、改变位置到local文件夹,改变mysql解压后的文件夹名称为mysql,然后执行提供的脚本,创建系统数据库。
[root@localhost local]#
mv mysql-cluster-gpl-7.4.10-linux-glibc2.5-i686/ mysql/ 没有创建mysql folder
[root@localhost mysql]# mkdir sock
[root@localhost mysql]# scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql
4、为MySQL服务及数据目录设置必要的服务。
[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
chgrp: missing operand after `mysql'
Try `chgrp --help' for more information.
[root@localhost mysql]# chgrp -R mysql .
[root@localhost mysql]# ls –l
5、复制MySQL的启动脚本到如下的文件夹,确保可以执行。并设置为当系统启动时,同时启动MySQL
[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
三、Cluster环境启动
注意启动顺序:首先是管理节点,然后是NDBD节点,最后是SQL节点。
1、[MGM]
[root@localhost ~]# ndb_mgmd -f /var/lib/mysql-cluster/config.ini
若出现MgmtSrvr] ERROR -- Could not determine which nodeid to use for this node. Specify it with --ndb-nodeid=<nodeid> on command line
是ip地址设置不对
[root@localhost local]# ndb_mgmd -f /var/lib/mysql-cluster/config.ini
MySQL Cluster Management Server mysql-5.6.28 ndb-7.4.10
[root@localhost local]# ndb_mgm
-- NDB Cluster -- Management Client --
ndb_mgm>
ndb_mgm> show
Connected to Management Server at: localhost:1186
Cluster Configuration
---------------------
[ndbd(NDB)] 2 node(s)
id=2 (not connected, accepting connect from 192.168.88.200)
id=3 (not connected, accepting connect from 192.168.88.200)
[ndb_mgmd(MGM)] 1 node(s)
id=1 @192.168.88.199 (mysql-5.6.28 ndb-7.4.10)
[mysqld(API)] 2 node(s)
id=4 (not connected, accepting connect from 192.168.88.202)
id=5 (not connected, accepting connect from 192.168.88.203)
若出错stop 1停掉管理节点
root@localhost mysql-cluster]# cat ndb_1_cluster.log
2016-02-13 23:23:46 [MgmtSrvr] INFO -- Loaded config from '/usr/local/mysql/mysql-cluster/ndb_1_config.bin.2'
2016-02-13 23:23:46 [MgmtSrvr] INFO -- Node 1: Node 1 Connected
2016-02-13 23:23:50 [MgmtSrvr] ERROR -- Unable to bind management service port: *:1186!
Please check if the port is already used,
(perhaps a ndb_mgmd is already running),
and if you are executing on the correct computer
2016-02-13 23:23:50 [MgmtSrvr] ERROR -- Failed to start mangement service!
[root@localhost mysql-cluster]# ps -ef |grep ndb
root 2975 1 1 22:29 ? 00:00:42 ndb_mgmd -f /var/lib/mysql-cluster/config.ini --reload
root 3352 3315 0 23:23 pts/1 00:00:00 ndb_mgm
root 3373 3358 0 23:24 pts/0 00:00:00 grep ndb
[root@localhost mysql-cluster]# kill -9 2975
[root@localhost mysql-cluster]# kill -9 3352
2、[NDBD]
首次启动,则需要添加--initial参数,以便进行NDB节点的初始化工作。在以后的启动过程中,则是不能添加该参数的,否则ndbd程序会清除在之前建立的所有用于恢复的数据文件和日志文件。
[root@localhost mysql]# /usr/local/mysql/bin/ndbd --initial
2016-02-13 20:12:56 [ndbd] INFO -- Angel connected to '192.168.88.199:1186'
2016-02-13 20:12:56 [ndbd] INFO -- Angel allocated nodeid: 2
如果不是首次启动,则执行下面的命令。
[root@localhost ~]# /usr/local/mysql/bin/ndbd