设为首页 收藏本站
查看: 1514|回复: 0

[经验分享] ansible+heartbeatV2构建高可用群集

[复制链接]
累计签到:2 天
连续签到:1 天
发表于 2014-11-19 11:21:04 | 显示全部楼层 |阅读模式
主机的ip地址分配


hostnameIP address role
master192.168.1.250/24ansible
node2.mictiger.com192.168.1.120/24heartbeat,httpd
node3.mictiger.com192.168.1.130/24heartbeat,httpd
1)修改hostname
在node2和node3的/etc/hosts加入如下信息
1
2
192.168.1.120   node2.mictiger.com  node2
192.168.1.130   node3.mictiger.com  node3



2)建立master到node2,node3的节点互信
生成密钥对
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
[iyunv@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 image is:
+--[ RSA 2048]----+
|                 |
|              +  |
|           ..* o |
|       . .++*.. .|
|        S o=.+o. |
|          . ..E. |
|         o . o  .|
|        . .   . .|
|               .+|
+-----------------+



将生成的公钥传到目标主机
1
2
3
[iyunv@master ~]# ssh-copy-id -i .ssh/id_rsa.pub root@192.168.1.120
[iyunv@master ~]# ssh-copy-id -i .ssh/id_rsa.pub root@192.168.1.130
[iyunv@master ~]# ssh-copy-id -i .ssh/id_rsa.pub root@192.168.1.150



在master上验证是否与node2,node3建立互信成功
1
2
3
4
[iyunv@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
1
2
3
4
5
6
7
8
9
10
11
[iyunv@master ~]# yum install ansible
[iyunv@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是否配置成功
1
2
3
4
5
6
7
8
9
[iyunv@master ~]# ansible all -a 'date'
192.168.1.120 | success | rc=0 >>
Tue Nov 18 13:40:21 CST 2014

192.168.1.150 | success | rc=0 >>
Tue Nov 18 13:40:21 CST 2014

192.168.1.130 | success | rc=0 >>
Tue Nov 18 13:40:21 CST 2014



4)利用ansible更新时间,高可用群集必须配置一样的时间
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
[iyunv@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 sec

192.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
[iyunv@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程序
1
2
3
4
5
6
7
8
9
10
11
12
13
14
[iyunv@master~]# ansible web -m yum -a 'name=httpd state=present'
[iyunv@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 ServerName

192.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
[iyunv@master ~]# touch index.html
[iyunv@master ~]# echo heartbeatV2 > index.html
[iyunv@master ~]# scp index.html root@192.168.1.130:/var/www/html/
index.html                                                                                                                   100%   16     0.0KB/s   00:00  
[iyunv@master ~]# scp index.html root@192.168.1.120:/var/www/html/
index.html                                                                                                                   100%   16     0.0KB/s   00:00



验证httpd是否安装成功
1
2
3
4
5
6
7
8
9
10
11
12
13
[iyunv@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 -->
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0    16    0    16    0     0   5072      0 --:--:-- --:--:-- --:--:--  8000

[2/2]: 192.168.1.130 -->
  0    16    0    16    0     0  10349      0 --:--:-- --:--:-- --:--:-- 10349



将httpd程序stop并不让它开机自动启动
1
2
3
4
5
6
7
8
9
10
11
12
[iyunv@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  ]

[iyunv@www ~]# ansible web -a 'chkconfig httpd off'
192.168.1.120 | success | rc=0 >>


192.168.1.130 | success | rc=0 >>



6)安装heatbeatV2需要处理依赖关系所以没有用ansible
1
2
3
4
5
6
[iyunv@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
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
[iyunv@node2 ~]# cp /usr/share/doc/heartbeat-2.1.4/{authkeys,ha.cf} /etc/ha.d/
配置authkeys
[iyunv@node2 ha.d]# openssl rand -hex 16    生成16的随机数作为heartbeat传递心跳信息的验证
701782e0e6872f444edd0bbb726871fb
auth 2
#1 crc
#2 sha1 HI!
#3 md5 Hello!
2 sha1 701782e0e6872f444edd0bbb726871f
[iyunv@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.com

ping 192.168.1.1                   网关地址
配置haresources添加如下信息
node2.mictiger.com       192.168.1.250/24/eth0 httpd    主节点和VIP绑定的网卡,管理的资源
复制node2 的配置信息到node3
[iyunv@localhost ~]# scp -r /etc/ha.d/* root@192.168.1.130:/etc/ha.d/



8)启动heartbeat
1
2
3
4
5
6
7
8
[iyunv@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 stopped

192.168.1.120 | success | rc=0 >>
Starting High-Availability services:
Done.2014/11/18_23:36:19 INFO:  Resource is stopped



查看heartbeat运行在哪个节点上
[iyunv@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
[iyunv@master ~]# curl 192.168.1.250
heartbeatV2
关闭node2验证是否能够访问验证高可用性
[iyunv@node2 ~]# service heartbeat stop
Stopping High-Availability services:
Done.
wKioL1Rraoaj1JfkAACCHVUiiyk015.jpg


运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-31492-1-1.html 上篇帖子: ansible批量搭建LAMP环境 下篇帖子: 通过运维工具ansible api来做平台接口
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表