利用salt stack pillar安装多组keepalived
利用salt stack pillar安装多组keepalived
环境描述
在生产环境中,需要搭建三套keepalived环境,3个master和3个backup,要安装的软件和配置文件,虽然不是很多,一个一个配置也工作量不大,最近看了一下salt的状态模块,感觉可以通过salt来直接进行安装并自定义配置,下面记录一下操作的过程。
操作过程
首先先分析一下keepalive的配置文件,主要需要修改的地方有6处:
Keepalived_Router_ID: router_id
Keepalived_Interface: interface
Keepalived_Mcast_src_ip: mcast_src_ip
Keepalived_Virtual_Router_ID: virtual_router_id
Keepalived_status: state
Keepalived_priority: priority
Keepalived_Virtual_Ipaddress: virtual_ipaddress
最开始想到的是,利用master和backup的区分,然后基于virtual_router_id来设置ip地址,所以想的是每一组keepalived做两个状态文件,一个文件是master主机用,一个是backup主机用,这样就需要做6个状态文件,虽然是能实现自动化配置,但是需要创建和修改的配置文件也是不少,划不来。
所以想到了pillar的方式,在salt中,为每一个主机,定义keepalived相关的属性参数,然后在安装配置keepalived的时候,基于这些属性参数,自定义修改配置文件,然后生效。首先对6台主机进行配置规划,也就是这6个字段。
Minion | 192.168.100.76 | 192.168.100.77 | 192.168.100.106 | 192.168.100.107 | 192.168.100.115 | 192.168.100.116 |
---|---|---|---|---|---|---|
Keepalived_Router_ID | 76 | 77 | 106 | 107 | 115 | 116 |
Keepalived_Interface | eth2 | eth2 | eth1 | eth1 | eth1 | eth1 |
Keepalived_Mcast_src_ip | 192.168.100.76 | 192.168.100.77 | 192.168.100.106 | 192.168.100.107 | 192.168.100.115 | 192.168.100.116 |
Keepalived_Virtual_Router_ID | 118 | 118 | 110 | 110 | 108 | 108 |
Keepalived_status | master | backup | master | backup | master | backup |
Keepalived_priority | 120 | 100 | 120 | 100 | 120 | 100 |
Keepalived_Virtual_Ipaddress | 192.168.100.118/26 | 192.168.100.118/26 | 192.168.100.110/26 | 192.168.100.110/26 | 192.168.100.108/26 | 192.168.100.108/26 |
在master上,为每个minion配置这些pillar属性。顶层创建top.sls文件,然后在top文件中定义minion和对应pillar的对应关系,然后创建状态文件。
启用pillar,在/etc/salt/master文件中,修改pillar_roots,设置base的路径为/srv/salt/base/pillar
pillar_roots:
base:
- /srv/salt/base/pillar
创建keepalived目录,在该目录中,放置对应节点的pillar定义,编写top文件
[root@mysqlbackup pillar]# cat top.sls
base:
'192.168.100.76':
- keepalived.Keepalived_76
[root@mysqlbackup pillar]# cat keepalived/Keepalived_76.sls
Keepalived_Router_ID: 76
Keepalived_Interface: eth2
Keepalived_Mcast_src_ip: 192.168.100.76
Keepalived_Virtual_Router_ID: 118
Keepalived_status: master
Keepalived_priority: 120
Keepalived_Virtual_Ipaddress: 192.168.100.118/26
编写完成后,查看生效情况
[root@mysqlbackup pillar]# salt '192.168.100.76' pillar.ls
192.168.100.76:
- Keepalived_Interface
- Keepalived_priority
- Keepalived_Virtual_Router_ID
- Keepalived_Router_ID
- Keepalived_status
- Keepalived_Virtual_Ipaddress
- Keepalived_Mcast_src_ip
[root@mysqlbackup pillar]# salt '192.168.100.76' pillar.items
192.168.100.76:
----------
Keepalived_Interface:
eth2
Keepalived_Mcast_src_ip:
192.168.100.76
Keepalived_Router_ID:
76
Keepalived_Virtual_Ipaddress:
192.168.100.118/26
Keepalived_Virtual_Router_ID:
118
Keepalived_priority:
120
Keepalived_status:
master
minion的pillar生效之后,就开始修改默认的配置文件,将相关的变量,设置为pillar取值。
[root@mysqlbackup keepalived]# cat ../files/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
notification_email {
acassen@firewall.loc
}
notification_email_from Alexandre.Cassen@firewall.loc
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id {{ pillar['Keepalived_Router_ID'] }}
}
vrrp_script chk_mysql_port {
script "/opt/chk_mysql.sh"
interval 2
weight -5
fall 2
rise 1
}
vrrp_instance VI_1 {
state {{ pillar['Keepalived_status'] }}
nopreempt
interface {{ pillar['Keepalived_Interface'] }}
mcast_src_ip {{ pillar['Keepalived_Mcast_src_ip'] }}
virtual_router_id {{ pillar['Keepalived_Virtual_Router_ID'] }}
priority {{ pillar['Keepalived_priority'] }}
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
{{ pillar['Keepalived_Virtual_Ipaddress'] }}
}
# track_script {
# chk_mysql_port
# }
}
下一步是编写状态文件,一个状态文件中,包含keepalived的安装、配置文件管理和服务管理。
[root@mysqlbackup keepalived]# cat keepalived.sls
include:
- keepalived.keepalived-install
- keepalived.configuration
- keepalived.services
[root@mysqlbackup keepalived]# cat keepalived-install.sls
keepalived-install:
pkg.installed:
- names:
- keepalived
[root@mysqlbackup keepalived]# cat configuration.sls
configuration:
file.managed:
- name: /etc/keepalived/keepalived.conf
- source: salt://files/keepalived/keepalived.conf
- user: root
- group: root
- mode: 644
- backup: minion
- template: jinja
[root@mysqlbackup keepalived]# cat services.sls
keepalived-service:
service.running:
- name: keepalived
- enable: True
- watch:
- file: /etc/keepalived/keepalived.conf
- reload: True
下一步就是在指定的minion上执行该状态文件,检查安装的结果。
[root@mysqlbackup keepalived]# salt '192.168.100.76' state.sls keepalived.keepalived
192.168.100.76:
----------
ID: keepalived-install
Function: pkg.installed
Name: keepalived
Result: True
Comment: All specified packages are already installed
Started: 08:06:42.776064
Duration: 1295.253 ms
Changes:
----------
ID: configuration
Function: file.managed
Name: /etc/keepalived/keepalived.conf
Result: True
Comment: File /etc/keepalived/keepalived.conf updated
Started: 08:06:44.075458
Duration: 125.626 ms
Changes:
----------
diff:
---
+++
@@ -23,7 +23,7 @@
nopreempt
interface eth2
mcast_src_ip 192.168.100.76
- virtual_router_id 76
+ virtual_router_id 118
priority 120
advert_int 1
authentication {
----------
ID: keepalived-service
Function: service.running
Name: keepalived
Result: True
Comment: Service reloaded
Started: 08:06:44.278083
Duration: 91.662 ms
Changes:
----------
keepalived:
True
Summary for 192.168.100.76
------------
Succeeded: 3 (changed=2)
Failed: 0
------------
Total states run: 3
Total run time: 1.513 s
在minion上查看配置文件,相关的变量参数,都是根据系统的pillar进行自定义配置的。
! Configuration File for keepalived
global_defs {
notification_email {
acassen@firewall.loc
}
notification_email_from Alexandre.Cassen@firewall.loc
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id 76
}
vrrp_script chk_mysql_port {
script "/opt/chk_mysql.sh"
interval 2
weight -5
fall 2
rise 1
}
vrrp_instance VI_1 {
state master
nopreempt
interface eth2
mcast_src_ip 192.168.100.76
virtual_router_id 118
priority 120
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.100.78/26
}
# track_script {
# chk_mysql_port
# }
}
利用salt stack pillar安装多组keepalived的更多相关文章
- 七天学会 SALT STACK 自动化运维 (1)
七天学会 SALT STACK 自动化运维 (1) 简单理解 SALTSTACK 安装与配置 基本的使用方法 结束语 引用资源 简单理解 SALT STACK 笔者是初次接触 自动化运维 这一技术领域 ...
- salt stack 工具之一——远程命令
salt stack 远程命令 salt stack是一种自动化的运维工具,可以同时对N台服务器进行配置管理.远程命令执行等操作. salt stack分为两个部分: salt-master,部署在控 ...
- Salt Stack 官方文档翻译 - 一个想做dba的sa - 博客频道 - CSDN.NET
OSNIT_百度百科 Salt Stack 官方文档翻译 - 一个想做dba的sa - 博客频道 - CSDN.NET Salt Stack 官方文档翻译 分类: 自动运维 2013-04-02 11 ...
- salt stack 远程命令
salt stack 远程命令 salt stack是一种自动化的运维工具,可以同时对N台服务器进行配置管理.远程命令执行等操作. salt stack分为两个部分 salt-master,部署在控制 ...
- salt之pillar组件
pillar也是salt最重要的组件之一,其作用是定义与被控主机相关的任何数据,定义好的数据可以被其他组件使用,如模板.state.API等.在pillar中定义的数据与不同业务特征的被控主机相关联, ...
- RabbitMQ集群安装配置+HAproxy+Keepalived高可用
RabbitMQ集群安装配置+HAproxy+Keepalived高可用 转自:https://www.linuxidc.com/Linux/2016-10/136492.htm rabbitmq 集 ...
- centos7安装配置LVS+keepalived高可用
Centos7-Lvs+Keepalived架构 LVS+Keepalived 介绍 1 . LVS LVS 是一个开源的软件,可以实现 LINUX 平台下的简单负载均衡. LVS 是 Linux ...
- Mac下利用(xcode)安装git
Mac下利用(xcode)安装git 一.AppStore 最安全途径:搜索下载Xcode,(需要AppleID). 其他:直接百度Xcode下载. 二.Xcode 打开Xcode-->Pref ...
- python 利用 setup.py 手动安装第三方类库
python 利用 setup.py 手动安装第三方类库 由于我在mac使用时,装了python3,默认有python2的环境,使用 pip 安装第三方类库时,老是安装到 python2的环境上: 在 ...
随机推荐
- linux高级管理第十四章--kvm虚拟化
案例 安装kvm所需软件 验证 注:虚拟机要开启虚拟引擎 开启服务 环境准备 安装相关软件包 启动 创建网桥 重启,reboot 安装虚拟机 完成.
- 1.Redis介绍和使用场景
(1)持久化数据库的缺点 平常我们使用的关系型数据库有Mysql.Oracle以及SqlServer等,在开发的过程中,数据通常都是通过Web提供的数据库驱动来链接数据库进行增删改查. 那么,我们日常 ...
- python3.7 64bit安装pygame1.9.3
https://blog.csdn.net/xiaolixi199311/article/details/79209506/
- Hadoop 伪分布模式安装
( 温馨提示:图片中有id有姓名,不要盗用哦,可参考流程,有问题评论区留言哦 ) 一.任务目标 1.了解Hadoop的3种运行模式 2.熟练掌握Hadoop伪分布模式安装流程 3.培养独立完成Hado ...
- burpsuite 2.0beta体验
这里有破解版:http://ximcx.cn/post-110.html 一直再用1.7x版本,2.0的还没怎么用过 移除了 Scanner 和spider 选项卡,全部整理到Dashboard里 代 ...
- [apue] 一个工业级、跨平台的 tcp 网络服务框架:gevent
作为公司的公共产品,经常有这样的需求:就是新建一个本地服务,产品线作为客户端通过 tcp 接入本地服务,来获取想要的业务能力. 与印象中动辄处理成千上万连接的 tcp 网络服务不同,这个本地服务是跑在 ...
- jchdl - RTL实例 - MOS6502 CPU
https://mp.weixin.qq.com/s/OguQKMU64GGdinCJjgyeKw 实现MOS6502 CPU,主要是实现状态机. 参考链接 https://github.co ...
- Java实现 LeetCode 104 二叉树的最大深度
104. 二叉树的最大深度 给定一个二叉树,找出其最大深度. 二叉树的深度为根节点到最远叶子节点的最长路径上的节点数. 说明: 叶子节点是指没有子节点的节点. 示例: 给定二叉树 [3,9,20,nu ...
- java类加载器是什么?
类加载器是有了解吗? 解析:底层原理的考察,其中涉及到类加载器的概念,功能以及一些底层的实现. 答:顾名思义,类加载器(class loader)用来加载 Java 类到 Java 虚拟机中.一般来说 ...
- Java实现 蓝桥杯 历届试题 翻硬币
问题描述 小明正在玩一个"翻硬币"的游戏. 桌上放着排成一排的若干硬币.我们用 * 表示正面,用 o 表示反面(是小写字母,不是零). 比如,可能情形是:**oo***oooo 如 ...