search
HomeDatabaseMysql TutorialMySQL-Cluster7.2.5安装和配置_MySQL

bitsCN.com

环境:

一台10.32.33.120 做一个数据节点,SQL节点,管理节点

一台 10.32.34.116 做一个数据节点,SQL节点。

操作系统都是 CentOS5.4 64位。

一 下载MySql Cluster7.2.5

http://www.mysql.com/downloads/cluster/

注:如果已经存在MySql,需要先删除,方法:

如果能联网 yum remove mysql

否则手动删除mysql

先看看都安装了什么包:

# rpm -qa|grep MySQL

然后把这些包都卸载掉

rpm -e MySQL-server-5.5.21-1.linux2.6

rpm -e MySQL-client-5.5.20-1.linux2.6

二 下载后解压

先设置10.32.33.120,把MySql Cluster下载到/downfiles下

#cd downfiles

#tar –zxvf mysql-cluster-gpl-7.2.5-linux2.6-x86_64.tar.gz //解压

三 把解压后的文件拷贝到/usr/local下,名字为mysql

#cp /downfiles/mysql-cluster-gpl-7.2.5-linux2.6-x86_64 /usr/local/mysql

#cd /usr/local/mysql

# chown –R root . //把mysql的目录设置成所有者为root

#chown –R mysql /data //把data目录设置所有者为mysql

#chgrp –R mysql . //改成所属组为mysql

#cd scripts/

#mysql_install_db –user=mysql 这句就是安装了

四 设置mysql服务为开机自启动

#chmod +x /etc/rc.d/init.d/mysqld //给这个文件赋予可修改权限

#chkconfig --add mysqld // chkconfig命令主要用来更新(启动或停止)和查询系统服务的运行级信息,chkconfig --add name:增加一项新的服务

此时还不能开机自启,还需要设置环境变量

#vi /etc/profile

最后面加上两句

PATH=$PATH:/usr/local/mysql/bin

export PATH

以上操作在两台服务器上做同样操作。

五:配置

1、配置管理节点

拷贝/usr/local/mysql/bin/ndb_mgm,ndb_mgmd两个文件到/usr/local/bin

#cp /usr/local/mysql/bin/ndb_mgm* /usr/local/bin

#mkdir /var/lib/mysql-cluster

#vim /var/lib/mysql-cluster/config.ini

输入下面内容:

[ndbd default]

NoOfReplicas=1 #每个数据节点的镜像数量

DataMemory=200M  #每个数据节点中给数据分配的内存

IndexMemory=20M #每个数据节点中给索引分配的内存

[ndb_mgmd]  #配置管理节点

NodeId=1

hostname=10.32.34.116

datadir=/var/lib/mysql-cluster/ #管理节点数据(日志)目录

[ndbd]  #数据节点配置

NodeId=2

hostname=10.32.33.120

datadir=/usr/local/mysql/data/  #数据节点目录

[ndbd]

NodeId=3

hostname=10.32.34.116

datadir=/usr/local/mysql/data/

[mysqld]

hostname=10.32.33.120

[mysqld]

hostname=10.32.34.116

[mysqld] #一定要留一个空的,以备扩展使用,否则会出现Failed to allocate nodeid No free node id found for ndbd(NDB)错误

[mysqld]

注:配置时, []右边的注释不要加上,否则系统不认。

[NDBD DEFAULT]:表示每个数据节点的默认配置在每个节点的[NDBD]中不用再写这些选项,只能有一个。

[NDB_MGMD]:表示管理节点的配置,只有一个。

[NDBD]:表示每个数据节点的配置,可以有多个。

[MYSQLD]:表示SQL节点的配置,可以有多个,分别写上不同SQL节点的IP地址。

2、配置数据节点和SQL节点

mysql服务启动时会默认加载/etc/my.cnf作为其配置文件,修改10.32.33.120上的my.cnf

[mysqld]

ndbcluster #运行NDB存储引擎

datadir=/usr/local/mysql/data

basedir=/usr/local/mysql

port=3306

[mysql_cluster]

ndb-connectstring=10.32.34.116 #声明管理节点

拷贝一份到另一台10.32.34.116

#scp /etc/my.cnf 10.32.34.116:/etc/

六 启动

节点的启动顺序为管理节点->数据节点->SQL节点。

1、120上启动管理节点

#cd /usr/local/bin

# ./ndb_mgmd -f /var/lib/mysql-cluster/config.ini // ndb_mgmd是mysqlcluster的管理服务器,后面的-f表示后面的参数是启动的参数配置文件。如果在启动后过了几天又添加了一个数据节点,这时修改了配置文件启动时就必须加上--initial参数,不然添加的节点不会作用在mysql cluster中

2、启动数据节点

安装后第一次启动数据节点时要加上--initial参数,其它时候不要加,除非是在备份、恢复或配置变化后重启时

#cd /var/local/mysql/bin/ndbd –initial

2012-03-28 02:01:38 [ndbd] INFO -- Angel connected to '10.32.33.120:1186'

2012-03-28 02:01:38 [ndbd] INFO -- Angel allocated nodeid: 36

出现这种信息表示启动成功.

3、启动SQL节点

#mysqld_safe --ndb_nodeid=5 --user=mysql &

同样方法,启动另外一个机器,注意nodeid的编号。

4、客户端查看

#cd /usr/local/bin

#.ndb_mgm

ndb_mgm> show

ndb_mgm> show

Cluster Configuration

---------------------

ndb_mgm> show

Cluster Configuration

---------------------

[ndbd(NDB)] 2 node(s)

id=2 @10.32.33.120 (mysql-5.5.20 ndb-7.2.5, Nodegroup: 0, Master)

id=3 @10.32.34.116 (mysql-5.5.20 ndb-7.2.5, Nodegroup: 1)

[ndb_mgmd(MGM)] 1 node(s)

id=1 @10.32.34.116 (mysql-5.5.20 ndb-7.2.5)

[mysqld(API)] 4 node(s)

id=4 @10.32.33.120 (mysql-5.5.20 ndb-7.2.5)

id=5 @10.32.34.116 (mysql-5.5.20 ndb-7.2.5)

id=6 (not connected, accepting connect from any host)

id=7 (not connected, accepting connect from any host)

可以看到各个节点已经连接上了, mysql cluster配置完成.

如果看不到上述信息,可能是防火墙问题,你可以选择把CentOS的防火墙关掉,命令为:/etc/init.d/iptables stop

管理节点关闭,在ndb_mgm>提示符下输入shutdown,再输入exit即可退出。

7 测试。

1、从SQL节点A登录,创建数据库和表,进行简单测试。

mysql> create database zxztest ;

mysql> use zxztest;
Database changed

mysql> create table test1(id int,name varchar(10)) engine=ndb ;

mysql> insert into test1 values(1,'zhaoxuezhi');

mysql> select * from test1 ;

+------+---------+
| id   | name    |
+------+---------+
|    1 | zhaoxuezhi |
+------+---------+

登陆B节点,查看效果,库,表和数据已经同步。

从B节点插入一条数据,同样登陆A,也能看到数据已经同步。

bitsCN.com
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
What are the different storage engines available in MySQL?What are the different storage engines available in MySQL?Apr 26, 2025 am 12:27 AM

MySQLoffersvariousstorageengines,eachsuitedfordifferentusecases:1)InnoDBisidealforapplicationsneedingACIDcomplianceandhighconcurrency,supportingtransactionsandforeignkeys.2)MyISAMisbestforread-heavyworkloads,lackingtransactionsupport.3)Memoryengineis

What are some common security vulnerabilities in MySQL?What are some common security vulnerabilities in MySQL?Apr 26, 2025 am 12:27 AM

Common security vulnerabilities in MySQL include SQL injection, weak passwords, improper permission configuration, and unupdated software. 1. SQL injection can be prevented by using preprocessing statements. 2. Weak passwords can be avoided by forcibly using strong password strategies. 3. Improper permission configuration can be resolved through regular review and adjustment of user permissions. 4. Unupdated software can be patched by regularly checking and updating the MySQL version.

How can you identify slow queries in MySQL?How can you identify slow queries in MySQL?Apr 26, 2025 am 12:15 AM

Identifying slow queries in MySQL can be achieved by enabling slow query logs and setting thresholds. 1. Enable slow query logs and set thresholds. 2. View and analyze slow query log files, and use tools such as mysqldumpslow or pt-query-digest for in-depth analysis. 3. Optimizing slow queries can be achieved through index optimization, query rewriting and avoiding the use of SELECT*.

How can you monitor MySQL server health and performance?How can you monitor MySQL server health and performance?Apr 26, 2025 am 12:15 AM

To monitor the health and performance of MySQL servers, you should pay attention to system health, performance metrics and query execution. 1) Monitor system health: Use top, htop or SHOWGLOBALSTATUS commands to view CPU, memory, disk I/O and network activities. 2) Track performance indicators: monitor key indicators such as query number per second, average query time and cache hit rate. 3) Ensure query execution optimization: Enable slow query logs, record and optimize queries whose execution time exceeds the set threshold.

Compare and contrast MySQL and MariaDB.Compare and contrast MySQL and MariaDB.Apr 26, 2025 am 12:08 AM

The main difference between MySQL and MariaDB is performance, functionality and license: 1. MySQL is developed by Oracle, and MariaDB is its fork. 2. MariaDB may perform better in high load environments. 3.MariaDB provides more storage engines and functions. 4.MySQL adopts a dual license, and MariaDB is completely open source. The existing infrastructure, performance requirements, functional requirements and license costs should be taken into account when choosing.

How does MySQL's licensing compare to other database systems?How does MySQL's licensing compare to other database systems?Apr 25, 2025 am 12:26 AM

MySQL uses a GPL license. 1) The GPL license allows the free use, modification and distribution of MySQL, but the modified distribution must comply with GPL. 2) Commercial licenses can avoid public modifications and are suitable for commercial applications that require confidentiality.

When would you choose InnoDB over MyISAM, and vice versa?When would you choose InnoDB over MyISAM, and vice versa?Apr 25, 2025 am 12:22 AM

The situations when choosing InnoDB instead of MyISAM include: 1) transaction support, 2) high concurrency environment, 3) high data consistency; conversely, the situation when choosing MyISAM includes: 1) mainly read operations, 2) no transaction support is required. InnoDB is suitable for applications that require high data consistency and transaction processing, such as e-commerce platforms, while MyISAM is suitable for read-intensive and transaction-free applications such as blog systems.

Explain the purpose of foreign keys in MySQL.Explain the purpose of foreign keys in MySQL.Apr 25, 2025 am 12:17 AM

In MySQL, the function of foreign keys is to establish the relationship between tables and ensure the consistency and integrity of the data. Foreign keys maintain the effectiveness of data through reference integrity checks and cascading operations. Pay attention to performance optimization and avoid common errors when using them.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.