MySQL群集双机模拟

2016-02-19 16:11 3 1 收藏

今天图老师小编给大家展示的是MySQL群集双机模拟,精心挑选的内容希望大家多多支持、多多分享,喜欢就赶紧get哦!

【 tulaoshi.com - 编程语言 】

  硬件配置

  普通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

  在两台主机上执行如下过程

  shellgroupadd mysql

  shelluseradd -g mysql mysql

  shelltar zxfv mysql-max-4.1.12-pc-linux-gnu-i686.tar.gz

  shellcp -vr mysql-max-4.1.12-pc-linux-gnu-i686 /usr/local/mysql-max-4.1.12-pc-linux-gnu-i686

  shellcd /usr/local

  shellln -s mysql-max-4.1.12-pc-linux-gnu-i686 mysql

  shellcd mysql;scripts/mysql_install_db –user=mysql

  shellchown -R root .;chown -R mysql data;chgrp -R mysql .

  shellcp support-files/mysql.server /etc/rc.d/init.d/

  shellchmod +x /etc/rc.d/init.d/mysql.server

  shellchkconfig --add mysql.server

  shellchkconfig –level 3 mysql.server off

  Management Node Installation

  在主机ndb1_mgmd_sqld1上执行如下过程

  shellcd /var/tmp

  shelltar -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

  在两台主机上执行如下过程:

  shellvi /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上执行如下过程

  shellmkdir /var/lib/mysql-cluster

  shellcd /var/lib/mysql-cluster

  shellvi 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

(本文来源于图老师网站,更多请访问https://www.tulaoshi.com/bianchengyuyan/)

  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

  在两台主机上执行如下过程

  shellndbd –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)

(本文来源于图老师网站,更多请访问https://www.tulaoshi.com/bianchengyuyan/)

  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

  MySQLDROP 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;

  MySQLINSERT 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

  MySQSLselect * from City;

  如果成功显示数据信息,则表示集群已经成功启动

  Safe Shutdown and Restart

  在主机ndb1_mgmd_sqld1上执行如下过程

  shellndb_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.tulaoshi.com/n/20160219/1611276.html

延伸阅读
  预备知识 先来了解无线局域网的Ad-Hoc结构。与有线局域网类似,这是一种对等网络结构,各计算机只需安装了无线网卡,彼此即可实现直接互联,无需中间起数据交换作用的AP。同时,该结构中各无线用户的位置是平等的,如不加特殊限制,各用户的操作权限也是相同的。 虽同为对等结构,但无线局域网却具备了有线局域网...
  文/佚名 出处:天极网摘 一、故障现象 寝室内的两台电脑,均集成10M/100M自适应网卡,使用的操作系统都是Windows XP。为方便文件共享,决定采用"双机互联"的方式将两台电脑连接起来。 按照正常的步骤做好物理连接和网络设置后,两台电脑实现了互相访问。可是在传输文件的时候,传输速度只有10K/s左右,其速度让人无法...
目前许多建立和应用信息系统的企业,在系统应用不断改进的同时,开始注意提高企业信息系统的可用性和可靠性。通过双机容错系统为企业提供系统高可用性保障是目前企业普遍采用的方法。医疗机构工作性质的特殊性要求其信息系统7天×24小时不间断运行,采用双机容错方案为系统提供了高可用解决方案。本文将对医疗信息系统的双机容错环境下Orac...
在DOS下用Intersvr和Interlnk连接 并不是所有的计算机都安装了Windows 95,也许你还用着386的计算机,你仍然可以使用电缆通过通信端口进行双机通信。从MSDOS 6.0开始,Microsoft在DOS中增加了Interlnk和Intersvr两条外部命令,使用这两条命令可实现双机连接。用25针并行口电缆连接即可,连接方法同下面Windows 95下用直接电缆连接所举的例...
安装完MySQL后,在MySQL的安装目录下会生成很多有用的程序,下面对这些程序进行一一介绍。 libmysqld----嵌入式MySQL服务器,它不能独立运行,它是一个函数库,可嵌入到其它程序中,使程序具有MySQL服务器的功能。 myisamchk和isamchk----检查和修复数据表、分析键值的分布情况、禁止或启用数据表索引的工具。 myisampack和pack_isam----压...

经验教程

822

收藏

24
微博分享 QQ分享 QQ空间 手机页面 收藏网站 回到头部