设为首页 收藏本站
查看: 520|回复: 0

[经验分享] 配置mysql cluster

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2015-6-4 08:53:53 | 显示全部楼层 |阅读模式
                      1.从mysql 5.1 以后 mysql安装包里就不包含mysql cluster ,而是单独作为一个产品发布,目前mysql网站上最新的版本是mysql cluster 7.2.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
    [iyunv@dbcp-db01 mysqlData]# pwd
    /mysqlData
    [iyunv@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.配置管理节点
   [iyunv@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 配置不同的参数路径)
              [iyunv@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


              [iyunv@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节点
             [iyunv@dbcp-db01 ~]# cd /usr/local/mysql/scripts/
             [iyunv@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
             [iyunv@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!


             [iyunv@dbcp-db01 ~]# cd /usr/local/mysql/scripts/
             [iyunv@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
             [iyunv@dbcp-db01 scripts]# Installing MySQL system tables...
             OK
             Filling help tables...
             OK
              .
              .
              .....

13.启动mysql-cluster,启动顺序为  管理节点->存储节点->SQL节点
     A.  启动管理节点
              [iyunv@dbcp-db01 ~]# ndb_mgmd -f /data/config/mysqlcluster.ini
              MySQL Cluster Management Server mysql-5.5.25 ndb-7.2.7
              [iyunv@dbcp-db01 ~]#
      B.  启动存储节点
              [iyunv@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
              [iyunv@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
              [iyunv@dbcp-db01 scripts]#
      C.  启动SQL节点
              [iyunv@dbcp-db01 scripts]# mysqld_safe --defaults-file=/data/config/my-node4.cnf --user=mysql &
             [1] 24649
             [iyunv@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/
             [iyunv@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
             [iyunv@dbcp-db01 scripts]# mysqld_safe --defaults-file=/data/config/my-node5.cnf --user=mysql &
             [2] 24761
             [iyunv@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/
             [iyunv@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
             [iyunv@dbcp-db01 scripts]#
14.所有节点都启动了 用 ndb_mgm 查看
             [iyunv@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上 创建数据库,表,插入数据
             [iyunv@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 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> create database cluster_one;
             Query OK, 1 row affected (0.12 sec)
             mysql> use cluster_one
             Database changed
             mysql> create table c_tb_a (id int ,tname varchar(10)) engine = ndbcluster default charset utf8;
             Query OK, 0 rows affected (0.25 sec)
             mysql> insert into  c_tb_a values (1,'qqqqqq');
             Query OK, 1 row affected (0.01 sec)
             mysql> insert into  c_tb_a values (2,'dddddd');
             Query OK, 1 row affected (0.00 sec)
             mysql>
16.在SQL节点端口3398 上查询数据
             [iyunv@dbcp-db01 config]# mysql -uroot -p -S /data/socket/my-n2.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 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> show databases;
             +--------------------+
             | Database           |
             +--------------------+
             | information_schema |
             | cluster_one        |
             | mysql              |
             | ndb_3_fs           |
             | ndbinfo            |
             | performance_schema |
             | test               |
             +--------------------+
             7 rows in set (0.04 sec)
             mysql> use cluster_one
             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_cluster_one |
             +-----------------------+
             | c_tb_a                |
             +-----------------------+
             1 row in set (0.00 sec)
             mysql> select * from c_tb_a;
             +------+--------+
             | id   | tname  |
             +------+--------+
             |    1 | qqqqqq |
             |    2 | dddddd |
             +------+--------+
             2 rows in set (0.00 sec)
             mysql>

以上就是在一台计算机上安装配置mysql cluster 的过程,其实跟在多台机器上配置差不多,只是在配置cnf的时候要用不同的路径,要注意的是在初始化的时候把--defaults-file  --datadir  --basedir 几个参数加上。
请多多关照。 spacer.jpg
                   


运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.iyunv.com/thread-73709-1-1.html 上篇帖子: MySQL多字符集备份恢复测试 下篇帖子: 基于DRBD实现高可用MariaDB mysql
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表