mysql集群安装说明
Mysql cluster安装说明 一、说明 本文档介绍了如何规划、安装、配置和运行MySQL集群的基本知识。 二、Mysql集群结构图 三、名词解释 ? 管理节点: 这类节点的作用是管理MySQL簇内的其他节点,如提供配置数据、启动并停止节点、运行备份等。由于这类节点负责
Mysql cluster安装说明
一、 说明
本文档介绍了如何规划、安装、配置和运行MySQL集群的基本知识。
二、 Mysql集群结构图
三、 名词解释
? 管理节点:这类节点的作用是管理MySQL簇内的其他节点,如提供配置数据、启动并停止节点、运行备份等。由于这类节点负责管理其他节点的配置,应在启动其他节点之前首先启动这类节点。
? 数据节点:这类节点用于保存簇的数据。数据节点的数目与副本的数目相关,是片段的倍数。例如,对于两个副本,每个副本有两个片段,那么就有4个数据节点。没有必要有一个以上的副本。数据节点是用命令ndbd启动的。
? SQL节点:这是用来访问簇数据的节点。对于MySQL簇,客户端节点是使用NDB簇存储引擎的传统MySQL服务器。
四、 安装环境
1. 操作系统
Linux version2.6.18-164.el5
2. 安装结构图
3. 部署列表
名称 |
Ip |
(MGM)管理节点 (NDBD)数据节点1 |
192.168.10.10 192.168.10.20 |
(NDBD)数据节点2 |
192.168.10.40 |
SQL节点1 |
192.168.10.30 |
SQL节点2 |
192.168.10.50 |
五、 安装软件
MySQL-Cluster-gpl-management-7.1.29-1.rhel5.x86_64.rpm
MySQL-Cluster-gpl-storage-7.1.29-1.rhel5.x86_64.rpm
MySQL-Cluster-gpl-tools-7.1.29-1.rhel5.x86_64.rpm
MySQL-Cluster-gpl-client-7.1.29-1.rhel5.x86_64.rpm
MySQL-Cluster-gpl-server-7.1.29-1.rhel5.x86_64.rpm
下载地址:http://www.mysql.com/downloads/cluster/7.1.html
六、 安装步骤
1. 管理节点安装
上传
MySQL-Cluster-gpl-management-7.1.29-1.rhel5.x86_64.rpm,MySQL-Cluster-gpl-tools-7.1.29-1.rhel5.x86_64.rpm到服务器192.168.10.10上
安装:
[root@192.168.10.10 ]# rpm -ivh MySQL-Cluster-gpl-management-7.1.29-1.rhel5.x86_64.rp [root@192.168.10.10 ]# rpm -ivh MySQL-Cluster-gpl-tools-7.1.29-1.rhel5.x86_64.rpm [root@192.168.10.10 ]# mkdir /var/lib/mysql-cluster [root@192.168.10.10 ]# vi /var/lib/mysql-cluster/config.ini
修改配置文件config.ini
[ndbd default] NoOfReplicas=2 DataMemory=80M IndexMemory=18M [tcp default] SendBufferMemory=2M ReceiveBufferMemory=2M [NDB_MGMD DEFAULT] PortNumber=1186 datadir=/var/lib/mysql-cluster [ndb_mgmd] NodeId=1 hostname=192.168.10.10 [ndbd] NodeId=2 hostname=192.168.10.20 datadir=/var/lib/mysql-data [ndbd] NodeId=4 hostname=192.168.10.40 datadir=/var/lib/mysql-data [mysqld] NodeId=3 hostname=192.168.10.30 [mysqld] NodeId=5 hostname=192.168.10.50
注意:NoOfReplicas的数字要和数据节点的数量一样!
2. 数据节点安装
上传MySQL-Cluster-gpl-storage-7.1.29-1.rhel5.x86_64.rpm分别到服务器192.168.10.20和192.168.10.40上
执行
[root@192.168.10.20]# rpm -ivh MySQL-Cluster-gpl-storage-7.1.29-1.rhel5.x86_64.rpm 输出如下成功 Preparing... ########################################### [100%] 1:MySQL-Cluster-gpl-stora########################################### [100%] [root@192.168.10.20]# mkdir /var/lib/mysql-data [root@192.168.10.20]# chmod 777 /var/lib/mysql-data –R [root@192.168.10.20]#vi /etc/my.cnf
修改my.cnf
192.168.10.40的安装同上
3. SQL节点安装
上传MySQL-Cluster-gpl-client-7.1.29-1.rhel5.x86_64.rpm
MySQL-Cluster-gpl-server-7.1.29-1.rhel5.x86_64.rpm分别到服务器192.168.10.30和192.168.10.50上
执行
[root@192.168.10.30]#rpm -ivh MySQL-Cluster-gpl-server-7.1.29-1.rhel5.x86_64.rpm 输出如下成功 Preparing... ########################################### [100%] 1:MySQL-Cluster-gpl-serve########################################### [100%] PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER ! To do so, start the server, then issue the following commands: /usr/bin/mysqladmin -u root password 'new-password' /usr/bin/mysqladmin -u root -h localhost.localdomain password 'new-password' Alternatively you can run: /usr/bin/mysql_secure_installation which will also give you the option of removing the test databases and anonymous user created by default. This is strongly recommended for production servers. See the manual for more instructions. Please report any problems with the /usr/bin/mysqlbug script! [root@192.168.10.30]# rpm -ivh MySQL-Cluster-gpl-client-7.1.29-1.rhel5.x86_64.rpm --nodeps –force 输出如下成功 Preparing... ########################################### [100%] 1:MySQL-Cluster-gpl-clien########################################### [100%] [root@192.168.10.30]# vi /etc/my.cnf
修改my.cnf
[mysqld] ndbcluster ndb-connectstring=192.168.10.10:1186 [mysql_cluster] ndb-connectstring=192.168.10.10:1186
192.168.10.50的安装同上
七、 Mysql集群启动
启动顺序为管理节点、数据节点、sql节点
1. 管理节点启动
//管理节点启动 //第一次启动 [root@192.168.10.10]# ndb_mgmd -f /var/lib/mysql-cluster/config.ini //以后启动 [root@192.168.10.10]# ndb_mgmd //config.ini 修改启动 [root@192.168.10.10]# ndb_mgmd -f /var/lib/mysql-cluster/config.ini //启动成功为: MySQL Cluster Management Server mysql-5.1.72 ndb-7.1.29 //查看状态 [root@192.168.10.10]# ndb_mgm ndb_mgm>show 如下信息,各个节点的状态 [ndbd(NDB)] 2 node(s) id=2 @192.168.10.20 (mysql-5.1.72 ndb-7.1.29, Nodegroup: 0, *) id=4 @192.168.10.40 (mysql-5.1.72 ndb-7.1.29, Nodegroup: 0) [ndb_mgmd(MGM)] 1 node(s) id=1 @192.168.10.10 (mysql-5.1.72 ndb-7.1.29) [mysqld(API)] 2 node(s) id=3 (not connected, accepting connect from 192.168.10.30) id=5 (not connected, accepting connect from 192.168.10.50)
2. 数据节点启动
//数据节点启动 第一个数据节点启动时用 –initial其它不需要 [root@192.168.10.20]# ndbd –initial //输出如下成功 2013-12-25 23:36:23 [ndbd] INFO -- Angel connected to '192.168.10.10:1186' 2013-12-25 23:36:23 [ndbd] INFO -- Angel allocated nodeid: 2
192.168.10.40 操作同上
3. Sql节点启动
//sql节点启动 [root@192.168.10.20]# mysqld_safe //输出如下成功 131226 01:02:43 mysqld_safe Logging to '/var/lib/mysql/localhost.localdomain.err'. 131226 01:02:43 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
192.168.10.50 操作同上
如果启动出现如下提示
//sql节点启动 131226 01:01:50 mysqld_safe Logging to '/var/lib/mysql/localhost.localdomain.err'. 131226 01:01:51 mysqld_safe A mysqld process already exists
手动杀掉mysql的进程重新启动
八、 验证
在其中一个sql节点上建一个库,并建立一个测试表插入数据,再从另外一个sql节点登陆看是否同步,如果同步成功,否则失败。
九、 关闭集群
1.关闭管理节点和数据节点,只需要在管理节点里执行:
[root@192.168.10.10]# ndb_mgm -e shutdown Node 2: Cluster shutdown initiated Node 4: Cluster shutdown initiated Node 4: Node shutdown completed. Node 2: Node shutdown completed. 3 NDB Cluster node(s) have shutdown. Disconnecting to allow management server to shutdown.
2.然后关闭Sql节点,分别在2个节点里运行:
[root@192.168.10.30]# service mysql stop
十、 重要说明
1.在建表的时候一定要用ENGINE=NDB或ENGINE=NDBCLUSTER指定使用NDB集群存储引擎,或用ALTERTABLE选项更改表的存储引擎。
2.NDB表必须有一个主键,因此创建表的时候必须定义主键,否则NDB存储引擎将自动生成隐含的主键。
3.Sql节点的用户权限表仍然采用MYISAM存储引擎保存的,所以在一个Sql节点创建的MySql用户只能访问这个节点,如果要用同样的用户访问别的Sql节点,需要在对应的Sql节点追加用户。
十一、 其它
先看看都安装了什么包:
如果安装过程中出现错误,删除重新装
rpm -qa|grep MySQL
然后把这些包都卸载掉
rpm -e MySQL-server*
rpm -e MySQL-client*

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



In MySQL database, the relationship between the user and the database is defined by permissions and tables. The user has a username and password to access the database. Permissions are granted through the GRANT command, while the table is created by the CREATE TABLE command. To establish a relationship between a user and a database, you need to create a database, create a user, and then grant permissions.

MySQL is suitable for beginners because it is simple to install, powerful and easy to manage data. 1. Simple installation and configuration, suitable for a variety of operating systems. 2. Support basic operations such as creating databases and tables, inserting, querying, updating and deleting data. 3. Provide advanced functions such as JOIN operations and subqueries. 4. Performance can be improved through indexing, query optimization and table partitioning. 5. Support backup, recovery and security measures to ensure data security and consistency.

Navicat itself does not store the database password, and can only retrieve the encrypted password. Solution: 1. Check the password manager; 2. Check Navicat's "Remember Password" function; 3. Reset the database password; 4. Contact the database administrator.

Create a database using Navicat Premium: Connect to the database server and enter the connection parameters. Right-click on the server and select Create Database. Enter the name of the new database and the specified character set and collation. Connect to the new database and create the table in the Object Browser. Right-click on the table and select Insert Data to insert the data.

Copying a table in MySQL requires creating new tables, inserting data, setting foreign keys, copying indexes, triggers, stored procedures, and functions. The specific steps include: creating a new table with the same structure. Insert data from the original table into a new table. Set the same foreign key constraint (if the original table has one). Create the same index. Create the same trigger (if the original table has one). Create the same stored procedure or function (if the original table is used).

Navicat for MariaDB cannot view the database password directly because the password is stored in encrypted form. To ensure the database security, there are three ways to reset your password: reset your password through Navicat and set a complex password. View the configuration file (not recommended, high risk). Use system command line tools (not recommended, you need to be proficient in command line tools).

View the MySQL database with the following command: Connect to the server: mysql -u Username -p Password Run SHOW DATABASES; Command to get all existing databases Select database: USE database name; View table: SHOW TABLES; View table structure: DESCRIBE table name; View data: SELECT * FROM table name;

Copy and paste in MySQL includes the following steps: select the data, copy with Ctrl C (Windows) or Cmd C (Mac); right-click at the target location, select Paste or use Ctrl V (Windows) or Cmd V (Mac); the copied data is inserted into the target location, or replace existing data (depending on whether the data already exists at the target location).
