2016-12-15 22:36:44 +00:00
|
|
|
.. _tutorial-salt-at-scale:
|
|
|
|
|
2014-08-11 16:33:55 +00:00
|
|
|
===================
|
2015-07-30 05:39:46 +00:00
|
|
|
Using Salt at scale
|
2014-08-11 16:33:55 +00:00
|
|
|
===================
|
2014-06-05 08:36:46 +00:00
|
|
|
|
2014-07-09 18:06:24 +00:00
|
|
|
The focus of this tutorial will be building a Salt infrastructure for handling
|
|
|
|
large numbers of minions. This will include tuning, topology, and best practices.
|
2014-07-02 10:39:58 +00:00
|
|
|
|
2015-07-30 05:39:46 +00:00
|
|
|
For how to install the Salt Master please
|
2014-07-02 10:44:52 +00:00
|
|
|
go here: `Installing saltstack <http://docs.saltstack.com/topics/installation/index.html>`_
|
2014-06-05 08:36:46 +00:00
|
|
|
|
2014-08-11 16:33:55 +00:00
|
|
|
.. note::
|
|
|
|
|
2014-07-09 18:06:24 +00:00
|
|
|
This tutorial is intended for large installations, although these same settings
|
|
|
|
won't hurt, it may not be worth the complexity to smaller installations.
|
2014-06-05 08:36:46 +00:00
|
|
|
|
2014-07-09 18:06:24 +00:00
|
|
|
When used with minions, the term 'many' refers to at least a thousand
|
2014-07-02 10:39:58 +00:00
|
|
|
and 'a few' always means 500.
|
2014-06-05 08:36:46 +00:00
|
|
|
|
2014-07-02 10:39:58 +00:00
|
|
|
For simplicity reasons, this tutorial will default to the standard ports
|
2015-07-30 05:39:46 +00:00
|
|
|
used by Salt.
|
2014-06-05 08:53:49 +00:00
|
|
|
|
2014-06-05 08:36:46 +00:00
|
|
|
The Master
|
|
|
|
==========
|
|
|
|
|
2015-07-30 05:39:46 +00:00
|
|
|
The most common problems on the Salt Master are:
|
2014-06-05 08:36:46 +00:00
|
|
|
|
2014-07-09 18:06:24 +00:00
|
|
|
1. too many minions authing at once
|
|
|
|
2. too many minions re-authing at once
|
2014-07-11 22:46:54 +00:00
|
|
|
3. too many minions re-connecting at once
|
2014-07-09 18:06:24 +00:00
|
|
|
4. too many minions returning at once
|
2014-07-11 22:46:54 +00:00
|
|
|
5. too few resources (CPU/HDD)
|
2014-06-05 08:36:46 +00:00
|
|
|
|
2014-07-09 18:06:24 +00:00
|
|
|
The first three are all "thundering herd" problems. To mitigate these issues
|
2015-07-30 05:39:46 +00:00
|
|
|
we must configure the minions to back-off appropriately when the Master is
|
2014-07-09 18:06:24 +00:00
|
|
|
under heavy load.
|
2014-06-05 08:36:46 +00:00
|
|
|
|
2014-07-11 22:46:54 +00:00
|
|
|
The fourth is caused by masters with little hardware resources in combination
|
2016-02-04 11:39:41 +00:00
|
|
|
with a possible bug in ZeroMQ. At least that's what it looks like till today
|
2014-07-02 10:39:58 +00:00
|
|
|
(`Issue 118651 <https://github.com/saltstack/salt/issues/11865>`_,
|
|
|
|
`Issue 5948 <https://github.com/saltstack/salt/issues/5948>`_,
|
|
|
|
`Mail thread <https://groups.google.com/forum/#!searchin/salt-users/lots$20of$20minions/salt-users/WxothArv2Do/t12MigMQDFAJ>`_)
|
2014-06-05 08:36:46 +00:00
|
|
|
|
2015-07-30 05:39:46 +00:00
|
|
|
To fully understand each problem, it is important to understand, how Salt works.
|
2014-06-05 08:36:46 +00:00
|
|
|
|
2015-07-30 05:39:46 +00:00
|
|
|
Very briefly, the Salt Master offers two services to the minions.
|
2014-06-05 08:36:46 +00:00
|
|
|
|
|
|
|
- a job publisher on port 4505
|
|
|
|
- an open port 4506 to receive the minions returns
|
|
|
|
|
2014-07-02 10:39:58 +00:00
|
|
|
All minions are always connected to the publisher on port 4505 and only connect
|
2015-07-30 05:39:46 +00:00
|
|
|
to the open return port 4506 if necessary. On an idle Master, there will only
|
2014-07-02 10:39:58 +00:00
|
|
|
be connections on port 4505.
|
2014-06-05 08:36:46 +00:00
|
|
|
|
2014-07-09 18:06:24 +00:00
|
|
|
Too many minions authing
|
2014-08-11 16:33:55 +00:00
|
|
|
------------------------
|
2015-07-30 05:28:27 +00:00
|
|
|
|
2015-07-30 05:39:46 +00:00
|
|
|
When the Minion service is first started up, it will connect to its Master's publisher
|
2014-07-09 18:06:24 +00:00
|
|
|
on port 4505. If too many minions are started at once, this can cause a "thundering herd".
|
|
|
|
This can be avoided by not starting too many minions at once.
|
2014-06-05 08:36:46 +00:00
|
|
|
|
2014-07-09 18:06:24 +00:00
|
|
|
The connection itself usually isn't the culprit, the more likely cause of master-side
|
2015-07-30 05:39:46 +00:00
|
|
|
issues is the authentication that the Minion must do with the Master. If the Master
|
|
|
|
is too heavily loaded to handle the auth request it will time it out. The Minion
|
2014-07-09 18:06:24 +00:00
|
|
|
will then wait `acceptance_wait_time` to retry. If `acceptance_wait_time_max` is
|
2015-07-30 05:39:46 +00:00
|
|
|
set then the Minion will increase its wait time by the `acceptance_wait_time` each
|
2014-07-09 18:06:24 +00:00
|
|
|
subsequent retry until reaching `acceptance_wait_time_max`.
|
2014-06-05 08:36:46 +00:00
|
|
|
|
2014-07-09 18:06:24 +00:00
|
|
|
Too many minions re-authing
|
2014-08-11 16:33:55 +00:00
|
|
|
---------------------------
|
2015-07-30 05:28:27 +00:00
|
|
|
|
2015-07-30 05:39:46 +00:00
|
|
|
This is most likely to happen in the testing phase of a Salt deployment, when
|
|
|
|
all Minion keys have already been accepted, but the framework is being tested
|
|
|
|
and parameters are frequently changed in the Salt Master's configuration
|
2015-07-30 05:26:51 +00:00
|
|
|
file(s).
|
|
|
|
|
2015-07-30 05:39:46 +00:00
|
|
|
The Salt Master generates a new AES key to encrypt its publications at certain
|
|
|
|
events such as a Master restart or the removal of a Minion key. If you are
|
|
|
|
encountering this problem of too many minions re-authing against the Master,
|
2015-07-30 05:26:51 +00:00
|
|
|
you will need to recalibrate your setup to reduce the rate of events like a
|
2015-07-30 05:39:46 +00:00
|
|
|
Master restart or Minion key removal (``salt-key -d``).
|
2015-07-30 05:26:51 +00:00
|
|
|
|
2015-07-30 05:39:46 +00:00
|
|
|
When the Master generates a new AES key, the minions aren't notified of this
|
|
|
|
but will discover it on the next pub job they receive. When the Minion
|
|
|
|
receives such a job it will then re-auth with the Master. Since Salt does
|
2015-07-30 05:26:51 +00:00
|
|
|
minion-side filtering this means that all the minions will re-auth on the next
|
|
|
|
command published on the master-- causing another "thundering herd". This can
|
|
|
|
be avoided by setting the
|
2014-06-05 08:36:46 +00:00
|
|
|
|
|
|
|
.. code-block:: yaml
|
|
|
|
|
2014-06-07 06:55:25 +00:00
|
|
|
random_reauth_delay: 60
|
2014-06-05 08:36:46 +00:00
|
|
|
|
2014-07-02 10:39:58 +00:00
|
|
|
in the minions configuration file to a higher value and stagger the amount
|
|
|
|
of re-auth attempts. Increasing this value will of course increase the time
|
2015-07-30 05:39:46 +00:00
|
|
|
it takes until all minions are reachable via Salt commands.
|
2014-06-05 08:36:46 +00:00
|
|
|
|
2014-07-09 18:06:24 +00:00
|
|
|
Too many minions re-connecting
|
2014-08-11 16:33:55 +00:00
|
|
|
------------------------------
|
2015-07-30 05:28:27 +00:00
|
|
|
|
2014-07-09 18:06:24 +00:00
|
|
|
By default the zmq socket will re-connect every 100ms which for some larger
|
|
|
|
installations may be too quick. This will control how quickly the TCP session is
|
|
|
|
re-established, but has no bearing on the auth load.
|
2014-06-05 08:36:46 +00:00
|
|
|
|
2014-07-02 10:39:58 +00:00
|
|
|
To tune the minions sockets reconnect attempts, there are a few values in
|
2014-07-02 12:29:35 +00:00
|
|
|
the sample configuration file (default values)
|
2014-06-05 08:36:46 +00:00
|
|
|
|
|
|
|
.. code-block:: yaml
|
|
|
|
|
2016-03-31 19:50:51 +00:00
|
|
|
recon_default: 1000
|
2014-07-02 11:44:50 +00:00
|
|
|
recon_max: 5000
|
|
|
|
recon_randomize: True
|
2014-06-05 08:36:46 +00:00
|
|
|
|
2016-03-31 19:50:51 +00:00
|
|
|
- recon_default: the default value the socket should use, i.e. 1000. This value is in
|
|
|
|
milliseconds. (1000ms = 1 second)
|
2014-07-02 12:29:35 +00:00
|
|
|
- recon_max: the max value that the socket should use as a delay before trying to reconnect
|
2016-03-31 19:50:51 +00:00
|
|
|
This value is in milliseconds. (5000ms = 5 seconds)
|
2014-06-05 08:36:46 +00:00
|
|
|
- recon_randomize: enables randomization between recon_default and recon_max
|
|
|
|
|
2014-06-05 13:01:27 +00:00
|
|
|
To tune this values to an existing environment, a few decision have to be made.
|
2014-06-05 08:36:46 +00:00
|
|
|
|
|
|
|
|
2015-07-30 05:39:46 +00:00
|
|
|
1. How long can one wait, before the minions should be online and reachable via Salt?
|
2014-07-02 12:31:49 +00:00
|
|
|
|
2015-07-30 05:39:46 +00:00
|
|
|
2. How many reconnects can the Master handle without a syn flood?
|
2014-06-05 08:36:46 +00:00
|
|
|
|
2014-07-09 18:06:24 +00:00
|
|
|
These questions can not be answered generally. Their answers depend on the
|
|
|
|
hardware and the administrators requirements.
|
2014-06-05 08:36:46 +00:00
|
|
|
|
2014-07-02 11:44:50 +00:00
|
|
|
Here is an example scenario with the goal, to have all minions reconnect
|
2015-07-30 05:39:46 +00:00
|
|
|
within a 60 second time-frame on a Salt Master service restart.
|
2014-06-05 08:36:46 +00:00
|
|
|
|
|
|
|
.. code-block:: yaml
|
|
|
|
|
|
|
|
recon_default: 1000
|
|
|
|
recon_max: 59000
|
|
|
|
recon_randomize: True
|
|
|
|
|
2015-07-30 05:39:46 +00:00
|
|
|
Each Minion will have a randomized reconnect value between 'recon_default'
|
2014-06-05 08:36:46 +00:00
|
|
|
and 'recon_default + recon_max', which in this example means between 1000ms
|
2014-07-02 11:44:50 +00:00
|
|
|
and 60000ms (or between 1 and 60 seconds). The generated random-value will
|
2014-07-13 18:43:33 +00:00
|
|
|
be doubled after each attempt to reconnect (ZeroMQ default behavior).
|
2014-06-05 08:36:46 +00:00
|
|
|
|
|
|
|
Lets say the generated random value is 11 seconds (or 11000ms).
|
|
|
|
|
2014-08-11 16:33:55 +00:00
|
|
|
.. code-block:: bash
|
|
|
|
|
|
|
|
reconnect 1: wait 11 seconds
|
|
|
|
reconnect 2: wait 22 seconds
|
|
|
|
reconnect 3: wait 33 seconds
|
|
|
|
reconnect 4: wait 44 seconds
|
|
|
|
reconnect 5: wait 55 seconds
|
|
|
|
reconnect 6: wait time is bigger than 60 seconds (recon_default + recon_max)
|
|
|
|
reconnect 7: wait 11 seconds
|
|
|
|
reconnect 8: wait 22 seconds
|
|
|
|
reconnect 9: wait 33 seconds
|
|
|
|
reconnect x: etc.
|
2014-06-05 08:36:46 +00:00
|
|
|
|
|
|
|
With a thousand minions this will mean
|
|
|
|
|
2014-08-11 16:33:55 +00:00
|
|
|
.. code-block:: text
|
2014-06-05 08:36:46 +00:00
|
|
|
|
2014-07-09 18:06:24 +00:00
|
|
|
1000/60 = ~16
|
|
|
|
|
2014-07-02 11:44:50 +00:00
|
|
|
round about 16 connection attempts a second. These values should be altered to
|
|
|
|
values that match your environment. Keep in mind though, that it may grow over
|
|
|
|
time and that more minions might raise the problem again.
|
2014-06-05 08:36:46 +00:00
|
|
|
|
|
|
|
Too many minions returning at once
|
2014-08-11 16:33:55 +00:00
|
|
|
----------------------------------
|
2014-09-17 23:00:18 +00:00
|
|
|
|
2014-07-02 10:39:58 +00:00
|
|
|
This can also happen during the testing phase, if all minions are addressed at
|
2014-07-02 11:44:50 +00:00
|
|
|
once with
|
2014-06-05 08:36:46 +00:00
|
|
|
|
|
|
|
.. code-block:: bash
|
|
|
|
|
2016-02-24 23:56:52 +00:00
|
|
|
$ salt * disk.usage
|
2014-06-05 08:36:46 +00:00
|
|
|
|
2015-07-30 05:39:46 +00:00
|
|
|
it may cause thousands of minions trying to return their data to the Salt Master
|
|
|
|
open port 4506. Also causing a flood of syn-flood if the Master can't handle that many
|
2014-07-02 10:39:58 +00:00
|
|
|
returns at once.
|
2014-06-05 08:36:46 +00:00
|
|
|
|
2015-07-30 05:39:46 +00:00
|
|
|
This can be easily avoided with Salt's batch mode:
|
2014-06-05 08:36:46 +00:00
|
|
|
|
|
|
|
.. code-block:: bash
|
|
|
|
|
2016-02-24 23:56:52 +00:00
|
|
|
$ salt * disk.usage -b 50
|
2014-06-05 08:36:46 +00:00
|
|
|
|
2014-07-02 10:39:58 +00:00
|
|
|
This will only address 50 minions at once while looping through all addressed
|
|
|
|
minions.
|
2014-06-05 08:36:46 +00:00
|
|
|
|
2014-07-11 22:46:54 +00:00
|
|
|
Too few resources
|
2014-08-11 16:33:55 +00:00
|
|
|
=================
|
2014-09-17 23:00:18 +00:00
|
|
|
|
2014-07-02 10:39:58 +00:00
|
|
|
The masters resources always have to match the environment. There is no way
|
2015-07-30 05:39:46 +00:00
|
|
|
to give good advise without knowing the environment the Master is supposed to
|
2014-07-02 10:39:58 +00:00
|
|
|
run in. But here are some general tuning tips for different situations:
|
2014-06-05 08:36:46 +00:00
|
|
|
|
2015-07-30 05:39:46 +00:00
|
|
|
The Master is CPU bound
|
2014-08-11 16:33:55 +00:00
|
|
|
-----------------------
|
2014-09-17 23:00:18 +00:00
|
|
|
|
2014-07-02 10:39:58 +00:00
|
|
|
Salt uses RSA-Key-Pairs on the masters and minions end. Both generate 4096
|
2015-07-30 05:39:46 +00:00
|
|
|
bit key-pairs on first start. While the key-size for the Master is currently
|
2014-07-02 10:39:58 +00:00
|
|
|
not configurable, the minions keysize can be configured with different
|
|
|
|
key-sizes. For example with a 2048 bit key:
|
2014-06-05 08:36:46 +00:00
|
|
|
|
|
|
|
.. code-block:: yaml
|
|
|
|
|
|
|
|
keysize: 2048
|
|
|
|
|
2014-07-11 22:46:54 +00:00
|
|
|
With thousands of decryptions, the amount of time that can be saved on the
|
2014-07-02 10:39:58 +00:00
|
|
|
masters end should not be neglected. See here for reference:
|
2014-07-02 10:44:52 +00:00
|
|
|
`Pull Request 9235 <https://github.com/saltstack/salt/pull/9235>`_ how much
|
2014-07-02 10:39:58 +00:00
|
|
|
influence the key-size can have.
|
2014-06-05 13:01:27 +00:00
|
|
|
|
2015-07-30 05:39:46 +00:00
|
|
|
Downsizing the Salt Master's key is not that important, because the minions
|
|
|
|
do not encrypt as many messages as the Master does.
|
2014-06-05 08:36:46 +00:00
|
|
|
|
2016-01-25 17:43:16 +00:00
|
|
|
In installations with large or with complex pillar files, it is possible
|
|
|
|
for the master to exhibit poor performance as a result of having to render
|
|
|
|
many pillar files at once. This exhibit itself in a number of ways, both
|
|
|
|
as high load on the master and on minions which block on waiting for their
|
|
|
|
pillar to be delivered to them.
|
|
|
|
|
|
|
|
To reduce pillar rendering times, it is possible to cache pillars on the
|
|
|
|
master. To do this, see the set of master configuration options which
|
|
|
|
are prefixed with `pillar_cache`.
|
|
|
|
|
|
|
|
.. note::
|
|
|
|
|
|
|
|
Caching pillars on the master may introduce security considerations.
|
|
|
|
Be certain to read caveats outlined in the master configuration file
|
|
|
|
to understand how pillar caching may affect a master's ability to
|
|
|
|
protect sensitive data!
|
|
|
|
|
2015-07-30 05:39:46 +00:00
|
|
|
The Master is disk IO bound
|
2014-08-11 16:33:55 +00:00
|
|
|
---------------------------
|
2014-09-17 23:00:18 +00:00
|
|
|
|
2015-07-30 05:39:46 +00:00
|
|
|
By default, the Master saves every Minion's return for every job in its
|
2014-07-02 10:39:58 +00:00
|
|
|
job-cache. The cache can then be used later, to lookup results for previous
|
|
|
|
jobs. The default directory for this is:
|
2014-06-05 08:36:46 +00:00
|
|
|
|
|
|
|
.. code-block:: yaml
|
2014-07-02 11:51:47 +00:00
|
|
|
|
2014-06-05 08:36:46 +00:00
|
|
|
cachedir: /var/cache/salt
|
|
|
|
|
|
|
|
and then in the ``/proc`` directory.
|
|
|
|
|
2015-07-30 05:39:46 +00:00
|
|
|
Each job return for every Minion is saved in a single file. Over time this
|
2014-07-09 18:06:24 +00:00
|
|
|
directory can grow quite large, depending on the number of published jobs. The
|
|
|
|
amount of files and directories will scale with the number of jobs published and
|
|
|
|
the retention time defined by
|
2014-06-05 08:36:46 +00:00
|
|
|
|
|
|
|
.. code-block:: yaml
|
|
|
|
|
2014-07-09 18:06:24 +00:00
|
|
|
keep_jobs: 24
|
2014-06-05 08:36:46 +00:00
|
|
|
|
2014-08-11 16:33:55 +00:00
|
|
|
.. code-block:: text
|
2014-07-09 18:06:24 +00:00
|
|
|
|
2016-04-19 17:41:05 +00:00
|
|
|
250 jobs/day * 2000 minions returns = 500,000 files a day
|
2014-06-05 08:36:46 +00:00
|
|
|
|
2017-11-07 17:14:40 +00:00
|
|
|
Use and External Job Cache
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~
|
2014-06-05 08:36:46 +00:00
|
|
|
|
2017-11-07 17:14:40 +00:00
|
|
|
An external job cache allows for job storage to be placed on an external
|
|
|
|
system, such as a database.
|
2014-09-17 23:00:18 +00:00
|
|
|
|
2014-07-09 18:06:24 +00:00
|
|
|
- ext_job_cache: this will have the minions store their return data directly
|
2015-07-30 05:39:46 +00:00
|
|
|
into a returner (not sent through the Master)
|
|
|
|
- master_job_cache (New in `2014.7.0`): this will make the Master store the job
|
2015-07-30 05:26:51 +00:00
|
|
|
data using a returner (instead of the local job cache on disk).
|
2016-07-24 17:54:21 +00:00
|
|
|
|
|
|
|
If a master has many accepted keys, it may take a long time to publish a job
|
|
|
|
because the master much first determine the matching minions and deliver
|
|
|
|
that information back to the waiting client before the job can be published.
|
|
|
|
|
|
|
|
To mitigate this, a key cache may be enabled. This will reduce the load
|
|
|
|
on the master to a single file open instead of thousands or tens of thousands.
|
|
|
|
|
|
|
|
This cache is updated by the maintanence process, however, which means that
|
|
|
|
minions with keys that are accepted may not be targeted by the master
|
|
|
|
for up to sixty seconds by default.
|
|
|
|
|
|
|
|
To enable the master key cache, set `key_cache: 'sched'` in the master
|
|
|
|
configuration file.
|
2017-11-07 17:14:40 +00:00
|
|
|
|
|
|
|
Disable The Job Cache
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
The job cache is a central component of the Salt Master and many aspects of
|
2017-11-07 19:16:28 +00:00
|
|
|
the Salt Master will not function correctly without a running job cache.
|
2017-11-07 17:14:40 +00:00
|
|
|
|
2017-11-07 19:16:28 +00:00
|
|
|
Disabling the job cache is **STRONGLY DISCOURAGED** and should not be done
|
2017-11-07 17:14:40 +00:00
|
|
|
unless the master is being used to execute routines that require no history
|
|
|
|
or reliable feedback!
|
|
|
|
|
|
|
|
The job cache can be disabled:
|
|
|
|
|
|
|
|
.. code-block:: yaml
|
|
|
|
|
|
|
|
job_cache: False
|
|
|
|
|