MySQL Cluster三机集群+HA高可用+负载均衡配置手册(2)

[ndb_mgmd default]
DataDir=/var/lib/mysql/data
[ndb_mgmd]
NodeId=1
HostName= 172.16.1.78
[ndbd]
NodeId= 2
HostName= 172.16.1.74
[ndbd]
NodeId= 3
HostName= 172.16.1.75
[mysqld]
ArbitrationRank=2
[mysqld]
ArbitrationRank=2
[mysqld]
[mysqld]
[mysqld]
[mysqld]
[tcp default]
portnumber=2279

以下步骤需要在db1和db2上各做一次
2.配置通用my.cnf文件(SQL节点及ndb节点均使用此文件)
# vi /etc/my.cnf
在my.cnf中添加如下内容:
[mysqld]
datadir=/var/lib/mysql/data/
socket=/var/lib/mysql/mysql.sock
lower_case_table_names=1
ndb_cluster_connection_pool=2
tmp_table_size=512M
max_heap_table_size=512M
max_connections =400
thread_stack=1M
# Default to using old password format for compatibility with mysql 3.x
# clients (those using the mysqlclient10 compatibility package).

old_passwords=1

default-storage-engine=ndbcluster
ndbcluster
ndb-connectstring=172.16.1.78
[ndbd]
connect-string=172.16.1.78
[ndb_mgm]
connect-string=172.16.1.78
[ndb_mgmd]
config-file=/var/lib/mysql-cluster/config.ini
[mysql_cluster]
ndb-connectstring=172.16.1.78
[mysql.server]
user=mysql
basedir=/usr
[mysqld_safe]
log-error=/var/log/mysqld.log

#pid-file=/var/run/mysqld/mysqld.pid
[mysql]
#socket=/usr/local/var/mysql.sock
[mysqladmin]
#socket=/usr/local/var/mysql.sock
[ndb_restore default]

四、启动管理节点
MySQL安装目录初始化
执行/usr/bin/mysql_install_db --user=mysql --datadir=/usr/local/mysql/data即可。注意这里的datadir要和config.ini和my.cnf中配置的datadir一致

[root@demo sbin]# ndb_mgmd --ndb_nodeid=1
MySQL Cluster Management Server mysql-5.5.31 ndb-7.2.13
2013-10-29 15:45:36 [MgmtSrvr] INFO    -- The default config directory '/usr/mysql-cluster' does not exist. Trying to create it...
2013-10-29 15:45:36 [MgmtSrvr] INFO    -- Sucessfully created config directory
2013-10-29 15:45:36 [MgmtSrvr] WARNING  -- at line 38: [tcp] portnumber is deprecated
2013-10-29 15:45:36 [MgmtSrvr] WARNING  -- at line 38: Cluster configuration warning:
arbitrator with id 1 and db node with id 2 on same host 172.16.1.74
arbitrator with id 2 and db node with id 3 on same host 172.16.1.75
arbitrator with id 4 has no hostname specified
arbitrator with id 5 has no hostname specified
Running arbitrator on the same host as a database node may
cause complete cluster shutdown in case of host failure.
注:在启动时几个警告提示
2013-10-29 15:45:36 [MgmtSrvr] WARNING  -- at line 38: [tcp] portnumber is deprecated这个警告提示可以不必理会,不影响使用;
2013-10-29 15:45:36 [MgmtSrvr] WARNING  -- at line 38: Cluster configuration warning这个警告提示说节点1和3,2和4的arbitrator一样,可能引起整个集群失败,由于是双管理节点所示此警告可以不用放在心上

[root@demo sbin]# netstat -lntpu
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address      Foreign Address    State      PID/Program name 
tcp        0      0 0.0.0.0:1186      0.0.0.0:*        LISTEN      9484/ndb_mgmd
看到1186端口开放了说明启动是正常的。

五、初始化集群
在db1中
[root@db1 sbin]# ndbd --ndb_nodeid=2 --initial
2013-10-30 09:37:07 [ndbd] INFO    -- Angel connected to '172.16.1.78:1186'
2013-10-30 09:37:07 [ndbd] INFO    -- Angel allocated nodeid: 2
执行netstat –lntpu,如果列表中有端口为2279,表示初始化成功
[root@db1 mysql-cluster]# netstat -lntpu
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address        Foreign Address  State      PID/Program name
tcp        0      0 0.0.0.0:1186          0.0.0.0:*      LISTEN      13713/ndb_mgmd
tcp        0      0 172.16.1.74:2279    0.0.0.0:*      LISTEN      13735/ndbd

在db2中
[root@db2 mysql]# ndbd --ndb_nodeid=3 --initial
2013-10-30 09:37:49 [ndbd] INFO    -- Angel connected to '172.16.1.78:1186'
2013-10-30 09:37:49 [ndbd] INFO    -- Angel allocated nodeid: 3
初始化集群也可以直接输入ndbd –initial命令,而不必输入节点号
注:只有在第一次启动ndbd时或者对config.ini进行改动后才需要使用--initial参数!数据库维护过程中慎用initial参数,
如果数据库中已经存在大量数据,并且在所有数据节点上都执行了 ndbd --initial,那么所有数据库中的表和数据都会消失。

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/e6d08f24de9c8aafe351cad59d812345.html