mysql cluster安装部署

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了mysql cluster安装部署相关的知识,希望对你有一定的参考价值。


mysql cluster安装部署:


http://www.178linux.com/36462


IPADDR=192.168.0.71

NETMASK=255.255.255.0

GATEWAY=192.168.0.1

DNS1=192.168.0.1


管理节点(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


scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql --ldata=/var/mysql/data/

scripts/mysql_install_db  -user=mysql -datadir=/usr/local/mysql/data 



/usr/local/mysql/bin/mysqladmin -u root -h mysql74 password ‘mysql‘


####################################################################


http://www.178linux.com/36462


一、安装要求


安装环境: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 -xvf mysql-cluster-gpl-7.2.25-linux2.6-i686.tar.gz


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


[[email protected] local]#mv mysql-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节点执行这条命令)

或者

scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql --ldata=/var/mysql/data/



1.jpg


三、集群配置


1.管理节点配置:


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


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


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


[[email protected] ]#mkdir /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  添加如下内容


-A INPUT -m state --state NEW -m tcp -p tcp --dport 1186 -j ACCEPT




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


 




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


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


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


[[email protected] ]#mkdir /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否则新增加的内容不会被使用)




 


3.数据节点:


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




 


4.sql节点:


[[email protected] ]#service mysqld start




 


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

[[email protected] mysql]# 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.72  (mysql-5.5.50 ndb-7.2.25, Nodegroup: 0, *)

id=3 @192.168.1.73  (mysql-5.5.50 ndb-7.2.25, Nodegroup: 0)


[ndb_mgmd(MGM)] 1 node(s)

id=1 @192.168.1.71  (mysql-5.5.50 ndb-7.2.25)


[mysqld(API)] 4 node(s)

id=4 @192.168.1.74  (mysql-5.5.50 ndb-7.2.25)

id=5 @192.168.1.75  (mysql-5.5.50 ndb-7.2.25)

id=6 (not connected, accepting connect from any host)

id=7 (not connected, accepting connect from any host)



 


五、测试


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节点来验证数据是否会同步。


本文出自 “梁小明的博客” 博客,请务必保留此出处http://7038006.blog.51cto.com/7028006/1893606

以上是关于mysql cluster安装部署的主要内容,如果未能解决你的问题,请参考以下文章

Fate部署实战——从零开始实现Fate cluster部署

Galera Cluster mysql+keepalived集群部署

MySQL NDB Cluster 7.5.16部署OGG同步

MySQL学习笔记03MySQL集群的安装部署

Mariadb Galera Cluster 部署

MySQL PXC部署实践