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

[经验分享] HA-web-services实验

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2016-11-15 08:27:41 | 显示全部楼层 |阅读模式
、HA部署
本次实验的程序选型为heartbeat v2 + hearesources。资源有IP和httpd,filesystem不包含。
    配置HA集群的前提:

        (1)各节点资源一致,硬件或软件环境一致

        (2)各节点时间保持一致,便于心跳传递,使用ntp协议实现

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
29
30
31
32
33
34
35
36
37
#使用ntpdate命令同步时间,并建立周期性任务
#可使用任意节点服务器作为ntp时间服务器,如各节点可上公网,可直接指定公网ntp服务器

1、安装ntp
[iyunv@jymlinux ~]# yum install -y ntp
[iyunv@jymlinux ~]# vim /etc/ntp.conf           #修改配置文件允许本网段客户端获取地址
将下面的语句
restrict default kod nomodify notrap nopeer noquery
修改为
restrict default nomodify
restrict 192.168.0.0 mask 255.255.255.0 nomodify

[iyunv@jymlinux ~]# service ntpd start
Starting ntpd:                                             [  OK  ]

查看同步过程
[iyunv@jymlinux ~]# ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
*202.118.1.81    202.118.1.47     2 u   30   64    1   92.249    8.602   0.714
202.112.31.197  .INIT.          16 u    -   64    0    0.000    0.000   0.000

2、客户端创建周期任务,每3秒同步时间
[iyunv@centfils ~]# crontab -e
*/3 * * * * /usr/sbin/ntpdate 192.168.0.16 &> /dev/null
[iyunv@centfils ~]# service crond start


#手动同步成功,因ntp一般为自动,手动前kill掉所有ntp进程即可
[iyunv@centfils ~]# ntpdate 192.168.0.16
14 Nov 20:26:09 ntpdate[3786]: adjust time server 192.168.0.16 offset -0.004440 sec

3、时间同步
[iyunv@jymlinux ~]# date; ssh 192.168.0.15 'date'
Mon Nov 14 20:36:17 CST 2016
root@192.168.0.15's password:
Mon Nov 14 20:36:20 CST 2016



        (3)节点间需要通过主机名互相通信,必须解析主机至IP地址
            (a)建议名称解析功能使用hosts文件来实现
            (b)通信中使用的名字与节点名字必须保持一致 “uname -n” 或hostname展示出的名字保持一致
1
2
3
[iyunv@jymlinux ~]# vim /etc/hosts
192.168.0.15   centfils
192.168.0.16   jymlinux



        (4)关于仲裁设备(共享硬盘或网关),如有偶数个节点,比如2个,应启用仲裁设备,奇数无需启用,大偶数也可以无需仲裁设备

        (5)配置各节点之间的root用户能够给予密钥认证
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
29
30
31
32
33
34
35
36
37
38
39
40
1、生成密钥对
[iyunv@centfils ~]# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
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:
a8:ad:2c:23:83:60:ff:36:73:9d:09:24:37:ae:da:c9 root@centfils
The key's randomart image is:
+--[ RSA 2048]----+
|                 |
|                 |
|                 |
|     . =         |
|      * S        |
|..   o o         |
|+ . . o o o      |
|+ ooo*.. +       |
| o +*E+          |
+-----------------+

2、把公钥传输至远程服务器对应用户的家目录
[iyunv@centfils ~]# ssh-copy-id -i .ssh/id_rsa.pub root@192.168.0.16
The authenticity of host '192.168.0.16 (192.168.0.16)' can't be established.
RSA key fingerprint is e5:84:6c:f7:c0:60:3d:0b:39:b6:1e:12:0d:48:8b:07.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.0.16' (RSA) to the list of known hosts.
root@192.168.0.16's password:
Now try logging into the machine, with "ssh 'root@192.168.0.16'", and check in:

  .ssh/authorized_keys

to make sure we haven't added extra keys that you weren't expecting.

3、测试
[iyunv@jymlinux ~]# date; ssh root@192.168.0.15 'date'
Mon Nov 14 21:02:30 CST 2016
Mon Nov 14 21:02:30 CST 2016



        (6)定义为集群的资源不能开机自启,而是由crm管理

    配置列表:
        node1:192.168.0.15
        node2:192.168.0.16

        fip:192.168.0.17


二、安装heartbeat
  因为heartbeat,红帽和centos官方不提供rpm,因此先下载并安装epel包
1
2
3
4
5
6
[iyunv@centfils ~]# wget
[iyunv@centfils ~]# rpm -ivh epel-release-6-8.noarch.rpm
[iyunv@centfils ~]# yum install heartbeat*

#安装依赖包
[iyunv@jymlinux ~]# yum install libnet




   heartbeat的配置文件在/etc/ha.d目录下,其主要配置文件为ha.cf,定义各节点上的heartbeat HA集群的基本属性。authkeys配置文件,为集群内节点间彼此传递消息时使用的加密算法及密钥。
haresources,为heartbeat v1提供的资源管理器配置接口,v1版专用。

1
2
#将配置文件模板复制到/etc/ha.d目录下
[iyunv@centfils ha.d]# cp /usr/share/doc/heartbeat-3.0.4/{ha.cf,haresources,authkeys} /etc/ha.d/



1
2
#节点间认证配置文件权限必须为400
[iyunv@centfils ha.d]# chmod 600 authkeys




三、配置heartbeat
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
1、配置authkeys文件,指明启用何种算法,使用何种密钥
#auth 1
#1 crc
2 sha1 dPCDBSAie31fz6d5MhM0/A
#3 md5 Hello!

生成随机字符串作为密钥
[iyunv@centfils ha.d]# openssl rand -base64 16
dPCDBSAie31fz6d5MhM0/A==


2、配置ha.cf文件,定义高可用集群的基本工作方式

定义日志文件位置(二选一) logfacility为将日志交由syslog管理     
logfile        /var/log/ha-log
#logfacility     local0
多长时间发送一次心跳信息,默认为2秒
#keepalive 2
多长时间宣布某节点死亡,默认30秒
#deadtime 30
多长时间警告对方心跳信息延迟了,默认10秒
#warntime 10
第一次死去时间,避免因网络问题导致宣布死亡
#initdead 120
使用udp694端口传递心跳,并选择哪种方式传递心跳
#udpport        694
串行线缆传递心跳
#serial /dev/ttyS0      # Linux
#serial /dev/cuaa0      # FreeBSD
#serial /dev/cuad0      # FreeBSD 6.x
#serial /dev/cua/a      # Solaris
串行线缆的工作频率
#baud   19200
广播传递心跳
#bcast  eth0            # Linux
#bcast  eth1 eth2       # Linux
#bcast  le0             # Solaris
#bcast  le1 le2         # Solaris
多播传递心跳,网卡必须支持多播,ifconfig | grep MULTICAST
mcast eth0 225.0.0.1 694 1 0          #端口694,TTL为1,不允许回传为0
#启用网卡支持多播
[iyunv@jymlinux ~]# ip link set eth0 multicast on

单薄传递心跳
#ucast eth0 192.168.1.2
自动故障转回
auto_failback on
指明节点
#node   ken3
#node   kathy
node    centfils
node    jymlinux
指明网关为ping node设备(仲裁设备)
#ping 10.10.10.254
ping 192.168.0.1
指明一个组为ping node设备(仲裁设备)
#ping_group group1 10.10.10.254 10.10.10.253
指明节点间传送的压缩算法
compression     bz2
指明节点间传送数据压缩的最小数据为2KB
compression_threshold 2



1
2
3
3、配置haresources文件,定义集群资源
直接加入资源
centfils         192.168.0.17/24/eth0/192.168.0.255 httpd



1
2
4、将httpd设置为开机不启动
[iyunv@centfils ~]# chkconfig httpd off



1
2
5、启动服务
[iyunv@centfils ~]# service heartbeat start




四、测试

启动服务后,浏览器输入fip192.168.0.17访问,down掉192.168.0.15,后出现
wKiom1gp19-gRZZZAAAh4NCiUr0228.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-300466-1-1.html 上篇帖子: AIX系统逻辑卷管理 下篇帖子: 网络通信中的加密解密及openssl和创建私有CA详解
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

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

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

扫描微信二维码查看详情

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


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


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


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



合作伙伴: 青云cloud

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