1、目录结构规划如下

mkdir -p /srv/salt/prod/haproxy

mkdir -p /srv/salt/prod/keepalived

mkdir -p /srv/salt/prod/pkg

mkdir -p /srv/salt/prod/cluster

mkdir -p /srv/salt/prod/haproxy/files/

mkdir -p /srv/salt/prod/cluster/files

2、依赖包安装

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

3、手动安装一遍,一遍获得需要的文件

cd /usr/local/src

tar xvf haproxy-1.6.3.tar.gz

cd haproxy-1.6.3/

make TARGET=linux31 PREFIX=/usr/local/haproxy-1.6.3

make install PREFIX=/usr/local/haproxy-1.6.3

ln -s /usr/local/haproxy-1.6.3 /usr/local/haproxy

修改启动脚本

vi /usr/local/src/haproxy-1.6.3/examples/haproxy.init

BIN=/usr/local/haproxy/sbin/$BASENAME

cp /usr/local/src/haproxy-1.6.3/examples/haproxy.init /srv/salt/prod/haproxy/files/

haproxy-1.6.3.tar.gz安装包放入/srv/salt/prod/modules/haproxy/files/目录下

4、编写haproxy状态 文件 安装haproxy

[root@zabbix files]# cat /srv/salt/prod/haproxy/install.sls
include:
- pkg.pkg-init haproxy-install:
file.managed:
- name: /usr/local/src/haproxy-1.6..tar.gz
- source: salt://haproxy/files/haproxy-1.6.3.tar.gz
- user: root
- group: root
- mode:
cmd.run:
- name: cd /usr/local/src/&&tar xf haproxy-1.6..tar.gz&&cd haproxy-1.6.&& make TARGET=linux31 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://haproxy/files/haproxy.init
- user: root
- group: root
- mode:
- require:
- cmd: haproxy-install haproxy-init:
cmd.run:
- name: /etc/init.d/haproxy
- unless: chkconfig --list|grep haproxy
- require:
- file: /etc/init.d/haproxy net.ipv4.ip_nonlocal_bind:
sysctl.present:
- value: haproxy-config-dir:
file.directory:
- name: /etc/haproxy
- user: root
- group: root
- mode:

5、编写haproxy配置文件

[root@zabbix files]# cat /srv/salt/prod/cluster/files/haproxy-outside.cfg
global
maxconn
chroot /usr/local/haproxy
uid
gid
daemon
nbproc
pidfile /usr/local/haproxy/logs/haproxy.pid
log 127.0.0.1 local3 info defaults
option http-keep-alive
maxconn
mode http
timeout connect 5000ms
timeout client 50000ms
timeout server 50000ms listen stats
mode http
bind 0.0.0.0:
stats enable
stats uri /haproxy-status
stats auth haproxy:saltstack frontend frontend_www_example_com
bind 172.16.80.199:
mode http
option httplog
log global
default_backend backend_www_example_com backend backend_www_example_com
option forwardfor header X-REAL-IP
option httpchk HEAD / HTTP/1.0
balance roundrobin
server web-node1 172.16.80.5: check inter rise fall
server web-node2 172.16.80.6: check inter rise fall

6、编写haproxy配置状态文件

[root@zabbix files]# cat /srv/salt/prod/cluster/haproxy-outside.sls
include:
- haproxy.install haproxy-service:
file.managed:
- name: /etc/haproxy/haproxy.cfg
- source: salt://cluster/files/haproxy-outside.cfg
- user: root
- group: root
- mode:
service.running:
- name: haproxy
- enable: True
- reload: True
- require:
- cmd: haproxy-init
- watch:
- file: haproxy-service

7、配置top 文件

[root@zabbix files]# cat /srv/salt/base/top.sls
base:
'*':
- init.env_init prod:
'*':
- cluster.haproxy-outside

8、执行

[root@zabbix files]#  salt "*" state.highstate test=True #先测试

[root@zabbix files]#  salt "*" state.highstate

9、验证

keepalived

Keepalived 自安装
[root@zabbix src]# tar xf keepalived-1.3..tar.gz
[root@zabbix src]# cd keepalived-1.3./
[root@zabbix keepalived-1.3.]# ./configure --prefix=/usr/local/keepalived
[root@zabbix keepalived-1.3.]#make && make install [root@zabbix ~]# mkdir /srv/salt/prod/keepalived
[root@zabbix ~]# mkdir /srv/salt/prod/keepalived/files [root@zabbix keepalived-1.3.]# cp /usr/local/src/keepalived-1.3./keepalived/etc/init.d/keepalived /srv/salt/prod/keepalived/files/
[root@zabbix keepalived-1.3.]# cp /usr/local/src/keepalived-1.3./keepalived/etc/keepalived/keepalived.conf /srv/salt/prod/keepalived/files/

[root@zabbix ~]# cp /usr/local/src/keepalived-1.3.7/keepalived/etc/sysconfig/keepalived /srv/salt/prod/keepalived/files/keepalived.sysconfig

[root@zabbix ~]# cp /usr/local/src/keepalived-1.3.7.tar.gz /srv/salt/prod/keepalived/files


改脚本
daemon keepalived ${KEEPALIVED_OPTIONS}
改为 daemon /usr/local/keepalived/sbin/keepalived ${KEEPALIVED_OPTIONS}

编写keepaliv[root@zabbix ~]# cat /srv/salt/prod/keepalived/install.sls        include:

- pkg.pkg-init

keepalived-install:
file.managed:
- name: /usr/local/src/keepalived-1.3..tar.gz
- source: salt://keepalived/files/keepalived-1.3.7.tar.gz
- user: root
- group: root
- mode:
cmd.run:
- name : cd /usr/local/src/&& tar xf keepalived-1.3..tar.gz&&cd keepalived-1.3.&&./configure --prefix=/usr/local/keepalived&&make&&make install
- unless: test -d /usr/local/keepalived
- require:
- file: keepalived-install /etc/sysconfig/keepalived:
file.managed:
- source: salt://keepalived/files/keepalived.sysconfig
- mode:
- user: root
- group: root /etc/init.d/keepalived:
file.managed:
- source: salt://keepalived/files/keepalived
- mode:
- 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

创建keepalived配置文件

[root@zabbix ~]# cat /srv/salt/prod/cluster/files/haproxy-outside-keepalived.conf
! Configuration File for keepalived
global_defs {
notification_email {
saltstack@example.com
}
notification_email_from keepalived@example.com
smtp_server 127.0.0.1
smtp_connect_timeout
router_id {{ ROUTEID }}
} vrrp_instance haproxy_ha {
state {{ STATEID }}
interface eth0
virtual_router_id
priority {{ PRIORITYID }}
advert_int
authentication {
auth_type PASS
auth_pass
}
virtual_ipaddress {
172.16.80.199
}
}

创建keepalived状态文件

[root@zabbix ~]# cat /srv/salt/prod/cluster/haproxy-outside-keepalived.sls
include:
- keepalived.install keepalived-server:
file.managed:
- name: /etc/keepalived/keepalived.conf
- source: salt://cluster/files/haproxy-outside-keepalived.conf
- mode:
- user: root
- group: root
- template: jinja
{% if grains['fqdn'] == 'zabbix' %}
- ROUTEID: haproxy_ha
- STATEID: MASTER
- PRIORITYID:
{% elif grains['fqdn'] == 'k8s-node1' %}
- ROUTEID: haproxy_ha
- STATEID: BACKUP
- PRIORITYID:
{% endif %}
service.running:
- name: keepalived
- enable: True
- watch:
- file: keepalived-server

[root@zabbix ~]# salt '*' state.sls cluster.haproxy-outside-keepalived saltenv=prod test=True

[root@zabbix ~]# cat /srv/salt/base/top.sls

[root@zabbix ~]# cat /srv/salt/base/top.sls
base:
'*':
- init.env_init prod:
'*':
- cluster.haproxy-outside
- cluster.haproxy-outside-keepalived

[root@zabbix ~]# salt '*' state.highstate

saltstack 实现haproxy+keepalived的更多相关文章

  1. SaltStack生产案例-服务部署(redis,mysql,apache+php,haproxy+keepalived)

    顺序代码资料链接 课上资料.zip 接上篇:SaltStack生产案例-系统初始化 1,redis 主从 2,mysql 主从 2.1 mysql-install.sls (安装 初始化) 2.2   ...

  2. 09 saltstack生产实例--Haproxy+keepalived

    1.如何理解haproxy+keepalived https://www.cnblogs.com/zs-wei/p/9213961.html HaProxy可以通过监听一个统一的端口对外提供能力,然后 ...

  3. Haproxy+Keepalived负载均衡

    Haproxy介绍 HAProxy是一个特别适用于高可用性环境的TCP/HTTP开源的反向代理和负载均衡软件.在7层负载均衡方面的功能很强大(支持cookie track, header rewrit ...

  4. HaProxy+Keepalived+Mycat高可用群集配置

    概述 本章节主要介绍配置HaProxy+Keepalived高可用群集,Mycat的配置就不在这里做介绍,可以参考我前面写的几篇关于Mycat的文章. 部署图: 配置  HaProxy安装 181和1 ...

  5. haproxy +keepalived 原创

    Haproxy+keepalived 原理: HAProxy介绍及其定位 HAProxy提供高可用性.负载均衡以及基于TCP和HTTP应用的代理,支持虚拟主机,它是免费.快速并且可靠的一种解决方案.根 ...

  6. haproxy+keepalived实现高可用负载均衡

    软件负载均衡一般通过两种方式来实现:基于操作系统的软负载实现和基于第三方应用的软负载实现.LVS就是基于Linux操作系统实现的一种软负载,HAProxy就是开源的并且基于第三应用实现的软负载. HA ...

  7. HaProxy+keepalived实现负载均衡

    HAProxy提供高可用性.负载均衡以及基于TCP和HTTP应用的代理,支持虚拟主机,它是免费.快速并且可靠的一种解决方案.HAProxy特别适用于那些负载特大的web站点,这些站点通常又需要会话保持 ...

  8. Haproxy+Keepalived搭建Weblogic高可用负载均衡集群

    配置环境说明: KVM虚拟机配置 用途 数量 IP地址 机器名 虚拟IP地址 硬件 内存3G  系统盘20G cpu 4核 Haproxy keepalived 2台 192.168.1.10 192 ...

  9. 实现基于Haproxy+Keepalived负载均衡高可用架构

    1.项目介绍: 上上期我们实现了keepalived主从高可用集群网站架构,随着公司业务的发展,公司负载均衡服务已经实现四层负载均衡,但业务的复杂程度提升,公司要求把mobile手机站点作为单独的服务 ...

随机推荐

  1. MySQL中使用group_concat()函数数据被截取(有默认长度限制),谨慎!

    最近在工作中遇到一个问题: 我们系统的一些逻辑处理是用存储过程实现的,但是有一天客服反馈说订单下单失败,查了下单牵扯到的产品基础资源,没有问题. 下单的存储过程中有这样两句代码: ; ; ; 执行存储 ...

  2. 还在使用pdf、word简历?简单五步实现github托管个人逼格简历

    写在前面: 什么是git.github? git 版本控制工具 github 通过git工具做的版本控制的项目托管平台 项目开发肯定不止一个程序猿,多个程序猿针对同一个文件进行代码读写操作时,是先保存 ...

  3. list推导式,dict推导式,set推导式

    生成一个1-14的列表 1.1 普通for循环 # lst = [] # for i in range(1,15): # lst.append(i) # print(lst) # # 结果: # [1 ...

  4. 一个简单的WPF MVVM实例【转载】

    引用地址:http://blog.csdn.net/yl2isoft/article/details/20838149 1 新建WPF 应用程序WPFMVVMExample 程序结构如下图所示. 2  ...

  5. php生成微信小程序二维码源码

    目前有3个接口可以生成小程序码,开发者可以根据自己的需要选择合适的接口.第一步:获取   access_token public function getWxAccessToken(){ $appid ...

  6. phpstorm 安装XeDbug

    第一步:根据phpinfo()下载相对应的Xdebug插件,Xdebug下载路径https://xdebug.org/download.php 第二步:将下载好的Xdebug放到 G:\Service ...

  7. B1081 检查密码 (15分)

    B1081 检查密码 (15分) 本题要求你帮助某网站的用户注册模块写一个密码合法性检查的小功能.该网站要求用户设置的密码必须由不少于6个字符组成,并且只能有英文字母.数字和小数点 .,还必须既有字母 ...

  8. 开放定址法——平方探测(Quadratic Probing)

    为了消除一次聚集,我们使用一种新的方法:平方探测法.顾名思义就是冲突函数F(i)是二次函数的探测方法.通常会选择f(i)=i2.和上次一样,把{89,18,49,58,69}插入到一个散列表中,这次用 ...

  9. Balance POJ - 1837

    Description Gigel has a strange "balance" and he wants to poise it. Actually, the device i ...

  10. ABAP CDS - SELECT, WHERE

    格式 ... WHERE cond_expr ... 结果 定义CDS视图结果集的Where条件.访问CDS视图时,结果集仅包含来自数据源数据源的数据,该数据源数据源满足在where之后指定的条件co ...