码迷,mamicode.com
首页 > 其他好文 > 详细

09 Haproxy+keepalived

时间:2019-11-04 17:09:07      阅读:82      评论:0      收藏:0      [点我收藏+]

标签:sysconf   openssl   info   unless   配置   prefix   rod   auto   lin   

1、如何理解haproxy+keepalived

https://www.cnblogs.com/zs-wei/p/9213961.html

HaProxy可以通过监听一个统一的端口对外提供能力,然后内部进行分发,相当于nginx

何保证前端程序使用单个ip又能保证后端的实际处理机器为多台,这就是KeepAlived的作用。

技术图片   技术图片

 

 技术图片

 2、负载均衡

视频配套的资源:https://github.com/unixhot/saltbook-code

技术图片

1、pkg

init.sls依赖包安装

[root@linux-node1 /srv/salt/prod/modules]# cat pkg/init.sls 
pkg-init:
  pkg.installed:
    - names:
      - gcc
      - gcc-c++
      - glibc
      - make
      - autoconf
      - openssl
      - openssl-devel

 2、haproxy

技术图片

安装文件 init.sls

[root@linux-node1 /srv/salt/prod/modules]# cat haproxy/init.sls 
include:
  - modules.pkg.init

haproxy-install:
  file.managed:
    - name: /usr/local/src/haproxy-1.5.3.tar.gz
    - source: salt://modules/haproxy/files/haproxy-1.5.3.tar.gz
    - mode: 755
    - user: root
    - group: root

  cmd.run:
    - name: cd /usr/local/src && tar zxf haproxy-1.5.3.tar.gz && cd haproxy-1.5.3 && make TARGET=linux26 PREFIX=/usr/local/haproxy && make install PREFIX=/usr/local/haproxy
    - unless: test -d /usr/local/haproxy
    - require:
      - pkg: pkg-init
      - file: haproxy-install

/etc/init.d/haproxy:
  file.managed:
    - source: salt://modules/haproxy/files/haproxy.init
    - mode: 755
    - user: root
    - group: root
    - require:
      - cmd: haproxy-install

net.ipv4.ip_nonlocal_bind:
  sysctl.present:
    - value: 1

haproxy-config-dir:
  file.directory:
    - name: /etc/haproxy
    - mode: 755
    - user: root
    - group: root

haproxy-init:
  cmd.run:
    - name: chkconfig --add haproxy
    - unless: chkconfig --list | grep haproxy
    - require:
      - file: /etc/init.d/haproxy

 

 

内核参数

默认不能监听不在本地的ipv4

技术图片

 

file配置

技术图片

3、keepalived

技术图片

 

 

 配置文件 init.sls

[root@linux-node1 /srv/salt/prod/modules]# cat keepalived/init.sls 
include:
  - modules.pkg.init

keepalived-install:
  file.managed:
    - name: /usr/local/src/keepalived-1.2.17.tar.gz
    - source: salt://modules/keepalived/files/keepalived-1.2.17.tar.gz
    - mode: 755
    - user: root
    - group: root
  cmd.run:
    - name: cd /usr/local/src && tar zxf keepalived-1.2.17.tar.gz && cd keepalived-1.2.17 && ./configure --prefix=/usr/local/keepalived --disable-fwmark && make && make install
    - unless: test -d /usr/local/keepalived
    - require:
      - file: keepalived-install

/etc/sysconfig/keepalived:
  file.managed:
    - source: salt://modules/keepalived/files/keepalived.sysconfig
    - mode: 644
    - user: root
    - group: root

/etc/init.d/keepalived:
  file.managed:
    - source: salt://modules/keepalived/files/keepalived.init
    - mode: 755
    - user: root
    - group: root

keepalived-init:
  cmd.run:
    - name: chkconfig --add keepalived
    - unless: chkconfig --list | grep keepalived
    - require:
      - file: /etc/init.d/keepalived

/etc/keepalived:
  file.directory:
    - user: root
    - group: root

 

 

 

 

 配置文件

技术图片

4、test

[root@linux-node1 ~]# salt \* state.sls modules.haproxy.init saltenv=prod

技术图片

 

 

 

[root@linux-node1 /srv/salt/prod/modules]# salt \* state.sls modules.keepalived.init saltenv=prod

技术图片

3、如何使用负载均衡

每个业务一个负载均衡

每个主机的负载均衡

负载均衡对内 对外

技术图片

作业

  1. 管理   Haproy+Keepalive 配置文件
  2. 必须使用jianja模板,配置不一样

 

09 Haproxy+keepalived

标签:sysconf   openssl   info   unless   配置   prefix   rod   auto   lin   

原文地址:https://www.cnblogs.com/venicid/p/11792804.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!