keepalived配置安装

什么是vrrp,阿里云不支持组播,所以阿里云上不能配置keepalived,但是它有自己的slb。
运维的大忌,在命令行复制粘贴,一般是先复制到文本中查看确认以后
salt编写配置管理keepalived之前,首先自己安装一遍

一、下载以及编译安装

wget http://www.keepalived.org/software/keepalived-1.2.19.tar.gz
tar zxf keepalived-1.2.19.tar.gz
cd keepalived-1.2.19
./configure --prefix=/usr/local/keepalived --disable-fwmark
make && make install

二、编写功能模块配置
1、创建keepalived配置管理相关目录

mkdir /srv/salt/prod/keepalived
mkdir /srv/salt/prod/leepalived/files cd /usr/local/src/keepalived-1.2.19/keepalived/etc
cp init.d/keepalived.init /srv/salt/prod/keepalived/files
cp keeplived/keepalived.conf /srv/salt/prod/leepalived/files keepalived文件位于编译安装后的目录下,该文件是keepalived后台运行配置文件
cp /usr/local/keepalived/etc/sysconfig/keepalived /srv/salt/prod/leepalived/files/keepalived.sysconfig
或在解压目目录下也存在该文件
cp keepalived/etc/init.d/keepalived.sysconfig /srv/salt/prod/keepalived/files/
cp /usr/local/src/keepalived-1.2.19.tar.gz /srv/salt/prod/leepalived/files/

2、修改启动脚本

cd /srv/salt/prod/keepalived/files
vim keeplived.init

daemon keeplived ${KEEPALIVED_OPTIONS}修改为
daemon /usr/local/keepalived/sbin/keepalived ${KEEPALIVED_OPTIONS}

3、keepalived安装配置install.sls
cd /srv/salt/prod/keepalived
vim install.sls

include:
- pkg.pkg-init
keepalived-install:
file.managed:
- name: /usr/local/src/keepalived-1.2.19.tar.gz
- source: salt://keepalived/files/keepalived-1.2.19.tar.gz
- user: root
- group: root
- mode: 755
cmd.run:
- name: cd /usr/local/src && tar zxf keepalived-1.2.19.tar.gz && cd keepalived-1.2.19 && ./configure --prefix=/usr/local/keepalived --disable-fwmark && make && make install
- unless: test -d /usr/local/keepalived
- require:
- pkg: pkg-init
- file: keepalived-install
keepalived-init:
file.managed:
- name: /etc/init.d/keepalived
- source: salt://keepalived/files/keepalived.init
- user: root
- group: root
- mode: 755
cmd.run:
- name: chkconfig --add keepalived
- unless: chkconfig --list | grep keepalived
- require:
- file: keepalived-init
/etc/sysconfig/keepalived:
file.managed:
- source: salt://keepalived/files/keepalived.sysconfig
- user: root
- group: root
- mode: 644
/etc/keepalived:
file.directory:
- user: root
- group: root
- mode: 755

4、测试

salt '*' state.sls keepalived.install env=prod test=True 

三、编写业务模块配置
1、编写keepalived的配置haproxy-outside-keepalived.conf
cd /srv/salt/prod/cluster/files
vim 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 30
# jinja模板变量
router_id {{ROUTEID}}
}
vrrp_instance haproxy_ha {
# jinja模板变量
state {{STATEID}}
interface eth0
virtual_router_id 36
# jinja模板变量
priority {{PRIORITYID}}
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
#虚ip
192.168.217.155
}
}

2、编写管理keepalived配置文件的sls
cd /srv/salt/prod/cluster/
vim haproxy-outside-keepalived.sls

include:
- keepalived.install
keepalived-service:
file.managed:
- name: /etc/keepalived/keepalived.conf
- source: salt://cluster/files/haproxy-outside-keepalived.conf
- user: root
- group: root
- mode: 644
- template: jinja
{% if grains['fqdn'] == 'node1' %}
- ROUTEID: haproxy_ha
- STATEID: MASTER
- PRIORITYID: 150
{% elif grains['fqdn'] == 'node2' %}
- ROUTEID: haproxy_ha
- STATEID: BACKUP
- PRIORITYID: 100
{% endif %}
service.running:
- name: keepalived
- enable: True
- watch:
- file: keepalived-service

3、配置完后的文件配置管理目录结构
│ ── base
│   ├── init
│   │   ├── audit.sls
│   │   ├── dns.sls
│   │   ├── env_init.sls
│   │   ├── files
│   │   │   └── resolv.conf
│   │   ├── history.sls
│   │   └── sysctl.sls
│   └── top.sls
├── prod
   ├── cluster
   │   ├── files
   │   │   ├── haproxy-outside.cfg
   │   │   └── haproxy-outside-keepalived.conf
   │   ├── haproxy-outside-keepalived.sls
   │   └── haproxy-outside.sls
   ├── haproxy
   │   ├── files
   │   │   ├── haproxy-1.6.2.tar.gz
   │   │   └── haproxy.init
   │   └── install.sls
   ├── keepalived
   │   ├── files
   │   │   ├── keepalived-1.2.19.tar.gz
   │   │   ├── keepalived.conf
   │   │   ├── keepalived.init
   │   │   └── keepalived.sysconfig
   │   └── install.sls
   └── pkg
   └── pkg-init.sls

4、测试
salt '*' state.sls cluster.haproxy-outside-keepalived env=prod test=True

5、在top.sls中加入keepalived

vim /srv/salt/base/top.sls

base:
'*':
- init.env_init
prod:
"node1":
- cluster.haproxy-outside
- cluster.haproxy-outside-keepalived
"node2":
- cluster.haproxy-outside
- cluster.haproxy-outside-keepalived

四、执行安装和配置keepalived以及vrrp测试查看
1、执行配置管理

salt '*' state.highstate

2、虚ip查看如下截图

web访问结果

SaltStack自动化安装配置haproxy的Keepalived的更多相关文章

  1. saltstack自动化运维系列⑥SaltStack实践安装配置HAproxy的Keepalived

    saltstack自动化运维系列⑥SaltStack实践安装配置HAproxy的Keepalived 安装配置Keepalived 1.编写功能模块 #创建keepalived目录# mkdir -p ...

  2. SaltStack自动化安装配置haproxy

    准备环境node1:192.168.217.149 (saltstack master)node2:192.168.217.150(saltstack minion)下载haproxy1.6.2.ta ...

  3. saltstack自动化运维系列⑥SaltStack实践安装配置HAproxy

    saltstack自动化运维系列⑥SaltStack实践安装配置HAproxy 下载haproxy1.6.2.tar.gz下载地址:http://www.haproxy.org/download/1. ...

  4. Centos7.4安装配置haproxy和Keepalived

    系统版本是centos7.4的 [root@data-1-1 ~]# cat /etc/redhat-release CentOS Linux release 7.4.1708 (Core) [roo ...

  5. Centos7.4安装配置haproxy和Keepalived补充内容

    补充比较杂 1.当master服务恢复正常之后,backup机器收到消息,然后让出vip 下面是master机器服务恢复正常后,backup机器的Keepalived日志 收到master的消息通知, ...

  6. RabbitMQ集群安装配置+HAproxy+Keepalived高可用

    RabbitMQ集群安装配置+HAproxy+Keepalived高可用 转自:https://www.linuxidc.com/Linux/2016-10/136492.htm rabbitmq 集 ...

  7. SaltStack自动化安装zabbix-server

    使用SaltStack自动化安装zabbix-server 1,设置ntp时间同步 2,安装zabbix-agent 3,安装zabbix-server 4,安装及配置mariadb(mariadb与 ...

  8. NTP时间同步 服务端 客户端 自动化安装配置

    NTP时间同步 服务端 客户端 自动化安装配置 原创内容 http://www.cnblogs.com/elvi/p/7657994.html #!/bin/sh #运行环境 centos6.cent ...

  9. Linux系统实现ansible自动化安装配置httpd

    1.使用ansible的playbook实现自动化安装httpd 1)首先配置好ansible的hosts文件,让其对应主机能够受ansible控制 提示:我们在主机清单上配置了所管控的主机地址,但是 ...

随机推荐

  1. linux 在后台运行数据库导入导出命令

    nohup imp dbusername/password@orcl file=/home/20170928.dmp ignore=y log=/home/oracle/20170928.log fu ...

  2. 如何在virtualenv环境中安装指定的python版本

    指定python版本:virtualenv   -p python执行文件路径     自定义虚拟环境名称.如果文件路径有空格,用引号. 如果不指定python版本,则默认使用环境变量中的python ...

  3. Linux mount指令

    -o,是指option,可以指定username,password:当时我们就碰到一个坎,如何来避免输入用户名密码,其实本质并不是避免输入用户名米吗,而是某种可知的方式来进行权限控制:解决的方式就是采 ...

  4. Azure自动化部署服务 (2)

    上一篇文章介绍了如何通过添加用户名和密码的方式实现自动化部署服务中与Azure Subscription的连接. 本文将介绍如何使用证书的方式实现Azure Automation与Azure的Subs ...

  5. RPM包及其管理 rpm命令

    一.什么是RPMRPM:RedHat Package Manager     //红帽包管理如果Linux发行版本是redhat .redflag .centos .fedora .suse等或者衍生 ...

  6. netty中的Channel、ChannelPipeline

    一.Channel与ChannelPipeline关系 每一个新创建的 Channel 都将会被分配一个新的 ChannelPipeline.这项关联是永久性 的:Channel 既不能附加另外一个 ...

  7. oracle--视图(2)---

    Oracle---视图 视图是基于一个表或多个表或视图的逻辑表,本身不包含数据,通过它可以对表里面的数据进行查询和修改.视图基于的表称为基表,Oracle的数据库对象分为五种:表,视图,序列,索引和同 ...

  8. ss2

    一. *** 服务端配置 1. 在命令行窗口输入下面4行命令并回车执行 yum -y update yum install -y python-setuptools && easy_i ...

  9. 问题:Oracle long 类型l;结果:oracle里long类型的总结

    oracle里long类型的总结 1.LONG 数据类型中存储的是可变长字符串,最大长度限制是2GB. 2.对于超出一定长度的文本,基本只能用LONG类型来存储,数据字典中很多对象的定义就是用LONG ...

  10. java电子书chm全套下载

    链接:http://pan.baidu.com/s/1qWmMlYk 密码:us3x 版权声明:本文为博主原创文章,未经博主允许不得转载.