通过heartbeat 2.X 实现高可用lamp
一,试验环境主机名IP地址角色node1.example.com192.168.86.185node1node2.example.com192.168.86.186node2fs.example.com192.168.86.111fileserver
二,配置三台服务器时间同步并修改crontab自动与ntp服务器同步
crontab -e
*/2 * * * * /usr/sbin/ntpdate cn.pool.ntp.org
三,编辑/etc/hosts文件配置ssh互信
1.vim /etc/hosts
192.168.86.185node1.example.com node1
192.168.86.186node2.example.com node2
192.168.86.111fs.example.com fsscp /etc/hosts 192.168.86.186:/etc/
scp /etc/hosts 192.168.86.111:/etc/ 2.配置ssh证书
在每台服务器运行 ssh-keygen --> ssh-copyid node2
四,准备NFS Server
1.添加一块新的磁盘分区后进行挂载
fdisk /dev/sdb
mkfs.ext4 /dev/sdb1
mkdir /mydata ; mount /dev/sdb1 /mydata 2.编辑/etc/exports文件
vim /etc/exports
/mydata 192.168.86.0/24(rw,no_root_squash) 启动nfs服务
service nfs start
在node1,node2节点上建立/mydata目录,并进行测试性挂载
mkdir /mydata ; mount -t nfs fs:/mydata /mydata ; mkdir /mydata/{db,webdoc}
五,在node1,node2节点安装heartbeat+crm+httpd+mariadb
将下载后的heartbeat-gui-2.1.4-12.el6.x86_64.rpm heartbeat-stonith-2.1.4-12.el6.x86_64.rpm heartbeat-2.1.4-12.el6.x86_64.rpm heartbeat-stonith-2.1.4-12.el6.x86_64.rpm 进行安装
推荐使用yum localinstall 安装可以解决依赖关系,也可以首先使用yum install heartbeat进行安装后再yum remove heartbeat解决好依赖关系后rpm -ivh 进行安装
httpd采用yum安装
yum install httpd php php-mysql -y mariadb采用编译好的tarball安装
tar xvf mariadb-5.5.46-linux-x86_64.tar.gz -C /usr/local ; ln -s /usr/local/mariadb-5.5.46 /mysql 1.mysql配置
groupadd -r -g mysql
useradd -r -g mysql mysql
chown -R root.mysql /usr/local/mysql copy mysql配置文件
cp /usr/local/mysql/support-fils/my-medium.cnf /etc/my.cnf 编辑配置文件
vim /etc/my.cnf
datadir = /mydata/db 指定数据库位置
innodb_file_per_table = on 指定innodb表空间存储方式
skip_name_resolve = on 跳过域名解析
copy启动脚本
cp /usr/local/mysql/mysql.server /etc/init.d/mysqld ; chmod +x /etc/init.d/mysqld 初始化数据库
/usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql --user=mysql 测试启动mysql
service mysqld start 建立wordpress库,并给wordpress用户授权
MariaDB [(none)]> create database wordpress;
Query OK, 1 row affected (0.01 sec)
MariaDB [(none)]> grant all privileges on wordpress.* to 'wordpress'@'192.168.86.%' identified by 'wordpress';
Query OK, 0 rows affected (0.01 sec)
MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.01 sec) 正常启动后关闭mysql
service mysqld stop
2.httpd配置
编辑httpd配置文件
vim /etc/httpd/conf/httpd.conf
DocumentRoot "/mydata/webdoc" 六,配置heartbeat
cp /usr/share/doc/heartbeat-2.1.4/{authkeys,ha.cf} /etc/ha.d/ 1.编辑authkeys
首先需要生成一个随机数作最为匹配对
openssl rand -base64 10
ABB7qPDGZVXdRA
vim /etc/ha.d/authkeys
auth 2
#1 crc
2 sha1 ABB7qPDGZVXdRA 修改为生成的随机数
#3 md5 Hello!
将authkeys复制到node2
scp /etc/ha.d/authkeys node2:/etc/ha.d 2.编辑ha.cf
vim /etc/ha.d/ha.cf
logfile/var/log/ha-log 开启日志功能
logfacilitylocal0
udpport694 监听udp 694端口
mcast eth0 225.0.0.1 694 1 0 配置组播地址,ttl值
auto_failback on 修复后自动转回功能开启
node node1.example.com 分别定义两个节点
node node2.example.com
ping 192.168.86.2 pingnode设备
crm on 开启heartbeat 2.x crm
将ha.cf复制到node2
scp /etc/ha.d/ha.cf node2:/etc/ha.d/ 修改hacluster密码
echo linuxha|passwd hacluster --stdin 七,配置集群资源
启动hb_gui添加一个组资源http://s3.运维网.com/wyfs02/M01/74/CF/wKiom1YprNjzsGmmAAIZBPeIDZc735.jpg
在组资源内添加vip,store,db,httpd资源
http://s3.运维网.com/wyfs02/M00/74/CF/wKiom1YprczS66uWAAB3095mfvk025.jpg
添加vip
http://s3.运维网.com/wyfs02/M00/74/CB/wKioL1YprgfSM96AAAK57eSt6KY711.jpg
添加store
http://s3.运维网.com/wyfs02/M01/74/CF/wKiom1Yprf3BoYmwAAKMOulW0cM176.jpg
http://s3.运维网.com/wyfs02/M01/74/CB/wKioL1YprligmVCAAALcQYsDFdk871.jpg
http://s3.运维网.com/wyfs02/M02/74/CF/wKiom1YpriuzYSA8AAKQ3aOY4C4674.jpg
http://s3.运维网.com/wyfs02/M02/74/CB/wKioL1YprljQZpYqAAK4vQsIUo4900.jpg
启动LAMP资源
http://s3.运维网.com/wyfs02/M00/74/CF/wKiom1YpriujXDLVAAKJpNCwcWs258.jpg
http://s3.运维网.com/wyfs02/M00/74/CB/wKioL1YprljRxgW1AAMQa55ki3w351.jpg
八,安装wordpress
解压wordpress到/mydata/webdoc下
# cp -r wordpress/* /mydata/webdoc
浏览器输入ha集群ip地址
http://s3.运维网.com/wyfs02/M00/74/CF/wKiom1Ypvn2z3ChpAAMpxrOBvXg817.jpg
http://s3.运维网.com/wyfs02/M01/74/CF/wKiom1Ypvn3wwvEdAAHHcpPUEd8876.jpg
http://s3.运维网.com/wyfs02/M00/74/CC/wKioL1YpvqrTv-MiAADCvgjdO8E654.jpg
测试资源迁移
在node2上停止heartbeat
service heartbeat stop
再次访问页面测试是否正常http://s3.运维网.com/wyfs02/M02/74/CF/wKiom1Ypv1Oio9cuAAKPDIyB0us233.jpg测试发现资源已经成功迁移到node1,页面也可以正常访问
页:
[1]