Salt无Master快速入门

Running a masterless salt-minion lets you use Salt's configuration management for a single machine without calling out to a Salt master on another machine.

Since the Salt minion contains such extensive functionality it can be useful to run it standalone. A standalone minion can be used to do a number of things:

  • 设立一个master server通过States (Salting a Salt Master)

  • 在一个系统使用salt-call命令不连接到一个master

  • 无Master states,完全从minion本地文件运行states

在部署到生产环境前用于测试state树。

Bootstrap Salt Minion

在任何操作系统上, 只要有Bourne shell, salt-bootstrap 脚本就可以一步步的使用Salt简单的创建一台服务器:

curl -L https://bootstrap.saltstack.com -o install_salt.sh
sudo sh install_salt.sh

See the salt-bootstrap documentation for other one liners. When using Vagrant to test out salt, the Vagrant salt provisioner will provision the VM for you.

通知Salt运行无Master模式

To instruct the minion to not look for a master, the file_client configuration option needs to be set in the minion configuration file. By default the file_client is set to remote so that the minion gathers file server and pillar data from the salt master. When setting the file_client option to local the minion is configured to not gather this data from the master.

file_client: local

Now the salt minion will not look for a master and will assume that the local system has all of the file and pillar resources.

Configuration which resided in the master configuration (e.g. /etc/salt/master) should be moved to the minion configuration since the minion does not read the master configuration.

注解

When running Salt in masterless mode, do not run the salt-minion daemon. Otherwise, it will attempt to connect to a master and fail. The salt-call command stands on its own and does not need the salt-minion daemon.

创建State树

安装成功salt-minion后, 接下来将创建一个state树, 用于存储构成该minion状态的SLS文件.

下边的例子将讲述如何确保服务器上已经安装了Apache Web服务的state树.

注解

For a complete explanation on Salt States, see the tutorial.

  1. 创建 top.sls 文件:

/srv/salt/top.sls:

base:
  '*':
    - webserver
  1. 创建webserver state树:

/srv/salt/webserver.sls:

apache:               # ID declaration
  pkg:                # state declaration
    - installed       # function declaration

注解

The apache package has different names on different platforms, for instance on Debian/Ubuntu it is apache2, on Fedora/RHEL it is httpd and on Arch it is apache

The only thing left is to provision our minion using salt-call and the highstate command.

Salt-call

The salt-call command is used to run module functions locally on a minion instead of executing them from the master. Normally the salt-call command checks into the master to retrieve file server and pillar data, but when running standalone salt-call needs to be instructed to not check the master for this data:

salt-call --local state.highstate

--local 标签告诉salt-minion在本地文件系统上寻找state tree, 而不是去连接Salt Master.

提供详细输出,使用 -l debug:

salt-call --local state.highstate -l debug

minion首先会检查 top.sls 文件, 确认其属于 * glob匹配组, 然后 webserver SLS会被运行.

接下来检查 webserver.sls 文件, 发现需要运行安装Apache包的 apache state.

The minion should now have Apache installed, and the next step is to begin learning how to write more complex states.