Contexte :

Nous allons voir comment configurer un cluster de Seach Head (SHC) dans le cadre d'un POC (pas d'optimisation), pour cela nous allons utiliser vagrant.

Nous utiliserons des CentOS 8 avec Splunk en version 8.2.1.

Préparation de l'environnement avec Vagrant :

Nous partirons avec 3 SH et 1 US (Utility Server, Splunk Core avec une fonctionnalité spécique) qui aura le rôle de Deployer (deploiement de config SH).
Utilisation de la doc : SHC deployement Overview v8.2.1

Vagrantfile :

  1 $ mkdir -p ~/.my_vagrant/demoSplunkSHC
  2 
  3 $ vi ~/.my_vagrant/demoSplunkSHC/Vagrantfile
  4 
  5 #Version 0.1
  6 # Command system/custom/add packages ....
  7 $packagesinstall = <<-SCRIPT
  8     # Package custom
  9     sudo yum install -y lsof vim git bind-utils
 10 
 11     # Package to Splunk health check iowait
 12     sudo yum install -y sysstat
 13 
 14 
 15     # Package installing
 16     echo "# Splunk RPM installation"
 17     sudo yum localinstall -y /vagrant/splunk-8.2.1-ddff1c41e5cf-linux-2.6-x86_64.rpm
 18 
19 # Setup Splunk config 20 echo "# Set permissions on Splunk folder" 21 sudo chown -R vagrant:vagrant /opt/splunk 22 23 # Splunk apps : 24 # Manage min Free Space to POC instance 25 echo "# Set minFreeSpace to POC instance" 26 sudo mkdir -p /opt/splunk/etc/apps/my_customsplunk/local/ 27 sudo echo "[diskUsage]" > /opt/splunk/etc/apps/my_customsplunk/local/server.conf 28 sudo echo "minFreeSpace = 50" >> /opt/splunk/etc/apps/my_customsplunk/local/server.conf 29 sudo chown -R vagrant:vagrant /opt/splunk/etc/apps/my_customsplunk/ 30 31 32 echo "# Splunk activation on boot with Vagrant user" 33 sudo /opt/splunk/bin/splunk enable boot-start -systemd-managed 1 --accept-license -user vagrant --seed-passwd changeme 34 35 echo "# Launch Splunk" 36 sudo /opt/splunk/bin/splunk start --no-prompt 37 SCRIPT 38 39 #Get IP to display after vagrant up 40 $getip= <<-SCRIPT 41 echo "IP of $(hostname) : " 42 ip -4 addr sh eth1 43 echo "" 44 echo "Splunk Version ; " 45 /opt/splunk/bin/splunk version 46 SCRIPT 47 48 #Message post up 49 $postupmessage = <<-SCRIPT 50 Congratulations VM/box available. 51 Generate by Vagrant ! 52 SCRIPT 53 54 #Customise OS env 55 $customenv= <<-SCRIPT 56 echo "Custom environnement" 57 #Bash profile 58 echo "Set .bash_profile to Vagrant user" 59 sudo curl -sk "https://raw.githubusercontent.com/alasta/dotfiles/master/.bash_profile_vagrant" -o /home/vagrant/.bash_profile 60 61 #inputrc 62 echo "Set inputrc" 63 echo "Set inputrc to Vagrant user" 64 sudo curl -sk "https://raw.githubusercontent.com/alasta/dotfiles/master/.inputrc" -o /home/vagrant/.inputrc
65
66 #.vimrc 67 echo "Set vimrc" 68 sudo curl -sk "https://raw.githubusercontent.com/alasta/dotfiles/master/.vimrc" -o /home/vagrant/.vimrc 69
70 #bash profile and inputrc to root 71 sudo curl -sk "https://raw.githubusercontent.com/alasta/dotfiles/master/.bash_profile_root" -o /root/.bash_profile 72 73 #Set timezone 74 echo "# Set timezone" 75 timedatectl set-timezone 'Europe/Paris' 76 77 # Manage DNS server to disable DNS on private net 78 echo "# Disable DNS private net" 79 sudo sed -i -e 's/.*10.0/#&/g' /etc/resolv.conf 80 81 SCRIPT 82 83 84 #Config box 85 Vagrant.configure("2") do |config| 86 (1..3).each do |i| 87 config.vm.define "shc#{i}" do |vm1| 88 #vm1.vm.provider "virtualbox" do |v| 89 # v.memory = 2048 90 # v.cpus = 2 91 #end 92 #vm1.vm.box = "centos/7" 93 vm1.vm.box = "centos/8" 94 vm1.vm.hostname = "shc#{i}" 95 vm1.vm.box_url = "centos/8" 96 vm1.vm.network "public_network", bridge: "en0: Wi-Fi (AirPort)", auto_config: false 97 vm1.vm.provision "file", source: "~/Downloads/splunk-8.2.1-ddff1c41e5cf-linux-2.6-x86_64.rpm", destination: "/vagrant/" 98 vm1.vm.provision "shell", inline: $packagesinstall 99 vm1.vm.provision "shell", inline: $customenv 100 vm1.vm.provision "shell", inline: $getip, run: "always" 101 vm1.vm.post_up_message = $postupmessage 102 #vm1.vm.provision "shell", inline: "ip -4 addr sh eth1", run: "always" 103 end 104 end 105 config.vm.define "us1" do |vm1| 106 #vm1.vm.provider "virtualbox" do |v| 107 # v.memory = 2048 108 # v.cpus = 2 109 #end 110 #vm1.vm.box = "centos/7" 111 vm1.vm.box = "centos/8" 112 vm1.vm.hostname = 'us1' 113 vm1.vm.box_url = "centos/8" 114 vm1.vm.network "public_network", bridge: "en0: Wi-Fi (AirPort)", auto_config: false 115 vm1.vm.provision "file", source: "~/Downloads/splunk-8.2.1-ddff1c41e5cf-linux-2.6-x86_64.rpm", destination: "/vagrant/" 116 vm1.vm.provision "shell", inline: $packagesinstall 117 vm1.vm.provision "shell", inline: $customenv 118 vm1.vm.provision "shell", inline: $getip, run: "always" 119 vm1.vm.post_up_message = $postupmessage 120 #vm1.vm.provision "shell", inline: "ip -4 addr sh eth1", run: "always" 121 end 122 123 end

Déploiement de l'environnement :

1 $ vagrant up
2 ....

Un moment plus tard ....
Disponible aussi via GitHub (avec les updates futures).

Config Splunk :

Deployer :

Sur us1

1 $ cd /opt/splunk/etc/apps
2 
3 $ mkdir -p myappdeployer/local
4 
5 $ vi myappdeployer/local/server.conf
6 [shclustering]
7 pass4SymmKey = mysecuritykey
8 shcluster_label = shclusterpoc

Redémarrage pour prise en compte :

1 $ sudo systemctl restart Splunkd

Note : au redémarrage, le pass4SymmKey va être chiffré.

Récupérer les fichiers suivants et les déployer sur toutes les autres instances Splunk core/full install :

  • $SPLUNK_HOME/etc/auth/splunk.secret
  • $SPLUNK_HOME/etc/passwd

Si l'instance a déjà démarrée avant la mise en place de ces fichiers, il faudra stopper Splunkd, supprimer les paramètres :

  • sslPassword
  • pass4SymmKey
    Dans le fichier $SPLUNK_HOME/etc/system/local/server.conf et redémarrer Splunkd.

Config SH Cluster :

Sur les 3 SH :

1 $ /opt/splunk/bin/splunk init shcluster-config -auth admin:changeme -mgmt_uri https://"$(hostname)".udmiot.lab:8089  -replication_port 9001 -replication_factor 2 -conf_deploy_fetch_url https://us1.udmiot.lab:8089 -secret mysecuritykey -shcluster_label shclusterpoc
2 Search head clustering has been initialized on this node.
3 You need to restart the Splunk Server (splunkd) for your changes to take effect.

On déclarre chaque membre comme faisant parti du cluster de SH avec le port de management, le compte admin (initialisé à l'installation), le port de réplication, le replication factor, le deployer et les informations du server.conf du deployer.

Redémarrage pour prise en compte :

1 $ sudo systemctl restart Splunkd

Election du captain :

Choisir un des SH pour être le premier Captain, il évoluera dans le temps :
Nous choisirons le shc1 :

1 $ /opt/splunk/bin/splunk bootstrap shcluster-captain -servers_list "https://shc1.udmiot.lab:8089,https://shc2.udmiot.lab:8089,https://shc3.udmiot.lab:8089" -auth admin:changeme
2 Successfully bootstrapped this node as the captain with the given servers.

Vérifications :

Sur tous les SH :
Etat du SHC :

 1 $ /opt/splunk/bin/splunk show shcluster-status -auth admin:changeme
 2 
 3  Captain:
 4                     dynamic_captain : 1
 5                     elected_captain : Mon Aug  9 22:33:02 2021
 6                                  id : 90F41B44-625A-4F69-BA23-4AD2435AEBC2
 7                    initialized_flag : 1
 8                               label : shc1
 9                            mgmt_uri : https://shc1.udmiot.lab:8089
10               min_peers_joined_flag : 1
11                rolling_restart_flag : 0
12                  service_ready_flag : 1
13 
14  Members:
15  shc2
16                               label : shc2
17               last_conf_replication : Mon Aug  9 22:34:11 2021
18                            mgmt_uri : https://shc2.udmiot.lab:8089
19                      mgmt_uri_alias : https://192.168.3.199:8089
20                              status : Up
21  shc3
22                               label : shc3
23               last_conf_replication : Mon Aug  9 22:34:09 2021
24                            mgmt_uri : https://shc3.udmiot.lab:8089
25                      mgmt_uri_alias : https://192.168.3.92:8089
26                              status : Up
27  shc1
28                               label : shc1
29                            mgmt_uri : https://shc1.udmiot.lab:8089
30                      mgmt_uri_alias : https://192.168.3.75:8089
31                              status : Up

Etat du KVStore :

 1 $ /opt/splunk/bin/splunk show kvstore-status -auth admin:changeme
 2 
 3  This member:
 4                 backupRestoreStatus : Ready
 5                                date : Mon Aug  9 22:35:34 2021
 6                             dateSec : 1628541334.208
 7                            disabled : 0
 8                                guid : D367F1FD-1006-44AD-95B1-BF085AB23AA5
 9                   oplogEndTimestamp : Mon Aug  9 22:35:33 2021
10                oplogEndTimestampSec : 1628541333
11                 oplogStartTimestamp : Mon Aug  9 22:33:15 2021
12              oplogStartTimestampSec : 1628541195
13                                port : 8191
14                          replicaSet : splunkrs
15                   replicationStatus : Non-captain KV store member
16                          standalone : 0
17                              status : ready
18                       storageEngine : mmapv1
19 
20  Enabled KV store members:
21  shc2.udmiot.lab:8191
22                                guid : 061286CC-8D57-4EDE-8EC1-24A15D9105D5
23                         hostAndPort : shc2.udmiot.lab:8191
24  shc3.udmiot.lab:8191
25                                guid : B3301141-F2CE-4597-ADD5-A34E58A03A42
26                         hostAndPort : shc3.udmiot.lab:8191
27  shc1.udmiot.lab:8191
28                                guid : D367F1FD-1006-44AD-95B1-BF085AB23AA5
29                         hostAndPort : shc1.udmiot.lab:8191
30 
31  KV store members:
32  shc2.udmiot.lab:8191
33                       configVersion : 1
34                        electionDate : Mon Aug  9 22:33:26 2021
35                     electionDateSec : 1628541206
36                         hostAndPort : shc2.udmiot.lab:8191
37                       lastHeartbeat : Mon Aug  9 22:35:33 2021
38                   lastHeartbeatRecv : Mon Aug  9 22:35:32 2021
39                lastHeartbeatRecvSec : 1628541332.81
40                    lastHeartbeatSec : 1628541333.956
41                          optimeDate : Mon Aug  9 22:35:33 2021
42                       optimeDateSec : 1628541333
43                              pingMs : 4
44                   replicationStatus : KV store captain
45                              uptime : 138
46  shc3.udmiot.lab:8191
47                       configVersion : 1
48                         hostAndPort : shc3.udmiot.lab:8191
49                       lastHeartbeat : Mon Aug  9 22:35:34 2021
50                   lastHeartbeatRecv : Mon Aug  9 22:35:33 2021
51                lastHeartbeatRecvSec : 1628541333.739
52                    lastHeartbeatSec : 1628541334.141
53                          optimeDate : Mon Aug  9 22:35:33 2021
54                       optimeDateSec : 1628541333
55                              pingMs : 0
56                   replicationStatus : Non-captain KV store member
57                              uptime : 133
58  shc1.udmiot.lab:8191
59                       configVersion : 1
60                         hostAndPort : shc1.udmiot.lab:8191
61                          optimeDate : Mon Aug  9 22:35:33 2021
62                       optimeDateSec : 1628541333
63                   replicationStatus : Non-captain KV store member
64                              uptime : 363

Test de bacule du captain :

Nous allons tester la bascule du captain, pour cela nous allons arrêter le service Splunkd sur le captain actuel, ici shc1 :
Sur shc1 :

1 sudo systemctl stop Splunkd

Sur un autre SH, ici shc2 :

1 $ /opt/splunk/bin/splunk show shcluster-status -auth admin:changeme
2 
3  Encountered some errors while trying to obtain shcluster status.
4 Failed to proxy call to member https://shc1.udmiot.lab:8089.

Pendant quelques minutes le cluster est en erreur le temps que la ré-élection se relance.

Aprés quelques minutes :

 1 $ /opt/splunk/bin/splunk show shcluster-status -auth admin:changeme
 2 
 3  Captain:
 4                     dynamic_captain : 1
 5                     elected_captain : Mon Aug  9 22:39:42 2021
 6                                  id : 90F41B44-625A-4F69-BA23-4AD2435AEBC2
 7                    initialized_flag : 1
 8                               label : shc3
 9                            mgmt_uri : https://shc3.udmiot.lab:8089
10               min_peers_joined_flag : 1
11                rolling_restart_flag : 0
12                  service_ready_flag : 1
13 
14  Members:
15  shc2
16                               label : shc2
17               last_conf_replication : Mon Aug  9 22:40:32 2021
18                            mgmt_uri : https://shc2.udmiot.lab:8089
19                      mgmt_uri_alias : https://192.168.3.199:8089
20                              status : Up
21  shc3
22                               label : shc3
23                            mgmt_uri : https://shc3.udmiot.lab:8089
24                      mgmt_uri_alias : https://192.168.3.92:8089
25                              status : Up
26  shc1
27                               label : shc1
28               last_conf_replication : Mon Aug  9 22:38:18 2021
29                            mgmt_uri : https://shc1.udmiot.lab:8089
30                      mgmt_uri_alias : https://192.168.3.75:8089
31                              status : Down

Retour à la normale :

Redémarrage du service Splunkd sur shc1 :

1 $ sudo systemctl start Splunkd

Etat du cluster :

 1 $ /opt/splunk/bin/splunk show shcluster-status -auth admin:changeme
 2 
 3  Captain:
 4                     dynamic_captain : 1
 5                     elected_captain : Mon Aug  9 22:39:42 2021
 6                                  id : 90F41B44-625A-4F69-BA23-4AD2435AEBC2
 7                    initialized_flag : 1
 8                               label : shc3
 9                            mgmt_uri : https://shc3.udmiot.lab:8089
10               min_peers_joined_flag : 1
11                rolling_restart_flag : 0
12                  service_ready_flag : 1
13 
14  Members:
15  shc2
16                               label : shc2
17               last_conf_replication : Mon Aug  9 22:43:27 2021
18                            mgmt_uri : https://shc2.udmiot.lab:8089
19                      mgmt_uri_alias : https://192.168.3.199:8089
20                              status : Up
21  shc3
22                               label : shc3
23                            mgmt_uri : https://shc3.udmiot.lab:8089
24                      mgmt_uri_alias : https://192.168.3.92:8089
25                              status : Up
26  shc1
27                               label : shc1
28               last_conf_replication : Mon Aug  9 22:43:27 2021
29                            mgmt_uri : https://shc1.udmiot.lab:8089
30                      mgmt_uri_alias : https://192.168.3.75:8089
31                              status : Up

Deployer une apps type Dashboard sur le SHC :

Sur le deployer us1 :
Télécharger une app sur la Splunkbase ici Splunk App for Infrastructure :

1 $ cd /opt/splunk/etc/shcluster/apps/
2 
3 $ tar xzf /PATH/OF/splunk-app-for-infrastructure_224.tgz
4 5 $ ln -s ../../apps/my_customsplunk/

Note :

  • On se positionne dans le dossier du deployer
  • On décompresse l'app
  • On fait un lien symbolique vers l'app qui configure le minFreeSpace (utile que dans un POC avec un petit disque) car le deployer va faire du ménage dans le $SPLUNK_HOME/etc/apps des SH

Déployement :

1 $ /opt/splunk/bin/splunk apply shcluster-bundle -target https://shc1.udmiot.lab:8089
2  Warning: Depending on the configuration changes being pushed, this command might initiate a rolling restart of the cluster members.  Please refer to the documentation for the details. Do you wish to continue? [y/n]: y
3 Splunk username: admin
4 Password:
5 
6 Bundle has been pushed successfully to all the cluster members.

Note : En fonction de la configuration les SH auront peut être besoin de redémarrer ce qui implique une indisponibilité des SH.

Vérifications :
Sur les SH :

1 $ ll /opt/splunk/etc/apps | grep splunk_app_infrastructure
2 drwx------. 10 vagrant vagrant  206 2021-08-09 22:59:14 splunk_app_infrastructure

Annexes :

Doc Officielle pour monter un SHC Aplura - CheatSheet SHC