Mysql-cluster环境配置
Mysql-cluster环境配置
硬件环境
4台机器
192.168.1.10 管理节点
192.168.1.11 存储节点 SQL节点
192.168.1.12 存储节点、SQL节点
192.168.1.13 SQL节点
软件环境:
操作系统:CentOS 6 .5(64位)
Mysql版本:MySQL-Cluster-gpl-7.3.5-1.el6.x86_64.rpm-bundle.tar
mysql-cluster-gpl-7.3.5-linux-glibc2.5-x86_64.tar.gz(需要其中的两个文件)
安装准备:
1. 解压MySQL-Cluster-gpl-7.3.5-1.el6.x86_64.rpm-bundle.tar:
将解压后的MySQL-Cluster-server-gpl-7.3.5-1.el6.x86_64.rpm分发至每台机器;
将解压后的MySQL-Cluster-client-gpl-7.3.5-1.el6.x86_64.rpm分发至SQL节点;
2. 清理旧的Mysql安装:
yum -y remove mysql
rpm -qa | grep mysql*
对于找到的1个剩余mysql包,请按照如下的命令格式予以删除:
rpm -e --nodeps mysql-libs-5.1.61-4.el6.x86_64
3. 安装依赖库:
yum -y install libaio
安装MySQL Cluster:
创建文件夹(分如下3个类来创建对应的文件夹)
存储节点:mkdir /var/lib/mysql/data
管理节点:mkdir /var/lib/mysql-cluster SQL节点:可不用 文件夹授权
进程DIR: mkdir /var/run/mysqld
使用如下的命令来变更权限保证可写入:
chmod -R 1777 /var/lib/mysql
chmod -R 1777 /var/run/mysqld
chmod -R 1777 /var/lib/mysql-cluster
1. 在每台机器上安装MySQL-Cluster-server-gpl-7.3.5-1.el6.x86_64.rpm
执行命令:rpm -Uvh MySQL-Cluster-server-gpl-7.3.5-1.el6.x86_64.rpm
安装后会提示默认密码存放在/root/.mysql_secret文件中(也有时候不提示)
2. 在SQL节点上安装MySQL-Cluster-client-gpl-7.3.5-1.el6.x86_64.rpm
执行命令:rpm -Uvh MySQL-Cluster-client-gpl-7.3.5-1.el6.x86_64.rpm
配置管理节点:
- 解压mysql-cluster-gpl-7.3.5-linux-glibc2.5-x86_64.tar.gz,进入其
mysql-cluster-gpl-7.3.5-linux-glibc2.5-x86_64/bin目录找到ndb_mgm和ndb_mgmd,将其复制到管理节点的/usr/local/bin,
然后使这两个文件成为可执行的:
cd /usr/local/bin
chmod +x ndb_mgm*
- 在管理节点上执行:
cd /var/lib/mysql-cluster
vi config.ini
内容如下:
[ndbd default]
NoOfReplicas=2
DataMemory=80M
IndexMemory=20M
[ndb_mgmd]
# Management process options:
hostname=192.168.1.10 # Hostname or IP address of MGM node
datadir=/var/lib/mysql-cluster # Directory for MGM node log files
[ndbd]
HostName=192.168.1.11
DataDir=/var/lib/mysql/data
[ndbd]
HostName=192.168.1.12
DataDir=/var/lib/mysql/data
[mysqld]
HostName=192.168.1.11
[mysqld]
HostName=192.168.1.12
[mysqld]
HostName=192.168.1.13
配置存储节点和SQL节点:
在所有存储节点和SQL节点上建立配置文件:
vi /etc/my.cnf
内容如下:
[client]
socket=/var/lib/mysql/mysql.sock
[mysqld]
max_connections=100
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
ndbcluster
ndb-connectstring=192.168.1.10
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
[mysql_cluster]
ndb-connectstring=192.168.1.10
~
启动各个节点:
注意顺序。
- 启动管理节点:ndb_mgmd -f /var/lib/mysql-cluster/config.ini
(需要在管理节点执行,这会创建一个目录/usr/local/mysql/mysql-cluster,没有的话可能报错,就自己手动创建一个
mkdir /usr/local/mysql
mkdir /usr/local/mysql/mysql-cluster)
2. 启动存储节点:ndbd --initial
(需要在存储节点执行) 初次启动时需要加--initial参数,以后只需要执行ndbd即可;
3. 启动SQL节点:nohup mysqld_safe --explicit_defaults_for_timestamp &
(需要在SQL节点执行)
启动之前,需要先检查其3306端口是否被占用,sudo netstat -anp | grep 3306 查看3306端口是否被占用
如果被占用需要kill掉,然后再启动
检查所有节点是否正常启动:
在管理节点中执行ndb_mgm 进入集群管理console,使用show命令列出所有节点信息:
可以看到sql节点没有启动成功,解决方法:
cd /var/lib/mysql
ls
rm -f ib* (删除掉lb开头的文件)
用命令:sudo netstat -anp | grep 3306 查看3306端口是否被占用
如果被占用kill杀掉
然后重新启动执行上面操作看到
常用命令:
1) ndb_mgmd管理命令:ndb_mgm
执行之后就是管理控制台了,里面可以继续输入命令。
查看集群里面的全部节点的状态:show
2) 停止集群服务器的命令:ndb_mgm -e shutdown
如果集群配置有更新了:rm /usr/mysql-cluster/ndb_1_config.bin.1
3) 停止SQL节点的命令:mysqladmin -uroot shutdown
4) SQL Node上连接MySQL:mysql -u root –pPASSWORD
执行之后就是MySQL控制台了,里面可以继续输入命令。
修改root用户密码:
在每个SQL节点中执行:
mysqladmin -u root -pOLDPASSWORD password 'newpassword'
其中OLDPASSWORD为/root/.mysql_secret中生成的:
cat /root/.mysql_secret (查看随机生成的密码)
# The random password set for the root user at Tue Apr 15 11:08:59 2014 (local time): Nnqn0u1MRcpXkMue
测试集群:
在192.168.1.12上登录
mysql -u root –ppassword
mysql> create database transenly;
Query OK, 1 row affected (0.06 sec)
mysql> use transenly;
Database changed
mysql> CREATE TABLE ctest2 (i INT) ENGINE=NDB;(创建表的时候必须加上后面的ENGINE=NDB,不然数据同步不成功)
Query OK, 0 rows affected (0.38 sec)
在192.168.1.11上登录
mysql -u root –ppassword
可以看到数据库和数据表都有了,说明数据同步成功
数据导入使用sql文件导入
将sql文件放入到本地的一个地方,如/var/lib/mysql/data/
其中需要将sql文件中 ENGINE= InnoDB修改为ENGINE-NDB,保证数据同步的
在其中随意一个sql节点登录
mysql -u root –ppassword
use transenly;(使用的数据库,前提是先创建好数据库)
source /var/lib/mysql/data/transenly.sql
出现Query OK, 0 rows affected (0.00 sec)说明导入成功
然后show tables;查看三个sql节点是否都创建成功
项目连不上数据库:
需要修改权限,是服务器可以随便访问
mysql> grant all privileges on *.* to root@'%' identified by 'mysql' with grant option;
//赋予任何主机访问数据的权限
3、mysql>FLUSH PRIVILEGES //修改生效
4、mysql>EXIT //退出MySQL服务器

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



The OKX trading platform can be downloaded through mobile devices (Android and iOS) and computers (Windows and macOS). 1. Android users can download it from the official website or Google Play, and they need to pay attention to security settings. 2. iOS users can download it through the App Store or follow the official announcement to obtain other methods. 3. Computer users can download the client of the corresponding system from the official website. Always make sure to use official channels when downloading, and register, log in and security settings after installation.

As a veteran cryptocurrency derivatives trading platform, the accuracy of its official website entrance is crucial. Due to rampant phishing websites, misent entry into fake websites can lead to account theft and loss of funds. This article aims to guide users to safely access the BitMEX official website, provide various methods such as trusted cryptocurrency information platforms (such as CoinMarketCap, CoinGecko), official social media, verification of existing addresses and official support channels, and emphasizes the use of security measures such as two-factor verification, regular password changes and use of security software to help users effectively avoid risks and ensure account security.

Regarding the problem of removing the Python interpreter that comes with Linux systems, many Linux distributions will preinstall the Python interpreter when installed, and it does not use the package manager...

This article describes how to optimize ZooKeeper performance on Debian systems. We will provide advice on hardware, operating system, ZooKeeper configuration and monitoring. 1. Optimize storage media upgrade at the system level: Replacing traditional mechanical hard drives with SSD solid-state drives will significantly improve I/O performance and reduce access latency. Disable swap partitioning: By adjusting kernel parameters, reduce dependence on swap partitions and avoid performance losses caused by frequent memory and disk swaps. Improve file descriptor upper limit: Increase the number of file descriptors allowed to be opened at the same time by the system to avoid resource limitations affecting the processing efficiency of ZooKeeper. 2. ZooKeeper configuration optimization zoo.cfg file configuration

Gate.io Sesame Open Exchange App Download Guide: This article explains the official Gate.io Exchange App Download Method to help you trade cryptocurrency anytime, anywhere. Gate.io App has the advantages of convenience, good user experience, comprehensive functions (spot, contract, leverage, financial management, etc.) and strong security, and provides real-time market information. To ensure safety, be sure to download the App from the official website of Gate.io to avoid downloading malware. The article introduces the official website download steps and iOS and Android installation procedures in detail, and provides frequently asked questions and security suggestions to help you quickly get started with the Gate.io App and start a safe and convenient cryptocurrency trading journey.

Binance is the world's leading cryptocurrency trading platform, supporting more than 350 cryptocurrencies and more than 1,700 trading pairs, and providing a variety of trading modes such as spot, futures, and leverage. Users can download the APP through the official website and select iOS or Android to install it. Founded in 2017, Binance has developed into a global large exchange, but it also faces settlement of US $4.3 billion in money laundering charges in 2023. Its advantages lie in its strong technical strength, rich product services, a huge user base and strict security measures, including the SAFU insurance fund. Binance also has diversified businesses such as Binance Smart Chain, Research Institute, Academy, and Binance Card.

This article introduces how to download the official Gate.io (Sesame Open Door) exchange app to help you trade cryptocurrency anytime, anywhere. The advantages of Gate.io App are convenience, smooth user experience, comprehensive trading functions (spot, contract, leverage, financial management, etc.), and powerful security, and provide real-time market information. The article explains in detail the steps to download the app through the official website, including the installation method of Android and iOS systems, and emphasizes the importance of downloading from official channels to avoid malware. In addition, the article also provides frequently asked questions and security suggestions to help users complete download and installation smoothly and ensure account security. Choose Gate.io to start your cryptocurrency investment journey!

Want to experience a safe and reliable Kraken exchange? This tutorial details how to download the Kraken App (iOS & Android) and access the web version, and reminds everyone to pay attention to safety. Be sure to download it from the official channel, enable two-factor authentication, and protect account security.
