CentOS中mysql cluster安装部署教程

CentOS中mysql cluster安装部署教程

一、安装要求

安装环境:CentOS-6.5-32bit

软件名称:mysql-cluster-gpl-7.2.25-linux2.6-i686.tar.gz

下载地址:http://mysql.mirror.kangaroot.net/Downloads/

软件包:mysql-cluster-gpl-7.2.25-linux2.6-i686.tar.gz

软件包存放目录:/usr/local

管理节点(MGM): 192.168.1.71

数据节点1(NDBD1):192.168.1.72

数据节点2(NDBD2):192.168.1.73

sql节点1(SQL1): 192.168.1.74

sql节点2(SQL2): 192.168.1.75

二、安装部署

1.安装前:(所有节点服务器需执行)

[[email protected] ]#rpm -qa|grep mysql* (查询系统中存在的mysql)

[[email protected] ]#rpm -e –nodeps mysql-libs-5.1.71-1.el6.i686 (根据自己查出来的mysql版本)

2.开始部署:(所有节点服务器需执行)

[[email protected] ]#groupadd mysql

[[email protected] ]#useradd mysql -g mysql

[[email protected] ]#cd /usr/local (软件包在此目录下,根据自己存放位置进入)

[[email protected] local]#tar -xvfmysql-cluster-gpl-7.2.25-linux2.6-i686.tar.gz

[[email protected] local]#mkdir /usr/local/mysql (创建mysql目录)

[[email protected] local]#mvmysql-cluster-gpl-7.2.25-linux2.6-i686/* mysql

[[email protected] local]#chown -R mysql:mysql mysql/

[[email protected] local]#cd mysql

[[email protected] mysql]#scripts/mysql_install_db –user=mysql (管理及数据节点执行这条命令)

#scripts/mysql_install_db –user=mysql –datadir=/var/mysql/data (sql节点执行这条命令)

CentOS中mysql cluster安装部署教程

三、集群配置

1.管理节点配置:

[[email protected] mysql]#mkdir /var/lib/mysql-cluster

[[email protected] ]#mkdir /var/mysql

[[email protected] ]#mkdir /var/mysql/data

[[email protected] ]#mkdit /var/mysql/log

[[email protected] mysql]#vi /var/lib/mysql-cluster/config.ini (添加以下内容)

[NDBD DEFAULT]

NoOfReplicas=2

#[TCP DEFAULT]

#PortNumber=1186

[NDB_MGMD]

#设置管理节点服务器

nodeid=1

HostName=192.168.1.71 

DataDir=/var/mysql/data

[NDBD]

nodeid=2

HostName=192.168.1.72 

DataDir=/var/mysql/data

[NDBD]

nodeid=3

HostName=192.168.1.73 

DataDir=/var/mysql/data

[MYSQLD]

nodeid=4

HostName=192.168.1.74 

[MYSQLD]

nodeid=5

HostName=192.168.1.75 

#必须有空的mysqld节点,不然数据节点断开后启动有报错

[MYSQLD]

nodeid=6

[mysqld]

nodeid=7

拷贝ndb_mgm、ndb_mgmd、config.ini到bin目录:

[[email protected] mysql]#cd /usr/local/mysql/bin

[[email protected] bin]#cp ./ndb_mgm /usr/local/bin/

[[email protected] bin]#cp ./ndb_mgmd /usr/local/bin/

[[email protected] bin]#cp /var/lib/mysql-cluster/config.ini /usr/local/bin/

[[email protected] bin]#vi /etc/sysconfig/iptables (添加红色方框内容)

CentOS中mysql cluster安装部署教程

[[email protected] bin]/etc/init.d/iptables restart 重启防火墙

2.数据节点配置:(所有数据节点需执行)

[[email protected] ]#mkdir /var/mysql

[[email protected] ]#mkdir /var/mysql/data

[[email protected] ]#mkdit /var/mysql/log

[[email protected] ]#/etc/init.d/iptables stop (关闭防火墙,也可自行添加开放端口)

[[email protected] ]#vi /etc/my.cnf (添加以下内容)

[mysqld]

datadir=/var/mysql/data

socket=/var/mysql/mysql.sock

user=mysql

# Disabling symbolic-links is recommended to prevent assorted security risks

symbolic-links=0

#运行NDB存储引擎

ndbcluster

#指定管理节点

ndb-connectstring=192.168.1.71

[MYSQL_CLUSTER]

ndb-connectstring=192.168.1.71

[NDB_MGM]

connect-string=192.168.1.71

[mysqld_safe]

log-error=/var/mysql/log/mysqld.log

pid-file=/var/run/mysqld/mysqld.pid

3.sql节点配置:(所有sql节点需执行)

[[email protected] ]#cd /usr/local/mysql/

[[email protected] mysql]#cp support-files/mysql.server /etc/rc.d/init.d/mysqld

[[email protected] mysql]#chmod +x /etc/rc.d/init.d/mysqld

[[email protected] mysql]#chkconfig –add mysqld

[[email protected] mysql]#mkdir /var/mysql

[[email protected] mysql]#mkdir /var/mysql/data

[[email protected] mysql]#mkdir /var/mysql/log

[[email protected] mysql]#chown -R mysql:mysql /var/mysql

[[email protected] mysql]#ln -s /usr/local/mysql/bin/mysql /usr/bin

[[email protected] mysql]#ln -s /var/mysql/mysql.sock /tmp/mysql.sock

[[email protected] mysql]#vi /etc/my.cnf

[mysqld]

datadir=/var/mysql/data

socket=/var/mysql/mysql.sock

user=mysql

# Disabling symbolic-links is recommended to prevent assorted security risks

symbolic-links=0

log-bin = /var/mysql/log/mysql-bin.log

max_connections=1000

#以下为mysql 主主模式的配置文件

# 忽略mysql数据库复制

binlog-ignore-db=mysql

# 每次增长2

auto-increment-increment=2

# 设置自动增长的字段的偏移量,即初始值为2

auto-increment-offset=1

ndbcluster

ndb-connectstring=192.168.1.71

[MYSQL_CLUSTER]

ndb-connectstring=192.168.1.71

[NDB_MGM]

connect-string=192.168.1.71

[mysqld_safe]

log-error=/var/mysql/log/mysqld.log

pid-file=/var/run/mysqld/mysqld.pid

四、mysql-cluster启动

1.启动mysql-cluster

mysql集群的启动顺序为:管理节点->数据节点->SQL节点

mysql集群的关闭顺序为,SQL节点->数据节点->管理节点

2.管理节点:

[[email protected] ]#ndb_mgmd -f /var/lib/mysql-cluster/config.ini –initial(注意第一次或者对config文件进行修改后,打开服务一定要加上initial否则新增加的内容不会被使用)

CentOS中mysql cluster安装部署教程

3.数据节点:

[[email protected] ]#/usr/local/mysql/bin/ndbd –initial(此处同上)

CentOS中mysql cluster安装部署教程

4.sql节点:

[[email protected] ]#service mysqld start

CentOS中mysql cluster安装部署教程

5.验证:(在管理节点上)

[[email protected] ]#ndb_mgm

ndb_mgm>show

CentOS中mysql cluster安装部署教程

五、测试

1.在sql1节点执行:

[[email protected] ]#mysql 调用mysql

mysql>create database tianyuan; 创建数据库

mysql>use tianyuan; 使用数据库

mysql>create table test(i int,name varchar(10)) engine=ndbcluster; 创建表

mysql>insert into test values(1,'ceshi'); 插入表数据

mysql>select * from test; 查询验证

2.在sql2节点验证sql1的数据是否已同步到sql2:

[[email protected] ]#mysql 调用mysql

mysql>show databases; 查询数据库

mysql>use tianyuan; 使用数据库

mysql>select * from test; 查询验证

3.可通过中断数据节点或sql节点来验证数据是否会同步。

分享到 :
相关推荐

发表评论

登录... 后才能评论