主机的ip地址分配

hostname IP address  role 
master 192.168.1.250/24 ansible
node2.mictiger.com 192.168.1.120/24 heartbeat,httpd 
node3.mictiger.com 192.168.1.130/24 heartbeat,httpd 

1)修改hostname

在node2和node3的/etc/hosts加入如下信息

192.168.1.120    node2.mictiger.com  node2
192.168.1.130   node3.mictiger.com  node3

2)建立master到node2,node3的节点互信

生成密钥对

[root@master ~]# ssh-keygen -t rsa -P ''    生成一对密钥
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
dc:a5:7d:fc:ff:42:8c:8a:55:38:73:87:35:9a:f5:6a root@CentOS
The key's randomart p_w_picpath is:
+--[ RSA 2048]----+
|                 |
|              +  |
|           ..* o |
|       . .++*.. .|
|        S o=.+o. |
|          . ..E. |
|         o . o  .|
|        . .   . .|
|               .+|
+-----------------+

将生成的公钥传到目标主机

[root@master ~]# ssh-copy-id -i .ssh/id_rsa.pub root@192.168.1.120
[root@master ~]# ssh-copy-id -i .ssh/id_rsa.pub root@192.168.1.130
[root@master ~]# ssh-copy-id -i .ssh/id_rsa.pub root@192.168.1.150

在master上验证是否与node2,node3建立互信成功

[root@master ~]# ssh 192.168.1.130 'date';ssh 192.168.1.120 'date';date
Tue Nov 18 22:39:55 CST 2014
Tue Nov 18 22:40:03 CST 2014
Tue Nov 18 22:40:04 CST 2014

3)安装配置ansible

[root@master ~]# yum install ansible
[root@master ~]# vim /etc/ansible/hosts   只需要配置这文件配置要管理的主机
[HA]
192.168.1.150
192.168.1.120
192.168.1.130
[web]
192.168.1.120
192.168.1.130
[master]
192.168.1.150

验证ansible是否配置成功

[root@master ~]# ansible all -a 'date'
192.168.1.120 | success | rc=0 >>
Tue Nov 18 13:40:21 CST 2014192.168.1.150 | success | rc=0 >>
Tue Nov 18 13:40:21 CST 2014192.168.1.130 | success | rc=0 >>
Tue Nov 18 13:40:21 CST 2014

4)利用ansible更新时间,高可用群集必须配置一样的时间

[root@master ~]# ansible web -a 'ntpdate  202.118.1.81'
192.168.1.130 | success | rc=0 >>
18 Nov 22:50:54 ntpdate[21487]: step time server 202.118.1.81 offset 1.531700 sec192.168.1.120 | success | rc=0 >>
18 Nov 22:50:54 ntpdate[13616]: adjust time server 202.118.1.81 offset 0.313219 sec
将时间更新写入cron
[root@master ~]# ansible all -m cron -a 'name="sync time" minute="*/5" job="/usr/sbin/ntpdate 202.118.1.81 &> /dev/null"'
192.168.1.130 | success >> {"changed": true, "jobs": ["sync time"]
}192.168.1.120 | success >> {"changed": true, "jobs": ["sync time"]
}192.168.1.150 | success >> {"changed": true, "jobs": ["sync time"]
}

5) 安装并配置httpd程序

[root@master~]# ansible web -m yum -a 'name=httpd state=present'[root@master ~]# ansible web -a 'service httpd start'
192.168.1.130 | success | rc=0 >>
Starting httpd: [  OK  ]httpd: apr_sockaddr_info_get() failed for CentOS
httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName192.168.1.120 | success | rc=0 >>
Starting httpd: [  OK  ]httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain for ServerName
[root@master ~]# touch index.html
[root@master ~]# echo heartbeatV2 > index.html
[root@master ~]# scp index.html root@192.168.1.130:/var/www/html/
index.html                                                                                                                   100%   16     0.0KB/s   00:00
[root@master ~]# scp index.html root@192.168.1.120:/var/www/html/
index.html                                                                                                                   100%   16     0.0KB/s   00:00

验证httpd是否安装成功

[root@master ~]# ansible master -a 'curl  192.168.1.{120,130}'
192.168.1.150 | success | rc=0 >>
--_curl_--192.168.1.120
heartbeatV2
--_curl_--192.168.1.130
heartbeatV2
[1/2]: 192.168.1.120 --> <stdout>% Total    % Received % Xferd  Average Speed   Time    Time     Time  CurrentDload  Upload   Total   Spent    Left  Speed0    16    0    16    0     0   5072      0 --:--:-- --:--:-- --:--:--  8000[2/2]: 192.168.1.130 --> <stdout>0    16    0    16    0     0  10349      0 --:--:-- --:--:-- --:--:-- 10349

将httpd程序stop并不让它开机自动启动

[root@www ~]# ansible web -a 'service httpd stop'
192.168.1.120 | success | rc=0 >>
Stopping httpd: [  OK  ]192.168.1.130 | success | rc=0 >>
Stopping httpd: [  OK  ][root@www ~]# ansible web -a 'chkconfig httpd off'
192.168.1.120 | success | rc=0 >>192.168.1.130 | success | rc=0 >>

6)安装heatbeatV2需要处理依赖关系所以没有用ansible

[root@node2 ~]#  rpm -ivh heartbeat-2.1.4-12.el6.x86_64.rpm heartbeat-gui-2.1.4-12.el6.x86_64.rpm heartbeat-stonith-2.1.4-12.el6.x86_64.rpm heartbeat-pils-2.1.4-12.el6.x86_64.rpm
Preparing...                ########################################### [100%]1:heartbeat-pils         ########################################### [ 25%]2:heartbeat-stonith      ########################################### [ 50%]3:heartbeat              ########################################### [ 75%]4:heartbeat-gui          ########################################### [100%]

7)配置heartbeat

[root@node2 ~]# cp /usr/share/doc/heartbeat-2.1.4/{authkeys,ha.cf} /etc/ha.d/
配置authkeys
[root@node2 ha.d]# openssl rand -hex 16    生成16的随机数作为heartbeat传递心跳信息的验证
701782e0e6872f444edd0bbb726871fb
auth 2
#1 crc
#2 sha1 HI!
#3 md5 Hello!
2 sha1 701782e0e6872f444edd0bbb726871f
[root@CentOS ha.d]# chmod 600 authkeys    修改authkeys的权限不让其他人访问
配置heartbeat的主配置文件ha.cf大概配置如下信息(根据个人需求而定)
logfile /var/log/ha-log            日志文件位置
mcast eth0 225.10.10.10 694 1 0    使用组播地址通告和端口
auto_failback on                   自动添加down了又重新上线的节点到群集
node    node2.mictiger.com         配置节点信息
node    node3.mictiger.comping 192.168.1.1                   网关地址
配置haresources添加如下信息
node2.mictiger.com       192.168.1.250/24/eth0 httpd    主节点和VIP绑定的网卡,管理的资源
复制node2 的配置信息到node3
[root@localhost ~]# scp -r /etc/ha.d/* root@192.168.1.130:/etc/ha.d/

8)启动heartbeat

[root@master ~]# ansible web -a 'service heartbeat start'
192.168.1.130 | success | rc=0 >>
Starting High-Availability services:
Done.2014/11/18_23:36:19 INFO:  Resource is stopped192.168.1.120 | success | rc=0 >>
Starting High-Availability services:
Done.2014/11/18_23:36:19 INFO:  Resource is stopped

查看heartbeat运行在哪个节点上

[root@master ~]# ansible web -a 'ifconfig eth0:0'

192.168.1.130 | success | rc=0 >>

eth0:0    Link encap:Ethernet  HWaddr 00:0C:29:8F:A0:EF

UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

192.168.1.120 | success | rc=0 >>

eth0:0    Link encap:Ethernet  HWaddr 00:0C:29:57:5C:BB

inet addr:192.168.1.250  Bcast:192.168.1.255  Mask:255.255.255.0

UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

[root@master ~]# curl 192.168.1.250

heartbeatV2

关闭node2验证是否能够访问验证高可用性

[root@node2 ~]# service heartbeat stop

Stopping High-Availability services:

Done.

转载于:https://blog.51cto.com/mictiger/1579341

ansible+heartbeatV2构建高可用群集相关推荐

  1. heartbeat+drbd+mysql构建mysql高可用群集

    heartbeat+drbd+mysql构建mysql高可用群集 1. 试验环境: 操作系统:Red Hat Enterprise Linux 5.4 所需的软件包: mysql-5.5.22.tar ...

  2. linux7自带haprox版本,CentOS7.4—构建最新版haproxy高可用群集

    CentOS7.4-构建haproxy高可用群集 目录 第一部分 实验环境 第二部分 搭建配置web服务器 第三部分 安装配置haproxy服务器 第四部分 测试验证 第五部分 haproxy配置相关 ...

  3. LVS + Keepalived 高可用群集

             Keepalived的设计目标识构建高可用的LVS负载均衡群集,可以调用ipvsadm工具来创建虚拟服务器.管理服务器池,而不仅仅用作双击热备.使用Keeepalived 构建LVS ...

  4. LVS+Keepalived实现高可用群集

    一.keepalived概述 keepalived是专门针对LVS设计的一款强大的辅助工具,主要用来提供故障切换和健康检查功能--判断LVS负载调度器,节点服务器的可用性,及时隔离并替换为新的服务器, ...

  5. 高性能Linux服务器 第11章 构建高可用的LVS负载均衡集群

    高性能Linux服务器 第11章 构建高可用的LVS负载均衡集群 libnet软件包<-依赖-heartbeat(包含ldirectord插件(需要perl-MailTools的rpm包)) l ...

  6. LVS+Keepalived高可用群集

    目录 一:Keepalived 二:keepalived实现原理剖析 三:vrrp虚拟路由冗余协议 四:Keepalived体系主要模块及其作用 4.1core模块 4.2vrrp模块 4.3chec ...

  7. 《构建高可用Linux服务器 第3版》—— 1.4 Linux服务器的日志管理

    本节书摘来自华章出版社<构建高可用Linux服务器 第3版>一 书中的第1章,第1.4节,作者:余洪春 ,更多章节内容可以访问云栖社区"华章计算机"公众号查看. 1.4 ...

  8. 《构建高可用Linux服务器》第一版勘误表(附脚本下载)

    <构建高可用Linux服务器>因为印刷或自己检查不仔细的原因还是有许多错误的,这个在第二次印刷时会统一改正(脚本下载地址为 http://www.hzbook.com/Books/6021 ...

  9. 恭贺《构建高可用Linux服务器》荣获几项殊荣

    恭贺<构建高可用Linux服务器>荣获<程序员>杂志评选的2011十大畅销书,51cto社区2011年最受读者喜欢的原创IT技术图书奖,CSDN社区2011年十大最具技术影响力 ...

最新文章

  1. python降温了吗_为“Python将纳入高考”降温
  2. python 读文件写数据库_python读文件写数据库
  3. word+增加水印+java_为Word2019文档添加水印的两种方法
  4. Python简洁的出入库系统(模块化)
  5. 开幕倒计时3天 | 2019中国大数据技术大会(BDTC)邀您一同共赴大数据+AI盛宴!...
  6. oracle進程時高時低,oracle低權限下獲取shell
  7. Eventbus收录
  8. mysql for centos下载_CentOS下载mysql哪个版本
  9. 移动 app 测试工具 bugtags
  10. hdu_5145_NPY and girls(莫队算法+组合)
  11. java设计模式之解释器模式
  12. python图形包是什么_介绍Python 图形计算工具包
  13. 国赛高教杯使用python/matlab必会基础数学建模-数据处理模块(课程4)
  14. API,SDK和API之间的关系和区别
  15. 怎样修复计算机系统声音,电脑没声音了如何恢复?电脑突然没声音修复方法汇总...
  16. Altium Designer出现“灾难性故障”,如何正确应对
  17. 带三方登录(qq,微信,微博)
  18. 怎么提醒通知自己每个月26日报送月度工作总结和计划
  19. Jetson AGX Xavier部署深度学习环境
  20. MATLAB Robotics Toolbox(Release 10)模块库--总结(一)

热门文章

  1. mysql8.0.15远程登陆权限,MySQL8.0给root用户赋予远程连接权限
  2. android应用案例开发大全_vue.js入门及经典应用案例总结(前端开发必看)
  3. 怎么复制远程服务器上的文件夹,Linux系统复制文件/文件夹到远程服务器
  4. linux centos 6.5压缩文件,CentOS 6.10 解压 rar压缩包
  5. 树莓派i2c python_树莓派2 python i2cPython中chr、unichr、ord字符函数之间的对比
  6. callablestatement.setstring会不会将字符串trim_Java String:重要到别人只能当老二的字符串类
  7. mysql 排除另一表_MYSQL 两表 排除 重复记录
  8. android 权限自动授权,Android判断是否某个权限是否授权
  9. django媒体文件上传设置
  10. Spring Cloud Alibaba 简介