Home > Database > Mysql Tutorial > Heartbeat_2.0.3配置MySQL5.0.18为高可用集群_MySQL

Heartbeat_2.0.3配置MySQL5.0.18为高可用集群_MySQL

WBOY
Release: 2016-06-01 13:54:30
Original
941 people have browsed it

Mysql集群

测试环境为:rehdat linux 9.0
hostname eth0 eth1
mysql5 192.168.0.50/24 10.4.66.35/24
mysql6 192.168.0.60/24 10.4.66.36/24

heartbeat interface eth0, with crosscab
service ip 10.4.66.88/24, by eth1, default gateway 10.4.66.2

共享存储采用NAS服务器,数据访问地址为10.4.66.251:/data
在服务器本地的挂在目录也是/data

1. 安装MySQL5.0,安装到默认目录
清除准备安装MySQL的服务器上linux自带的mysql-server,
[root@c0101 bin]# rpm -e mysql-server
[root@c0101 bin]# rpm -qa|grep mysql
mysql-3.23.54a-11

[root@c0101 bin]# userdel mysql
[root@c0101 bin]# mv /etc/my.cnf /etc/my.cnf.bak

(1)首先在第一台服务器(HA系统的主节点服务器),
开始安装
1056 useradd mysql
1057 tar xzvf mysql-max-5.0.18-linux-i686-glibc23.tar.gz
1059 mv mysql-max-5.0.18-linux-i686-glibc23 /usr/local/mysql
1060 cd /usr/local/mysql
1088 chown -R root .
1089 chown -R mysql ./data/
1090 chgrp -R mysql .

设置数据路径,把数据库数据文件放在共享的NFS目录下(NAS服务器),
PID和innioDB文件要放到服务器本地目录上,才能正常启动、停止服务:
1125 vi /etc/my.cnf
[mysqld]
#Where to install a database data
datadir=/data/mysqldata

#Where to install a innoDB engine
innodb_data_home_dir = /usr/local/mysql/data
innodb_log_group_home_dir= /usr/local/mysql/data
innodb_data_file_path=ibdata1:50M;ibdata2:50M:autoextend

1106 cp ./support-files/mysql.server /etc/rc.d/init.d/
vi /etc/rc.d/init.d/mysql.server
编译第222开始的相关的两行,把PID文件放在服务器本地目录上:
pid_file=/usr/local/mysql/data/mysqlmanager-`/bin/hostname`.pid
server_pid_file=/usr/local/mysql/data/`/bin/hostname`.pid

安装MySQL的基本数据库:
1123 mount 10.4.66.251:/data /data
1124 mkdir /data/mysqldata
1127 ./scripts/mysql_install_db --user=mysql
1145 chown -R mysql.mysql /data/mysqldata/

如果正常的话,可以看到mysql正常启动了;

1146 /etc/rc.d/init.d/mysql.server start
1146 /etc/rc.d/init.d/mysql.server stop

配置HA高可用,不要设置NFS挂载和mysql服务在启动服务器时自动运行;


(2)然后在第二台服务器(HA系统的备份节点服务器),

1090 tar xzvf mysql-max-5.0.18-linux-i686-glibc23.tar.gz
1092 mv mysql-max-5.0.18-linux-i686-glibc23 /usr/local/mysql
1093 cd /usr/local/mysql/
1095 chown -R root .
1096 chown -R mysql ./data/
1097 chgrp -R mysql .

设置数据路径,把数据库数据文件放在共享的NFS目录下(NAS服务器),
PID和innioDB文件要放到服务器本地目录上,才能正常启动、停止服务:
1125 vi /etc/my.cnf
[mysqld]
#Where to install a database data
datadir=/data/mysqldata

#Where to install a innoDB engine
innodb_data_home_dir = /usr/local/mysql/data
innodb_log_group_home_dir= /usr/local/mysql/data
innodb_data_file_path=ibdata1:50M;ibdata2:50M:autoextend

1106 cp ./support-files/mysql.server /etc/rc.d/init.d/
vi /etc/rc.d/init.d/mysql.server
编译第222开始的相关的两行,把PID文件放在服务器本地目录上:
pid_file=/usr/local/mysql/data/mysqlmanager-`/bin/hostname`.pid
server_pid_file=/usr/local/mysql/data/`/bin/hostname`.pid

在NFS目录/data/下,已经有了基本数据库,所以只需要
设置一下,就可以启动了,
1123 mount 10.4.66.251:/data /data
1149 /etc/rc.d/init.d/mysql.server start

如果首次启动失败,察看一下日志,
使用ps -A命令查看进程,杀掉失败的进程,应该可以正常启动的;
killall -9 mysqld_safe
killall -9 mysqld

(3)保证在两台服务器上,都可以正常启动、停止MySQL服务,
由于数据共享的原因,要注意保证,同时只有1台服务器启动MySQL服务
/etc/rc.d/init.d/mysql.server start
/etc/rc.d/init.d/mysql.server stop

2.安装Heartbeat HA,安装到默认目录,
两台服务器安装方法相同:

(1)安装libnet,这是编译Heartbeat HA需要的:
1046 tar xzvf libnet.tar.gz
1047 cd libnet
1048 ls
1049 ./configure
1051 make
1052 make install

(2)编译安装Heartbeat HA
1019 groupadd haclient
1020 useradd hacluster -g haclient
1058 tar xzvf heartbeat-2.0.3.tar.gz
1059 ls
1060 cd heartbeat-2.0.3
1061 ls
1062 ./ConfigureMe configure
1063 make
1064 make install

3. 编辑Heartbeat HA的三个配置文件,配置MySQL的HA服务
两台服务器配置方法相同:

1067 cd /etc/ha.d
1068 cp /root/heartbeat-2.0.3/doc/ha.cf .
1069 vi ha.cf
logfile /var/log/ha-log # Log file
keepalive 2 # Heartbeat interval
deadtime 30 # How long to say the server's death
warntime 10

udpport 694 # Heartbeat port
bcast eth0 # Linux Heartbeat interface

auto_failback on # How to do when the failure server comes back
node mysql5 # How many servers in the HA system
node mysql6
ping 10.4.66.2 #ping a robust server to ensure the server's health;
#here is the default gateway
respawn hacluster /usr/lib/heartbeat/ipfail

配置心跳的加密,本次测试因为采用交叉电缆,所以采用最简单的crc方式:
1076 cp /root/heartbeat-2.0.3/doc/authkeys .
1077 vi authkeys
auth 1
1 crc

1078 chmod 600 authkeys

1073 cp /root/heartbeat-2.0.3/doc/haresources .

配置资源,本次测试mysql服务的迁移,配置资源文件是关键
1074 vi haresources
mysql5 IPaddr::10.4.66.88/24/eth1 Filesystem::10.4.66.251:/data::/data::nfs mysql.server
这一行配置了3个资源,第一个是IP地址,第二个是NFS共享数据,
第三个是mysql.server服务,文件在/etc/rc.d/init.d/目录,
可以使用mysql.server start或stop来启动或停止服务。

4.设置Heartbeat HA服务自动启动,
heartbeat会自动把/data目录挂载,会自动启动MySQL Server;
配置HA高可用,不要设置NFS挂载和mysql服务在启动服务器时自动运行,
也就是说,把与HA相关资源交给Heartbeat HA去自动管理,
cd /etc/rc.d/rc0.d ; ln -s ../init.d/heartbeat K05heartbeat
cd /etc/rc.d/rc3.d ; ln -s ../init.d/heartbeat S75heartbeat
cd /etc/rc.d/rc5.d ; ln -s ../init.d/heartbeat S75heartbeat
cd /etc/rc.d/rc6.d ; ln -s ../init.d/heartbeat K05heartbeat

可以拔掉主节点服务器的网线,看看有什么情况发生,测试是否正常?
然后再把网线插回去,看看HA服务是否运行,MySQL服务能否自动切换回来?

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template