saltstack 实现haproxy+keepalived
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的更多相关文章
- SaltStack生产案例-服务部署(redis,mysql,apache+php,haproxy+keepalived)
顺序代码资料链接 课上资料.zip 接上篇:SaltStack生产案例-系统初始化 1,redis 主从 2,mysql 主从 2.1 mysql-install.sls (安装 初始化) 2.2 ...
- 09 saltstack生产实例--Haproxy+keepalived
1.如何理解haproxy+keepalived https://www.cnblogs.com/zs-wei/p/9213961.html HaProxy可以通过监听一个统一的端口对外提供能力,然后 ...
- Haproxy+Keepalived负载均衡
Haproxy介绍 HAProxy是一个特别适用于高可用性环境的TCP/HTTP开源的反向代理和负载均衡软件.在7层负载均衡方面的功能很强大(支持cookie track, header rewrit ...
- HaProxy+Keepalived+Mycat高可用群集配置
概述 本章节主要介绍配置HaProxy+Keepalived高可用群集,Mycat的配置就不在这里做介绍,可以参考我前面写的几篇关于Mycat的文章. 部署图: 配置 HaProxy安装 181和1 ...
- haproxy +keepalived 原创
Haproxy+keepalived 原理: HAProxy介绍及其定位 HAProxy提供高可用性.负载均衡以及基于TCP和HTTP应用的代理,支持虚拟主机,它是免费.快速并且可靠的一种解决方案.根 ...
- haproxy+keepalived实现高可用负载均衡
软件负载均衡一般通过两种方式来实现:基于操作系统的软负载实现和基于第三方应用的软负载实现.LVS就是基于Linux操作系统实现的一种软负载,HAProxy就是开源的并且基于第三应用实现的软负载. HA ...
- HaProxy+keepalived实现负载均衡
HAProxy提供高可用性.负载均衡以及基于TCP和HTTP应用的代理,支持虚拟主机,它是免费.快速并且可靠的一种解决方案.HAProxy特别适用于那些负载特大的web站点,这些站点通常又需要会话保持 ...
- Haproxy+Keepalived搭建Weblogic高可用负载均衡集群
配置环境说明: KVM虚拟机配置 用途 数量 IP地址 机器名 虚拟IP地址 硬件 内存3G 系统盘20G cpu 4核 Haproxy keepalived 2台 192.168.1.10 192 ...
- 实现基于Haproxy+Keepalived负载均衡高可用架构
1.项目介绍: 上上期我们实现了keepalived主从高可用集群网站架构,随着公司业务的发展,公司负载均衡服务已经实现四层负载均衡,但业务的复杂程度提升,公司要求把mobile手机站点作为单独的服务 ...
随机推荐
- (转)零基础学习 Hadoop 该如何下手?
推荐一些Hadoop家族系列文章,主要介绍Hadoop家族产品,常用的项目包括Hadoop, Hive, Pig, HBase, Sqoop, Mahout, Zookeeper, Avro, Amb ...
- MongoDb第一天
安装之后进入cmd.进入到安装目录下的bin目录下. 任意选一个空目录,建立db,log的文件夹.之后终端命令行里面输入回车. D:\ProgramFiles\MongoDB\Server\3.6\b ...
- Spring使用mutipartFile上传文件报错【Failed to instantiate [org.springframework.web.multipart.MultipartFile]】
报错场景: 使用SSM框架实现文件上传时报“Failed to instantiate [org.springframework.web.multipart.MultipartFile]”错,控制器源 ...
- python-4函数式编程
1-高阶函数 变量可以指向函数. def add(x, y, f): 例如f参数为函数 编写高阶函数,就是让函数的参数能够接收别的函数. Python内建了map()和reduce()高阶函数. ...
- python基础之入门基础
编程语言分类 机器语言 使用二进制代码直接编程,直接与硬件交互,执行速度非常快,灵活,但是开发难度高,开发效率低下,缺乏移植性. 汇编语言 对机器语言指令进行了英文封装,较机器语言容易记忆,直接与硬件 ...
- idea push reject:push mater to origin/master was rejected by remote
用idea commit之后,执行push操作,总是提示push reject:push mater to origin/master was rejected by remote,如下图 上网说执行 ...
- PHP.31-TP框架商城应用实例-后台7-商品会员修改-页面优化,多表数据更新
商品表修改功能 1.页面优化,类似添加页面 <layout name="layout" /> <div class="tab-div"> ...
- 2,Python常用库之二:Pandas
Pandas是用于数据操纵和分析,建立在Numpy之上的.Pandas为Python带来了两种新的数据结构:Pandas Series和Pandas DataFrame,借助这两种数据结构,我们能够轻 ...
- java 1.7 新io 实践 NIO2
Files 类使用 package com.xinyu.test; import java.io.IOException; import java.nio.ByteBuffer; import jav ...
- springboot遇见问题总结
今天开始学习创建springboot项目 问题1: 产生异常: 创建项目目录: demo代码: 代码Controller import org.springframework.web.bind.ann ...