Centos安装mysqlcluster7.4.7(集群)的安装和配置

实践是知识的母亲,知识是生活的明灯。这篇文章主要讲述Centos安装mysqlcluster7.4.7(集群)的安装和配置相关的知识,希望能为你提供帮助。
转发自我的新浪博客:??http://blog.sina.com.cn/s/blog_4fa20e8c0102vvpm.html??
基本信息
Centos 6.5x64
mysql-cluster7.4.7
java:jdk-7u71-linux-x64
                  jdk-8u60-linux-x64.rpm 包
mysql集群的特点:
自上而下分别是一个Management(ndb_mgmd)、多个NDB Cluster(nddb)、多个SQL(mysqld)
我自己的测试情况
MDMD(cluster)节点:IP:10.62.4.87
NDB节点:IP:10.62.4.87
NDB节点:IP:10.62.42.83
SQL节点:IP:10.62.4.87
SQL节点:IP:10.62.4.83
这是在10.62.4.87上的操作
1,安装需要的软件
yum -y install gcc gcc-c++ make cmake ncurses-devel zlib-devel perl perl-devel
2,创建mysql用户
useradd -s /sbin/nologin -M mysql
3,调整mysql目录
  tar -xzvf mysql-cluster-gpl-7.4.7.tar.gz
  mv mysql-cluster-gpl-7.4.7 /usr/local
mv /usr/local/mysql-cluster-gpl-7.4.7  /usr/local/mysql
4,安装java环境
tar -xzvf jdk-7u71-linux-x64.tar
mv jdk-7u71 /usr/local/
vi /etc/profile
在最后加入
#set java environment
JAVA_HOME=/usr/local/jdk-7u71
CLASSPATH=.:$JAVA_HOME/lib/tools.jar
PATH=$JAVA_HOME/bin:$PATH
export JAVA_HOME CLASSPATH PATH
注意java一般到此就结束了,但是还没有完成,还需要几个插件
下载了最新的jdk-8u60-linux-64.rpm包
rpm -ivh jdk-8u60-liunx-64.rpm
5,安装mysql管理节点
cd /usr/local/mysql
cd mysql-cluster-gpl-7.4.7
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \\
-DMYSQL_UNIX_ADDR=/data/mysql/mysql.sock \\
-DDEFAULT_CHARSET=utf8 \\
-DDEFAULT_COLLATION=utf8_general_ci \\
-DWITH_EXTRA_CHARSETS:STRING=utf8,gbk \\
-DWITH_INNOBASE_STORAGE_ENGINE=1 \\
-DWITH_READLINE=1 \\
-DENABLED_LOCAL_INFILE=1 \\
-DMYSQL_DATADIR=/data/mysql/ \\
-DMYSQL_USER=mysql \\
-DMYSQL_TCP_PORT=3306


make
make install
安装SQL节点的DB
/usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql
6,修改配置(注意这里只在主节点87上加config.ini)
mkdir -p /data/mysql-cluster
mkdir -p /data/mysql
cd /data/mysql-cluster
touch config.int & & vi config.int
[NDBD DEFAULT]
NoOfReplicas=2
DataMemory=5500M
IndexMemory=500M
MaxNoOfAttributes:20480
MaxNoOfTables:1024
MaxNoOfOrderedIndexes:2048
MaxNoOfTriggers:10240
TransactionDeadlockDetectionTimeOut=10000
[MGM DEFAULT]
PortNumber:1186
[ndb_mgmd]
NodeId=1
Hostname=10.62.4.87
datadir=/data/mysql/
[NDBD]
NodeId=2
Hostname=10.62.4.87
datadir=/data/mysql/
[NDBD]
NodeId=3
Hostname=10.62.4.83
datadir=/data/mysql/
[MYSQLD]
hostname=10.62.4.87
[MYSQLD]
hostname=10.62.4.83
[MYSQLD]
保存即可!


vi /etc/my.cnf
[mysqld]
character_set_server=utf8
ndbcluster
ndb-connectstring=10.62.4.87
datadir=/data/mysql
basedir=/usr/local/mysql
port=3306
interactive_timeout = 432000
wait_timeout = 432000
max_connections = 2000
explicit_defaults_for_timestamp = true
performance_schema_max_table_instances = 400
table_definition_cache = 400
table_open_cache = 256
join_buffer_size = 512k
key_buffer_size = 24M
sort_buffer_size = 512k
read_rnd_buffer_size = 2M
thread_cache_size = 10
query_cache_size = 1M
query_cache_limit = 2M
query_cache_min_res_unit = 4K
innodb_buffer_pool_size = 16M
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
explicit_defaults_for_timestamp=true
skip-name_resolve


[mysql_cluster]
ndb_connectstring=10.62.4.87


[mysqld_safe]
explicit_defaults_for_timestamp=true
保存即可!


7,启动管理节点
/usr/local/mysql/bin/ndb_mgmd -f /data/mysql-cluster/config.int --initial
如果要更改了config.ini的参数,以下命令使其生效
/usr/local/mysql/bin/ndb_mgmd -f /data/mysql-cluster/config.int --reload
  启动数据节点
/usr/local/mysql/bin/nbdb --initial
注意以上两个命令--initial这个参数只有在首次启动的时候加上,除非是在备份、恢复和配置变化后重启时,其他的情况不要加,否则数据会清空
启动SQL节点
/usr/local/mysql/bin/mysqld_safe &
8,10.62.4.83上的操作
  重复以上1-6的步骤,
vi /etc/my.cnf
[mysqld]
character_set_server=utf8
ndbcluster
ndb-connectstring=10.62.4.83
datadir=/data/mysql
basedir=/usr/local/mysql
port=3306
interactive_timeout = 432000
wait_timeout = 432000
max_connections = 2000
explicit_defaults_for_timestamp = true
performance_schema_max_table_instances = 400
table_definition_cache = 400
table_open_cache = 256
join_buffer_size = 512k
key_buffer_size = 24M
sort_buffer_size = 512k
read_rnd_buffer_size = 2M
thread_cache_size = 10
query_cache_size = 1M
query_cache_limit = 2M
query_cache_min_res_unit = 4K
innodb_buffer_pool_size = 16M
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
explicit_defaults_for_timestamp=true
skip-name_resolve


[mysql_cluster]
ndb_connectstring=10.62.4.87


[mysqld_safe]
explicit_defaults_for_timestamp=true
保存
然后
开启数据节点
/usr/local/mysql/bin/ndbd --initial
开启SQL节点
/usr/local/mysql/bin/mysqld_safe &




9,防火墙单开启1186和3306端口是不行的,需要互设白名单:在/etc/sysconfig/iptatables中添加,重启防火墙即可
-A INPUT -s 10.62.4.87/32 -j ACCEPT
-A INPUT -s 10.62.4.83/32 -j ACCEPT
10,验证,可在两台机子上分别验证
查看节点等状态
/usr/local/mysql/bin/ndb_mgm -e show


Connected to Management Server at: 10.62.4.87:1186
Cluster Configuration
---------------------
[ndbd(NDB)]  2 node(s)
id=2  @10.62.4.87  (mysql-5.6.25 ndb-7.4.7, Nodegroup: 0, *)
id=3  @10.62.4.83  (mysql-5.6.25 ndb-7.4.7, Nodegroup: 0)

[ndb_mgmd(MGM)]  1 node(s)
id=1  @10.62.4.87  (mysql-5.6.25 ndb-7.4.7)

[mysqld(API)]  3 node(s)
id=4  @10.62.4.87  (mysql-5.6.25 ndb-7.4.7)
id=5  @10.62.4.83  (mysql-5.6.25 ndb-7.4.7)
id=6 (not connected, accepting connect from any host)



进入命令/usr/local/mysql/bin/ndb_mgm
再输入all report memory
Node 2: Data usage is 6%(15131 32K pages of total  171875)
Node 2: Index usage is 0%(1267 8K pages of total 62500)
Node 3: Data usage is 6%(15131 32K pages of total 171875)
Node 3: Index usage is 0%(1267 8K pages of total 62500)
以上两个32k*171875和8k*62500是和
DataMemory=5500M
IndexMemory=500M
两个数相对应的
停止管理节点与数据节点
/usr/local/mysql/bin/ndb_mgm -e shutdown


开启的步骤:管理节点--> 数据节点(以上两台主机的数据节点)--> SQL节点(以上两台的)
  关闭的步骤:恰好相反


11,设置密码
/usr/local/mysql/bin/mysqladmin  -u root  -password  你的密码’
在两台机子上都要改
/usr/local/mysql/bin/mysql -u root -p
授权用户,你想root使用密码从任何主机连接到mysql服务器
\\GRANT ALL PRIVILEGES ON *.* TO root@% IDENTIFIED BY admin123 WITH GRANT OPTION;
flush privileges;
mysql的参数调优,请看我的博文
??http://blog.sina.com.cn/s/blog_4fa20e8c0102v9ch.html??
测试
create database testa;
你可以去看看另外一个节点是否有数据,我的测试是有的,实现了同步。


到此全部结束!
借鉴并感谢以下两位文档:
【Centos安装mysqlcluster7.4.7(集群)的安装和配置】?? http://wenku.baidu.com/link?url=SxOSyg1gvNGc5prJxGrgqcLMCndLBnHOMlWqGkcS7Z0Oh4Amm2gq_4kI_3X1Dx4hCvkdeoHN4kAR-C2y2p3Blsk5hfKnzStBdSyTCGXcdf3??

    推荐阅读