当前位置:Gxlcms > 数据库问题 > 配置mysql cluster

配置mysql cluster

时间:2021-07-01 10:21:17 帮助过:7人阅读


  下载地址:http://www.mysql.com/downloads/cluster/#downloads
2.建立有5个节点的MySQL CLuster体系 ( OS :   REDHAT 6.1 )
  管理节点(MGM)                192.168.251.141
  SQL节点1(SQL1)                         192.168.251.141
  SQL节点2(SQL2)                         192.168.251.141
  数据节点1(NDBD1)                    192.168.251.141
  数据节点2(NDBD2)                    192.168.251.141
3.首先去下载文件 mysql-cluster-gpl-7.2.7-linux2.6-x86_64.tar.gz 
4.解压文件到/mysqlData/ 并 重命名为 mysql-cluster
    [root@dbcp-db01 mysqlData]# pwd
    /mysqlData
    [root@dbcp-db01 mysqlData]# ls
    mysql-cluster-gpl-7.2.7-linux2.6-x86_64.tar.gz  mysql-cluster
5.建立软连
    ln -s /mysqlData/mysql-cluster/ /usr/local/mysql
6.在/etc/profile 加入 export PATH=$PATH:/usr/local/mysql/bin
   echo “export PATH=$PATH:/usr/local/mysql/bin” >> /etc/profile 
   source /etc/profile
7.配置管理节点
   [root@dbcp-db01 config]# vi /data/config/mysqlcluster.ini
   [NDBD DEFAULT]
   NoOfReplicas=1
   [TCP DEFAULT]
   portnumber=3388
   #
   [NDB_MGMD]
   NodeId = 1
   hostname=192.168.251.141
   #
   datadir=/mysqlData/clustermgmd-data/
   #
   [NDBD]
   NodeId = 2
   hostname=192.168.251.141
   datadir=/mysqlData/clusterndb1-data/
   #
   [NDBD]
   NodeId = 3
   hostname=192.168.251.141
   datadir=/mysqlData/clusterndb2-data/
   #
   [MYSQLD]
   NodeId = 4
   hostname=192.168.251.141
   #
   [MYSQLD]
   NodeId = 5
   hostname=192.168.251.141
   [MYSQLD]
8.配置存储节点和SQL节点(配置两个cnf 配置不同的参数路径)
              [root@dbcp-db01 config]# vi /data/config/my-node4.cnf
              [mysqld]
              ndbcluster
              basedir=/mysqlData/mysql-cluster
              datadir=/mysqlData/clusterndb1-data/
              socket=/data/socket/my-n1.sock
              pid-file=/data/socket/n1.pid
              log-error = /mysqlLog/n1_err.log
              slow_query_log_file = /mysqlLog/n1_slow.log
              port = 3399
              ndb-connectstring=192.168.251.141
              [mysql_cluster]
              ndb-connectstring=192.168.251.141


              [root@dbcp-db01 config]# vi /data/config/my-node5.cnf
              [mysqld]
              ndbcluster
              basedir=/mysqlData/mysql-cluster
              datadir=/mysqlData/clusterndb2-data/
              socket=/data/socket/my-n2.sock
              pid-file=/data/socket/n2.pid
              log-error = /mysqlLog/n2_err.log
              slow_query_log_file = /mysqlLog/n2_slow.log
              port = 3398
              ndb-connectstring=192.168.251.141
              [mysql_cluster]
              ndb-connectstring=192.168.251.141
9.建立mysql用户组和mysql用户
              groupadd mysql
              useradd -g mysql mysql
10.创建配置文件中所用到的目录
              mkdir -p /mysqlData/clusterndb2-data/
              mkdir -p /mysqlData/clusterndb1-data/
              mkdir -p /data/socket/
              mkdir -p /mysqlLog/ 
              mkdir -p /mysqlData/clustermgmd-data/

11.更改相关目录的权限
             chown -R mysql.mysql /mysqlData/
             chown -R mysql.mysql /mysqlLog/

12.初始化SQL节点
             [root@dbcp-db01 ~]# cd /usr/local/mysql/scripts/
             [root@dbcp-db01 scripts]# ./mysql_install_db --defaults-file=/data/config/my-node4.cnf --datadir=/mysqlData/clusterndb1-data/ --user=mysql --basedir=/mysqlData/mysql-cluster/ &
             [1] 24447
             [root@dbcp-db01 scripts]# 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:
             /mysqlData/mysql-cluster//bin/mysqladmin -u root password ‘new-password‘
             /mysqlData/mysql-cluster//bin/mysqladmin -u root -h dbcp-db01 password ‘new-password‘
             Alternatively you can run:
             /mysqlData/mysql-cluster//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 /mysqlData/mysql-cluster/ ; /mysqlData/mysql-cluster//bin/mysqld_safe &
             You can test the MySQL daemon with mysql-test-run.pl
             cd /mysqlData/mysql-cluster//mysql-test ; perl mysql-test-run.pl
             Please report any problems with the /mysqlData/mysql-cluster//scripts/mysqlbug script! 


             [root@dbcp-db01 ~]# cd /usr/local/mysql/scripts/
             [root@dbcp-db01 scripts]# ./mysql_install_db --defaults-file=/data/config/my-node5.cnf --datadir=/mysqlData/clusterndb1-data/ --user=mysql --basedir=/mysqlData/mysql-cluster/ &
             [1] 24508
             [root@dbcp-db01 scripts]# Installing MySQL system tables...
             OK
             Filling help tables...
             OK
              .
              .
              .....

13.启动mysql-cluster,启动顺序为  管理节点->存储节点->SQL节点
     A.  启动管理节点
              [root@dbcp-db01 ~]# ndb_mgmd -f /data/config/mysqlcluster.ini
              MySQL Cluster Management Server mysql-5.5.25 ndb-7.2.7
              [root@dbcp-db01 ~]#
      B.  启动存储节点
              [root@dbcp-db01 scripts]# /usr/local/mysql/bin/ndbd --defaults-file=/data/config/my-node4.cnf --initial
              2012-08-10 11:25:13 [ndbd] INFO     -- Angel connected to ‘192.168.251.141:1186‘
              2012-08-10 11:25:13 [ndbd] INFO     -- Angel allocated nodeid: 2
              [root@dbcp-db01 scripts]# /usr/local/mysql/bin/ndbd --defaults-file=/data/config/my-node5.cnf --initial
              2012-08-10 11:25:25 [ndbd] INFO     -- Angel connected to ‘192.168.251.141:1186‘
              2012-08-10 11:25:25 [ndbd] INFO     -- Angel allocated nodeid: 3
              [root@dbcp-db01 scripts]#
      C.  启动SQL节点
              [root@dbcp-db01 scripts]# mysqld_safe --defaults-file=/data/config/my-node4.cnf --user=mysql &
             [1] 24649
             [root@dbcp-db01 scripts]# 120810 11:26:41 mysqld_safe Logging to ‘/mysqlLog/n1_err.log‘.
             120810 11:26:41 mysqld_safe Starting mysqld daemon with databases from /mysqlData/clusterndb1-data/
             [root@dbcp-db01 scripts]# ps aux | grep mysqld
             root     24649  0.1  0.0 106012  1316 pts/1    S    11:26   0:00 /bin/sh /usr/bin/mysqld_safe --defaults-file=/data/config/my-node4.cnf --user=mysql
             mysql    24732  1.2  2.2 953944 46772 pts/1    Sl   11:26   0:00 /usr/libexec/mysqld --defaults-file=/data/config/my-node4.cnf --basedir=/mysqlData/mysql-cluster 
             --datadir=/mysqlData/clusterndb1-data/ --user=mysql --log-error=/mysqlLog/n1_err.log --pid-file=/data/socket/n1.pid --socket=/data/socket/my-n1.sock --port=3399
             root     24760  0.0  0.0 103152   796 pts/1    S+   11:27   0:00 grep mysqld
             [root@dbcp-db01 scripts]# mysqld_safe --defaults-file=/data/config/my-node5.cnf --user=mysql &
             [2] 24761
             [root@dbcp-db01 scripts]# 120810 11:27:18 mysqld_safe Logging to ‘/mysqlLog/n2_err.log‘.
             120810 11:27:18 mysqld_safe Starting mysqld daemon with databases from /mysqlData/clusterndb2-data/
             [root@dbcp-db01 scripts]# ps aux | grep mysqld
             root     24649  0.0  0.0 106012  1316 pts/1    S    11:26   0:00 /bin/sh /usr/bin/mysqld_safe --defaults-file=/data/config/my-node4.cnf --user=mysql
             mysql    24732  0.8  2.2 953944 47184 pts/1    Sl   11:26   0:00 /usr/libexec/mysqld --defaults-file=/data/config/my-node4.cnf --basedir=/mysqlData/mysql-cluster 
             --datadir=/mysqlData/clusterndb1-data/ --user=mysql --log-error=/mysqlLog/n1_err.log --pid-file=/data/socket/n1.pid --socket=/data/socket/my-n1.sock --port=3399
             root     24761  0.2  0.0 106012  1320 pts/1    S    11:27   0:00 /bin/sh /usr/bin/mysqld_safe --defaults-file=/data/config/my-node5.cnf --user=mysql
             mysql    24844  2.6  2.2 953944 46932 pts/1    Sl   11:27   0:00 /usr/libexec/mysqld --defaults-file=/data/config/my-node5.cnf --basedir=/mysqlData/mysql-cluster 
             --datadir=/mysqlData/clusterndb2-data/ --user=mysql --log-error=/mysqlLog/n2_err.log --pid-file=/data/socket/n2.pid --socket=/data/socket/my-n2.sock --port=3398
             root     24873  0.0  0.0 103152   796 pts/1    S+   11:27   0:00 grep mysqld
             [root@dbcp-db01 scripts]#
14.所有节点都启动了 用 ndb_mgm 查看
             [root@dbcp-db01 ~]# 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.251.141  (mysql-5.5.25 ndb-7.2.7, Nodegroup: 0, Master)
             id=3    @192.168.251.141  (mysql-5.5.25 ndb-7.2.7, Nodegroup: 1)
             [ndb_mgmd(MGM)] 1 node(s)
             id=1    @192.168.251.141  (mysql-5.5.25 ndb-7.2.7)
             [mysqld(API)]   2 node(s)
             id=4    @192.168.251.141  (mysql-5.5.25 ndb-7.2.7)
             id=5    @192.168.251.141  (mysql-5.5.25 ndb-7.2.7)
             ndb_mgm> 
15.在SQL节点端口3399上 创建数据库,表,插入数据
             [root@dbcp-db01 config]# mysql -uroot -p -S /data/socket/my-n1.sock 
             Enter password: 
             Welcome to the MySQL monitor.  Commands end with ; or \g.
             Your MySQL connection id is 2
             Server version: 5.5.25a-ndb-7.2.7-gpl MySQL Cluster Community Server (GPL)
             Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserv

人气教程排行