0

0

MySQL群集双机模拟_MySQL

php中文网

php中文网

发布时间:2016-06-01 14:06:23

|

1118人浏览过

|

来源于php中文网

原创

  硬件配置
  
  普通PC server * 2 (最小集群环境需要4台服务器)
  
  模拟环境
  
  red hat linux9 for x86 (or red hat AS 2以上版本),glibc-2.2, static, gcc
  
  MySQL版本4.1.12 binares
  
  mysql-max binary版本目前只支持linux、max os x和solaris
  
  本方案不涉及从源代码编译安装
  
  主机 IP地址 用途
  
  ndb1_mgmd_sqld 1192.168.1.100 Ndb node1+mgmd node1+sqld node1
  ndb2_sqld2 192.168.1.200 Ndb node2+sqld node2
  
  Mgmd:management server
  sqld:mysql server
  ndb:storaged node (share-nothing,base in memory)
  
  安装
  
  从http://dev.mysql.com/downloads/mysql/4.1.html下载mysql-max-4.1.12-pc-linux-gnu-i686.tar.gz到/var/tmp
  Storage and SQL Node Installation
  
  在两台主机上执行如下过程
  
  shell>groupadd mysql
  shell>useradd -g mysql mysql
  shell>tar zxfv mysql-max-4.1.12-pc-linux-gnu-i686.tar.gz
  shell>cp -vr mysql-max-4.1.12-pc-linux-gnu-i686 /usr/local/mysql-max-4.1.12-pc-linux-gnu-i686
  shell>cd /usr/local
  shell>ln -s mysql-max-4.1.12-pc-linux-gnu-i686 mysql
  shell>cd mysql;scripts/mysql_install_db –user=mysql
  shell>chown -R root .;chown -R mysql data;chgrp -R mysql .
  shell>cp support-files/mysql.server /etc/rc.d/init.d/
  shell>chmod +x /etc/rc.d/init.d/mysql.server
  shell>chkconfig --add mysql.server
  shell>chkconfig –level 3 mysql.server off
  Management Node Installation
  
  在主机ndb1_mgmd_sqld1上执行如下过程
  
  shell>cd /var/tmp
  shell>tar -zxvf mysql-max-4.1.12a-pc-linux-gnu-i686.tar.gz /usr/local/bin '*/bin/ndb_mgm*'
  Configuration
  Configuring the Storage and SQL Nodes
  
  在两台主机上执行如下过程:
  
  shell>vi /etc/my.cnf
  [MYSQLD]             # Options for mysqld process:
  ndbcluster           # run NDB engine
  ndb-connectstring=192.168.1.100  # location of MGM node
  
  [MYSQL_CLUSTER]         # Options for ndbd process:
  ndb-connectstring=192.168.1.100  # location of MGM node
  
  Configuring the Management Node
  
  在主机ndb1_mgmd_sqld1上执行如下过程
  
  shell>mkdir /var/lib/mysql-cluster
  shell>cd /var/lib/mysql-cluster
  shell>vi config.ini
  [NDBD DEFAULT]   # Options affecting ndbd processes on all data nodes:
  NoOfReplicas=2   # Number of replicas
  DataMemory=80M   # How much memory to allocate for data storage
  IndexMemory=52M  # 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 DEFAULT]
  
  [NDB_MGMD]        # Management process options:
  hostname=192.168.1.100 # Hostname or IP address of MGM node
  datadir=/var/lib/mysql-cluster  # Directory for MGM node logfiles
  
  [NDBD]             # Options for data node "A":
  # (one [NDBD] section per data node)
  HostName=192.168.1.100      # Hostname or IP address
  DataDir=/usr/local/mysql/data  # Directory for this data node's datafiles
  
  [NDBD]             # Options for data node "B":
  hostname=192.168.1.200      # Hostname or IP address
  datadir=/usr/local/mysql/data  # Directory for this data node's datafiles
  
  [MYSQLD]             # SQL node options:
  hostname=192.168.1.100     # Hostname or IP address
  # Directory for SQL node's datafiles
  # (additional mysqld connections can be
  # specified for this node for various
  # purposes such as running ndb_restore)
  
  [MYSQLD] # SQL node options:
  hostname=192.168.1.200     # Hostname or IP address
  # Directory for SQL node's datafiles
  # (additional mysqld connections can be
  # specified for this node for various
  # purposes such as running ndb_restore)
  
  第一次启动
  
  在主机ndb1_mgmd_sqld1上执行如下过程
  
  shell> ndb_mgmd -f /var/lib/mysql-cluster/config.ini
  
  在两台主机上执行如下过程
  
  shell>ndbd –initial (note:--initial选项只能在第一次启动的时候使用)
  shell>/etc/init.d/mysql.server start
  
  测试
  
  在主机ndb1_mgmd_sqld1上执行如下过程
  shell> 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.100 (Version: 4.1.12, Nodegroup: 0, Master)
  id=3  @192.168.0.200 (Version: 4.1.12, Nodegroup: 0)
  
  [ndb_mgmd(MGM)] 1 node(s)
  id=1  @192.168.0.100 (Version: 4.1.12)
  
  [mysqld(SQL)]  1 node(s)
  id=4  (Version: 4.1.12)
  
  出现如上信息则表示mysql群集安装成功
  
  数据抽样测试
  
  在主机ndb1_mgmd_sqld1上执行如下过程
  
  shell>/usr/local/mysql/bin/mysql -u root test
  MySQL>DROP TABLE IF EXISTS City;
  CREATE TABLE City (
  ID int(11) NOT NULL auto_increment,
  Name char(35) NOT NULL default '',
  CountryCode char(3) NOT NULL default '',
  District char(20) NOT NULL default '',
  Population int(11) NOT NULL default '0',
  PRIMARY KEY (ID)
  ) ENGINE=NDBCLUSTER;
  
  MySQL>INSERT INTO City VALUES (1,'Kabul','AFG','Kabol',1780000);
  INSERT INTO City VALUES (2,'Qandahar','AFG','Qandahar',237500);
  INSERT INTO City VALUES (3,'Herat','AFG','Herat',186800);
  
  在主机ndb2_sqld2上执行如下过程
  
  shell>/usr/local/mysql/bin/mysql -u root mysql
  MySQSL>select * from City;
  
  如果成功显示数据信息,则表示集群已经成功启动
  
  Safe Shutdown and Restart
  
  在主机ndb1_mgmd_sqld1上执行如下过程
  
  shell>ndb_mgm -e shutdown (关闭集群服务器,storage node也会自动被关闭)
  
  在两台主机上执行如下过程
  
  shell>/etc/init.d/mysql.server stop
  
  重新启动集群(顺序不能弄错)
  
  在主机ndb1_mgmd_sqld1上执行如下过程
  
  shell> ndb_mgmd -f /var/lib/mysql-cluster/config.ini
  
  在两台主机上执行如下过程
  
  shell>/usr/local/mysql/bin/ndbd
  
  启动完ndbd进程后启动sqld进程
  
  shell>/etc/init.d/mysql.server start
  
  附:
  
  config.ini中各部分解释
  
  [COMPUTER]: 定义群集主机.
  
  [NDBD]: 定义群集数据节点.
  
  [MYSQLD]: 定义Sql server节点.
  
  [MGM|NDB_MGMD]: Defines the management server node in the cluster.
  [TCP]: Defines TCP/IP connections between nodes in the cluster, with TCP/IP being the default connection protocol.
  [SHM]: Defines shared-memory connections between nodes. 在MySQL 4.1.9之前,这个功能必须使用--with-ndb-shm option编译进去, 从MySQL 4.1.9-max版本开始, it is enabled by default(默认为打开状态)

相关专题

更多
苹果官网入口直接访问
苹果官网入口直接访问

苹果官网直接访问入口是https://www.apple.com/cn/,该页面具备0.8秒首屏渲染、HTTP/3与Brotli加速、WebP+AVIF双格式图片、免登录浏览全参数等特性。本专题为大家提供相关的文章、下载、课程内容,供大家免费下载体验。

115

2025.12.24

拼豆图纸在线生成器
拼豆图纸在线生成器

拼豆图纸生成器有PixelBeads在线版、BeadGen和“豆图快转”;推荐通过pixelbeads.online或搜索“beadgen free online”直达官网,避开需注册的诱导页面。本专题为大家提供相关的文章、下载、课程内容,供大家免费下载体验。

82

2025.12.24

俄罗斯搜索引擎yandex官方入口地址(最新版)
俄罗斯搜索引擎yandex官方入口地址(最新版)

Yandex官方入口网址是https://yandex.com。用户可通过网页端直连或移动端浏览器直接访问,无需登录即可使用搜索、图片、新闻、地图等全部基础功能,并支持多语种检索与静态资源精准筛选。本专题为大家提供相关的文章、下载、课程内容,供大家免费下载体验。

546

2025.12.24

JavaScript ES6新特性
JavaScript ES6新特性

ES6是JavaScript的根本性升级,引入let/const实现块级作用域、箭头函数解决this绑定问题、解构赋值与模板字符串简化数据处理、对象简写与模块化提升代码可读性与组织性。本专题为大家提供相关的文章、下载、课程内容,供大家免费下载体验。

150

2025.12.24

php框架基础知识汇总
php框架基础知识汇总

php框架是构建web应用程序的架构,提供工具和功能,以简化开发过程。选择合适的框架取决于项目需求和技能水平。实战案例展示了使用laravel构建博客的步骤,包括安装、创建模型、定义路由、编写控制器和呈现视图。本专题为大家提供相关的文章、下载、课程内容,供大家免费下载体验。

20

2025.12.24

Word 字间距调整方法汇总
Word 字间距调整方法汇总

本专题整合了Word字间距调整方法,阅读下面的文章了解更详细操作。

47

2025.12.24

任务管理器教程
任务管理器教程

本专题整合了任务管理器相关教程,阅读下面的文章了解更多详细操作。

7

2025.12.24

AppleID格式
AppleID格式

本专题整合了AppleID相关内容,阅读专题下面的文章了解更多详细教程。

12

2025.12.24

csgo视频观看入口合集
csgo视频观看入口合集

本专题整合了csgo观看入口合集,阅读下面的文章了知道更多入口地址。

371

2025.12.24

热门下载

更多
网站特效
/
网站源码
/
网站素材
/
前端模板

精品课程

更多
相关推荐
/
热门推荐
/
最新课程
Bootstrap 5教程
Bootstrap 5教程

共46课时 | 2.6万人学习

【web前端】Node.js快速入门
【web前端】Node.js快速入门

共16课时 | 1.9万人学习

Go语言实战之 GraphQL
Go语言实战之 GraphQL

共10课时 | 0.8万人学习

关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号