2018年04月6日网站服务器迁移完成……

MySQL集群安装与配置

mysql 苏 demo 1488℃ 0评论

MySQL集群安装与配置 | Linux服务器运维日志

MySQL Cluster 是 MySQL 适合于分布式计算环境的高实用、高冗余版本。它采用了NDB Cluster 存储引擎,允许在1个 Cluster 中运行多个MySQL服务器。MySQL Cluster 能够使用多种故障切换和负载平衡选项配置NDB存储引擎,但在 Cluster 级别上的存储引擎上做这个最简单。下面我们简单介绍MySQL Cluster如何安装与配置。
基本设定
管理(MGM)节点:192.168.0.111
MySQL服务器(SQL)节点:192.168.0.110
数据(NDBD)节点”A”:192.168.0.112
数据(NDBD)节点”B”:192.168.0.113

一、mysql集群安装

mysql的集群安装可以有三种方式,一是直接下载二进制使用,二是使用rpm安装,三是源码编译。我们这里使用第一种安装。
1、每个节点做相同的操作

  1. cd /tmp
  2. wget http://cdn.mysql.com/Downloads/MySQL-Cluster-7.2/mysql-cluster-gpl-7.2.8-linux2.6-i686.tar.gz
  3. tar xzf mysql-cluster-gpl-7.2.8-linux2.6-i686.tar.gz
  4. mv mysql-cluster-gpl-7.2.8-linux2.6-i686 /usr/local/mysql

注意:这里下载的是32位的二进制包,如果你的系统是64位,需要下载64位的包。
2、存储节点和SQL节点安装

  1. groupadd mysql
  2. useradd -g mysql mysql
  3. /usr/local/mysql/scripts/mysql_install_db –basedir=/usr/local/mysql –datadir=/usr/local/mysql/data –user=mysql
  4. chown -R root /usr/local/mysql
  5. chown -R mysql /usr/local/mysql/data
  6. chgrp -R mysql /usr/local/mysql
  7. cp /usr/local/mysql/support-files/my-medium.cnf /etc/my.cnf

二、节点配置

1、配置存储节点和SQL节点

  1. vi /etc/my.cnf
  2. 类似于:
  3. # Options for mysqld process:
  4. [MYSQLD]
  5. ndbcluster                      # run NDB engine
  6. ndb-connectstring=198.168.0.111  # location of MGM node
  7. # Options for ndbd process:
  8. [MYSQL_CLUSTER]
  9. ndb-connectstring=198.168.0.111  # location of MGM node

2、配置管理节点

  1. mkdir /var/lib/mysql-cluster
  2. cd /var/lib/mysql-cluster
  3. vi config.ini
  4. config.ini文件应类似于:
  5. # Options affecting ndbd processes on all data nodes:
  6. [NDBD DEFAULT]
  7. NoOfReplicas=2    # Number of replicas
  8. DataMemory=80M    # How much memory to allocate for data storage
  9. IndexMemory=18M   # How much memory to allocate for index storage
  10.                   # For DataMemory and IndexMemory, we have used the
  11.                   # default values. Since the “world” database takes up
  12.                   # only about 500KB, this should be more than enough for
  13.                   # this example Cluster setup.
  14. # TCP/IP options:
  15. [TCP DEFAULT]
  16. portnumber=2202   # This the default; however, you can use any
  17.                   # port that is free for all the hosts in cluster
  18.                   # Note: It is recommended beginning with MySQL 5.0 that
  19.                   # you do not specify the portnumber at all and simply allow
  20.                   # the default value to be used instead
  21. # Management process options:
  22. [NDB_MGMD]
  23. hostname=198.168.0.111           # Hostname or IP address of MGM node
  24. datadir=/var/lib/mysql-cluster  # Directory for MGM node logfiles
  25. # Options for data node “A”:
  26. [NDBD]
  27.                                 # (one [NDBD] section per data node)
  28. hostname=198.168.0.112         # Hostname or IP address
  29. datadir=/usr/local/mysql/data   # Directory for this data node’s datafiles
  30. # Options for data node “B”:
  31. [NDBD]
  32. hostname=198.168.0.113       # Hostname or IP address
  33. datadir=/usr/local/mysql/data   # Directory for this data node’s datafiles
  34. # SQL node options:
  35. [MYSQLD]
  36. hostname=198.168.0.110           # Hostname or IP address
  37.                                 # (additional mysqld connections can be
  38.                                 # specified for this node for various
  39.                                 # purposes such as running ndb_restore)

三、首次启动节点

1、启动管理节点

  1. /usr/local/mysql/bin/ndb_mgmd –configdir=/var/lib/mysql-cluster -f /var/lib/mysql-cluster/config.ini

2、启动数据节点
首次启动需要–initial参数初始化,下一次启动就不需要了。

  1. /usr/local/mysql/bin/ndbd –initial

3、启动SQL节点

  1. /usr/local/mysql/bin/mysqld_safe  &

4、检查状态
如果一切正常,执行命令 /usr/local/mysql/bin/ndb_mgm -e show应该会输出类似信息:

[root@localhost mysql-cluster]# /usr/local/mysql/bin/ndb_mgm -e show
Connected to Management Server at: localhost:1186
Cluster Configuration
———————
[ndbd(NDB)] 2 node(s)
id=2 @192.168.0.112 (mysql-5.5.27 ndb-7.2.8, Nodegroup: 0, Master)
id=3 @192.168.0.113 (mysql-5.5.27 ndb-7.2.8, Nodegroup: 0)

[ndb_mgmd(MGM)] 1 node(s)
id=1 @192.168.0.111 (mysql-5.5.27 ndb-7.2.8)

[mysqld(API)] 1 node(s)
id=4 @192.168.0.110 (mysql-5.5.27 ndb-7.2.8)

四、测试服务是否正常

在SQL节点上执行如下数据库操作:

  1. /usr/local/mysql/bin/mysql -uroot -p
  2. mysql> create database clusterdb;use clusterdb;
  3. mysql> create table simples (id int not null primary key) engine=ndb;
  4. mysql> insert into simples values (1),(2),(3),(4);
  5. mysql> select * from simples;

如果出现:
+—-+
| id |
+—-+
| 1 |
| 2 |
| 4 |
| 3 |
+—-+
则表示工作正常。

五、安全关闭和重启

1、关闭mysql集群,可在管理节点在执行如下命令:

  1. /usr/local/mysql/bin/ndb_mgm -e shutdown

2、重启管理节点

  1. /usr/local/mysql/bin/ndb_mgmd –configdir=/var/lib/mysql-cluster -f /var/lib/mysql-cluster/config.ini

3、重启数据节点

  1. /usr/local/mysql/bin/ndbd

参考:http://dev.mysql.com/doc/refman/5.1/zh/ndbcluster.html

打赏

转载请注明:苏demo的别样人生 » MySQL集群安装与配置

   如果本篇文章对您有帮助,欢迎向博主进行赞助,赞助时请写上您的用户名。
支付宝直接捐助帐号oracle_lee@qq.com 感谢支持!
喜欢 (0)or分享 (0)
发表我的评论
取消评论
表情