数据库

位置:IT落伍者 >> 数据库 >> 浏览文章

MySQL群集双机模拟方案


发布日期:2021年02月10日
 
MySQL群集双机模拟方案

硬件配置

普通PC server * (最小集群环境需要台服务器)

模拟环境

red hat linux for x (or red hat AS 以上版本)glibc static gcc

MySQL版本 binares

mysqlmax binary版本目前只支持linuxmax os x和solaris

本方案不涉及从源代码编译安装

主机 IP地址 用途

ndb_mgmd_sqld Ndb node+mgmd node+sqld node

ndb_sqld Ndb node+sqld node

Mgmd:management server

sqld:mysql server

ndb:storaged node (sharenothingbase in memory)

安装

从下载mysqlmaxpclinuxgnuitargz到/var/tmp

Storage and SQL Node Installation

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

shell>groupadd mysql

shell>useradd g mysql mysql

shell>tar zxfv mysqlmaxpclinuxgnuitargz

shell>cp vr mysqlmaxpclinuxgnui /usr/local/mysqlmaxpclinuxgnui

shell>cd /usr/local

shell>ln s mysqlmaxpclinuxgnui mysql

shell>cd mysql;scripts/mysql_install_db –user=mysql

shell>chown R root ;chown R mysql data;chgrp R mysql

shell>cp supportfiles/mysqlserver /etc/rcd/initd/

shell>chmod +x /etc/rcd/initd/mysqlserver

shell>chkconfig add mysqlserver

shell>chkconfig –level mysqlserver off

Management Node Installation

在主机ndb_mgmd_sqld上执行如下过程

shell>cd /var/tmp

shell>tar zxvf mysqlmaxapclinuxgnuitargz /usr/local/bin */bin/ndb_mgm*

Configuration

Configuring the Storage and SQL Nodes

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

shell>vi /etc/f

[MYSQLD] # Options for mysqld process:

ndbcluster # run NDB engine

ndbconnectstring= # location of MGM node

[MYSQL_CLUSTER] # Options for ndbd process:

ndbconnectstring= # location of MGM node

Configuring the Management Node

在主机ndb_mgmd_sqld上执行如下过程

shell>mkdir /var/lib/mysqlcluster

shell>cd /var/lib/mysqlcluster

shell>vi configini

[NDBD DEFAULT] # Options affecting ndbd processes on all data nodes:

NoOfReplicas= # Number of replicas

DataMemory=M # How much memory to allocate for data storage

IndexMemory=M # 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 KB this should be more than enough for

# this example Cluster setup

[TCP DEFAULT]

[NDB_MGMD] # Management process options:

hostname= # Hostname or IP address of MGM node

datadir=/var/lib/mysqlcluster # Directory for MGM node logfiles

[NDBD] # Options for data node A:

# (one [NDBD] section per data node)

HostName= # Hostname or IP address

DataDir=/usr/local/mysql/data # Directory for this data nodes datafiles

[NDBD] # Options for data node B:

hostname= # Hostname or IP address

datadir=/usr/local/mysql/data # Directory for this data nodes datafiles

[MYSQLD] # SQL node options:

hostname= # Hostname or IP address

# Directory for SQL nodes datafiles

# (additional mysqld connections can be

# specified for this node for various

# purposes such as running ndb_restore)

[MYSQLD] # SQL node options:

hostname= # Hostname or IP address

# Directory for SQL nodes datafiles

# (additional mysqld connections can be

# specified for this node for various

# purposes such as running ndb_restore)

第一次启动

在主机ndb_mgmd_sqld上执行如下过程

shell> ndb_mgmd f /var/lib/mysqlcluster/configini

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

shell>ndbd –initial (note:initial选项只能在第一次启动的时候使用)

shell>/etc/initd/mysqlserver start

测试

在主机ndb_mgmd_sqld上执行如下过程

shell> ndb_mgm

NDB Cluster Management Client

ndb_mgm> show

Connected to Management Server at: localhost:

Cluster Configuration

[ndbd(NDB)] node(s)

id=@(Version: Nodegroup: Master)

id=@(Version: Nodegroup: )

[ndb_mgmd(MGM)] node(s)

id=@(Version: )

[mysqld(SQL)] node(s)

id= (Version: )

出现如上信息则表示mysql群集安装成功

数据抽样测试

在主机ndb_mgmd_sqld上执行如下过程

shell>/usr/local/mysql/bin/mysql u root test

MySQL>DROP TABLE IF EXISTS City;

CREATE TABLE City (

ID int() NOT NULL auto_increment

Name char() NOT NULL default

CountryCode char() NOT NULL default

District char() NOT NULL default

Population int() NOT NULL default

PRIMARY KEY(ID)

) ENGINE=NDBCLUSTER;

MySQL>INSERT INTO City VALUES (KabulAFGKabol);

INSERT INTO City VALUES (QandaharAFGQandahar);

INSERT INTO City VALUES (HeratAFGHerat);

在主机ndb_sqld上执行如下过程

shell>/usr/local/mysql/bin/mysql u root mysql

MySQSL>select * from City;

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

Safe Shutdown and Restart

在主机ndb_mgmd_sqld上执行如下过程

shell>ndb_mgm e shutdown (关闭集群服务器storage node也会自动被关闭)

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

shell>/etc/initd/mysqlserver stop

重新启动集群(顺序不能弄错)

在主机ndb_mgmd_sqld上执行如下过程

shell> ndb_mgmd f /var/lib/mysqlcluster/configini

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

shell>/usr/local/mysql/bin/ndbd

启动完ndbd进程后启动sqld进程

shell>/etc/initd/mysqlserver start

configini中各部分解释

[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 sharedmemory connections between nodes 在MySQL 之前这个功能必须使用withndbshm option编译进去 从MySQL max版本开始 it is enabled by default               

上一篇:RedHat Linux 下实现MySQL 数据库镜像

下一篇:MYSQL服务维护笔记