Saltstack——saltstack配置keepalived高可用

  • 打开pillar工具
[root@server1 ~]# cd /etc/salt/
[root@server1 salt]# vim master
 828 pillar_roots:
 829   base:
 830     - /srv/pillar
 [root@server1 salt]# systemctl restart salt-master


  • 建立pillar目录,创建web角色
[root@server1 salt]# mkdir /srv/pillar
[root@server1 salt]# cd /srv/pillar/
[root@server1 pillar]# mkdir web
[root@server1 pillar]# cd web/
[root@server1 web]# ls
[root@server1 web]# vim vars.sls
[root@server1 web]# cat vars.sls 
{% if grains['fqdn'] == 'server2' %}
ip: 172.25.8.2
state: MASTER
vrid: 100
priority: 100
{% elif grains['fqdn'] == 'server3' %}
state: BACKUP
vrid: 100
priority: 50
{% endif %}

  • 编写pillar的top文件
[root@server1 pillar]# ls
web
[root@server1 pillar]# vim top.sls
[root@server1 pillar]# cat top.sls 
base:
  '*':
    - web.vars

  • apache角色
[root@server1 salt]# cd apache/
[root@server1 apache]# ls
files  install.sls
[root@server1 apache]# cat install.sls 
install-apache:
  pkg.installed:
    - pkgs:
      - httpd

  file.managed:
    - name: /etc/httpd/conf/httpd.conf
    - source: salt://apache/files/httpd.conf
    - template: jinja
    - context:
      port: 80
      host: 172.25.8.2

  service.running:
    - name: httpd
    - watch:
      - file: install-apache

  • nginx角色
[root@server1 salt]# cd nginx/
[root@server1 nginx]# ls
files  install.sls  service.sls
[root@server1 nginx]# cat service.sls 
include:
  - nginx.install

/usr/local/nginx/conf/nginx.conf:
  file.managed:
    - source: salt://nginx/files/nginx.conf


service-nginx:
  file.managed:
    - name: /usr/lib/systemd/system/nginx.service
    - source: salt://nginx/files/nginx.service

  service.running:
    - name: nginx
    - reload: True
    - watch:
      - file: /usr/local/nginx/conf/nginx.conf	

  • keepalived角色
[root@server1 salt]# cd keepalived/
[root@server1 keepalived]# ls
files  install.sls
[root@server1 keepalived]# cat install.sls 
install-keepalived:
  pkg.installed:
    - pkgs:
      - keepalived

  file.managed:
    - name: /etc/keepalived/keepalived.conf
    - source: salt://keepalived/files/keepalived.conf
    - template: jinja
    - context:
      STATE: {{ pillar['state'] }}
      VRID: {{pillar['vrid'] }}
      PRIORITY: {{ pillar[priority] }}

  service.running:
      - name: keepalived
      - watch:
        - file: install-keepalived

  • keepalived的配置文件我们需要修改
[root@server1 keepalived]# cd files/
[root@server1 files]# ls
keepalived.conf
[root@server1 files]# vim keepalived.conf 
 16     state {{ STATE}}
 17     interface eth0
 18     virtual_router_id {{ VRID }}
 19     priority {{ PRIORITY }}
 

  • top文件
[root@server1 salt]# ls
apache  keepalived  nginx  pkgs  top.sls
[root@server1 salt]# cat top.sls 
base:
  'roles:apache':
     - match: grain
     - apache.install
     - keepalived.install
  'roles:nginx':
     - match: grain
     - nginx.service
     - keepalived.install

  • 执行
[root@server1 salt]# salt '*' state.highstate

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值