Manage server configurations through SaltStack
When I searched for alternatives to Puppet, I accidentally met Salt. I like puppet, but I love Salt again :). I found that Salt is easier to configure and use than Puppet. Of course, this is just a saying. You don't have to worry about it. Another reason for falling in love with Salt is that it allows you to manage server configurations from the command line, such:
To update all servers through Salt, you only need to run the following command:
- Salt '* 'pkg. upgrade
Install SaltStack on Linux
If you are installing it on CentOS 6/7, you can obtain it through the EPEL repository. For Pi and Ubuntu Linux users, you can add the Salt repository here. Salt is based on python, so you can use 'pip 'to install it, but you have to use yum-utils or other package manager to handle its dependencies on your own.
Salt adopts the server-client mode. The server is called the Lord, while the client is called the subordinate.
Install and configure the Salt lord
- [Root @ salt-master ~] # Yum install salt-master
The Salt configuration file is located at/etc/salt and/srv/salt. Although Salt can be used out of the box, I suggest you configure the log in more detail to facilitate troubleshooting in the future.
- [Root @ salt-master ~] # Vim/etc/salt/master
- # The default value is warning. The modification is as follows:
- Log_level: debug
- Log_level_logfile: debug
-
- [Root @ salt-master ~] # Systemctl start salt-master
Install and configure Salt subordinates
- [Root @ salt-minion ~] # Yum install salt-minion
-
- # Add the Host Name of your Salt lord
- [Root @ salt-minion ~] # Vim/etc/salt/minion
- Master: salt-master.com
- # Start subordinates
- [Root @ salt-minion ~] Systemctl start salt-minion
At startup, a subordinate customer generates a key and an id. It then connects to the Salt Lord server and verifies its identity. The Salt Lord server must accept the subordinate key before allowing its subordinate clients to download the configuration.
List and accept keys on the Salt Lord Server
- # List all keys
- [Root @ salt-master ~] Salt-key-L
- AcceptedKeys:
- UnacceptedKeys:
- Minion.com
- RejectedKeys:
-
- # Use the id 'minion. com' command to receive the key
- [Root @ salt-master ~] Salt-key-a minion.com
-
- [Root @ salt-master ~] Salt-key-L
- AcceptedKeys:
- Minion.com
- UnacceptedKeys:
- RejectedKeys:
After accepting the secret of a subordinate client, you can use the 'salt' command to obtain information immediately.
Salt command line instance
- # Check whether subordinates are started and running
- [Root @ salt-master ~] Salt 'minion. com' test. ping
- Minion.com:
- True
- # Run shell commands on subordinate clients
- [Root @ salt-master ~] # Salt 'minion. com 'cmd. run 'LS-l'
- Minion.com:
- Total 2988
- -Rw-r --. 1 root 1024Jul3108: 241g. img
- -Rw -------. 1 root 940Jul1415: 04 anaconda-ks.cfg
- -Rw-r --. 1 root 1024Aug1417: 21 test
- # Install/update software on all servers
- [Root @ salt-master ~] # Salt '* 'pkg. install git
The salt Command requires some components to send information, one of which is the id of the subordinate client, and the other is the function to be called on the subordinate client.
In the first instance, I used the 'ping' FUNCTION OF THE 'test' module to check whether the system was started. This function does not actually implement a ping. It only returns 'true' when the subordinate client responds '.
'COMMAND. run' is used to execute remote commands, while the 'pkg 'module contains package management functions. At the end of this article, a list of all built-in modules is provided.
Granular instance
Salt uses a page named Grains to obtain system information. You can use particles to run commands on the system with the specified attributes.
- [Root @ vps4544 ~] # Salt-g' OS: Centos 'test. ping
- Minion:
- True
For more details, please continue to read the highlights on the next page: