如何在 Debian 11 上安装 Saltstack Master 和 Minion如何在 Debian 11 上安装 Saltstack Master 和 Minion如何在 Debian 11 上安装 Saltstack Master 和 Minion如何在 Debian 11 上安装 Saltstack Master 和 Minion
  • 文章
  • 正则表达式
    • 工具
  • 登录
找到的结果: {phrase} (显示: {results_count} 共: {results_count_total})
显示: {results_count} 共: {results_count_total}

加载更多搜索结果...

搜索范围
模糊匹配
搜索标题
搜索内容
发表 admin at 2025年2月28日
类别
  • 未分类
标签

如何在 Debian 11 上安装 Saltstack Master 和 Minion

在此页

  1. 先决条件
  2. 安装 Saltstack Master
  3. 配置 Saltstack Master
  4. 安装和配置 Saltstack Minion
  5. 从主人那里控制仆从
  6. 使用 Salt State 文件管理 Minions
  7. 结论

SaltStack 是一款免费、开源、基于 Python 的自动化和配置管理软件。它是一个命令行工具,可帮助您从中央位置管理基础架构。 SoltStack 由四个组件组成。每个组件的简要说明如下所示:

  • Salt Master 充当其 minions 的命令行控制器。它用于控制和管理多个 minions。
  • Salt Minion 是从属守护进程,从主进程接收配置和命令。
  • 公式是配置管理文件。
  • 执行是在 minions 上执行的一些命令和模块。

在本文中,我将向您展示如何在 Debian 11 上安装 SaltStack Master 和 Minion 系统。

先决条件

  • 两台运行 Debian 11 的服务器。
  • 在服务器上配置了根密码。

安装 Saltstack Master

默认情况下,SaltStack 不包含在 Debian 11 默认存储库中。因此,您需要将 SaltStack 存储库添加到 APT。您可以通过运行以下命令来添加它:

curl -fsSL -o /usr/share/keyrings/salt-archive-keyring.gpg https://repo.saltproject.io/py3/debian/11/amd64/latest/salt-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/salt-archive-keyring.gpg arch=amd64] https://repo.saltproject.io/py3/debian/11/amd64/latest bullseye main" | tee /etc/apt/sources.list.d/salt.list

添加存储库后,使用以下命令更新存储库缓存:

apt-get update -y

接下来,使用以下命令安装所需的依赖项:

apt-get install python3 salt-common -y

接下来,使用以下命令安装 SaltStack master:

apt-get install salt-master -y

安装成功后,就可以进行下一步了。

配置 Saltstack 主机

接下来,您需要在 SaltSTack 配置文件中定义绑定接口。

nano /etc/salt/master

更改以下行:

interface: 0.0.0.0

保存并关闭文件,然后使用以下命令重新启动 SaltStack 主机:

systemctl restart salt-master

您现在可以使用以下命令验证 SaltStack 的状态:

systemctl status salt-master

您将获得以下输出:

? salt-master.service - The Salt Master Server
     Loaded: loaded (/lib/systemd/system/salt-master.service; enabled; vendor preset: enabled)
     Active: active (running) since Sat 2022-02-12 07:39:48 UTC; 9s ago
       Docs: man:salt-master(1)
             file:///usr/share/doc/salt/html/contents.html
             https://docs.saltproject.io/en/latest/contents.html
   Main PID: 19403 (salt-master)
      Tasks: 32 (limit: 2341)
     Memory: 201.5M
        CPU: 6.109s
     CGroup: /system.slice/salt-master.service
             ??19403 /usr/bin/python3 /usr/bin/salt-master
             ??19407 /usr/bin/python3 /usr/bin/salt-master
             ??19431 /usr/bin/python3 /usr/bin/salt-master
             ??19434 /usr/bin/python3 /usr/bin/salt-master
             ??19435 /usr/bin/python3 /usr/bin/salt-master
             ??19436 /usr/bin/python3 /usr/bin/salt-master
             ??19437 /usr/bin/python3 /usr/bin/salt-master
             ??19444 /usr/bin/python3 /usr/bin/salt-master
             ??19445 /usr/bin/python3 /usr/bin/salt-master
             ??19446 /usr/bin/python3 /usr/bin/salt-master
             ??19448 /usr/bin/python3 /usr/bin/salt-master
             ??19451 /usr/bin/python3 /usr/bin/salt-master
             ??19454 /usr/bin/python3 /usr/bin/salt-master

Feb 12 07:39:48 debian11 systemd[1]: Starting The Salt Master Server...
Feb 12 07:39:48 debian11 systemd[1]: Started The Salt Master Server.

完成后,您可以继续下一步。

安装和配置 Saltstack Minion

至此,SaltStack Master 安装配置完成。现在,登录到另一台机器并使用以下命令添加 SaltStack Minion 存储库:

curl -fsSL -o /usr/share/keyrings/salt-archive-keyring.gpg https://repo.saltproject.io/py3/debian/11/amd64/latest/salt-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/salt-archive-keyring.gpg arch=amd64] https://repo.saltproject.io/py3/debian/11/amd64/latest bullseye main" | tee /etc/apt/sources.list.d/salt.list

添加存储库后,使用以下命令更新存储库缓存:

apt-get update -y

接下来,使用以下命令安装 SaltStack Minion:

apt-get install salt-minion -y

安装成功后,编辑SaltStack Minion配置文件,定义master IP地址。

nano /etc/salt/minion

更改以下行:

master: salt-master-ip

完成后保存并关闭文件。

接下来,您需要使用 master 的公共指纹对 minions 进行身份验证。

在 Salt Master 机器上,使用以下命令列出所有指纹:

salt-key --finger-all

您将获得以下输出:

Local Keys:
master.pem:  b7:f0:ed:19:bf:e8:e0:9d:c3:9c:a2:09:2c:97:2f:6b:0f:cb:eb:76:3d:d7:d5:a9:7d:0c:3a:60:6e:9f:d7:78
master.pub:  5e:4f:2b:37:41:cc:4b:9c:b0:ed:cb:0a:fb:c7:59:54:5f:11:34:ab:d2:99:96:c1:e7:ef:4d:95:b0:7c:d3:d1

现在,复制 master.pub 指纹行并将其添加到 Minion 配置文件中。

在 Minion 机器上,编辑配置文件:

nano /etc/salt/minion

添加主指纹如下图:

master_finger:  '5e:4f:2b:37:41:cc:4b:9c:b0:ed:cb:0a:fb:c7:59:54:5f:11:34:ab:d2:99:96:c1:e7:ef:4d:95:b0:7c:d3:d1'

您还需要定义 Minion 的名称:

id: Minion1

保存并关闭文件,然后使用以下命令重新启动 SaltStack Minion:

systemctl restart salt-minion

您还可以使用以下命令验证 SaltStack Minion 的状态:

systemctl status salt-minion

您将获得以下输出:

? salt-minion.service - The Salt Minion
     Loaded: loaded (/lib/systemd/system/salt-minion.service; enabled; vendor preset: enabled)
     Active: active (running) since Sat 2022-02-12 07:46:04 UTC; 7s ago
       Docs: man:salt-minion(1)
             file:///usr/share/doc/salt/html/contents.html
             https://docs.saltproject.io/en/latest/contents.html
   Main PID: 2324 (salt-minion)
      Tasks: 8 (limit: 2341)
     Memory: 59.9M
        CPU: 1.185s
     CGroup: /system.slice/salt-minion.service
             ??2324 /usr/bin/python3 /usr/bin/salt-minion
             ??2326 /usr/bin/python3 /usr/bin/salt-minion
             ??2328 /usr/bin/python3 /usr/bin/salt-minion

Feb 12 07:46:04 debian11 systemd[1]: Starting The Salt Minion...
Feb 12 07:46:04 debian11 systemd[1]: Started The Salt Minion.

您还可以使用以下命令检查 minion 指纹:

salt-call key.finger --local

您将获得以下输出:

local:
    14:12:ef:33:d2:1e:49:23:7b:a2:74:8d:19:fc:be:5e:6d:a6:57:ec:4f:a9:da:23:69:3f:62:1b:6b:4b:2f:27

在 SaltStack Master 机器上,使用以下命令匹配指纹:

salt-key --finger-all

您将获得以下输出:

Local Keys:
master.pem:  b7:f0:ed:19:bf:e8:e0:9d:c3:9c:a2:09:2c:97:2f:6b:0f:cb:eb:76:3d:d7:d5:a9:7d:0c:3a:60:6e:9f:d7:78
master.pub:  5e:4f:2b:37:41:cc:4b:9c:b0:ed:cb:0a:fb:c7:59:54:5f:11:34:ab:d2:99:96:c1:e7:ef:4d:95:b0:7c:d3:d1
Unaccepted Keys:
Minion1:  14:12:ef:33:d2:1e:49:23:7b:a2:74:8d:19:fc:be:5e:6d:a6:57:ec:4f:a9:da:23:69:3f:62:1b:6b:4b:2f:27

在 SaltStack Master 上,使用以下命令接受 Minion:

salt-key -a Minion1

您将获得以下输出:

The following keys are going to be accepted:
Unaccepted Keys:
Minion1
Proceed? [n/Y] Y
Key for minion Minion1 accepted.

现在,使用以下命令验证 Master 和 Minion 之间的连接:

salt Minion1 test.ping

您将获得以下输出:

Minion1:
    True

完成后,您可以继续下一步。

从主人控制仆从

Master和Minion连接成功后。让我们开始在 Minions 上执行一些命令。

运行以下命令以列出 Minion 上的可用磁盘空间:

salt '*' disk.usage

您将获得以下输出:

Minion1:
    ----------
    /:
        ----------
        1K-blocks:
            51538400
        available:
            47658628
        capacity:
            4%
        filesystem:
            /dev/sda1
        used:
            1661604
    /dev:
        ----------
        1K-blocks:
            998936
        available:
            998936
        capacity:
            0%
        filesystem:
            udev
        used:
            0
    /dev/shm:
        ----------
        1K-blocks:
            1015232
        available:
            1015152
        capacity:
            1%
        filesystem:
            tmpfs
        used:
            80

要在 Minion 上安装 Apache 包,请运行以下命令:

salt Minion1 pkg.install apache2

您将获得以下输出:

Minion1:
    ----------
    apache2:
        ----------
        new:
            2.4.52-1~deb11u2
        old:
    apache2-bin:
        ----------
        new:
            2.4.52-1~deb11u2
        old:
    apache2-data:
        ----------
        new:
            2.4.52-1~deb11u2
        old:
    apache2-utils:
        ----------
        new:
            2.4.52-1~deb11u2
        old:
    libapr1:
        ----------
        new:
            1.7.0-6+deb11u1
        old:
    libaprutil1:
        ----------
        new:
            1.6.1-5
        old:
    libaprutil1-dbd-sqlite3:
        ----------
        new:
            1.6.1-5
        old:
    libaprutil1-ldap:
        ----------
        new:
            1.6.1-5
        old:

要检查 Minion 上的可用内存,请运行以下命令:

salt '*' cmd.run 'free -m'

您将获得以下输出:

Minion1:
                   total        used        free      shared  buff/cache   available
    Mem:            1982         140        1392           2         450        1691
    Swap:              0           0           0

使用 Salt State 文件管理 Minions

状态文件也称为配置管理文件,用于配置和管理 Minion。

要创建状态文件,您需要为 SaltStack 创建环境基础。

mkdir /src/salt

接下来,使用以下命令创建状态文件:

nano /src/salt/setup.sls

添加以下代码以在 Minions 上安装 PHP、UNZIP 和 Apache 包:

network_utilities: 
 pkg.installed: 
   - pkgs: 
     - php 
     - unzip 

apache2_pkg: 
 pkg.installed: 
   - name: apache2 

apache2_service: 
 service.running: 
   - name: apache2 
   - enable: True 
   - require: 
     - pkg: apache2_pkg

保存并关闭文件,然后使用以下命令将配置应用于所有 Minion:

salt '*' state.apply setup

您将获得以下输出:

Minion1:
----------
          ID: network_utilities
    Function: pkg.installed
      Result: True
     Comment: The following packages were installed/updated: php, unzip
     Started: 07:51:22.424504
    Duration: 17349.907 ms
     Changes:   
              ----------
              libapache2-mod-php7.4:
                  ----------
                  new:
                      7.4.25-1+deb11u1
                  old:
              php:
                  ----------
                  new:
                      2:7.4+76
                  old:
              php-common:
                  ----------
                  new:
                      2:76
                  old:
              php7.4:
                  ----------
                  new:
                      7.4.25-1+deb11u1
                  old:
              php7.4-cli:
                  ----------
                  new:
                      7.4.25-1+deb11u1
                  old:
              php7.4-common:
                  ----------
                  new:
                      7.4.25-1+deb11u1
                  old:
              php7.4-json:
                  ----------
                  new:
                      7.4.25-1+deb11u1
                  old:
              php7.4-opcache:
                  ----------
                  new:
                      7.4.25-1+deb11u1
                  old:
              php7.4-readline:
                  ----------
                  new:
                      7.4.25-1+deb11u1
                  old:
              psmisc:
                  ----------
                  new:
                      23.4-2
                  old:
              unzip:
                  ----------
                  new:
                      6.0-26
                  old:
----------
          ID: apache2_pkg
    Function: pkg.installed
        Name: apache2
      Result: True
     Comment: All specified packages are already installed
     Started: 07:51:39.780956
    Duration: 1029.457 ms
     Changes:   
----------
          ID: apache2_service
    Function: service.running
        Name: apache2
      Result: True
     Comment: The service apache2 is already running
     Started: 07:51:40.812210
    Duration: 35.61 ms
     Changes:   

Summary for Minion1
------------
Succeeded: 3 (changed=1)
Failed:    0
------------
Total states run:     3
Total run time:  18.415 s

结论

恭喜!您已经在 Debian 11 服务器上成功安装并配置了 SaltStack Master 和 Minion。我们还解释了如何使用状态文件和命令行管理 Minion。我希望这将帮助您从中央位置自动化和管理您的基础架构。如果您有任何问题,请随时问我。

©2015-2025 艾丽卡 support@alaica.com