利用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的环境上: 在 ...
随机推荐
- [书籍分享]0-008.商业模式新生代[Business Model Generation]
封面 内容简介 <商业模式新生代>内容简介:当你愉快的看完第一章:商业模式画布,赫然发现这些构成要素全都交织成一幅清晰的图像在脑海中呈现,它们如何互相影响.如何交互作用全都历历在目.利用商 ...
- [安卓基础] 008.Android中的显示单位
*:first-child { margin-top: 0 !important; } body > *:last-child { margin-bottom: 0 !important; } ...
- Parrot os安装docker及docker-compose
一.安装docker 1.添加Docker pgp key curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key ...
- 08 . Nginx状态码
HTTP状态码 本篇文章主要介绍运维过程中经常遇到的状态码,并通过业界流行的Nginx进行模拟实现. 2XX状态码 2XX类型状态码表示一个HTTP请求成功,最典型的就是200 # 200状态码 # ...
- uwsgi+nginx 502 bad get away 错误
用uwsgi和nginx部署网站时有时候访问网站会出现502错误 配置,启动文件等完全没有问题. 目前解决方法是重启uwsgi就可以了(虽然说502错误应该有很多产生原因啦) 所用命令: $ ps - ...
- ES6-常用四种数组
1.map 1.1 个人理解 映射 一个对一个 例如:[45,57,138]与[{name:'blue',level:0},{name:'zhangsan',level:99},{name:'lisi ...
- ffmpeg转码步骤源码实现的一点点浅析
ffmpeg转码实现的一点点浅析 ffmpeg转码过程对解码的处理封装在process_input()中(process_input()->decode_video()->decode() ...
- html css javascript实现弹弹球
效果如图: 原创代码: <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> & ...
- MySQL国内镜像下载地址
最近重新下载MySQL发现官网下载速度不是一般的慢,官网下载要几个钟而且一不注意就被取消下载了,实在受不了 可以使用sohu的镜像:http://mirrors.sohu.com/mysql/MySQ ...
- Java实现 LeetCode 645 错误的集合(暴力)
645. 错误的集合 集合 S 包含从1到 n 的整数.不幸的是,因为数据错误,导致集合里面某一个元素复制了成了集合里面的另外一个元素的值,导致集合丢失了一个整数并且有一个元素重复. 给定一个数组 n ...