002.Heartbeat部署及httpd高可用
2019-01-15 02:37:07来源:博客园 阅读 ()
一 前期准备
1.1 依赖准备
1.2 环境准备
1 # hostnamectl set-hostname master1.yewu.com 2 # hostnamectl set-hostname master2.yewu.com #分别配置主机名 3 # /etc/hosts 4 127.0.0.1 localhost.localdomain localhost 5 #public ip #业务host解析 6 192.168.88.100 master1.yewu.com master1 7 192.168.88.101 master2.yewu.com master2 8 9 #private ip #Heartbeat心跳解析 10 192.168.77.100 master1-private.ha.com master1-private 11 192.168.77.101 master2-private.ha.com master2-private
1 [root@master1 ~]# ifconfig |grep eth[0-9] -A1 #确认相应IP地址
1 [root@master1 ~]# ssh-keygen -t rsa -f ~/.ssh/id_rsa -P '' 2 [root@master1 ~]# ssh-copy-id -i ./.ssh/id_rsa.pub root@192.168.88.101 3 [root@master2 ~]# ssh-keygen -t rsa -f ~/.ssh/id_rsa -P '' 4 [root@master2 ~]# ssh-copy-id -i ./.ssh/id_rsa.pub root@192.168.88.100
二 正式安装Heartbeat
2.1 下载相应包
1 [root@master1 ~]# wget http://hg.linux-ha.org/glue/archive/0a7add1d9996.tar.bz2 2 [root@master1 ~]# wget http://hg.linux-ha.org/heartbeat-STABLE_3_0/archive/958e11be8686.tar.bz2 3 [root@master1 ~]# wget https://github.com/ClusterLabs/resource-agents/archive/v3.9.6.tar.gz
2.2 安装cluster-glue
1 [root@master1 ~]# groupadd haclient 2 [root@master1 ~]# useradd -g haclient hacluster 3 [root@master1 ~]# tar xf 0a7add1d9996.tar.bz2 4 [root@master1 ~]# mv Reusable-Cluster-Components-glue--0a7add1d9996/ cluster_glue 5 [root@master1 ~]# cd cluster_glue/ 6 [root@master1 cluster_glue]# ./autogen.sh 7 [root@master1 cluster_glue]# ./configure --prefix=/usr/local/heartbeat --with-daemon-user=hacluster --with-daemon-group=haclient --enable-fatal-warnings=no LIBS='/lib64/libuuid.so.1'
1 [root@master1 cluster_glue]# make && make install
2.3 安装Resource Agents
1 [root@master1 ~]# tar xf v3.9.6.tar.gz 2 [root@master1 ~]# cd resource-agents-3.9.6/ 3 [root@master1 resource-agents-3.9.6]# ./autogen.sh 4 [root@master1 resource-agents-3.9.6]# ./configure --prefix=/usr/local/heartbeat --with-daemon-user=hacluster --with-daemon-group=haclient --enable-fatal-warnings=no LIBS='/lib64/libuuid.so.1'
1 [root@master1 resource-agents-3.9.6]# make && make install
1 ln -s /usr/local/heartbeat/lib/* /lib/ 2 ln -s /usr/local/heartbeat/lib/* /lib64/ #将生成的动态库,添加快捷方式到/lib下
2.4 安装Heartbeat
1 [root@master1 ~]# tar xf 958e11be8686.tar.bz2 2 [root@master1 ~]# export CFLAGS="$CFLAGS -I/usr/local/heartbeat/include -L/usr/local/heartbeat/lib" 3 [root@master1 ~]# cd Heartbeat-3-0-958e11be8686/ 4 [root@master1 Heartbeat-3-0-958e11be8686]# ./bootstrap 5 [root@master1 Heartbeat-3-0-958e11be8686]# ./configure --prefix=/usr/local/heartbeat --with-daemon-user=hacluster --with-daemon-group=haclient --enable-fatal-warnings=no LIBS='/lib64/libuuid.so.1'
1 [root@master1 Heartbeat-3-0-958e11be8686]# make && make install
2.5 Heartbeat优化
1 [root@master1 ~]# cp /root/Heartbeat-3-0-958e11be8686/doc/{ha.cf,haresources,authkeys} \ 2 /usr/local/heartbeat/etc/ha.d/ #复制相关配置文件 3 [root@master1 ~]# chmod 600 /usr/local/heartbeat/etc/ha.d/authkeys 4 [root@master1 ~]# mkdir -pv /usr/local/heartbeat/usr/lib/ocf/lib/heartbeat/ 5 [root@master1 ~]# cp /usr/lib/ocf/lib/heartbeat/ocf-* \ 6 /usr/local/heartbeat/usr/lib/ocf/lib/heartbeat/ 7 [root@master1 ~]# ln -svf /usr/local/heartbeat/lib64/heartbeat/plugins/RAExec/* \ 8 /usr/local/heartbeat/lib/heartbeat/plugins/RAExec/ 9 [root@master1 ~]# ln -svf /usr/local/heartbeat/lib64/heartbeat/plugins/* \ 10 /usr/local/heartbeat/lib/heartbeat/plugins/ 11 [root@master1 ~]# chkconfig --add heartbeat #CentOS7可省略 12 [root@master1 ~]# systemctl enable heartbeat.service 13 [root@master1 ~]# systemctl start heartbeat.service
三 配置Heartbeat
3.1 安装httpd服务
1 [root@master1 ~]# yum -y install httpd 2 [root@master1 ~]# systemctl stop httpd 3 [root@master1 ~]# systemctl disable httpd #master2也需要安装 4 [root@master1 ~]# echo "master1.yewu.com" >>/var/www/html/index.html 5 [root@master2 ~]# echo "master2.yewu.com" >>/var/www/html/index.html
3.2 配置authkeys
1 [root@master1 ~]# vi /usr/local/heartbeat/etc/ha.d/authkeys 2 auth 3 3 3 md5 Yes!
3.3 配置Heartbeat
1 [root@master1 ~]# vi /usr/local/heartbeat/etc/ha.d/ha.cf 2 logfile /var/log/ha-log #记录Heartbeat其他相关日志信息 3 logfacility local0 #设置heartbeat的日志,这里用的是系统日志 4 keepalive 2 #设定心跳(监测)时间间隔为2秒 5 deadtime 15 #宣告死亡时间 6 warntime 10 #心跳延时时间 7 initdead 60 #初始化时间 8 udpport 694 #用于通信的UDP端口 9 bcast eth1 #接受广播心跳的网卡接口 10 ucast eth1 192.168.77.101 #置对方机器心跳检测的IP 11 auto_failback off #关闭自动切回恢复正常的主节点 12 node master1.yewu.com #集群节点的名称,必须匹配uname -n的结果。 13 node master2.yewu.com 14 ping 192.168.88.1 15 respawn hacluster /usr/local/heartbeat/libexec/heartbeat/ipfail
3.4 配置haresources
1 [root@master1 ~]# ll /usr/local/heartbeat/etc/ha.d/resource.d/ #查看现有资源类型 2 [root@master1 ~]# vi /usr/local/heartbeat/etc/ha.d/haresources 3 master1.yewu.com IPaddr::192.168.88.88/24/eth0 apache 4 [root@master1 ~]# scp /usr/local/heartbeat/etc/ha.d/{ha.cf,haresources,authkeys} 192.168.88.101:/usr/local/heartbeat/etc/ha.d/ #将所有配置复制至master2节点 5 [root@master2 ~]# vi /usr/local/heartbeat/etc/ha.d/ha.cf 6 ucast eth1 192.168.77.100 #置对方机器心跳检测的IP
四 验证Heartbeat
4.1 master1单节点启动验证
1 [root@master1 ~]# systemctl start heartbeat.service 2 [root@master1 ~]# tail -f /var/log/ha-log #验证日志
4.2 master2启动并验证
1 [root@master2 ~]# systemctl start heartbeat.service 2 [root@master1 ~]# tail -f /var/log/ha-log #观察master2节点启动后的master1日志
1 [root@master1 ~]# shutdownr #模拟master1节点宕机 2 [root@master2 ~]# ifconfig #master2节点会自动接管vip
原文链接:https://www.cnblogs.com/itzgr/p/10160659.html
如有疑问请与原作者联系
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
上一篇:1.shell学习之常用语句
- 附020.Nginx-ingress部署及使用 2020-06-02
- corosync v1 + pacemaker高可用集群部署(二)资源配置(VIP+ 2020-05-28
- 在树莓派里搭建 Lighttpd 服务器 2020-05-27
- Nginx + Docker 多阶段构建的部署学习 2020-05-25
- 私有云技术 2020-05-23
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash