赞
踩
Ubuntu进行mysql集群
表ha 条数437326条
/*
未优性能优化的情况下
单台mysql并发连数75个时为最优:
单表执行6000个select、insert操作大约29S,
单表执行1000个select、insert操作大约7S,
单表执行1000个select操作大约4S,
单表执行1000个insert操作大约5S
*/
http://dev.mysql.com/doc/refman/5.7/en/mysql-cluster-installation.html
root@hadoop0:/usr/local/mysql/mysql-cluster#more config.ini
[ndbd default]
NoOfReplicas=2
DataMemory=128M
IndexMemory=32M
[tcp default]
#portnumber=2202
[ndb_mgmd]
#ndb-nodeid=1
hostname=172.17.0.2
datadir=/usr/local/mysql/mysql-cluster
[ndbd]
#ndb-nodeid=2
hostname=172.17.0.3
datadir=/usr/local/mysql/data
[ndbd]
#ndb-nodeid=3
hostname=172.17.0.4
datadir=/usr/local/mysql/data
[mysqld]
hostname=172.17.0.3
[mysqld]
hostname=172.17.0.4
[mysqld]
[mysqld]
root@hadoop1:/etc/mysql# more my.cnf
[mysql]
socket=/tmp/mysql.sock
[mysqld]
ndbcluster
skip-name-resolve
[mysql_cluster]
ndb-connectstring=172.17.0.2
root@hadoop1:/etc/mysql# more my.cnf
[mysql]
socket=/tmp/mysql.sock
[mysqld]
ndbcluster
skip-name-resolve
[mysql_cluster]
ndb-connectstring=172.17.0.2
shell> ndb_mgmd -f /usr/local/mysql/mysql-cluster/config.ini
查看集群状态
shell> ndb_mgm
-- NDB Cluster -- ManagementClient --
ndb_mgm> SHOW
Connected to Management Serverat: localhost:1186
Cluster Configuration
---------------------
[ndbd(NDB)] 2 node(s)
id=2 @192.168.0.30 (Version: 5.7.16-ndb-7.5.5, Nodegroup: 0, *)
id=3 @192.168.0.40 (Version: 5.7.16-ndb-7.5.5, Nodegroup: 0)
[ndb_mgmd(MGM)] 1 node(s)
id=1 @192.168.0.10 (Version: 5.7.16-ndb-7.5.5)
[mysqld(API)] 1 node(s)
id=4 @192.168.0.20 (Version: 5.7.16-ndb-7.5.5)
shell> ndbd
以用户ROOT启动,且在后台运行。引用/etc/mysq/my.cnf文件作为配置文件
shell>mysqld –-user=root &
Table 5.2 OptionFiles Read on Unix and Unix-Like Systems
File Name | Purpose |
/etc/my.cnf | Global options |
/etc/mysql/my.cnf | Global options |
SYSCONFDIR/my.cnf | Global options |
$MYSQL_HOME/my.cnf | Server-specific options (server only) |
defaults-extra-file | The file specified with --defaults-extra-file, if any |
~/.my.cnf | User-specific options |
~/.mylogin.cnf | User-specific login path options (clients only) |
mysql> ALTER USER 'root'@'localhost' IDENTIFIEDBY '123456';
grant allprivileges on*.* to root@'%' identified by '123456';
shell>mysql –uroot –hipadress -p
https://my.oschina.net/bobo2cj/blog/203852
创建虚拟网络:
# brctl addbr lvs (建立一个逻辑网段,名称为lvs)
# 安装IPVS后,就可以配置LVS集群了,首先在Director Server上绑定一个虚拟IP(也叫VIP),此IP用于对外提供服务,执行如下命令:
/sbin/ifconfiglvs $VIP broadcast $VIP netmask 255.255.255.255 up
# 然后给设备lvs指定一条路由,执行如下指令:
/sbin/routeadd -host $VIP dev lvs
分别在lbserver1、lbserver2上创建启动脚本 (* 附录B)
#!/bin/bash
vip=192.168.56.200
rs1=192.168.56.201
rs2=192.168.56.202
#clear ipvs tables
ipvsadm -C
#set LVS Server
ipvsadm -A -t $vip:80 -s rr
ipvsadm -a -t $vip:80 -r $rs1:80 -g -w 1 #-w表示权重,默认为1
ipvsadm -a -t $vip:80 -r $rs2:80 -g #不加-w 1效果同上句
# update /etc/sysctl.conf,以下配置重启后将复原
echo "1" >/proc/sys/net/ipv4/ip_forward #启用ip转发
echo "1" >/proc/sys/net/ipv4/conf/all/send_redirects
echo "1" >/proc/sys/net/ipv4/conf/default/send_redirects
echo "1" >/proc/sys/net/ipv4/conf/eth0/send_redirects
#sysctl -p #查看sysctl的配置变化,可不执行
分别在real server1、real server2上创建启动脚本 (* 附录B)
#!/bin/bash
vip=192.168.56.200
ifconfig lo:0 $vip netmask 255.255.255.255 broadcast $vip up #网关要和虚ip一样,掩码不能同于eth0的
route add -host $vip dev lo:0 #添加永久路由
#echo "0" >/proc/sys/net/ipv4/ip_forward #关闭real server ip转发,2.6.*内核默认是关闭的
echo "1" >/proc/sys/net/ipv4/conf/lo/arp_ignore
echo "2" >/proc/sys/net/ipv4/conf/lo/arp_announce
echo "1" >/proc/sys/net/ipv4/conf/all/arp_ignore
echo "2" >/proc/sys/net/ipv4/conf/all/arp_announce
#sysctl -p #查看sysctl的配置变化,可不执行
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。