博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Nginx+keepalived高可用部署
阅读量:6564 次
发布时间:2019-06-24

本文共 2932 字,大约阅读时间需要 9 分钟。

hot3.png

环境:

主机:192.168.102.50

备机:192.168.102.101

vip:192.168.102.30

  • 安装keepalived
tar xzf keepalived-1.2.24.tar.gzcd keepalived-1.2.24./configure --prefix=/usr/local/keepalivedmake && make installmkdir /etc/keepalivedcp keepalived.conf /etc/keepalived/keepalived.confcp check_nginx.sh /etc/keepalived/check_nginx.shcp /usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/init.d/cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/cp /usr/local/keepalived/sbin/keepalived /usr/sbin/chkconfig --level 2345 keepalived on  #注册开机启动
  • keepalived.conf
! Configuration File for keepalivedglobal_defs {   notification_email {     ninglong@twsm.com.cn   }   notification_email_from ninglong@twsm.com.cn   smtp_server 127.0.0.1   smtp_connect_timeout 30   router_id LVS_DEVEL_jjrb_prtal   vrrp_skip_check_adv_addr   vrrp_strict   vrrp_garp_interval 0   vrrp_gna_interval 0}vrrp_script chk_nginx {    script "/etc/keepalived/check_nginx.sh"     interval 2     weight -5     fall 3      rise 2 }vrrp_instance VI_1 {    state BACKUP    interface eth0    virtual_router_id 61    priority 100    mcast_src_ip 172.10.101.12    advert_int 1    authentication {        auth_type PASS        auth_pass 1111    }    virtual_ipaddress {        172.10.101.21    }    track_script {       chk_nginx     }}
  • check_nginx.sh
#!/bin/bashcounter=$(ps -C nginx --no-heading|wc -l)if [ "${counter}" = "0" ]; then    /usr/local/bin/nginx    sleep 2    counter=$(ps -C nginx --no-heading|wc -l)    if [ "${counter}" = "0" ]; then        /etc/init.d/keepalived stop    fifi

然后在192.168.102.50上 

[root@jjrb ~]# ip a1: lo: 
mtu 16436 qdisc noqueue state UNKNOWN link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo inet6 ::1/128 scope host valid_lft forever preferred_lft forever2: eth0:
mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 8c:dc:d4:4e:73:58 brd ff:ff:ff:ff:ff:ff inet 192.168.102.50/24 brd 192.168.102.255 scope global eth0 inet 192.168.102.30/24 scope global secondary eth0 inet6 fe80::8edc:d4ff:fe4e:7358/64 scope link valid_lft forever preferred_lft forever[root@jjrb ~]#

在192.168.102.101上

[root@jjrb1 ~]# ip a1: lo: 
mtu 16436 qdisc noqueue state UNKNOWN link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo inet6 ::1/128 scope host valid_lft forever preferred_lft forever2: eth0:
mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 50:65:f3:32:4a:48 brd ff:ff:ff:ff:ff:ff inet 192.168.102.101/24 brd 192.168.102.255 scope global eth0 inet6 fe80::5265:f3ff:fe32:4a48/64 scope link valid_lft forever preferred_lft forever[root@jjrb1 ~]#

停掉50上的keepalived,再查看vip是否转移到101上来,如果转移成功,则配制成功了。另如果主备机上都出现了vip则考虑在防火墙里添加

-A INPUT -d 224.0.0.18/32 -i bond0 -j ACCEPT-A OUTPUT -d 224.0.0.18/32 -o bond0 -j ACCEPT

 

转载于:https://my.oschina.net/u/933928/blog/799994

你可能感兴趣的文章
登录时旋转等待效果
查看>>
CUDA中的归约
查看>>
如何遍历安装的SQL实例名称?
查看>>
spring配置 quartz-config.xml
查看>>
Form开发中组件控制的几个常用方法
查看>>
bzoj 3626 LCA
查看>>
团队博客:软件单元测试概述
查看>>
九、Python-面向对象程序设计
查看>>
ZOJ-1203 Swordfish---最小生成树
查看>>
php获取用户IPv4或IPv6地址的代码
查看>>
单元测试调试之传参篇
查看>>
Java多线程中断机制
查看>>
查看log_buffer
查看>>
map数据结构
查看>>
各种进制之间的转换
查看>>
[LeetCode] Spiral Matrix
查看>>
[LeetCode] Binary Tree Paths
查看>>
[LeetCode] Missing Number
查看>>
ubantu 黑屏
查看>>
C#中的扩展方法
查看>>