Mysql ndb-cluster centos6.4 简单配置

 

NDB Cluster

Server1

192.168.0.30

Mysql集群服务器1

Server2

192.168.0.31

Mysql集群服务器2

Server3

192.168.0.214

管理(MGM)节点

 

 

--在server1和server2分别安装mysql,如下

tar zxvf mysql-cluster-gpl-7.4.6-linux-glibc2.5-x86_64.tar.gz

[root@ryxr1 mysql]# groupadd mysql

[root@ryxr1 mysql]# useradd -g mysql mysql

 

[root@ryxr2 mysql]# ./scripts/mysql_install_db --user=mysql 

Installing MySQL system tables...2015-04-22 14:26:43 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).

2015-04-22 14:26:43 0 [Note] ./bin/mysqld (mysqld 5.6.24-ndb-7.4.6-cluster-gpl) starting as process 26442 ...

2015-04-22 14:26:43 26442 [Note] InnoDB: Using atomics to ref count buffer pool pages

2015-04-22 14:26:43 26442 [Note] InnoDB: The InnoDB memory heap is disabled

2015-04-22 14:26:43 26442 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins

2015-04-22 14:26:43 26442 [Note] InnoDB: Memory barrier is not used

2015-04-22 14:26:43 26442 [Note] InnoDB: Compressed tables use zlib 1.2.3

2015-04-22 14:26:43 26442 [Note] InnoDB: Using Linux native AIO

2015-04-22 14:26:43 26442 [Note] InnoDB: Using CPU crc32 instructions

2015-04-22 14:26:43 26442 [Note] InnoDB: Initializing buffer pool, size = 128.0M

2015-04-22 14:26:43 26442 [Note] InnoDB: Completed initialization of buffer pool

2015-04-22 14:26:43 26442 [Note] InnoDB: The first specified data file ./ibdata1 did not exist: a new database to be created!

2015-04-22 14:26:43 26442 [Note] InnoDB: Setting file ./ibdata1 size to 12 MB

2015-04-22 14:26:43 26442 [Note] InnoDB: Database physically writes the file full: wait...

2015-04-22 14:26:43 26442 [Note] InnoDB: Setting log file ./ib_logfile101 size to 48 MB

2015-04-22 14:26:43 26442 [Note] InnoDB: Setting log file ./ib_logfile1 size to 48 MB

2015-04-22 14:26:43 26442 [Note] InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile0

2015-04-22 14:26:43 26442 [Warning] InnoDB: New log files created, LSN=45781

2015-04-22 14:26:43 26442 [Note] InnoDB: Doublewrite buffer not found: creating new

2015-04-22 14:26:43 26442 [Note] InnoDB: Doublewrite buffer created

2015-04-22 14:26:43 26442 [Note] InnoDB: 128 rollback segment(s) are active.

2015-04-22 14:26:43 26442 [Warning] InnoDB: Creating foreign key constraint system tables.

2015-04-22 14:26:43 26442 [Note] InnoDB: Foreign key constraint system tables created

2015-04-22 14:26:43 26442 [Note] InnoDB: Creating tablespace and datafile system tables.

2015-04-22 14:26:43 26442 [Note] InnoDB: Tablespace and datafile system tables created.

2015-04-22 14:26:43 26442 [Note] InnoDB: Waiting for purge to start

2015-04-22 14:26:43 26442 [Note] InnoDB: 5.6.24 started; log sequence number 0

2015-04-22 14:26:43 26442 [Note] Binlog end

2015-04-22 14:26:43 26442 [Note] InnoDB: FTS optimize thread exiting.

2015-04-22 14:26:43 26442 [Note] InnoDB: Starting shutdown...

2015-04-22 14:26:45 26442 [Note] InnoDB: Shutdown completed; log sequence number 1625977

OK

 

Filling help tables...2015-04-22 14:26:45 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).

2015-04-22 14:26:45 0 [Note] ./bin/mysqld (mysqld 5.6.24-ndb-7.4.6-cluster-gpl) starting as process 26473 ...

2015-04-22 14:26:45 26473 [Note] InnoDB: Using atomics to ref count buffer pool pages

2015-04-22 14:26:45 26473 [Note] InnoDB: The InnoDB memory heap is disabled

2015-04-22 14:26:45 26473 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins

2015-04-22 14:26:45 26473 [Note] InnoDB: Memory barrier is not used

2015-04-22 14:26:45 26473 [Note] InnoDB: Compressed tables use zlib 1.2.3

2015-04-22 14:26:45 26473 [Note] InnoDB: Using Linux native AIO

2015-04-22 14:26:45 26473 [Note] InnoDB: Using CPU crc32 instructions

2015-04-22 14:26:45 26473 [Note] InnoDB: Initializing buffer pool, size = 128.0M

2015-04-22 14:26:45 26473 [Note] InnoDB: Completed initialization of buffer pool

2015-04-22 14:26:45 26473 [Note] InnoDB: Highest supported file format is Barracuda.

2015-04-22 14:26:45 26473 [Note] InnoDB: 128 rollback segment(s) are active.

2015-04-22 14:26:45 26473 [Note] InnoDB: Waiting for purge to start

2015-04-22 14:26:45 26473 [Note] InnoDB: 5.6.24 started; log sequence number 1625977

2015-04-22 14:26:45 26473 [Note] Binlog end

2015-04-22 14:26:45 26473 [Note] InnoDB: FTS optimize thread exiting.

2015-04-22 14:26:45 26473 [Note] InnoDB: Starting shutdown...

2015-04-22 14:26:47 26473 [Note] InnoDB: Shutdown completed; log sequence number 1625987

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:

 

  ./bin/mysqladmin -u root password 'new-password'

  ./bin/mysqladmin -u root -h ryxr2.localdomain password 'new-password'

 

Alternatively you can run:

 

  ./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 . ; ./bin/mysqld_safe &

 

You can test the MySQL daemon with mysql-test-run.pl

 

  cd mysql-test ; perl mysql-test-run.pl

 

Please report any problems at http://bugs.mysql.com/

 

The latest information about MySQL is available on the web at

 

  http://www.mysql.com

 

Support MySQL by buying support/licenses at http://shop.mysql.com

 

New default config file was created as ./my.cnf and

will be used by default by the server when you start it.

You may edit this file to change server settings

 

WARNING: Default config file /etc/my.cnf exists on the system

This file will be read by default by the MySQL server

If you do not want to use this, either remove it, or use the

--defaults-file argument to mysqld_safe when starting the server

 

 

[root@ryxr2 mysql]# chown -R root .

[root@ryxr2 mysql]# chown -R mysql data

[root@ryxr2 mysql]# chgrp -R mysql .

 

 

Server3:

作为管理节点服务器,Server3需要ndb_mgm和ndb_mgmd两个文件,可以从server1或server2从copy过来,scp /usr/local/mysql/bin/ndb_mgm* root@192.168.0.214:/usr/bin/

为管理节点服务器建立配置文件

mkdir /var/lib/mysql-cluster

# cd /var/lib/mysql-cluster

# vi 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

# 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.

 

[MYSQLD DEFAULT]

[NDB_MGMD DEFAULT]

[TCP DEFAULT]

# Managment Server

[NDB_MGMD]

HostName=192.168.0.214                        #管理节点服务器Server3的IP地址

Datadir=/var/lib/mysql-cluster    #Directory for MGM node logfiles

# Storage Engines

[NDBD]

HostName=192.168.0.30                         #MySQL集群Server1的IP地址

DataDir= /usr/local/mysql/data

[NDBD]

HostName=192.168.0.31                         #MySQL集群Server2的IP地址

DataDir=/usr/local/mysql/data

# 以下2个[MYSQLD]

[MYSQLD]

HostName=192.168.0.30

[MYSQLD]

HostName=192.168.0.31

 

创建后,启动管理节点服务器Server3,

[root@dgryxrdb mysql-cluster]# ndb_mgmd 

MySQL Cluster Management Server mysql-5.6.24 ndb-7.4.6

2015-04-22 14:42:18 [MgmtSrvr] INFO     -- The default config directory '/usr/local/mysql/mysql-cluster' does not exist. Trying to create it...

2015-04-22 14:42:18 [MgmtSrvr] INFO     -- Sucessfully created config directory

2015-04-22 14:42:18 [MgmtSrvr] ERROR    -- Could not determine which nodeid to use for this node. Specify it with --ndb-nodeid= on command line

 

如果以上执行错误,则执行

ndb_mgmd -f /var/lib/mysql-cluster/config.ini --用参数“-f”或“--config-file”告诉ndb_mgmd配置文件所在位置,默认是在ndb_mgmd相同目录下。

Cluster的管理节点的默认端口是1186,数据节点的默认端口2202,从Mysql5.0.3开始,该限制已被放宽,Cluster能够根据空闲的端口自动地为数据节点分配端口

启动管理节点后应该注意,这只是管理节点服务,并不是管理终端。启动Mysql Cluster合理的顺序是,先启动管理节点服务器,然后启动存储节点服务器,最后才启动SQL节点服务器。

 

在Server1和Server2做如下改动

# vi /etc/my.cnf

 

 

[root@ryxr2 ~]# vi /etc/my.cnf 

[client]

port            = 3306

socket          = /tmp/mysql.sock

[mysqld]

port            = 3306

socket          = /tmp/mysql.sock

datadir = /usr/local/mysql/data

basedir = /usr/local/mysql

ndbcluster

ndb-connectstring=192.168.0.214

[MYSQL_CLUSTER]

ndb-connectstring=192.168.0.214

 

----------------以下为实际

[client]

port = 3306

socket = /tmp/mysql.sock

 

[mysqld]

datadir=/usr/local/mysql/data

basedir/usr/local/mysql

socket=/tmp/mysql.sock

user=mysql

# Disabling symbolic-links is recommended to prevent assorted security risks

symbolic-links=0

ndbcluster

ndb-connectstring=192.168.0.214

 

[mysqld_safe]

log-error=/usr/local/mysql/data/mysqld.log

pid-file=/usr/local/mysql/data/mysqld.pid

 

[MYSQL_CLUSTER]

ndb-connectstring=192.168.0.214

 

修改完后,保存,执行

在存储节点上(server1和server2)

[root@ryxr1 mysql]# ./bin/ndbd --initial

2015-04-22 15:23:37 [ndbd] INFO     -- Angel connected to '192.168.0.214:1186'

2015-04-22 15:23:37 [ndbd] INFO     -- Angel allocated nodeid: 3

注:只有在第一次启动ndbd时或者对Server3的config.ini进行改动后或在备份、恢复数据后才需要使用--initial参数,因为该参数会使节点删除由早期ndbd

启动sql节点服务器

[root@ryxr2 mysql]# /etc/rc.d/init.d/mysql start

或/usr/local/mysql/bin/mysqld_safe --user=mysql --explicit_defaults_for_timestamp &

Server1和Server2均启动后,回到管理节点Server3,启动管理终端

键入:show命令,查看当前工作状态

[root@dgryxrdb mysql-cluster]# /usr/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.0.30  (mysql-5.6.24 ndb-7.4.6, Nodegroup: 0)

id=3    @192.168.0.31  (mysql-5.6.24 ndb-7.4.6, Nodegroup: 0, *)

 

[ndb_mgmd(MGM)] 1 node(s)

id=1    @192.168.0.214  (mysql-5.6.24 ndb-7.4.6)

 

[mysqld(API)]   2 node(s)

id=4    @192.168.0.30  (mysql-5.6.24 ndb-7.4.6)

id=5    @192.168.0.31  (mysql-5.6.24 ndb-7.4.6)

 

如上,在Server2,创建表(只能是基于ndb存储引擎的)查看是否在Server1中也存在。

mysql> create table c_testb(id varchar(10)) engine=ndbcluster default charset utf8;

Query OK, 0 rows affected (0.19 sec)

在Server1中执行insert,Server2数据同步完成

mysql> select * from c_testb;

+------+

| id   |

+------+

| 1    |

| 2    |

+------+

2 rows in set (0.01 sec)

 

 

安全关闭

在MGM节点所在机器上,输入

# /usr/local/mysql/ndb_mgm -e shutdown 

关闭SQL节点的mysqld服务

#/usr/local/mysql/bin/mysqladmin -uroot shutdown

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/28258625/viewspace-1651185/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/28258625/viewspace-1651185/

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值