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

[root@db1 heartbeat-3.0.3]# ls
apphbd.cf  authkeys  AUTHORS  ChangeLog  COPYING  COPYING.LGPL  ha.cf  haresources  README
[root@db1 heartbeat-3.0.3]# cp ha.cf /etc/ha.d/
[root@db1 heartbeat-3.0.3]# cp haresources /etc/ha.d/
[root@db1 heartbeat-3.0.3]# cp authkeys /etc/ha.d/

vi /etc/ha.d/ha.cf添加如下内容
debugfile /var/log/ha.log
logfile /var/log/ha.log
logfacility    local0
bcast  eth0            # Linux
mcast eth0 225.0.0.1 694 1 0
auto_failback off
node  db1
node  db2
respawn hacluster /usr/lib/heartbeat/ipfail  #64位系统此处应该是/usr/lib64/heartbeat/ipfail
apiauth ipfail gid=haclient uid=hacluster
keepalive 1
deadtime  10
#warntime 10
initdead 120
#udpport 694
#baud 19200

64位系统需要执行下面的操作:
[root@db2 lib]# mkdir heartbeat
[root@db2 lib]# ln -s /usr/lib64/heartbeat/ipfail /usr/lib/heartbeat/ipfail

vi /etc/ha.d/haresources 设置虚拟IP地址
db1.test.com ldirectord::ldirectord.cf LVSSyncDaemonSwap::master IPaddr::172.16.1.73/24/eth0/172.16.1.255

vi /etc/ha.d/authkeys
auth 3
3 md5 Hello!
[root@db1 ha.d]# chmod 600 authkeys
[root@db2 ha.d]# chmod 600 authkeys
上述三个文件的配置db1、db2节点要相同

配置ldirectord
[root@db1 ha.d]# find / -name ldirectord.cf
/usr/share/doc/ldirectord-1.0.4/ldirectord.cf
[root@db1 ha.d]# cd /usr/share/doc/ldirectord-1.0.4/
[root@db1 ldirectord-1.0.4]# cp ldirectord.cf /etc/ha.d/
[root@db1 ldirectord-1.0.4]# vi /etc/ha.d/ldirectord.cf
配置如下的内容:

# Global Directives
checktimeout=10
checkinterval=2
#fallback=127.0.0.1:80
#fallback6=[::1]:80
autoreload=yes
logfile="/var/log/ldirectord.log"
#logfile="local0"
#emailalert="admin@x.y.z"
#emailalertfreq=3600
#emailalertstatus=all
quiescent=yes

# Sample for an http virtual service
virtual=172.16.1.73:3306
        real=172.16.1.74:3306 gate
        real=172.16.1.75:3306 gate
#      real=192.168..: gate
#      fallback=127.0.0.1:3306 gate
        service=mysql
        scheduler=wrr
        #persistent=600
        #netmask=255.255.255.255
        protocol=tcp
        checktype=negotiate
#      checkport=80
        login="ldirectord"
        passwd="ldirectord"
        database="ldirectordb"
        request="select * from ldirectordtest"
        receive="ldirectord is OK"
#      virtualhost=www.x.y.z

阻止ldirectord服务开机启动,推迟heartbeat启动的操作怎么弄呢?让hearbeat来控制ldirectord
/sbin/chkconfig --level 2345 heartbeat on
/sbin/chkconfig --del ldirectord

还有怎样才能修改heartbeat启动时候的优先级别呢?
目前的方法是/etc/rc.d/init.d/目录下的heatbeat的脚本的注释
# chkconfig: - 75 05
# description: Startup script high-availability services.
# processname: heartbeat
# pidfile: /var/run/heartbeat.pid
# config: /etc/ha.d/ha.cf

创建数据库和测试表
mysql>GRANT ALL ON ldirectordb.* TO 'ldirectord'@'%' IDENTIFIED BY 'ldirectord';
mysql>GRANT ALL ON ldirectordb.* TO 'ldirectord'@'localhost' IDENTIFIED BY 'ldirectord';
mysql>GRANT ALL ON ldirectordb.* TO 'ldirectord'@'db1' IDENTIFIED BY 'ldirectord';
mysql>GRANT ALL ON ldirectordb.* TO 'ldirectord'@'db2' IDENTIFIED BY 'ldirectord';
mysql>FLUSH PRIVILEGES;
mysql>CREATE DATABASE ldirectordb;
mysql>USE ldirectordb;
mysql>CREATE TABLE ldirectordtest (Status INT) ;
mysql>INSERT INTO ldirectordtest() VALUES (1);
mysql>quit

先设置IP路由
检查是否已经安装了iproute包
[root@db1 mysql]# rpm -qa |grep iproute
iproute-2.6.18-11.el5
修改/etc/sysctl.conf文件
net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.eth0.arp_ignore = 1
net.ipv4.conf.all.arp_announce = 2
net.ipv4.conf.eth0.arp_announce = 2
sysctl -p

配置虚拟IP地址,虚拟IP应该使用lo:0来配置,不应该使用eth0:0来配置,使用eth0:0来配置会导致虚拟IP地址在局域网内冲突,使用lo:0
不会有这样情况发生。
/etc/sysconfig/network-scripts/
db1服务器lo:0的设置(虚拟IP地址)
DEVICE=lo:0
IPADDR=172.16.1.73
NETMASK=255.255.255.255
ONBOOT=yes         
db2上设置lo:0的IP地址(虚拟IP地址)
DEVICE=lo:0
IPADDR=172.16.1.73
NETMASK=255.255.255.255
ONBOOT=yes

[root@db1.test.com network-scripts]# ifup ifcfg-lo:0
db2.test.com上执行同样的配置和操作即可。

高可用性和负载均衡测试
[root@db2 init.d]# ldirectord stop
[root@db2 init.d]# heartbeat start

执行上面命令若没有报错,就表示一切正常
重启两台服务器db1和db2

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

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