Chinaunix首页 | 论坛 | 博客
  • 博客访问: 19660
  • 博文数量: 9
  • 博客积分: 34
  • 博客等级: 民兵
  • 技术积分: 55
  • 用 户 组: 普通用户
  • 注册时间: 2012-05-21 09:52
文章分类
文章存档

2012年(9)

分类:

2012-05-23 16:35:11

            Keepalived+LVS+Mysql-Cluster(7.1.10)的安装配置



NDB Cluster的硬件需求:

管理节点:对硬件没什么要求,差 一点的机器完全能够胜任

数据节点:可以选择大内存,cpu也相对来讲不错 的,尤其是以后ndbmtd对多核Cpu的支持

Mysql节 点:对cpu要求较高,选择多核,高频CPU较好


环境:

Role                IP                OS                  Cpu                 Mem
管理节点(LVS)    192.168.100.223    CentOS 5.5 64bit    E5405  @ 2.00GHz    3G
Ndb节点1           192.168.100.231    CentOS 5.5 64bit    E5506  @ 2.13GHz    16G
Ndb节点2           192.168.100.232    CentOS 5.5 64bit    E5506  @ 2.13GHz    16G
Mysql节点1         192.168.100.225    CentOS 5.5 64bit    E5506  @ 2.13GHz    16G
Mysql节点2         192.168.100.226    CentOS 5.5 64bit    E5506  @ 2.13GHz    16G

Mysql版本:mysql-5.1.51
NDB版本:ndb-7.1.10



架构图:

Mysql-Cluster 7.1.10的安装配置
数据节点的安装:
tar xzvf mysql-cluster-gpl-7.1.10-linux-i686-glibc23.tar.gz
mv mysql-cluster-gpl-7.1.10-linux-i686-glibc23 /usr/local/mysql
#编辑/etc/my.cnf,添加如下内容:
 [mysql_cluster]
ndb-connectstring="nodeid=21, 192.168.100.223"
#修改环境变量,增加mysql命令路径
vi /root/.bash_profile
#修改如下
PATH=$PATH:$HOME/bin:/usr/local/mysql/bin
然后执行source  /root/.bash_profile命令使更改生效!
另一个数据节点的安装类似。

Mysql节点的安装
/usr/sbin/groupadd mysql
/usr/sbin/useradd -g mysql mysql
tar xzvf mysql-cluster-gpl-7.1.10-linux-i686-glibc23.tar.gz
mv mysql-cluster-gpl-7.1.10-linux-i686-glibc23 /usr/local/mysql
chown -R root.mysql /usr/local/mysql
chown -R mysql.mysql /usr/local/mysql/data
cd /usr/local/mysql
./scripts/mysql_install_db  --user=mysql
cp /usr/local/mysql/support-files/my-huge.cnf  /etc/my.cnf
添加如下内容:
[mysql_cluster]
ndb-connectstring="nodeid=12,192.168.100.223"
在[mysqld]下添加如下内容
ndbcluster
ndb-connectstring="nodeid=12,192.168.100.223"
ndb-force-send=1
ndb-use-exact-count=0
ndb-autoincrement-prefetch-sz=256
engine-condition-pushdown=1
ndb-cluster-connection-pool=4
default-storage-engine = ndbcluster
#编辑 /root/.bash_profile
#修改如下
PATH=$PATH:$HOME/bin:/usr/local/mysql/bin
然后执行source  /root/.bash_profile命令使更改生效!
cp support-files/mysql.server /etc/rc.d/init.d/mysqld
#设置成服务启动
chkconfig --add mysqld
chkconfig --level 2345 mysqld on
另一个mysql节点的安装类似。


管理节点的安装
tar xzvf mysql-cluster-gpl-7.1.10-linux-i686-glibc23.tar.gz
cp mysql-cluster-gpl-7.1.10-linux-i686-glibc23/
cp mysql-cluster-gpl-7.1.10-linux-i686-glibc23/bin/ndb_mgm* /usr/bin/
chmod +x /usr/bin/ ndb_mgm*
新建/etc/my.cnf,添加如下内容:
[mysqld]
ndbcluster
ndb-connectstring=192.168.100.223
[mysql_cluster]
ndb-connectstring=192.168.100.223

#新建config.ini文件,添加如下内容:


[tcp default]
SendBufferMemory=2M
ReceiveBufferMemory=2M

[NDB_MGMD]
HostName=192.168.100.223

[NDBD DEFAULT]
TotalSendBufferMemory = 256M
NoOfReplicas=2
DataMemory=10240M
IndexMemory=1024M
DataDir=/data/dbdata
#DataDir=/usr/local/mysql/mysql-cluster
#FileSystemPath=/data/dbdata
FragmentLogFileSize=256M
NoOfFragmentLogFiles=16

LockPagesInMainMemory=1
MaxNoOfTables=4096
MaxNoOfOrderedIndexes=2048
MaxNoOfUniqueHashIndexes=2048
MaxNoOfAttributes=20480
MaxNoOfTriggers=10240
ODirect=1
MaxNoOfConcurrentTransactions=50000
MaxNoOfConcurrentOperations=100000
TimeBetweenGlobalCheckpoints=1000
TimeBetweenEpochs=200
TransactionBufferMemory=10M
DiskCheckpointSpeed=10M
DiskCheckpointSpeedInRestart=100M
RedoBuffer=64M

SchedulerSpinTimer=400
SchedulerExecutionTimer=100
RealTimeScheduler=1

BackupMaxWriteSize=1M
BackupDataBufferSize=16M
BackupLogBufferSize=4M
BackupMemory=20M

MaxNoOfExecutionThreads=4

TransactionDeadLockDetectionTimeOut=10000

BatchSizePerLocalScan=512

#disk
SharedGlobalMemory=256M
DiskPageBufferMemory=512MB


[NDBD]
id=11
HostName=192.168.100.231
#LockExecuteThreadToCpu=1,2,3
#LockMaintThreadsToCPU=0

[NDBD]
id=12
HostName=192.168.100.232
#LockExecuteThreadToCpu=1,2,3
#LockMaintThreadsToCPU=0

[MYSQLD]
id=13
HostName=192.168.100.225
[MYSQLD]
id=14
HostName=192.168.100.226
[MYSQLD]
[MYSQLD]
[MYSQLD]
[MYSQLD]
[MYSQLD]
[MYSQLD]
[MYSQLD]
[MYSQLD]
[MYSQLD]

keepalived的安装配置
Lvs的安装
wget
ln -s /usr/src/kernels/2.6.18-164.el5-i686/ /usr/src/linux
tar zxvf ipvsadm-1.24.tar.gz
cd ipvsadm-1.24
make && make install

Keepalived的安装
wget
tar zxvf keepalived-1.1.19.tar.gz
cd keepalived-1.1.19
./configure --prefix=/usr/local/keepalived
make
make install
cp /usr/local/keepalived/sbin/keepalived /usr/sbin/
cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/
cp /usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/init.d/
mkdir /etc/keepalived

keepalived的配置
server端的配置
vi /etc/keepalived/keepalived.conf
添加如下内容:

global_defs {

   notification_email {

        zhangxy@zhang.com  

}

   notification_email_from zhangxy@zhang.com

   smtp_server 192.168.1.250

   smtp_connect_timeout 30

   router_id LVS_DEV

}

 

vrrp_instance VI_9 {

    state MASTER

    interface eth0

    virtual_router_id 100

    priority 100

    advert_int 1

    authentication {

        auth_type PASS

        auth_pass 2209

    }

    virtual_ipaddress {

        192.168.100.229/24 dev eth0 label eth0:1

 }

}

 

    virtual_server 192.168.100.229 3306 {

    delay_loop 2

    lb_algo wrr

    lb_kind DR

    nat_mask 255.255.255.0

   # persistence_timeout 60

protocol TCP

    real_server 192.168.100.225 3306 {

        weight 3

        TCP_CHECK {

        connect_timeout 3

        nb_get_retry 3

        delay_before_retry 3

        connect_port 3306

                }

        }

 

 

    real_server 192.168.100.226 3306 {

        weight 3

        TCP_CHECK {

        connect_timeout 3

        nb_get_retry 3

        delay_before_retry 3

        connect_port 3306

                }

        }

}



Client端的配置
vi /etc/rc.d/init.d/realserver.sh 添加如下配置:

#!/bin/bash

# description: Config realserver lo and apply noarp

SNS_VIP=192.168.100.229

/etc/rc.d/init.d/functions

case "$1" in

start)

       ifconfig lo:0 $SNS_VIP netmask 255.255.255.255 broadcast $SNS_VIP

       /sbin/route add -host $SNS_VIP dev lo:0

       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 >/dev/null 2>&1

       echo "RealServer Start OK"

       ;;

stop)

       ifconfig lo:0 down

       route del $SNS_VIP >/dev/null 2>&1

       echo "0" >/proc/sys/net/ipv4/conf/lo/arp_ignore

       echo "0" >/proc/sys/net/ipv4/conf/lo/arp_announce

       echo "0" >/proc/sys/net/ipv4/conf/all/arp_ignore

       echo "0" >/proc/sys/net/ipv4/conf/all/arp_announce

       echo "RealServer Stoped"

       ;;

*)

       echo "Usage: $0 {start|stop}"

       exit 1

esac

exit 0


添加加可执行的权限
chmod +x  /etc/rc.d/init.d/realserver.sh
keepalived的服务器端启动
/etc/rc.d/init.d/keepalived  start
keepalived的客户端启动
/etc/rc.d/init.d/realserver.sh  start

ndb各节点的关闭和启动
节点的启动和关闭是有顺序的,启动的时候应该先启动管理节点,然后是数据节点,最后是mysql节点。关闭节点的时候应该先关闭mysql节点,然后再通过管理节点关闭所有的管理节点和数据节点。
启动:
/usr/bin/ndb_mgmd -f /usr/local/mysql/mysql-cluster/config.ini(启动管理节点)
/usr/bin/ndbd  --initial(启动数据节点,只有第一次启动或者有的配置变更后才需要--initial参数)
/etc/rc.d/init.d/mysqld start(启动mysql节点)
停止:
/etc/rc.d/init.d/mysqld stop
ndb_mgm -e shutdown

阅读(636) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~