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

[经验分享] mysql集群的配置

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2015-7-23 08:49:05 | 显示全部楼层 |阅读模式
最近在 学习MYSQL集群的配置,首先要了解什么集群,为什么要使用集群,以及安装集群的软件是什么和集群中的进程有哪些。      1.什么是集群?
         集群是一组服务器提供相同的服务
        2.为什么要使用集群?
         解决单点故障和数据的备份问题。
        操作系统以及mysql配置文件的说明。
            Linux系统:redhat6.5
       安装集群软件: MySQL-Cluster-gpl-7.3.3-1.el6.x86_64.rpm-bundle.tar
       服务器的角色:

        实验要求:5台服务器,分别ip地址192.168.1.10做管理节点,192.168.1.20/192.168.1.30做数据节点使数据能够同时备份当其中任意一台服务器宕机后,对数据库进行操作,当宕机的服务器恢复后自动同步数据,192.168.1.40/192.168.1.50做sql节点当任意一台mysql节点故障后,都可以登陆数据库。   

         192.168.1.10(mgmd)
               192.168.1.20(ndbd)

         192.168.1.30 (ndbd)
         192.168.1.40 (sql)
         192.168.1.50 (sql)
一。在所有服务器上安装提供集群服务的软件 mysql-cluster (.rpm  源码)
最简单是的PRM包,下面采用二进制包的方法进行安装
1.解压软件包。
[iyunv@fanxh opt]# tar -xvf MySQL-Cluster-gpl-7.3.3-1.el6.x86_64.rpm-bundle.tar
2.安装软件包,tar解压出来的是rpm包,直接安装就可以。
[iyunv@fanxh opt]# rpm  -Uvh  MySQL-Cluster-*.rpm
3.查看软件包是否已安装。

[iyunv@fanxh opt]# rpm -qa | grep -i mysql
MySQL-Cluster-shared-compat-gpl-7.3.3-1.el6.x86_64
MySQL-Cluster-devel-gpl-7.3.3-1.el6.x86_64
MySQL-Cluster-embedded-gpl-7.3.3-1.el6.x86_64
perl-DBD-MySQL-4.013-3.el6.x86_64
MySQL-Cluster-test-gpl-7.3.3-1.el6.x86_64
MySQL-Cluster-server-gpl-7.3.3-1.el6.x86_64
MySQL-Cluster-client-gpl-7.3.3-1.el6.x86_64
MySQL-Cluster-shared-gpl-7.3.3-1.el6.x86_64
4.在192.168.1.10上配置管理节点。
    管理节点运行的是管理进程,运行时加载自己的主配置文件,主配置文件需要自己写。
例如:配置文件为config.ini   配置文件的内容包括:

  1 数据节点的公共配置[ndbd  default]
  2 指定管理节点[ndb_mgmd]
  3 指定数据节点 [ndbd]
  4 指定sql节点  [mysqld]
[iyunv@fanxh ~]# vim /etc/config.ini
[ndbd  default]
NoOfReplicas=2 (表示数据节点的份数,有几个数据节点就写几)
DataMemory=80M  (表示数据缓存的大小)
IndexMemory=18M  (表示索引缓存的大小)
[ndb_mgmd]
nodeid=1  ( 用来设置当前主机在集群中的编号)
hostname=192.168.1.10  (指定管理节点的IP地址)
datadir=/var/log/mysql-cluster (指定把运行中的信息放在/var/log/mysql-cluster,这个文件夹   必须在系统中存在,如果没有创建该文件夹。)
[ndbd]
nodeid=2  (数据节点的编号)
hostname=192.168.1.20 (数据节点的IP地址)
datadir=/var/log/mysql-cluster/data  (存储数据的位置)
[ndbd]
nodeid=3
hostname=192.168.1.30
datadir=/var/log/mysql-cluster/data
[mysqld]
nodeid=4
hostname=192.168.1.40
[mysqld]
nodeid=5
hostname=192.168.1.50


在192.168.1.10创建/var/log/mysql-cluster文件夹

[iyunv@fanxh ~]# mkdir -p /var/log/mysql-cluster/
5.在192.168.1.20/192.168.1.30上配置数据节点

  在192.168.1.20和192.168.1.30上 分别创建/var/log/mysql-cluster文件夹用来存储数据的位置

  [iyunv@fanxh ~]# mkdir -p /var/log/mysql-cluster/
创建主配置文件。
[iyunv@fanxh ~]# vim /etc/my.cnf
[mysqld]
datadir=/var/log/mysql-cluster/data   (指定数据库目录)
ndb-connectstring=192.168.1.10   (指定连接管理集群的服务器IP)
ndbcluster        (表的存储引擎必须是ndbcluster)
[mysql_cluster]   ( 指定管理集群的机器)
ndb-connectstring=192.168.1.10(指定谁来管理集群的服务器IP)

6.在192.168.1.40/192.168.1.50上配置sql节点
[iyunv@fanxh ~]# vim /etc/my.cnf
[mysqld]
ndbcluster
default-storage-engine=ndbcluster     (指定默认的存储引擎)
ndb-connectstring=192.168.1.10 (指定连接管理集群的服务器IP)
[mysql_cluster]
ndb-connectstring=192.168.1.10 (指定谁来管理集群的服务器IP)

7.启动不同角色服务对应进程(有启动顺序,按照以下顺序进行启动)。
    1  启动管理进程在192.168.1.10上。
[iyunv@fanxh ~]# ndb_mgmd -f /etc/config/init        启动mysql cluster服务
MySQL Cluster Management Server mysql-5.6.14 ndb-7.3.3
   

[iyunv@fanxh ~]# netstat -anuptl | grep :1186       查看集群端口是否开启
tcp        0      0 0.0.0.0:1186                0.0.0.0:*                   LISTEN      4341/ndb_mgmd
tcp        0      0 127.0.0.1:38177             127.0.0.1:1186              ESTABLISHED 4341/ndb_mgmd
tcp        0      0 127.0.0.1:1186              127.0.0.1:38177             ESTABLISHED 4341/ndb_mgmd
tcp        0      0 192.168.1.10:1186           192.168.1.50:43075          ESTABLISHED 4341/ndb_mgmd
tcp        0      0 192.168.1.10:1186           192.168.1.40:37459          ESTABLISHED 4341/ndb_mgmd
   

[iyunv@fanxh ~]# 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 192.168.1.20)
id=3 (not connected, accepting connect from 192.168.1.30)

[ndb_mgmd(MGM)] 1 node(s)
id=1    @192.168.1.10  (mysql-5.6.14 ndb-7.3.3)

[mysqld(API)]   2 node(s)
id=4 (not connected, accepting connect from 192.168.1.40)
id=5 (not connected, accepting connect from 192.168.1.50)
   2  启动192.168.1.20/192.168.1.30上的数据进程
   [iyunv@fanxh ~]# ndbd           在192.168.1.20启动数据进程的命令
2015-07-21 15:49:24 [ndbd] INFO     -- Angel connected to '192.168.1.10:1186'
2015-07-21 15:49:24 [ndbd] INFO     -- Angel allocated nodeid: 2  3  
[iyunv@localhost ~]# ndbd        在192.168.1.30启动数据进程的命令
2015-07-21 10:16:16 [ndbd] INFO     -- Angel connected to '192.168.1.10:1186'
2015-07-21 10:16:16 [ndbd] INFO     -- Angel allocated nodeid: 3   service mysql start     

  3.启动完数据进程后在管理节点192.168.1.10上查看数据进程是否已经启动。

ndb_mgm> show
Cluster Configuration
---------------------
[ndbd(NDB)]     2 node(s)
id=2    @192.168.1.20  (mysql-5.6.14 ndb-7.3.3, starting, Nodegroup: 0, *)
id=3    @192.168.1.30  (mysql-5.6.14 ndb-7.3.3, starting, Nodegroup: 0)

[ndb_mgmd(MGM)] 1 node(s)
id=1    @192.168.1.10  (mysql-5.6.14 ndb-7.3.3)

[mysqld(API)]   2 node(s)
id=4 (not connected, accepting connect from 192.168.1.40)
id=5 (not connected, accepting connect from 192.168.1.50)

ndb_mgm> Node 2: Started (version 7.3.3)
Node 3: Started (version 7.3.3)
  4.在192.168.1.40/192.168.1.50启动mysql数据库服务。
[iyunv@fanxh ~]# service mysql start
Starting MySQL SUCCESS!

5.启动完mysql数据库服务后在管理节点192.168.1.10上查看mysql进程是否已经启动。
ndb_mgm> show
Cluster Configuration
---------------------
[ndbd(NDB)]     2 node(s)
id=2    @192.168.1.20  (mysql-5.6.14 ndb-7.3.3, Nodegroup: 0, *)
id=3    @192.168.1.30  (mysql-5.6.14 ndb-7.3.3, Nodegroup: 0)

[ndb_mgmd(MGM)] 1 node(s)
id=1    @192.168.1.10  (mysql-5.6.14 ndb-7.3.3)

[mysqld(API)]   2 node(s)
id=4    @192.168.1.40  (mysql-5.6.14 ndb-7.3.3)
id=5    @192.168.1.50  (mysql-5.6.14 ndb-7.3.3)


8.客户端测试
1.访问节点的单点故障。
在mysql 数据库服务上建表建库,进行查看。

登陆mysql服务器192.168.1.40/192.168.1.50
[iyunv@fanxh~]# cat /root/.mysql_secret
# The random password set for the root user at Mon Jul  6 04:54:27 2015 (local time): umdVqWxz
[iyunv@fanxh ~]# mysql -hlocalhost -uroot -pumdVqWxz
mysql>set password for root@localhost=password("123")

mysql>quit
[iyunv@fanxh ~]# mysql -hlocalhost -uroot -p123
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.6.14-ndb-7.3.3-cluster-gpl MySQL Cluster Community Server                                                (GPL)

Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved                                               .

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

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



查看存储引擎默认是不是dbcluster
mysql> show engines;
+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+
| Engine             | Support | Comment                                                        | Transactions | XA   | Savepoints |
+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+
| ndbcluster         | DEFAULT | Clustered, fault-tolerant tables                               | YES          | NO   | NO         |

关闭192.168.1.50上的 mysql服务
  [iyunv@fanxh ~]# service mysql stop
查看192.168.1.10上的信息
ndb_mgm> show
Cluster Configuration
---------------------
[ndbd(NDB)]     2 node(s)
id=2    @192.168.1.20  (mysql-5.6.14 ndb-7.3.3, Nodegroup: 0, *)
id=3    @192.168.1.30  (mysql-5.6.14 ndb-7.3.3, Nodegroup: 0)

[ndb_mgmd(MGM)] 1 node(s)
id=1    @192.168.1.10  (mysql-5.6.14 ndb-7.3.3)

[mysqld(API)]   2 node(s)
id=4    @192.168.1.40  (mysql-5.6.14 ndb-7.3.3)
id=5 (not connected, accepting connect from 192.168.1.50)

用192.168.1.40查看是否可以登陆数据库,如果可以登陆说明解决单点故障。
[iyunv@localhost ~]# mysql -hlocalhost -uroot -p123
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.14-ndb-7.3.3-cluster-gpl MySQL Cluster Community Server (GPL)

Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

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

mysql>


2.数据节点单点故障。(关闭1个数据服务,在表中进行插入,查看等一些操作,当另外一个恢复服务后,看能不能进行同步数据,如果可以说明就解决单点故障)
验证数据节点单点故障的步骤:

   1.关闭192.168.1.20的数据节点的服务。

[iyunv@fanxh ~]# pkill -9 ndbd

   2. 查看管理节点的192.168.1.20的状态。

ndb_mgm> show
Cluster Configuration
---------------------
[ndbd(NDB)]     2 node(s)
id=2 (not connected, accepting connect from 192.168.1.20)
id=3    @192.168.1.30  (mysql-5.6.14 ndb-7.3.3, Nodegroup: 0, *)

[ndb_mgmd(MGM)] 1 node(s)
id=1    @192.168.1.10  (mysql-5.6.14 ndb-7.3.3)

[mysqld(API)]   2 node(s)
id=4    @192.168.1.40  (mysql-5.6.14 ndb-7.3.3)
id=5    @192.168.1.50  (mysql-5.6.14 ndb-7.3.3)

     3.在sql节点上查看数据库的信息,当192.168.1.20宕机后查看的信息是192.168.1.30的信息。
在数据库上对表进行select ,insert into 等信息后,当192.168.1.30恢复后能不能同步数据,如果可以说明可以解决单点故障。


运维网声明 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.yunweiku.com/thread-89665-1-1.html 上篇帖子: MySQL处理请求的整体结构 下篇帖子: ERROR 1093 (HY000): You can't specify target table 'bm_area' for update in FROM mysql
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

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

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

扫描微信二维码查看详情

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


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


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


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



合作伙伴: 青云cloud

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