linux下mysql集群的安装

3台redhat服务器:

SQL节点(mysqld): 192.168.1.77;192.168.1.78

数据节点(ndbd): 192.168.1.77;192.168.1.78

管理节点(ndb_mgmd): 192.168.1.79

一、准备工作

删除系统自带mysql

[root@localhost ~]# rpm -qa | grep -i '^mysql-'
[root@localhost ~]# rpm -e --nodeps mysql-server-5.1.66-2.el6_3.x86_64
[root@localhost ~]# rpm -e --nodeps mysql-5.1.66-2.el6_3.x86_64
[root@localhost ~]# rpm -e --nodeps mysql-libs-5.1.66-2.el6_3.x86_64

创建相关用户和用户组:

groupadd mysql
useradd –s /sbin/nologin -g mysql –M mysql

去官网下载相关安装包:

MySQL-Cluster-gpl-client-7.1.34-1.el6.x86_64.rpm
MySQL-Cluster-gpl-management-7.1.34-1.el6.x86_64.rpm
MySQL-Cluster-gpl-server-7.1.34-1.el6.x86_64.rpm
MySQL-Cluster-gpl-storage-7.1.34-1.el6.x86_64.rpm
MySQL-Cluster-gpl-tools-7.1.34-1.el6.x86_64.rpm

二、管理节点安装:

[root@localhost ~]# rpm -ivh MySQL-Cluster-gpl-management-7.1.34-1.el6.x86_64.rpm
[root@localhost ~]# rpm -ivh MySQL-Cluster-gpl-tools-7.1.34-1.el6.x86_64.rpm
[root@localhost ~]# mkdir /var/lib/mysql-cluster
[root@localhost ~]# vim /var/lib/mysql-cluster/config.ini

配置内容如下:(NoOfReplicas为数据节点数量)

[root@localhost ~]# more /var/lib/mysql-cluster/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.1.79 [ndbd]
NodeId=2
HostName=192.168.1.77
datadir=/var/lib/mysql-data [ndbd]
NodeId=3
HostName=192.168.1.78
datadir=/var/lib/mysql-data [mysqld]
NodeId=4
HostName=192.168.1.77 [mysqld]
NodeId=5
HostName=192.168.1.78

启动管理节点:

ndb_mgmd -f /var/lib/mysql-cluster/config.ini

三、 数据节点安装:

[root@localhost ~]# rpm -ivh MySQL-Cluster-gpl-storage-7.1.34-1.el6.x86_64.rpm
[root@localhost ~]# mkdir /var/lib/mysql-data
[root@localhost ~]# chmod 777 /var/lib/mysql-data -R
[root@localhost ~]# chonw -R mysql.mysql /var/lib/mysql
[root@localhost ~]# chonw -R mysql.mysql /var/lib/mysql-cluster
[root@localhost ~]# chonw -R mysql.mysql /var/lib/mysql-data
[root@localhost ~]# mv /etc/my.cnf /etc/my.cnf.bak
[root@localhost ~]# vim /etc/my.cnf

配置内容如下:

[root@localhost ~]# more /etc/my.cnf
[mysqld]
max_connections = 100
slow_query_log = /var/lib/mysql-cluster/slow_query.log
long_query_time = 1
datadir = /var/lib/mysql-cluster
ndbcluster
ndb-connectstring = 192.168.1.79:1186 [mysql_cluster]
ndb-connectstring = 192.168.1.79:1186

启动数据节点:

ndbd --initial   #第一次启动时才需要加 --initial

四、 SQL节点的安装:

[root@localhost ~]# rpm -ivh MySQL-Cluster-gpl-server-7.1.34-1.el6.x86_64.rpm
[root@localhost ~]# rpm -vi MySQL-Cluster-gpl-client-7.1.34-1.el6.x86_64.rpm

安装数据库文件:

[root@localhost mysql]# /usr/bin/mysql_install_db --user=mysql

启动sql节点:

[root@localhost ~]# /usr/bin/mysqld_safe --user=mysql &

五、 管理节点查看:

[root@localhost ~]# ndb_mgm
-- NDB Cluster -- Management Client --
ndb_mgm> show
Connected to Management Server at: localhost:1186
Cluster Configuration
---------------------
[ndbd(NDB)] 2 node(s)
id=2 @192.168.1.77 (mysql-5.1.73 ndb-7.1.34, Nodegroup: 0, *)
id=3 (not connected, accepting connect from 192.168.1.78) [ndb_mgmd(MGM)] 1 node(s)
id=1 @192.168.1.79 (mysql-5.1.73 ndb-7.1.34) [mysqld(API)] 2 node(s)
id=4 @192.168.1.77 (mysql-5.1.73 ndb-7.1.34)
id=5 @192.168.1.78 (mysql-5.1.73 ndb-7.1.34) ndb_mgm>
上一篇:SpringMVC访问静态资源[转]


下一篇:最强黑吃黑:WEBSHELL大马隐藏万能密码大全