In this guide, we are about to go through how to setup Saltstack configuration management tools in Centos Linux.
Install with two servers for SaltStack Server and Salt minion (client) server.
Set the hostname for salt server and minion server.
# hostnamectl set-hostname saltmaster.linuxgeekvideos.com # hostnamectl set-hostname minion.linuxgeekvideos.com
Hence we don’t have a DNS server adding localhost hosts entry.
192.168.107.194 saltmaster.linuxgeekvideos.com saltmaster salt 192.168.107.195 minion.linuxgeekvideos.com minion
By default, Saltstack server will use below ports. If we have firewalld enabled required to create firewalld rules.
4505 and 4506
To begin the installation add the yum repo
# sudo yum install https://repo.saltstack.com/yum/redhat/salt-repo-latest-2.el7.noarch.rpm# sudo yum install salt-master # sudo yum install salt-minion # sudo yum install salt-ssh # sudo yum install salt-syndic # sudo yum install salt-cloud # sudo yum install salt-api
The salt master configuration will be under location.
# ls -lthr /etc/salt
By default saltmaster will listen to all interfaces, to listen on only specific interface define directive as follows in master configuration.
# vi /etc/salt/master interface: 192.168.107.194 log_file: /var/log/salt/master
Save the configuration and start the salt master using below commands.
# systemctl status salt-master # systemctl start salt-master
Client Side Configuration:
Install with the same repository as above, and install with only the client side package.
# sudo yum install https://repo.saltstack.com/yum/redhat/salt-repo-latest-2.el7.noarch.rpm # sudo yum install salt-minion
Modify the client side configuration to talk with the salt master server by defining required directive.
# vi /etc/salt/minionmaster: saltmaster.linuxgeekvideos.com pidfile: /var/run/salt-minion.pid
Start the client service and check for status.
# systemctl start salt-minion # systemctl status salt-minion
List aall the keys in master server
# salt-key -F master
To list the keys in minion server
# salt-call --local key.finger
To list pending keys and to accept pending keys.
# salt-key -P # salt-key -A
Few ad-hoc commands
# salt '*' test.ping
Few ad-hoc commands
Sample Output:
[root@saltmaster ~]# salt '*' test.ping minion.linuxgeekvideos.com: True [root@saltmaster ~]#
To check uptime.
# sudo salt '*' cmd.run "uptime"
Sample Output:
[root@saltmaster ~]# sudo salt '*' cmd.run "uptime" minion.linuxgeekvideos.com: 12:50:38 up 12:57, 1 user, load average: 0.00, 0.01, 0.05 [root@saltmaster ~]#
Mount point details
# sudo salt '*' cmd.run df
Sample Output:
[root@saltmaster ~]# sudo salt '*' cmd.run df minion.linuxgeekvideos.com: Filesystem 1K-blocks Used Available Use% Mounted on /dev/mapper/linixvideogeek-root 10475520 4598156 5877364 44% / devtmpfs 165984 0 165984 0% /dev tmpfs 176392 12 176380 1% /dev/shm tmpfs 176392 12780 163612 8% /run tmpfs 176392 0 176392 0% /sys/fs/cgroup /dev/sda1 508588 172752 335836 34% /boot /dev/mapper/linixvideogeek-home 1038336 33012 1005324 4% /home tmpfs 35280 0 35280 0% /run/user/0 [root@saltmaster ~]#
To check the free output
# sudo salt '*' cmd.run free
Sample Output:
[root@saltmaster ~]# sudo salt '*' cmd.run free minion.linuxgeekvideos.com: total used free shared buff/cache available Mem: 352784 159368 48740 12432 144676 126556 Swap: 524284 3792 520492 [root@saltmaster ~]#
Listing all available minion functions.
# salt '*' sys.doc # salt '*' disk.usage # salt '*' pkg.install vim # salt '*' cmd.run 'ls -l /etc' # salt '*' network.interfaces
To make more configuration under salt master we can uncomment and add more directives as per the requirement for our environment.