Linux下编译安装MySQL Cluster 7.1

操作系统使用CentOS 5.6 64-bit,MySQL Cluster版本是mysql-cluster-gpl-7.1.19使用4服务器分别如下:
db1 192.168.105.24 mgm node
db2 192.168.105.21 ndbd,mysqld node
db3 192.168.105.22 ndbd,mysqld node

db4 192.168.105.23 mysqld node

关闭iptables和selinux,在每台服务器上yum安装rpm依赖包,创建mysql用户、用户组和安装目录


yum install autoconf automake bison.x86_64 bzip2-devel.x86_64 cpp.x86_64 cyrus-sasl.x86_64 cyrus-sasl-plain.x86_64 flex freetype-devel.x86_64 gd.x86_64 gcc.x86_64 gcc-c++.x86_64 gcc-g77 gdbm-devel.x86_64 glibc-devel glibc-headers glibc-kernheaders libtool.x86_64 libxml2.x86_64 libjpeg-devel.x86_64 libpng-devel.x86_64 libtiff-devel.x86_64 libc-client-devel.x86_64 libstdc++-devel.x86_64 libmcrypt.x86_64 libmcrypt-devel.x86_64 libtool-ltdl.x86_64 mhash.x86_64 mhash-devel.x86_64 libxslt-devel.x86_64 libtidy-devel.x86_64 libtidy.x86_64 zlib-devel.x86_64 expat.x86_64 expat-devel.x86_64 pcre.x86_64 pcre-devel.x86_64 libXp.x86_64 fontconfig-devel libXpm-devel db4-utils
[root@db1 ~]# groupadd mysql
[root@db1 ~]# useradd -g mysql mysql
[root@db1 ~]# mkdir -p /service/mysql/etc /service/mysql/tmp


在db1 mgm node上安装

[root@db1 ~]# cd /service/mysql-cluster-gpl-7.1.19
[root@db1 mysql-cluster-gpl-7.1.19]# ./configure --prefix=/service/mysql/ --with-charset=gbk --with-collation=gbk_chinese_ci --with-client-ldflags=-all-static -with-mysqld-ldflags=-all-static --enable-assembler --with-extra-charsets=complex --enable-thread-safe-client --with-big-tables --with-readline --with-ssl --with-embedded-server --enable-local-infile --with-unix-socket-path=/service/mysql/tmp/mysql.sock --sysconfdir=/service/mysql/etc --without-debug --with-mysqld-user=mysql --with-plugins=max
[root@db1 mysql-cluster-gpl-7.1.19]# make && make install

创建mgm node配置文件

[root@db1 mysql-cluster-gpl-7.1.19]# cd /service/mysql
[root@db1 mysql]# mkdir mysql-cluster
[root@db1 mysql]# cd mysql-cluster/
[root@db1 mysql-cluster]# cat config.ini 
[NDBD DEFAULT]
NoOfReplicas= 2
[MYSQLD DEFAULT]
[NDB_MGMD DEFAULT]
DataDir= /service/mysql/mysql-cluster
[NDB_MGMD]
HostName= db1
[NDBD]
HostName= db2
DataDir= /service/mysql/mysql-cluster
[NDBD]
HostName= db3
DataDir= /service/mysql/mysql-cluster
[MYSQLD]
HostName= db2
[MYSQLD]
HostName= db3
[MYSQLD]
HostName= db4
[root@db1 mysql-cluster]# 

启动ndb_mgmd服务

[root@db1 mysql-cluster]# /service/mysql/libexec/ndb_mgmd -f /service/mysql/mysql-cluster/config.ini 
MySQL Cluster Management Server mysql-5.1.56 ndb-7.1.19
[root@db1 mysql-cluster]# ps -ef|grep ndb
root     29368     1  0 15:07 ?        00:00:00 /service/mysql/libexec/ndb_mgmd -f /service/mysql/mysql-cluster/config.ini
root     29380  2263  0 15:07 pts/0    00:00:00 grep ndb
[root@db1 mysql-cluster]# 

登陆ndb_mgm node查看cluster的状态,可以看到除了mgm node是启动的,其余node都处于not connected状态

[root@db1 mysql-cluster]# /service/mysql/bin/ndb_mgm 
-- NDB Cluster -- Management Client --
ndb_mgm> show
Connected to Management Server at: localhost:1186
Cluster Configuration
---------------------
[ndbd(NDB)]     2 node(s)
id=2 (not connected, accepting connect from db2)
id=3 (not connected, accepting connect from db3)

[ndb_mgmd(MGM)] 1 node(s)
id=1    @192.168.105.24  (mysql-5.1.56 ndb-7.1.19)

[mysqld(API)]   3 node(s)
id=4 (not connected, accepting connect from db2)
id=5 (not connected, accepting connect from db3)
id=6 (not connected, accepting connect from db4)

ndb_mgm> exit

安装db2,db3上的ndb和sql node,步骤相同,这里以db2为例

[root@db2 service]# cd mysql-cluster-gpl-7.1.19
[root@db2 mysql-cluster-gpl-7.1.19]# ./configure --prefix=/service/mysql --with-charset=gbk --with-collation=gbk_chinese_ci --with-client-ldflags=-all-static -with-mysqld-ldflags=-all-static --enable-assembler --with-extra-charsets=complex --enable-thread-safe-client --with-big-tables --with-readline --with-ssl --with-embedded-server --enable-local-infile --with-unix-socket-path=/service/mysql/tmp/mysql.sock --sysconfdir=/service/mysql/etc --without-debug --with-mysqld-user=mysql --with-plugins=max
[root@db2 mysql-cluster-gpl-7.1.19]# make && make install

创建数据字典和my.cnf配置文件

[root@db2 mysql-cluster-gpl-7.1.19]# cd /service/mysql
[root@db2 mysql]# mkdir mysql-cluster
[root@db2 mysql]# /service/mysql/bin/mysql_install_db --user=mysql
Installing MySQL system tables...
OK
Filling help tables...
OK

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:

/service/mysql/bin/mysqladmin -u root password 'new-password'
/service/mysql/bin/mysqladmin -u root -h db2 password 'new-password'

Alternatively you can run:
/service/mysql/bin/mysql_secure_installation

which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.

See the manual for more instructions.

You can start the MySQL daemon with:
cd /service/mysql ; /service/mysql/bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl
cd /service/mysql/mysql-test ; perl mysql-test-run.pl

Please report any problems with the /service/mysql/bin/mysqlbug script!

[root@db2 mysql]# 
[root@db2 mysql]# cat etc/my.cnf 
[mysqld]
basedir = /service/mysql/
datadir = /service/mysql/var
user = mysql
port = 3306
socket = /service/mysql/tmp/mysql.sock
ndbcluster
ndb-connectstring=192.168.105.24
[mysql_cluster]
ndb-connectstring=192.168.105.24
[root@db2 mysql]# 

启动ndb和mysql服务,ndb第一次启动需要加上initial参数,之后不需要

[root@db2 mysql]# /service/mysql/libexec/ndbd --initial
2012-03-20 15:40:32 [ndbd] INFO     -- Angel connected to '192.168.105.24:1186'
2012-03-20 15:40:32 [ndbd] INFO     -- Angel allocated nodeid: 2
[root@db2 mysql]# chown -R mysql.mysql *
[root@db2 mysql]# /service/mysql/bin/mysqld_safe &
[1] 30008
[root@db2 mysql]# 120320 15:42:02 mysqld_safe Logging to '/service/mysql/var/db2.err'.
120320 15:42:02 mysqld_safe Starting mysqld daemon with databases from /service/mysql/var

[root@db2 mysql]# /service/mysql/bin/mysqladmin -uroot password 'yourpwd'

[root@db2 mysql]# ps -ef|grep mysql
root     29970     1  0 15:40 ?        00:00:00 /service/mysql/libexec/ndbd --initial
root     29971 29970  0 15:40 ?        00:00:00 /service/mysql/libexec/ndbd --initial
root     30008  2776  0 15:42 pts/0    00:00:00 /bin/sh /service/mysql/bin/mysqld_safe
mysql    30083 30008  0 15:42 pts/0    00:00:00 /service/mysql/libexec/mysqld --basedir=/service/mysql/ --datadir=/service/mysql/var --user=mysql --log-error=/service/mysql/var/db2.err --pid-file=/service/mysql/var/db2.pid --socket=/service/mysql/tmp/mysql.sock --port=3306
root     30109  2776  0 15:43 pts/0    00:00:00 grep mysql
[root@db2 mysql]# /service/mysql/bin/mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.1.56-ndb-7.1.19 Source distribution

Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2 license

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> select @@version;
+-------------------+
| @@version         |
+-------------------+
| 5.1.56-ndb-7.1.19 |
+-------------------+
1 row in set (0.00 sec)

mysql> 

在db4上安装sql node,步骤和db2,db3大致相同

[root@db4 service]# cd mysql-cluster-gpl-7.1.19
[root@db4 mysql-cluster-gpl-7.1.19]# ./configure --prefix=/service/mysql --with-charset=gbk --with-collation=gbk_chinese_ci --with-client-ldflags=-all-static -with-mysqld-ldflags=-all-static --enable-assembler --with-extra-charsets=complex --enable-thread-safe-client --with-big-tables --with-readline --with-ssl --with-embedded-server --enable-local-infile --with-unix-socket-path=/service/mysql/tmp/mysql.sock --sysconfdir=/service/mysql/etc --without-debug --with-mysqld-user=mysql --with-plugins=max
[root@db4 mysql-cluster-gpl-7.1.19]# make && make install


创建数据字典和my.cnf参数文件,启动mysql服务

[root@db4 mysql-cluster-gpl-7.1.19]# cd /service/mysql
[root@db4 mysql]# mkdir mysql-cluster
[root@db4 mysql]# /service/mysql/bin/mysql_install_db --user=mysql
Installing MySQL system tables...
OK
Filling help tables...
OK

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:

/service/mysql/bin/mysqladmin -u root password 'new-password'
/service/mysql/bin/mysqladmin -u root -h db4 password 'new-password'

Alternatively you can run:
/service/mysql/bin/mysql_secure_installation

which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.

See the manual for more instructions.

You can start the MySQL daemon with:
cd /service/mysql ; /service/mysql/bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl
cd /service/mysql/mysql-test ; perl mysql-test-run.pl

Please report any problems with the /service/mysql/bin/mysqlbug script!

[root@db4 mysql]# 

[root@db4 mysql]# chown -R mysql.mysql *
[root@db4 mysql]# cat etc/my.cnf
[mysqld]
basedir = /service/mysql/
datadir = /service/mysql/var
user = mysql
port = 3306
socket = /service/mysql/tmp/mysql.sock
ndbcluster
ndb-connectstring=192.168.105.24
[mysql_cluster]
ndb-connectstring=192.168.105.24

[root@db4 mysql]# /service/mysql/bin/mysqld_safe &
[1] 3471
[root@db4 mysql]# 120320 16:07:18 mysqld_safe Logging to '/service/mysql/var/db4.err'.
120320 16:07:18 mysqld_safe Starting mysqld daemon with databases from /service/mysql/var

[root@db4 mysql]# /service/mysql/bin/mysqladmin -uroot password 'yourpwd'
[root@db4 mysql]# ll /service/mysql/tmp/
total 0
srwxrwxrwx 1 mysql mysql 0 Mar 20 16:07 mysql.sock
[root@db4 mysql]# /service/mysql/bin/mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.1.56-ndb-7.1.19 Source distribution

Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2 license

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> select now(),@@version;
+---------------------+-------------------+
| now()               | @@version         |
+---------------------+-------------------+
| 2012-03-20 16:08:12 | 5.1.56-ndb-7.1.19 |
+---------------------+-------------------+
1 row in set (0.00 sec)

mysql> 

最后登录mgm node查看,看见所有node都连接上

[root@db1 mysql-cluster]# /service/mysql/bin/ndb_mgm 
-- NDB Cluster -- Management Client --
ndb_mgm> show
Connected to Management Server at: localhost:1186
Cluster Configuration
---------------------
[ndbd(NDB)]     2 node(s)
id=2    @192.168.105.21  (mysql-5.1.56 ndb-7.1.19, Nodegroup: 0, Master)
id=3    @192.168.105.22  (mysql-5.1.56 ndb-7.1.19, Nodegroup: 0)

[ndb_mgmd(MGM)] 1 node(s)
id=1    @192.168.105.24  (mysql-5.1.56 ndb-7.1.19)

[mysqld(API)]   3 node(s)
id=4    @192.168.105.21  (mysql-5.1.56 ndb-7.1.19)
id=5    @192.168.105.22  (mysql-5.1.56 ndb-7.1.19)
id=6    @192.168.105.23  (mysql-5.1.56 ndb-7.1.19)

ndb_mgm> 

测试ndb engine同步

mysql> system hostname
db2
mysql> create table test.zhongwc(
    -> id int(5) primary key,
    -> name varchar(10)
    -> ) engine=ndb comment='ndb test';
Query OK, 0 rows affected (0.16 sec)

mysql> insert into test.zhongwc values(1,'zhongwc');
Query OK, 1 row affected (0.01 sec)

mysql> 

mysql> system hostname
db4
mysql> use test
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> show tables;
+----------------+
| Tables_in_test |
+----------------+
| zhongwc        |
+----------------+
1 row in set (0.01 sec)

mysql> show create table zhongwc;
+---------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table   | Create Table                                                                                                                                                        |
+---------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| zhongwc | CREATE TABLE `zhongwc` (
  `id` int(5) NOT NULL,
  `name` varchar(10) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=ndbcluster DEFAULT CHARSET=gbk COMMENT='ndb test' |
+---------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

mysql> select * from zhongwc;
+----+---------+
| id | name    |
+----+---------+
|  1 | zhongwc |
+----+---------+
1 row in set (0.00 sec)

mysql> 

mysql> system hostname
db3
mysql> use test
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> show tables;
+----------------+
| Tables_in_test |
+----------------+
| zhongwc        |
+----------------+
1 row in set (0.02 sec)

mysql> show create table zhongwc;
+---------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table   | Create Table                                                                                                                                                        |
+---------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| zhongwc | CREATE TABLE `zhongwc` (
  `id` int(5) NOT NULL,
  `name` varchar(10) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=ndbcluster DEFAULT CHARSET=gbk COMMENT='ndb test' |
+---------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

mysql> select * from zhongwc;
+----+---------+
| id | name    |
+----+---------+
|  1 | zhongwc |
+----+---------+
1 row in set (0.00 sec)

mysql> 





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值