您的当前位置:首页正文

MySQL集群与LVS实现apache负载均衡

2024-05-16 来源:独旅网
先发一张图,文档整理中。。。

先讲MySQL:

groupadd -g 40 mysql &&

useradd -c \"MySQL Server\" -d /dev/null -g mysql -s /bin/false \\ -u 40 mysql

CPPFLAGS=\"-D_GNU_SOURCE\" ./configure --prefix=/usr/local/mysql --sysconfdir=/etc \\ --localstatedir=/srv/mysql --with-unix-socket-path=/var/run/mysql/mysql.sock \\ --enable-thread-safe-client \\

--with-named-thread-libs=-lpthread \\ --enable-local-infile --with-charset=ascii \\

--with-extra-charsets=gb2312,gbk,utf8 --enable-assembler \\ --with-ndbcluster --without-ndb-debug \\

--without-debug --without-bench --without-readline make && make install

ln -v -sf ../local/mysql/lib/mysql/libmysqlclient{,_r}.so* /usr/lib

install -v -m644 /usr/local/mysql/share/mysql/my-medium.cnf /etc/my.cnf

/usr/local/mysql/bin/mysql_install_db --user=mysql && chgrp -v mysql /srv/mysql{,/test,/mysql}

/usr/local/mysql/bin/mysqld_safe --user=mysql 2>&1 >/dev/null &

mkdir -p /data/cluster/{manager, ndb111,ndb112,ndb113}

管理机上设置如下:

cat > /data/cluster/manager/config.ini << EOF [NDBD DEFAULT] NoOfReplicas=3

[TCP DEFAULT] PortNumber=2202

# Managment Server 管理机 [NDB_MGMD]

HostName=192.168.126.100

# Storage Engines 存贮服务器 [NDBD]

HostName=192.168.126.111 DataDir=/data/cluster/ndb111 [NDBD]

HostName=192.168.126.112 DataDir=/data/cluster/ndb112 [NDBD]

HostName=192.168.126.113 DataDir=/data/cluster/ndb113

# SQL node options: 检索服务器 [MYSQLD] [MYSQLD] [MYSQLD] EOF

用下面的命令启动管理机服务

/usr/local/mysql/libexec/ndb_mgmd -f /data/cluster/manager/config.ini

其它各节点服务器设置 cat > /etc/my.cnf << EOF [mysqld] ndbcluster

ndb-connectstring=192.168.126.100 [mysql_cluster]

ndb-connectstring=192.168.126.100 EOF

启动初始化其它节点服务

/usr/local/mysql/libexec/ndbd --initial

注:只有第一次运行或者管理机改动了config.ini文件,要不只执行以下命令即可 /usr/local/mysql/libexec/ndbd

启动各节点mysqld服务

/usr/local/mysql/bin/mysqld_safe --user=mysql 2>&1 >/dev/null &

在管理机上运行

/usr/local/mysql/bin/ndb_mgm

LVS:有关内核配置待整理中。。。

director:

echo 1 > /proc/sys/net/ipv4/ip_forward

echo 1 > /proc/sys/net/ipv4/conf/all/send_redirects echo 1 > /proc/sys/net/ipv4/conf/all/hidden

echo 1 > /proc/sys/net/ipv4/conf/default/send_redirects

ifconfig dummy up ifconfig dummy0 up

ifconfig dummy0 192.168.126.121 netmask 255.255.255.255 broadcast 192.168.126.121

route add -host 192.168.126.121 dev dummy0

ipvsadm -C

ipvsadm -A -t 192.168.126.121:80 -s wlc

ipvsadm -a -t 192.168.126.121:80 -r 192.168.126.52 -g ipvsadm -a -t 192.168.126.121:80 -r 192.168.126.11 -g

web节点:

ifconfig dummy up ifconfig dummy0 up

ifconfig dummy0 192.168.126.121 netmask 255.255.255.255 broadcast 192.168.126.121

route add -host 192.168.126.121 dev dummy0 echo 1 > /proc/sys/net/ipv4/conf/dummy0/hidden

因篇幅问题不能全部显示,请点此查看更多更全内容