keepalived的初级使用

    1、双主模型的ipvs高可用

 

一、双主模型的ipvs高可用

    1)网络结构图

 

 

keepalived的初级使用

 

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

      RS1和RS2都是centos6.8

对RS1和RS2的配置:

(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)安装httpd的web服务

            #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)配置dir1和dir2主机

            安装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)后端的RS1和RS2都是httpd服务,去lo:0的别名设置

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

      3)在前端的dir1和dir2停止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)
luoxzluoxz
上一篇 2017-05-15 15:03
下一篇 2017-05-15 15:46

相关推荐

  • SElinux

    SElinux:Secure Enhanced Linux   SElinux工作与linux内核中他所实现的功能叫做强制访问控制机制。DAC:是linux的自主访问控制。MAC:是SElinux引入的访问法则,叫作强制访问控制。   SElinux有两种工作级别:     strick:严格级别,每个进程都收到SEl…

    Linux干货 2016-09-23
  • Linux网络属性管理

    Linux网络属性管理 linux的网络配置方法有多种,而且随发行版及版本而略微不同。我目前的测试环境为CentOS6和CentOS7。 常用的网络配置命令或方法有:ifconfig,route,netstat,ip,ss,nmcli,配置文件。 首先:命令方法介绍 一、命令简介 ifconfig:是个比较传统的命令,可以配置网络接口的启用及关闭,IP地址等…

    系统运维 2016-05-29
  • CentOS系统启动流程、selinux、Systemd剖析

    交互式登录配置文件读取顺序: /etc/profile –> /etc/profile.d/*.sh –> ~/.bash_profile –> ~/.bashrc –> /etc/bashrc 非交互式登录配置文件读取顺序: ~/.bashrc –> /etc/bas…

    Linux干货 2018-03-04
  • 防火墙原理以及iptables重要实践

    防火墙 主机间通信大致过程: 请求报文由客户端IP+PORT和服务器端IP+PORT构成。当客户端网络地址和服务端地址在同一网段时,不需要经由路由转发,可以直接到目标服务器,再经由服务器端口请求道所需资源; 当服务器端和客户端不在同一网段时。目标IP和源IP是不会改变的,会经由互联网中的路由器,按照其的路由表,指向该路由器的下一跳主机,知道找到服务器端所在网…

    2017-06-18
  • ip,ss,htop,vmstat,until,while,ping命令使用. N28

    第六周(2018-1.1 – 2018-1.7)

    2018-01-08
  • httpd服务归纳:网络服务基础篇

    一、网络传输基础     1. 套接字:两类          1) Unix Sock: 一种本地文件系统          2) Socket: IP port (I…

    Linux干货 2015-05-04