keepalived的初级使用

    1、双主模型的ipvs高可用

 

一、双主模型的ipvs高可用

    1)网络结构图

 

 

keepalived的初级使用

 

2)ipvs的类型是dr模型,调度算法是rr

      RS1RS2都是centos6.8

RS1RS2的配置:

1)实现对内核参数的更改

#echo 1 >
/proc/sys/net/ipv4/conf/all/arp_ignore

#echo 2 >
/proc/sys/net/ipv4/conf/all/arp_announce

#ifconfig lo:0
172.18.52.10/32 broadcast 172.18.52.10 up

#ifconfig lo:1
172.18.52.20/32 broadcast 172.18.52.20 up

      2)安装httpdweb服务

            #yum install httpd –y

           

RS1主机上

#echo “This test web1 server” >
/var/www/html/index.html

RS2主机上

#echo “This test web2 server” >
/var/www/html/index.html

      (3)启动httpd服务

            #service httpd start

     

      4)配置dir1dir2主机

            安装keepalived

            #yum install keepalived –y

            keepalived的配置文件修改

            #vim /etc/keepalived/keepalived.conf

——————–以下是配置文件的内容——————–

! Configuration File for keepalived

 

global_defs {

  
notification_email {  #
向谁发送通知

  root@localhost  

}

  
notification_email_from Alexandre.Cassen@firewall.loc

  
smtp_server 127.0.0.1

  
smtp_connect_timeout 30

  
router_id www.zorro.org  #
可以随意修改

  vrrp_mcast_group4
224.18.52.2 #
发送多播的地址,建议修改免得和别人冲突

}

 

#建立两个实例分别对应两个集群服务,但是都是指向后端的80web服务

vrrp_instance VI_1 {

   
state MASTER

   
interface eth0

   
virtual_router_id 199

   
priority 100

   
advert_int 1

   
authentication {

       
auth_type PASS

       
auth_pass 3344520

   
}

   
virtual_ipaddress {

        172.18.52.10
   

   
}

vrrp_instance VI_2 {

   
state BACKUP

   
interface eth0

   
virtual_router_id 200

   
priority 100

   
advert_int 1

   
authentication {

       
auth_type PASS

       
auth_pass 3344521

   
}

   
virtual_ipaddress {

        172.18.52.20
   

   
}

}

}

 

———-使用ipvs的相关配置—————————

———–VIP1的ipvs设置———————————-

virtual_server 172.18.52.10 80 {

   
delay_loop 6

    lb_algo
rr

   
lb_kind DR

   
nat_mask 255.255.255.255

   
persistence_timeout 0

   
protocol TCP

 

   
real_server 172.18.52.3 80 {

       
weight 1

       
HTTP_GET {

           
url {

              path /

      status_code 200

           
}

           
connect_timeout 3

           
nb_get_retry 3

           
delay_before_retry 3

       
}

   
}

  real_server
172.18.52.4 80 {

       
weight 1

       
HTTP_GET {

           
url {

              path /

       status_code 200

           
}

           
connect_timeout 3

           
nb_get_retry 3

           
delay_before_retry 3

       
}

   
}

}

—————–VIP2的ipvs设置————————————–

virtual_server 172.18.52.20 80 {

   
delay_loop 6

   
lb_algo rr

   
lb_kind DR

   
nat_mask 255.255.255.255

   
persistence_timeout 0

   
protocol TCP

 

   
real_server 172.18.52.3 80 {

       
weight 1

       
HTTP_GET {

           
url {

              path /

       status_code 200

           
}

           
connect_timeout 3

           
nb_get_retry 3

           
delay_before_retry 3

       
}

   
}

  real_server
172.18.52.4 80 {

       
weight 1

       
HTTP_GET {

           
url {

              path /

       status_code 200

           
}

           
connect_timeout 3

           
nb_get_retry 3

           
delay_before_retry 3

       
}

   
}

}

二、双主模型的nginx
proxy
高可用集群

      1网络拓扑

keepalived的初级使用

      2)后端的RS1RS2都是httpd服务,去lo0的别名设置

      取消内核参数的设置,都设置为0

      3)在前端的dir1dir2停止keeplaived服务

            #service stop keeplaived

      4)安装nginx

            #yum install nginx –y

      5)设置nginx的配置文件/etc/nginx/nginx.conf

            http字段中添加两个

                  Upstream webserver1 {

                       Server 172.18.52.3;

                       Server 172.18.52.4;

                  }

Upstream webserver2 {

                       Server 172.18.52.3;

                       Server 172.18.52.4;

                  }

 

server字段”location /”中添加

            Server {

                  Listen 80;

Location / {

Proxy_pass http://webserver1;

}

            }

            Server {

                  Listen 80;

Location / {

Proxy_pass http://webserver2;

}

            }

 


关于第二个部分对于nginx的双主模型的设计比较粗糙,如果有更好的方法,请不吝赐教。

原创文章,作者:luoxz,如若转载,请注明出处:http://www.178linux.com/75741

(0)
上一篇 2017-05-15 15:03
下一篇 2017-05-15 15:46

相关推荐

  • 第二周作业

    1、linux上的文件管理类命令都有哪些,其常用的使用方法及其相关示例演示。    linux上的文件管理类命令有:cat、tac、more、less、head、tail、cp、mv、rm、rmdir、mkdir等    cat:文件文本查看工具     cat [option]…

    Linux干货 2016-09-06
  • LVS产生背景、原理及LVS-DR应用实例(二)

    六、LVS-DR应用实例          (一)基本构建思路:           Director: 通过Director实现访问调度到RS1,RS2,实现负载均衡,RS3负责动态分离。…

    Linux干货 2016-10-29
  • 使用monit搭建一个监控系统

     上周用monit搭建或者说定制了一个监控系统,来监控服务器发生事情。当然了主要是监控异常,因为我们的产品属于服务器类型,很多进程都daemon,要不停的运行。我们搭建监控目的不过是出现问题能够及时的知道,平时可从web UI上看到整个系统的状况,同时它本身要轻量级,不要影响性能。当然了类似的产品很多了,比如Ganglia,我在老科长波哥曾经搭建过…

    Linux干货 2015-02-15
  • lamp简介

    lamp 构建一个有着动态服务器端技术的网站 LAMP基础 1)开源领域LAMP组成: L:Linux;A:apache (httpd);M:mysql, mariadb;P:php, perl, python httpd:接收用户的web请求;静态资源则直接响应;动态资源为php脚本交由php来运行; php:运行p…

    Linux干货 2016-11-07
  • python Django分页

    自定义html_helper.py  —>  Page_helper类 #coding:utf-8 from django.utils.safestring import mark_safe class Page_Helper(object):    …

    Linux干货 2016-08-22
  • linux网络属性命令操作介绍(第十一天)

            linux网络属性常用命令有ifconfig\route\ip命令,centos7 的还是nmcli\nmtui。     网络属性的三大文件:修改DNS的文件/etc/resolv.conf  、修改网卡IP地址/etc/sysconfig/…

    Linux干货 2016-06-01