文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档> keepalived + nginx 双机互备

keepalived + nginx 双机互备

时间:2010-05-23  来源:jack_sir


版权声明:原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。http://deidara.blog.51cto.com/400447/171078
        文章有更新:http://deidara.blog.51cto.com/400447/302402 更新日期2010-4.21 号多谢8楼兄弟的意见,我是没有考虑清楚。            由于keepalived 切换速度极其快,所以就把流量小的站换成了 双机互备份,也在昨天有人在群里问我是如何配置的,其实很简单,由于双机互备,也就不需要关什么arp 呵呵看我操作吧。  vip          192.168.6.7 nginx1     192.168.6.162 nginx2     192.168.6.118    1.安装NGINX我就不多说了,可以参照我写的另一篇文章 http://deidara.blog.51cto.com/400447/130427 2.安装 keepalived 因为我是 ubuntu 我就懒一点apt-get 安装 shell $> apt-get install keepalived 3.修改 两个机器的  hosts shell $> cat  /etc/hosts 192.168.6.162  nginx1 192.168.6.118  nginx2 4.配置 nginx1  为 MASTER 配置如下,因为apt-get 安装默认是没有配置的所以要新建一个配置。 shell $> vim  /etc/keepalived/keepalived.conf global_defs {
   notification_email {
     [email protected]
   }
   notification_email_from [email protected]
   smtp_server 127.0.0.1
   smtp_connect_timeout 30
   router_id LVS_DEVEL
}
vrrp_instance VI_1 {
    state MASTER        ############ 辅机为 BACKUP
    interface eth0
    virtual_router_id 51
    mcast_src_ip 192.168.6.162
    priority 102                  ########### 权值要比 bauck 高
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
       192.168.6.7
    }
}
5。配置 nginx2 为 BACKUP 配置如下 shell $> vim /etc/keepalived/keepalived.conf global_defs {
   notification_email {
     [email protected]
   }
   notification_email_from [email protected]
   smtp_server 127.0.0.1
   smtp_connect_timeout 30
   router_id LVS_DEVEL
}
vrrp_instance VI_1 {
    state BACKUP
    interface eth0
    virtual_router_id 51
    mcast_src_ip 192.168.6.118     priority 101              ##########权值 要比 master 低。。
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
       192.168.6.7
    }
}

6.重启服务两台机器服务
shell $> /etc/init.d/keepalived restart 7.测试,为了测试方便,我在 nginx1 建立一个 index.html shell $> echo "hello nginx1"  > /var/www/index.html 在nginx2 建立一个 index.html shell $> echo "hello nginx2" > /var/www/index.html   打开浏览器输入VIP 地址 http://192.168.6.7 , 显示如下 然后 停掉 nginx1 网络 shell $> /etc/init.d/networking stop ## 为了 显示 keepalived 切换速度,我在我测试机器上开了 CMD 窗口,一直在ping  192.168.6.7 -t 看 有几次 time out ,切换如下 相信大家的眼睛是 雪亮的。。。切换神速,要比  HA 快很多啊。 打开浏览器 输入 http://192.168.6.7  ,显示如下:     PS :注意的是,重启完 keepalived 服务后,ifconfig 是看不到 VIP 地址的 但是你别怀疑,VIP地址 确实起来了~~ 执行 ip a  可以看到

本文出自 “linuxer” 博客,请务必保留此出处http://deidara.blog.51cto.com/400447/171078

相关阅读 更多 +
排行榜 更多 +
坦克冒险大师安卓版

坦克冒险大师安卓版

策略塔防 下载
自动防御

自动防御

策略塔防 下载
枪战大乱斗2

枪战大乱斗2

飞行射击 下载