mysql cluster安装配置
一.集群的搭建1.添加用户及用户组
groupadd mysql
useradd -g mysql mysql
2.解压安装包
tar xzvf mysql-cluster-gpl-7.3.7-linux-glibc2.5-x86_64.tar.gz
mv mysql-cluster-gpl-7.3.7-linux-glibc2.5-x86_64 /usr/local/mysql
3.进入安装目录
cd /usr/local/mysql
安装mysql
./scripts/mysql_install_db --user=mysql
授权及转移配置文件
chown -R mysql data
cp /usr/local/mysql/support-files/ /etc/
安装后提示
To do so, start the server, then issue http://
./bin/mysqladmin -u root password 'new-password'
./bin/mysqladmin -u root -h BZYWPT-server2 password 'new-password'
新建密码
./bin/mysqladmin -uroot password 'liuyu33@6a+'
4、SQL节点和存储节点(NDBD节点)安装
vi /etc/
[MYSQLD]
basedir = /usr/local/mysql/
datadir = /usr/local/mysql/data
user = mysql
port = 3306
socket = /tmp/mysql.sock
ndbcluster
ndb-connectstring=10.5.61.155
[MYSQL_CLUSTER]
ndb-connectstring=10.5.61.155
5.安装和配置管理节点
mkdir /var/lib/mysql-cluster/
cd /var/lib/mysql-cluster/
vi config.ini
新建配置文件
###########################
[ndbd default]
NoOfReplicas= 2 #备份,副本,这样的话2台数据节点的数据就会同步
[MYSQLD DEFAULT]
[ndb_mgmd default] #管理节点数据目录
DataDir= /usr/local/mysql/mysql-cluster
[ndb_mgmd] #管理节点
HostName= 10.5.61.155
[ndbd] #数据节点
HostName= 10.5.61.156
DataDir= /usr/local/mysql/mysql-cluster
[ndbd] #数据节点
HostName= 10.5.61.157
DataDir= /usr/local/mysql/mysql-cluster
[mysqld] #查询节点
HostName= 10.5.61.156
[mysqld] #查询节点
HostName= 10.5.61.157
################################
6. 在管理节点服务器上启动管理节点服务
/usr/local/mysql/bin/ndb_mgmd -f /var/lib/mysql-cluster/config.ini
7.查看管理结点
/usr/local/mysql/bin/ndb_mgm
ndb_mgm> show
*******************************************************************
-- NDB Cluster -- Management Client --
ndb_mgm> show
Connected to Management Server at: localhost:1186
Cluster Configuration
---------------------
[ndbd(NDB)] 2 node(s)
id=2 (not connected, accepting connect from 10.5.61.156)
id=3 (not connected, accepting connect from 10.5.61.157)
[ndb_mgmd(MGM)] 1 node(s)
id=1 @10.5.61.155 (mysql-5.6.21 ndb-7.3.7)
[mysqld(API)] 2 node(s)
id=4 (not connected, accepting connect from 10.5.61.156)
id=5 (not connected, accepting connect from 10.5.61.157)
*******************************************************************
4. 进入数据节点服务器,分别启动数据节点服务
/usr/local/mysql/bin/ndbd --initial(第一次启动)
/usr/local/mysql/bin/ndbd (第二次开始)
ps:有可能会遇到不允许本地登陆的提示
5. 启动sql节点
第一次先安装数据库:
cd /usr/local/mysql/ #不进入这个目录下面执行不成功
/usr/local/mysql/scripts/mysql_install_db --user=mysql
然后启动数据库
启动执行:
/usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/ &
或者运行: root# /usr/local/mysql/support-files/mysql.server start 启动sql节点
这时在查看管理机就可以看到存储节点和sql节点状态
6.安装后的使用
/usr/local/mysql/bin/mysql -uroot
修改root密码
SET PASSWORD = PASSWORD('123456');
新建haproxy用户,无权限无密码
CREATE USER 'haproxy'@'10.5.61.158';
增加端口
-A RH-Firewall-1-INPUT -p tcp -m state --state NEW -m tcp --dport 1080 -j ACCEPT
-A RH-Firewall-1-INPUT -p tcp -m state --state NEW -m tcp --dport 3306 -j ACCEPT
-A RH-Firewall-1-INPUT -p tcp -m state --state NEW -m tcp --dport 23306 -j ACCEPT