saltstack搭建keepalived高可用集群

本文详细介绍SaltStack自动化运维工具的安装、配置与应用实例。通过SaltStack,管理员能高效管理多台服务器,实现远程执行、配置管理和云资源管理。文章演示了如何在两台服务器上部署Keepalived高可用集群,展示SaltStack的强大功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一、SaltStack简介

SaltStack管理工具允许管理员对多个操作系统创建一个一致的管理系统。

二、特点

 1.快;多线程并发执行

 2.底层基于python

 3.丰富的api

 4.运行模式:本地运行;master/minion;salt SSH

  5.三大功能:远程执行;配置管理;云管理

  6.支持的操作系统比较丰富

三、SaltStack安装基础环境准备
1.server1:安装saltstack

[root@server1 2018]# cd /root/saltstack/rhel7/2018
[root@server1 2018]# ls
PyYAML-3.11-1.el7.x86_64.rpm            python2-libcloud-2.0.0-2.el7.noarch.rpm
libsodium-1.0.16-1.el7.x86_64.rpm       repodata
openpgm-5.2.122-2.el7.x86_64.rpm        salt-2018.3.3-1.el7.noarch.rpm
python-cherrypy-5.6.0-2.el7.noarch.rpm  salt-api-2018.3.3-1.el7.noarch.rpm
python-crypto-2.6.1-2.el7.x86_64.rpm    salt-cloud-2018.3.3-1.el7.noarch.rpm
python-futures-3.0.3-1.el7.noarch.rpm   salt-master-2018.3.3-1.el7.noarch.rpm
python-msgpack-0.4.6-1.el7.x86_64.rpm   salt-minion-2018.3.3-1.el7.noarch.rpm
python-psutil-2.2.1-1.el7.x86_64.rpm    salt-ssh-2018.3.3-1.el7.noarch.rpm
python-tornado-4.2.1-1.el7.x86_64.rpm   salt-syndic-2018.3.3-1.el7.noarch.rpm
python-zmq-15.3.0-3.el7.x86_64.rpm      zeromq-4.1.4-7.el7.x86_64.rpm
[root@server1 2018]# yum install -y *

设置iserver1为主master:

[root@server1 ~]# cd /etc/salt/
[root@server1 salt]# ls
cloud           cloud.maps.d       master    minion.d  proxy.d
cloud.conf.d    cloud.profiles.d   master.d  pki       roster
cloud.deploy.d  cloud.providers.d  minion    proxy
[root@server1 salt]# vim minion

 16 master: 172.25.60.1

开启服务:

[root@server1 salt]# systemctl start salt-master.service  
[root@server1 salt]# systemctl start salt-minion.service 

查看端口是否开启:

[root@server1 salt]# netstat -antlp

4505端口:用来链接slave,发布订阅
4506端口:请求响应,模式为:zmq(消息队列)

server2操作与1相同,但只需要开启salt-minion.service服务即可

安装saltstack
[root@server2 2018]# cd /etc/salt/
[root@server2 salt]# vim minion
16 master: 172.25.60.1

[root@server2 salt]# systemctl start salt-minion.service 

2.Salt秘钥认证设置

[root@server1 salt]# salt-key -L
[root@server1 salt]# salt-key -A
Proceed? [n/Y] Y   
[root@server1 salt]# salt-key -L

3.编辑执行文件

[root@server1 ~]# mkdir /srv/salt 
[root@server1 ~]# cd /srv/salt/ 
[root@server1 salt]# mkdir keepalived
[root@server1 salt]# cd keepalived/
[root@server1 keepalived]# mkdir files
[root@server1 keepalived]# vim install.sls
kp-install: 
  pkg.installed: 
    - pkgs: 
      - keepalived 
  file.managed: 
    - name: /etc/keepalived/keepalived.conf 
    - source: salt://keepalived/files/keepalived.conf 
    - template: jinja 
      {% if grains['fqdn'] == 'server1' %} 
      STATE: MASTER 
      VRID: 51 
      PRIORITY: 100 
      {% elif grains['fqdn'] == 'server2' %}
      STATE: BACKUP 
      VRID: 51 
      PRIORITY: 50 
      {% endif %} 

  service.running: 
    - name: keepalived 
    - reload: True 
    - watch: 
      - file: kp-install

 

[root@server1 keepalived]# cd files/
[root@server1 files]# vim keepalived.conf
! Configuration File for keepalived

global_defs {
   notification_email {
	root@localhost
   }
   notification_email_from keepalived@localhost
   smtp_server 127.0.0.1
   smtp_connect_timeout 30
   router_id LVS_DEVEL
}

vrrp_instance VI_1 {
    state {{ STATE }}
    interface eth0
    virtual_router_id {{ VRID }}
    priority {{ PRIORITY }}
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        172.25.60.100
    }
}

 

[root@server1 salt]# cd /srv/salt/
[root@server1 salt]# vim top.sls
base:
  'server1':
    - keepalived.install        
 
  'server2':
    - keepalived.install

4.执行top.sls文件,向所有节点安装部署服务

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

5.测试:

[root@server1 salt]# ip addr

vip在server1上,关闭keepalived服务再次查看:

[root@server1 salt]# systemctl stop keepalived.service 
[root@server1 salt]# ip addr

[root@server2 ~]# ip a    

当server1宕机时,vip漂移到server2上。

再次打开keepalived,vip又回到server1上:

[root@server1 salt]# systemctl start keepalived.service 
[root@server1 salt]# ip addr

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

马克图布s

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值