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

[经验分享] 配置 MySQL cluster

[复制链接]

尚未签到

发表于 2018-9-30 11:22:12 | 显示全部楼层 |阅读模式
      服务器使用情况:
      Node
      IP Address
      Management (MGMD) node
      192.168.0.10
      MySQL server (SQL) node
      192.168.0.20
      Data (NDBD) node "A"
      192.168.0.30
      Data (NDBD) node "B"
      192.168.0.40
      1,安装Management、Sql node、 Data node 重复以下步骤:
      [root@www local]# tar -zxvf mysql-cluster-gpl-7.1.3-linux-i686-glibc23.tar.gz
      [root@www local]# mv mysql-cluster-gpl-7.1.3-linux-i686-glibc23 mysql
      [root@www local]# groupadd mysql
      [root@www local]# useradd -g mysql mysql
      [root@www local]# chown -R mysql.mysql mysql
      [root@www local]# /usr/local/mysql/scripts/mysql_install_db  --user=mysql
      [root@www mysql]# cp support-files/mysql.server /etc/rc.d/init.d/
      [root@www mysql]# chmod +x /etc/rc.d/init.d/mysql.server
      [root@www mysql]# chkconfig --add mysql.server
      2,配置Management节点:
      [root@www mysql]# mkdir /var/lib/mysql-cluster
      [root@www mysql]# vi /var/lib/mysql-cluster/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.
      # TCP/IP options:
      [tcp default]
      portnumber=2202   # This the default; however, you can use any port that is free
      # for all the hosts in the cluster
      # Note: It is recommended that you do not specify the port
      # number at all and allow the default value to be used instead
      # Management process options:
      [ndb_mgmd]
      hostname=192.168.0.10           # Hostname or IP address of management node
      datadir=/var/lib/mysql-cluster  # Directory for management node log files
      # Options for data node "A":
      [ndbd]
      # (one [ndbd] section per data node)
      hostname=192.168.0.30           # Hostname or IP address
      datadir=/usr/local/mysql/data   # Directory for this data node's data files
      # Options for data node "B":
      [ndbd]
      hostname=192.168.0.40           # Hostname or IP address
      datadir=/usr/local/mysql/data   # Directory for this data node's data files
      # SQL node options:
      [mysqld]
      hostname=192.168.0.20           # Hostname or IP address
      # (additional mysqld connections can be
      # specified for this node for various
      # purposes such as running ndb_restore)
      [root@www mysql-cluster]# cp bin/ndb_mgm* /usr/local/bin
      3,配置MySQL server (SQL) node:
      创建  /etc/my.cnf并添加下面的内容
      #ptions for mysqld process:
      [mysqld]
      ndbcluster                      # run NDB storage engine
      ndb-connectstring=192.168.0.10  # location of management server
      # Options for ndbd process:
      [mysql_cluster]
      ndb-connectstring=192.168.0.10  # location of management server
      4,配置 Data (NDBD) node "A":
      创建/etc/my.cnf文件,并添加下面的内容
      #ptions for mysqld process:
      [mysqld]
      ndbcluster                      # run NDB storage engine
      ndb-connectstring=192.168.0.10  # location of management server
      # Options for ndbd process:
      [mysql_cluster]
      ndb-connectstring=192.168.0.10  # location of management server
      5,配置 Data (NDBD) node "B":
      创建/etc/my.cnf文件,并添加下面的内容
      #ptions for mysqld process:
      [mysqld]
      ndbcluster                      # run NDB storage engine
      ndb-connectstring=192.168.0.10  # location of management server
      # Options for ndbd process:
      [mysql_cluster]
      ndb-connectstring=192.168.0.10  # location of management server

      6,启动Management节点:
      [root@www local]# ndb_mgmd -f /var/lib/mysql-cluster/config.ini
      2010-05-05 13:20:19 [MgmtSrvr] INFO     -- NDB Cluster Management Server. mysql-5.1.44 ndb-7.1.3
      2010-05-05 13:20:19 [MgmtSrvr] INFO     -- Loaded config from '/usr/local/mysql/mysql-cluster/ndb_1_config.bin.1'
      7,起动  Data (NDBD) node "A"及 Data (NDBD) node "B":
      [root@www local]# /usr/local/mysql/bin/ndbd
      2010-05-05 13:20:30 [ndbd] INFO     -- Configuration fetched from '192.168.0.10:1186', generation: 1
      8,起动  MySQL server (SQL) node
      [root@www local]# /etc/init.d/mysql.server start
      9,如果一切顺利,执行ndb_mgm命令之后,其输出如下:
      [root@www local]# 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.1.44 ndb-7.1.3, Nodegroup: 0, Master)
      id=3    @192.168.0.40  (mysql-5.1.44 ndb-7.1.3, Nodegroup: 0)
      [ndb_mgmd(MGM)] 1 node(s)
      id=1    @192.168.0.10  (mysql-5.1.44 ndb-7.1.3)
      [mysqld(API)]   1 node(s)
      id=4    @192.168.0.20  (mysql-5.1.44 ndb-7.1.3)
      测试单点故障:
      1,模拟NDB节点崩溃:
      Data (NDBD) node "A"
      [root@www ~]# netstat -tunlp
      Active Internet connections (only servers)
      Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name
      tcp        0      0 127.0.0.1:2208              0.0.0.0:*                   LISTEN      4456/hpiod
      tcp        0      0 0.0.0.0:111                 0.0.0.0:*                   LISTEN      4240/portmap
      tcp        0      0 0.0.0.0:627                 0.0.0.0:*                   LISTEN      4261/rpc.statd
      tcp        0      0 127.0.0.1:631               0.0.0.0:*                   LISTEN      4487/cupsd
      tcp        0      0 127.0.0.1:25                0.0.0.0:*                   LISTEN      4507/sendmail: acce
      tcp        0      0 192.168.0.30:2202           0.0.0.0:*                   LISTEN      6205/ndbd
      tcp        0      0 127.0.0.1:2207              0.0.0.0:*                   LISTEN      4461/python
      tcp        0      0 :::3306                     :::*                        LISTEN      11766/mysqld
      tcp        0      0 :::22                       :::*                        LISTEN      4476/sshd
      udp        0      0 0.0.0.0:32768               0.0.0.0:*                               4617/avahi-daemon:
      udp        0      0 0.0.0.0:5353                0.0.0.0:*                               4617/avahi-daemon:
      udp        0      0 0.0.0.0:621                 0.0.0.0:*                               4261/rpc.statd
      udp        0      0 0.0.0.0:111                 0.0.0.0:*                               4240/portmap
      udp        0      0 0.0.0.0:624                 0.0.0.0:*                               4261/rpc.statd
      udp        0      0 0.0.0.0:631                 0.0.0.0:*                               4487/cupsd
      udp        0      0 :::32769                    :::*                                    4617/avahi-daemon:
      udp        0      0 :::5353                     :::*                                    4617/avahi-daemon:
      [root@www ~]# kill -9 6205
      [root@www ~]# netstat -tunlp
      Active Internet connections (only servers)
      Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name
      tcp        0      0 127.0.0.1:2208              0.0.0.0:*                   LISTEN      4456/hpiod
      tcp        0      0 0.0.0.0:111                 0.0.0.0:*                   LISTEN      4240/portmap
      tcp        0      0 0.0.0.0:627                 0.0.0.0:*                   LISTEN      4261/rpc.statd
      tcp        0      0 127.0.0.1:631               0.0.0.0:*                   LISTEN      4487/cupsd
      tcp        0      0 127.0.0.1:25                0.0.0.0:*                   LISTEN      4507/sendmail: acce
      tcp        0      0 127.0.0.1:2207              0.0.0.0:*                   LISTEN      4461/python
      tcp        0      0 :::3306                     :::*                        LISTEN      11766/mysqld
      tcp        0      0 :::22                       :::*                        LISTEN      4476/sshd
      udp        0      0 0.0.0.0:32768               0.0.0.0:*                               4617/avahi-daemon:
      udp        0      0 0.0.0.0:5353                0.0.0.0:*                               4617/avahi-daemon:
      udp        0      0 0.0.0.0:621                 0.0.0.0:*                               4261/rpc.statd
      udp        0      0 0.0.0.0:111                 0.0.0.0:*                               4240/portmap
      udp        0      0 0.0.0.0:624                 0.0.0.0:*                               4261/rpc.statd
      udp        0      0 0.0.0.0:631                 0.0.0.0:*                               4487/cupsd
      udp        0      0 :::32769                    :::*                                    4617/avahi-daemon:
      udp        0      0 :::5353                     :::*                                    4617/avahi-daemon:
      [root@www ~]# kill -9
      mysql> use test;
      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> select * from youshengtao;
      +------+
      | a    |
      +------+
      |  400 |
      |  300 |
      |  200 |
      |  500 |
      +------+
      4 rows in set (0.60 sec)
      2, 在 MySQL server (SQL) node执行查询,可见down掉其中的一台data node,对cluster没有任何影响
      mysql> use test;
      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> select * from youshengtao;
      +------+
      | a    |
      +------+
      |  400 |
      |  300 |
      |  200 |
      |  500 |
      +------+
      4 rows in set (0.60 sec)
      3,模拟NDB节点崩溃:
      Data (NDBD) node "B"
      [root@www ~]# netstat -tunlp
      Active Internet connections (only servers)
      Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name
      tcp        0      0 127.0.0.1:2208              0.0.0.0:*                   LISTEN      4453/hpiod
      tcp        0      0 0.0.0.0:622                 0.0.0.0:*                   LISTEN      4256/rpc.statd
      tcp        0      0 0.0.0.0:111                 0.0.0.0:*                   LISTEN      4235/portmap
      tcp        0      0 127.0.0.1:631               0.0.0.0:*                   LISTEN      4484/cupsd
      tcp        0      0 127.0.0.1:25                0.0.0.0:*                   LISTEN      4504/sendmail: acce
      tcp        0      0 192.168.0.40:2202           0.0.0.0:*                   LISTEN      6105/ndbd
      tcp        0      0 127.0.0.1:2207              0.0.0.0:*                   LISTEN      4458/python
      tcp        0      0 :::3306                     :::*                        LISTEN      11940/mysqld
      tcp        0      0 :::22                       :::*                        LISTEN      4473/sshd
      udp        0      0 0.0.0.0:32768               0.0.0.0:*                               4614/avahi-daemon:
      udp        0      0 0.0.0.0:616                 0.0.0.0:*                               4256/rpc.statd
      udp        0      0 0.0.0.0:5353                0.0.0.0:*                               4614/avahi-daemon:
      udp        0      0 0.0.0.0:619                 0.0.0.0:*                               4256/rpc.statd
      udp        0      0 0.0.0.0:111                 0.0.0.0:*                               4235/portmap
      udp        0      0 0.0.0.0:631                 0.0.0.0:*                               4484/cupsd
      udp        0      0 :::32769                    :::*                                    4614/avahi-daemon:
      udp        0      0 :::5353                     :::*                                    4614/avahi-daemon:
      [root@www ~]# kill -9 6105
      [root@www ~]# netstat -tunlp
      Active Internet connections (only servers)
      Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name
      tcp        0      0 127.0.0.1:2208              0.0.0.0:*                   LISTEN      4453/hpiod
      tcp        0      0 0.0.0.0:622                 0.0.0.0:*                   LISTEN      4256/rpc.statd
      tcp        0      0 0.0.0.0:111                 0.0.0.0:*                   LISTEN      4235/portmap
      tcp        0      0 127.0.0.1:631               0.0.0.0:*                   LISTEN      4484/cupsd
      tcp        0      0 127.0.0.1:25                0.0.0.0:*                   LISTEN      4504/sendmail: acce
      tcp        0      0 127.0.0.1:2207              0.0.0.0:*                   LISTEN      4458/python
      tcp        0      0 :::3306                     :::*                        LISTEN      11940/mysqld
      tcp        0      0 :::22                       :::*                        LISTEN      4473/sshd
      udp        0      0 0.0.0.0:32768               0.0.0.0:*                               4614/avahi-daemon:
      udp        0      0 0.0.0.0:616                 0.0.0.0:*                               4256/rpc.statd
      udp        0      0 0.0.0.0:5353                0.0.0.0:*                               4614/avahi-daemon:
      udp        0      0 0.0.0.0:619                 0.0.0.0:*                               4256/rpc.statd
      udp        0      0 0.0.0.0:111                 0.0.0.0:*                               4235/portmap
      udp        0      0 0.0.0.0:631                 0.0.0.0:*                               4484/cupsd
      udp        0      0 :::32769                    :::*                                    4614/avahi-daemon:
      udp        0      0 :::5353                     :::*                                    4614/avahi-daemon:
      [root@www ~]#
      4,在 MySQL server (SQL) node执行查询,data node节点全down掉之后无法进行查询了:
      mysql> select * from youshengtao;
      ERROR 1296 (HY000): Got error 157 'Unknown error code' from NDBCLUSTER
      mysql> select * from youshengtao;
      ERROR 1296 (HY000): Got error 157 'Unknown error code' from NDBCLUSTER
      mysql> show tables;
      +----------------+
      | Tables_in_test |
      +----------------+
      | t1             |
      | youshengtao    |
      +----------------+
      2 rows in set (0.00 sec)
      mysql> desc youshengtao;
      ERROR 1296 (HY000): Got error 157 'Unknown error code' from NDBCLUSTER
      mysql> desc t1;
      ERROR 1296 (HY000): Got error 157 'Unknown error code' from NDBCLUSTER



运维网声明 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-606672-1-1.html 上篇帖子: MySql集群配置 下篇帖子: MySQL 日常整理
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

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

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

扫描微信二维码查看详情

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


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


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


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



合作伙伴: 青云cloud

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