利用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的环境上: 在 ...
随机推荐
- Kivy中ActionBar控件的使用
这个控件可以作为导航栏来使用,效果非常好. 1. ActionBar包含的组件 ActionBar中需要一个ActionView作为容器来存放其他控件,比如:ActionPrevious.Action ...
- 【C++】运算符优先级和结合性
从上表可以大致总结这样一个规律: 优先级 运算符 高 初等运算符 | 单目运算符 | 算术运算符(先乘除,后加减) | 关系运算符 | 逻辑运算符(不包括!) | 条件运算符 ↓ 赋值运算符 低 逗号 ...
- [Objective-C] 020_ Block
1.定义和使用Block #import "ViewController.h" @interface ViewController () @end @implementation ...
- [Objective-C] Xcode中常用的快捷键操作与插件
古人云“工欲善其事必先利其器”,打造和熟悉一个强大的开发环境,是每个程序员必须的! 在Xcode 6中有许多快捷键的设定可以使得你的编程工作更为高效,对于在代码文件中快速导航.定位Bug以及新增应用特 ...
- [JavaWeb基础] 006.Struts1的配置和简单使用
1.框架简介 采用Struts能开发出基于MVC(Model-View-Controller)设计模式的应用构架,用于快速开发Java Web应用.Struts实现的重点在C(Controller), ...
- Springboot之actuator未授权访问
copy 子杰的哈,懒的写了 0x01 未授权访问可以理解为需要授权才可以访问的页面由于错误的配置等其他原因,导致其他用户可以直接访问,从而引发各种敏感信息泄露. 0x02 Spring Boot ...
- 50个SQL语句(MySQL版) 问题三
--------------------------表结构-------------------------- student(StuId,StuName,StuAge,StuSex) 学生表 tea ...
- Rocket - interrupts - NullIntSource
https://mp.weixin.qq.com/s/Fn3u2OSLAzPDrlZTiLfikg 简单介绍NullIntSource的实现. 1. 简单介绍 NullIntSource实现一个不会发 ...
- jchdl - RTL实例 - Adder
https://mp.weixin.qq.com/s/9S29BCTcJfbpR62ALjSidA 加法器. 参考链接 https://github.com/wjcdx/jchdl/blob/ ...
- Java实现 LeetCode 423 从英文中重建数字
423. 从英文中重建数字 给定一个非空字符串,其中包含字母顺序打乱的英文单词表示的数字0-9.按升序输出原始的数字. 注意: 输入只包含小写英文字母. 输入保证合法并可以转换为原始的数字,这意味着像 ...