心 涯

NET&JAVA&PHP(要跨界,你不只要跨「脑」的界限,更要跨越「心」的界限,不怕改变,不怕再学习!)

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

MySQL Cluster集群负载配置

一、软件包

a) MySQL-ndb-management-5.0.90-1.i386.rpm

b) MySQL-ndb-management-5.0.90-1.i386.rpm

c) mysql-5.0.27.tar.gz

二、安装[管理节点]

a) rpm -ivh MySQL-ndb-tools-5.0.90-1.i386.rpm

b) rpm -ivh MySQL-ndb-management-5.0.90-1.i386.rpm

c) mkdir /var/lib/mysql-cluster

d) cd /var/lib/mysql-cluster

e) touch config.ini

[NDBD DEFAULT]

NoOfReplicas=2

[MYSQLD DEFAULT]

[NDB_MGMD DEFAULT]

[TCP DEFAULT]

# Managment Server

[NDB_MGMD]

HostName=192.168.1.67

# Storage Engines

[NDBD]

HostName=192.168.1.91

DataDir=/usr/local/mysql/data

#DataDir=/var/lib/mysql-cluster

[NDBD]

HostName=192.168.1.92

DataDir=/usr/local/mysql/data

#DataDir=/var/lib/mysql-cluster

[MYSQLD]

[MYSQLD]

f) /usr/bin/ndb_mgm –initial

g) /usr/bin/ndb_mgmd shutdown

h) /usr/bin/ndb_mgmd -f /var/lib/mysql-cluster/config.ini[启动管理节点]

i) /usr/sbin/ndb_mgmd -f /etc/ndb_mgmd.cnf

三、安装[数据节点]

a) Cd /var/local/software

b) Tar zxvf mysql-5.0.27.tar.gz

c) Cd mysql-5.0.27

d) ./configure --prefix=/usr/local/mysql --localstatedir=/usr/local/mysql/data --disable-maintainer-mode --with-mysqld-user=mysql --with-unix-socket-path=/tmp/mysql.sock --without-comment --without-debug --with-bench --with-ndbcluster;

e) Make & make install

f) Finger mysql

g) Useradd mysql

h) cd scripts

i) ./mysql_install_db

j) chown -R mysql:mysql /usr/local/mysql

k) chown -R mysql:mysql /usr/local/mysql/data

l) cd /usr/local/src/mysql-5.0.27/support-files/

m) cp my-medium.cnf /etc/my.cnf

n) killall mysqld

o) /usr/local/mysql/bin/mysqld_safe --user=mysql --skip-grant-tables --skip-networking &

# /usr/local/mysql/bin/mysql -u root mysql
mysql> UPDATE user SET Password=PASSWORD('123456') where USER='root';
mysql> FLUSH PRIVILEGES;
mysql> quit

修改root用户远程访问的权限:
# killall mysqld
# /usr/local/mysql/bin/mysqld_safe –user=mysql &
# /usr/local/mysql/bin/mysql -u root –p123456 mysql

mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION;
mysql> FLUSH PRIVILEGES;
mysql> quit

vi /etc/my.cnf

[mysqld]

ndbcluster

ndb-connectstring=192.168.1.67

[mysql_cluster]

ndb-connectstring=192.168.1.67

killall mysqld

/usr/local/mysql/bin/mysqld_safe &

/usr/local/mysql/libexec/ndbd –initial(初始化数据节点)

四、 查看管理节点

a) /usr/bin/ndb_mgmd shutdown

b) /usr/bin/ndb_mgmd -f /var/lib/mysql-cluster/config.ini

c) /usr/bin/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.91 (Version: 5.0.27, Nodegroup: 0, Master)

id=3 @192.168.1.92 (Version: 5.0.27, Nodegroup: 0)

[ndb_mgmd(MGM)] 1 node(s)

id=1 @192.168.1.67 (Version: 5.0.90)

[mysqld(API)] 2 node(s)

id=4 @192.168.1.92 (Version: 5.0.27)

id=5 @192.168.1.91 (Version: 5.0.27)

ndb_mgm>

以上为正常显示

五、测试节点同步

a) 在其中一数据节点中/usr/local/mysql/bin/mysql –uroot –p

b) create database   member;
use member ;
create table   admin (id int ) engine=ndbcluster ;
insert into admin values(1) ;

c) 在另一数据节点中/usr/local/mysql/bin/mysql –uroot –p

d) Create database member;

e) Use member;

f) flush tables ;

g) Show tables;

h) 可以看到admin表已同步

i) Select * from admin

j) 可以看到有一条记录已同步

k) 集群正常

六、相关命令

a) /usr/local/mysql/libexec/ndbd –initial(初始化数据节点)

b) /usr/bin/ndb_mgmd shutdown(关闭管理节点)

c) /usr/bin/ndb_mgmd -f /var/lib/mysql-cluster/config.ini(启动管理节点)

d) /usr/bin/ndb_mgm查看集群情况

e) Ps aux|grep mysql查看mysql是否启动

f) Ps aux|grep ndb查看管理节点是否启动

g) Ndb_mgm –e “show”;

h) Ndb_mgm>all stauts;

i) Ndb_mgm >2 status;(2为节点编号)

j) Ndbd –no-wait-nodes=2,3

k) Mysql>Show engine ndb status;

l) Ndb_mgm>clusterlog info;

m) Mysql>show status like ‘ndb%’;

n) Mysql>show warnings;

o) Ndb_mgm>2 stop;

p) SHOW ENGINES;

Vi /etc/ndb_mgmd.cnf

[NDBD DEFAULT]

NoOfReplicas=2

MaxNoOfConcurrentOperations= 10000

DataMemory=1800M

IndexMemory=200M

MaxNoOfAttributes=500000[无法创建表问题]

MaxNoOfTables=1760

MaxNoOfUniqueHashIndexes=5000

MaxNoOfOrderedIndexes=5000

MaxNoOfTriggers=4000

TimeBetweenLocalCheckpoints=2

NoOfFragmentLogFiles=100

DataDir= /var/lib/mysql-cluster

[MYSQLD DEFAULT]

[NDB_MGMD DEFAULT]

DataDir= /var/lib/mysql-cluster

[TCP DEFAULT]

# Managment Server

[NDB_MGMD]

HostName=192.168.1.67

# Storage Engines

[NDBD]

HostName=192.168.1.91

MaxNoOfAttributes=500000

DataDir=/usr/local/mysql/data

#DataDir=/var/lib/mysql-cluster

[NDBD]

HostName=192.168.1.92

MaxNoOfAttributes=500000

DataDir=/usr/local/mysql/data

#DataDir=/var/lib/mysql-cluster

[MYSQLD]

[MYSQLD]

七、IPVSADM安装

a) Rpm –ivh ipvsadm-1.24-8.1.i386.rpm

b) Vi /opt/ipvsadm.sh

#!/bin/bash

ipvsadm -C

ipvsadm -A -t 59.64.28.94:3306 -s rr

ipvsadm -a -t 59.64.28.94:3306 -r 59.64.28.91:3306 -g -w 1

ipvsadm -a -t 59.64.28.94:3306 -r 59.64.28.92:3306 -g -w 1

/etc/rc.d/init.d/ipvsadm save

c) Chmod 755 ipvsadm.sh

d) Service ipvsadm restart

e) Vi /etc/sysconifg/ipvsadm

八、Keepalived安装(监测心跳)

a) Tar zxvf keepalived-1.1.15.tar.gz

b) ln -s /usr/src/kernels/2.6.18-164.el5-PAE-i686 /usr/src/linux

c) Cd keepalived-1.1.15

d) ./configure --prefix=/usr/local/keepalive/ --with-kernel-dir=/usr/src/linux

e) Make

f) Make install

g) cd /usr/local/keepalive/

h) cp /usr/local/keepalive/etc/rc.d/init.d/keepalived /etc/rc.d/init.d/

i) cp /usr/local/keepalive/etc/sysconfig/keepalived /etc/sysconfig/

j) mkdir /etc/keepalived

k) cp /usr/local/keepalive/etc/keepalived/keepalived.conf /etc/keepalived/

l) cp /usr/local/keepalive/sbin/keepalived /usr/sbin/

m) chkconfig --add keepalived

n) chkconfig keepalived on

o) service keepalived restart

p) vi /etc/keepalived/keepalived.conf

! Configuration File for keepalived

global_defs {

notification_email {

acassen@firewall.loc

failover@firewall.loc

sysadmin@firewall.loc

}

notification_email_from Alexandre.Cassen@firewall.loc

smtp_server 127.0.0.1

smtp_connect_timeout 30

router_id LVS_DEVEL

}

vrrp_instance VI_1 {

state MASTER

interface eth1

lvs_sync_daemon_interface eth1

virtual_router_id 51

priority 100

advert_int 1

authentication {

auth_type PASS

auth_pass 1111

}

virtual_ipaddress {

59.64.28.94 dev eth1 label eth1:1(虚拟IP)

}

}

virtual_server 59.64.28.94 3306 {

delay_loop 6

lb_algo rr

lb_kind DR

nat_mask 255.255.255.0

persistence_timeout 60

protocol TCP

real_server 59.64.28.91 3306 {

weight 1

TCP_CHECK {

connect_timeout 10

nb_get_retry 3

delay_before_retry 3

connect_port 3306

}

}

real_server 59.64.28.92 3306 {

weight 1

TCP_CHECK {

connect_timeout 10

nb_get_retry 3

delay_before_retry 3

connect_port 3306

}

}

}

q) service keepalived restart

r) ipvsadm

IP Virtual Server version 1.2.1 (size=4096)

Prot LocalAddress:Port Scheduler Flags

-> RemoteAddress:Port Forward Weight ActiveConn InActConn

TCP 59.64.28.94:mysql rr persistent 60

-> 59.64.28.92:mysql Route 1 0 0

-> 59.64.28.91:mysql Route 1 0 0

s) 应用程序数据库连接主机改成59..64.28.94测试。

九、相关命令

a) service ipvsadm restart

b) service keepalived restart

c) ipvsadm

d) vi /usr/local/keepalive/etc/keepalived/keepalived.conf[/etc/keepalived/keepalived.conf]

posted on 2010-11-09 13:59  witer666  阅读(427)  评论(0编辑  收藏  举报