[bigdata-65] ubuntu 14.04服务器版 keepalived 双机热备ip漂移
发布时间:2020-12-14 03:13:16 所属栏目:大数据 来源:网络整理
导读:1. 两个节点 192.168.17.112 192.168.17.109 2. 安装配置keepalived 2.1 双机执行 apt-get install keepalived 2.2 在112上配置/etc/keepalived/keepalived.conf,内容如下 ------------------------------ global_defs { ? ? router_id NodeA ? } ? vrrp_in
1. 两个节点
192.168.17.112 192.168.17.109 2. 安装配置keepalived 2.1 双机执行 apt-get install keepalived ------------------------------ global_defs { ? ? router_id NodeA ? } ? vrrp_instance VI_1 { ? ? state BACKUP ? interface eth0 ? virtual_router_id 51 ? priority 150 ? advert_int 1 ? authentication { ? ??? auth_type PASS ??? auth_pass 1111 ? } ? ? virtual_ipaddress { ? ??? 192.168.17.113 ? } } ------------------------------ 2.3 在109上配置/etc/keepalived/keepalived.conf,内容如下 ------------------------------ global_defs { ? router_id NodeA } vrrp_instance VI_1 { ? state BACKUP ? interface eth0 ? virtual_router_id 51 ? priority 90 ? advert_int 1 ? authentication { ??? auth_type PASS ??? auth_pass 1111 ? } ? virtual_ipaddress { ??? 192.168.17.113 ? } } ------------------------------ 2.4 两个节点都配置为Backup,但priority不同,高priority的自动成为master。 2.5 在两个节点上都启动keepalived /etc/init.d/keepalived start 2.6 在两个节点上都执行ip a,那么,其中,112的优先级高,在112上能看到有两个ip地址 ??? inet 192.168.17.112/24 brd 192.168.17.255 scope global eth0 ?????? valid_lft forever preferred_lft forever ??? inet 192.168.17.113/32 scope global eth0 ?????? valid_lft forever preferred_lft forever ??? inet6 fe80::20c:29ff:fe0d:2112/64 scope link ?????? valid_lft forever preferred_lft forever 而在109上只有一个ip地址 link/ether 00:0c:29:8c:ef:e6 brd ff:ff:ff:ff:ff:ff ??? inet 192.168.17.109/24 brd 192.168.17.255 scope global eth0 ?????? valid_lft forever preferred_lft forever ??? inet6 fe80::20c:29ff:fe8c:efe6/64 scope link ?????? valid_lft forever preferred_lft forever 2.7 如果在112上执行/etc/init.d/keepalived stop,那么,此时ip a,能看到112上只有一个ip地址了,然后立刻在109上执行ip a,在109上就能看到两个ip地址,此时,ip就漂移到了109上。 2.8 在112上再次启动keepalived,/etc/init.d/keepalived start,此时能发现113这个ip又漂移到了112上。 3. 以web服务进行测试 3.1 双节点都安装 apt-get install python34 python3-pip pip install gevent flask 3.2 在112上部署如下web程序 -------------------------- #!/usr/bin/env python3 ? #! -*- coding:utf-8 -*- ? ? from flask import Flask,jsonify ? from gevent.wsgi import WSGIServer ? ? app = Flask(__name__) ? ? #这里的json使用中文key ? @app.route("/",methods=['GET','POST']) ? def index(): ? ??? return jsonify({'ret':'1'}) ? ? WSGIServer(('0.0.0.0',8888),app).serve_forever() -------------------------- 3.3 在109上部署如下web程序 -------------------------- #!/usr/bin/env python3 ? #! -*- coding:utf-8 -*- ? ? from flask import Flask,'POST']) ? def index(): ? ??? return jsonify({'ret':'2'}) ? ? WSGIServer(('0.0.0.0',app).serve_forever() -------------------------- 3.4 在两个节点上都启动keepalived 然后,在第三个节点的浏览器访问 http://192.168.17.113:8888 此时,能看到"1" 关闭112上的keepavlied,然后再次访问 http://192.168.17.113:8888 此时,能看到"2" 然后,打开112上的keepalived,然后再次访问 http://192.168.17.113:8888 此时,能看到"1" 这个过程就是,113这个ip先指向112,再漂移到109,然后再漂移回112的过程(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |