Quick Setup of Salt on CentOS/RHEL
Just some quick notes on installing and configuring Salt master server and minions to run remote commands for various sysamdin needs.
Installing Salt Master
[label type=”important”]Note[/label] you may need to enable EPEL repo. For some quick instructions, check here.
yum install salt-master -y chkconfig salt-master on
Edit /etc/salt/master and add a line “interface: master_ip_address”, where “master_ip_address” is the IP address of the Salt master server’s primary network interface to be used for Salt-related tasks. Once the “interface” line is added, start Salt master:
service salt-master start
Installing Salt Minions
yum install salt-minion -y chkconfig salt-minion on echo "master: master_ip_address" >> /etc/salt/minion service salt-minion start
You can also use FQDN or even short hostname for the Salt Master, as long as the minion node can correctly resolve it. However, if you do use a hostname instead of IP, it is a good idea to have the corresponding entry in /etc/hosts on every minion and not rely on DNS. You wouldn’t want to lose your entire Salt environment if DNS becomes unavailable.
You request the key from a specific Salt minion by running:
salt-key -a minion_node
In this case, “minion_node” is the FQDN of a particular Salt minion. This will not automatically add the minion’s key to the Salt inventory: it will just put it on the “pending” list. To view pending keys and accept them, run the following on the Salt master:
salt-key -L # to view what's what salt-key -A # to accept everything
Running Remote Commands
Just a few simple remote execution commands:
[root@saltshaker salt]# salt '*' test.ping minion01a.krazyworks.com: True minion01b.krazyworks.com: True
[root@saltshaker salt]# salt '*' cmd.run "uname -a ; uptime" minion01a.krazyworks.com: Linux minion01a.krazyworks.com 2.6.32-131.0.15.el6.x86_64 #1 SMP Tue May 10 15:42:40 EDT 2011 x86_64 x86_64 x86_64 GNU/Linux 14:56:22 up 170 days, 23:36, 2 users, load average: 0.00, 0.01, 0.00 minion01b.krazyworks.com: Linux minion01b.krazyworks.com 2.6.32-431.3.1.el6.x86_64 #1 SMP Fri Jan 3 21:39:27 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux 14:56:22 up 202 days, 3:18, 0 users, load average: 0.05, 0.18, 0.19