Splunk - Configuration d'un cluster d'indexers
Alasta 21 Août 2021 splunk splunk admin cli vagrant cluster
Description : Nous allons voir comment configurer un cluster d'indexers multisites.
Contexte :
Nous allons voir comment configurer un cluster d'indexers multisites dans le cadre d'un POC (pas d'optimisations), pour cela nous allons utiliser vagrant.
Nous utiliserons des CentOS 8 avec Splunk en version 8.2.1.
Nous aurons aussi besoin du cluster de SH que nous avons créé dans l'article ICI.
Nous utiliserons la documentation suivantes :
Préparation de l'environnement avec Vagrant :
Nous partirons avec 4 IDX (idx1-4) et un 1 US (us2) pour le Cluster Master/Manager Nodes.
Vagrantfile :
1 $ mkdir -p ~/.my_vagrant/demoSplunkIDXCluster
2
3 $ vi ~/.my_vagrant/demoSplunkIDXCluster/Vagrantfile
4 #Version 0.1
5 # Command system/custom/add packages ....
6 $packagesinstall = <<-SCRIPT
7 # Package custom
8 sudo yum install -y lsof vim git bind-utils
9
10 # Package to Splunk health check iowait
11 sudo yum install -y sysstat
12
13
14 # Package installing
15 echo "# Splunk RPM installation"
16 sudo yum localinstall -y /vagrant/splunk-8.2.1-ddff1c41e5cf-linux-2.6-x86_64.rpm
17
18 # Setup Splunk config
19 echo "# Set permissions on Splunk folder"
20 sudo chown -R vagrant:vagrant /opt/splunk
21
22 # Splunk apps :
23 # Manage min Free Space to POC instance
24 echo "# Set minFreeSpace to POC instance"
25 sudo mkdir -p /opt/splunk/etc/apps/my_customsplunk/local/
26 sudo echo "[diskUsage]" > /opt/splunk/etc/apps/my_customsplunk/local/server.conf
27 sudo echo "minFreeSpace = 50" >> /opt/splunk/etc/apps/my_customsplunk/local/server.conf
28 sudo chown -R vagrant:vagrant /opt/splunk/etc/apps/my_customsplunk/
29
30
31 echo "# Splunk activation on boot with Vagrant user"
32 sudo /opt/splunk/bin/splunk enable boot-start -systemd-managed 1 --accept-license -user vagrant --seed-passwd changeme
33
34 echo "# Launch Splunk"
35 sudo /opt/splunk/bin/splunk start --no-prompt
36 SCRIPT
37
38 #Get IP to display after vagrant up
39 $getip= <<-SCRIPT
40 echo "IP of $(hostname) : "
41 ip -4 addr sh eth1
42 echo ""
43 echo "Splunk Version ; "
44 /opt/splunk/bin/splunk version
45 SCRIPT
46 #Message post up
47 $postupmessage = <<-SCRIPT
48 Congratulations VM/box available.
49 Generate by Vagrant !
50 SCRIPT
51
52
53 #Customise OS env
54 $customenv= <<-SCRIPT
55 echo "Custom environnement"
56 #Bash profile
57 echo "Set .bash_profile to Vagrant user"
58 sudo curl -sk "https://raw.githubusercontent.com/alasta/dotfiles/master/.bash_profile_vagrant" -o /home/vagrant/.bash_profile
59
60 #inputrc
61 echo "Set inputrc"
62 echo "Set inputrc to Vagrant user"
63 sudo curl -sk "https://raw.githubusercontent.com/alasta/dotfiles/master/.inputrc" -o /home/vagrant/.inputrc
64
65 #.vimrc
66 echo "Set vimrc"
67 sudo curl -sk "https://raw.githubusercontent.com/alasta/dotfiles/master/.vimrc" -o /home/vagrant/.vimrc
68
69 #bash profile and inputrc to root
70 sudo curl -sk "https://raw.githubusercontent.com/alasta/dotfiles/master/.bash_profile_root" -o /root/.bash_profile
71
72 #Set timezone
73 echo "# Set timezone"
74 timedatectl set-timezone 'Europe/Paris'
75
76 # Manage DNS server to disable DNS on private net
77 echo "# Disable DNS private net"
78 sudo sed -i -e 's/.10.0.//g' /etc/resolv.conf
79
80 SCRIPT
81
82
83 #Config box
84 Vagrant.configure("2") do |config|
85 (1..4).each do |i|
86 config.vm.define "idx#{i}" do |vm1|
87 #vm1.vm.provider "virtualbox" do |v|
88 # v.memory = 2048
89 # v.cpus = 2
90 #end
91 #vm1.vm.box = "centos/7"
92 vm1.vm.box = "centos/8"
93 vm1.vm.hostname = "idx#{i}"
94 vm1.vm.box_url = "centos/8"
95 vm1.vm.network "public_network", bridge: "en0: Wi-Fi (AirPort)", auto_config: false
96 vm1.vm.provision "file", source: "~/Downloads/splunk-8.2.1-ddff1c41e5cf-linux-2.6-x86_64.rpm", destination: "/vagrant/"
97 vm1.vm.provision "shell", inline: $packagesinstall
98 vm1.vm.provision "shell", inline: $customenv
99 vm1.vm.provision "shell", inline: $getip, run: "always"
100 vm1.vm.post_up_message = $postupmessage
101 #vm1.vm.provision "shell", inline: "ip -4 addr sh eth1", run: "always"
102 end
103 end
104 config.vm.define "us2" do |vm1|
105 #vm1.vm.provider "virtualbox" do |v|
106 # v.memory = 2048
107 # v.cpus = 2
108 #end
109 #vm1.vm.box = "centos/7"
110 vm1.vm.box = "centos/8"
111 vm1.vm.hostname = 'us2'
112 vm1.vm.box_url = "centos/8"
113 vm1.vm.network "public_network", bridge: "en0: Wi-Fi (AirPort)", auto_config: false
114 vm1.vm.provision "file", source: "~/Downloads/splunk-8.2.1-ddff1c41e5cf-linux-2.6-x86_64.rpm", destination: "/vagrant/"
115 vm1.vm.provision "shell", inline: $packagesinstall
116 vm1.vm.provision "shell", inline: $customenv
117 vm1.vm.provision "shell", inline: $getip, run: "always"
118 vm1.vm.post_up_message = $postupmessage
119 #vm1.vm.provision "shell", inline: "ip -4 addr sh eth1", run: "always"
120 end
121
122 end
Déploiement de l'environnement :
1 $ vagrant up
2 ....
Un moment plus tard ....
Disponible aussi via GitHub (avec les updates futures).
Note :
Nous avons besoin du cluster de Search Head, il ne faut pas oublier d'utiliser celui créer dans le précédent article.
Utiliser le splunk.secret et passwd identique de ceux utilisés par les SHC.
Configuration de Splunk :
Cluster Master / Manager Nodes :
Sur us2 :
1 $ cd /opt/splunk/etc/apps
2
3 $ mkdir -p myappclustermaster/local
4
5 $ vi myappclustermaster/local/server.conf
6 [general]
7 site = site1
8
9 [clustering]
10 mode = manager
11 multisite = true
12 available_sites = site1,site2
13 site_replication_factor = origin:1,total:2
14 site_search_factor = origin:1,total:2
15 pass4SymmKey = mysecuritykey2
16 cluster_label = idxclusterpoc
17 #To set default parameter
18 replication_factor=2
19 search_factor=2
Redémarrage de Splunk pour prise en compte des modifications :
1 $ sudo systemctl restart Splunkd
Indexers :
Comme nous allons mettre en place un cluster multi-site, il faut définir quel IDX sera sur quel site :
- Site 1 : IDX 1 & 2
- Site 2 : IDX 3 & 4
Il y a une configuration minimale à faire en local pour indiquer le site.
Site 1 :
1 $ cd /opt/splunk/etc/apps
2
3 $ mkdir -p myappclusteridxsite1/local
4
5 $ vi myappclusteridxsite1/local/server.conf
6 [general]
7 site = site1
Site 2 :
1 $ cd /opt/splunk/etc/apps
2
3 $ mkdir -p myappclusteridxsite2/local
4
5 $ vi myappclusteridxsite2/local/server.conf
6 [general]
7 site = site2
Et une autre app pour déclarer le Cluster Master, sur les 2 sites.
1 $ cd /opt/splunk/etc/apps
2
3 $ mkdir -p myappclusteridxcommon/local
4
5 $ vi myappclusteridxcommon/local/server.conf
6 [replication_port://9887]
7 disabled = false
8
9 [clustering]
10 manager_uri = https://us2.udmiot.lab:8089
11 mode = peer
12 pass4SymmKey = mysecuritykey2
Redémarrage de Splunk pour prise en compte :
1 $ sudo systemctl restart Splunkd
Vérifions l'état du cluster IDX : Depuis us2 (Cluster Master)
1 $ /opt/splunk/bin/splunk show cluster-status
2
3 Replication factor met
4 Search factor met
5 All data is searchable
6 Indexing Ready YES
7
8 idx2 15E8906A-A42A-4100-ACFF-36331EDAFBFB site1
9 Searchable YES
10 Status Up
11 Bucket Count=7
12
13 idx3 5EC1F638-E8CC-48BC-9C4E-E1953BACDBC4 site2
14 Searchable YES
15 Status Up
16 Bucket Count=6
17
18 idx4 676DC36E-DABC-410D-9A53-173208E62249 site2
19 Searchable YES
20 Status Up
21 Bucket Count=6
22
23 idx1 A795DCB4-0B27-43CB-B461-836E132101D2 site1
24 Searchable YES
25 Status Up
26 Bucket Count=5
Nous allons ouvrir un port de collecte sur les IDX, pour cela nous allons passer par le Cluster Master pour déployer l'app. Sur us2 :
1 $ cd /opt/splunk/etc/master-apps
2
3 $ mkdir -p myappclusteridxcommon/local/
4
5 $ vi myappclusteridxcommon/local/inputs.conf
6 [splunktcp://9997]
Déployement sur les IDX :
1 $ /opt/splunk/bin/splunk apply cluster-bundle
2 Created new bundle with checksum=51C3FCC91493AC2C60D916C09EF5C2B3
3 Applying new bundle. The peers may restart depending on the configurations in applied bundle.
4 Please run 'splunk show cluster-bundle-status' for checking the status of the applied bundle.
5 OK
Vérification du déployement du bundle sur les IDX.
Depuis us2 :
1 $ splunk show cluster-bundle-status
2
3 master
4 cluster_status=Rolling restart of the peers is in progress.
5 active_bundle
6 checksum=51C3FCC91493AC2C60D916C09EF5C2B3
7 timestamp=1629578526 (in localtime=Sat Aug 21 22:42:06 2021)
8 latest_bundle
9 checksum=51C3FCC91493AC2C60D916C09EF5C2B3
10 timestamp=1629578526 (in localtime=Sat Aug 21 22:42:06 2021)
11 last_validated_bundle
12 checksum=51C3FCC91493AC2C60D916C09EF5C2B3
13 last_validation_succeeded=1
14 timestamp=1629578526 (in localtime=Sat Aug 21 22:42:06 2021)
15 last_check_restart_bundle
16 last_check_restart_result=restart not required
17 checksum=
18 timestamp=0 (in localtime=Thu Jan 1 01:00:00 1970)
19
20 idx2 15E8906A-A42A-4100-ACFF-36331EDAFBFB site1
21 active_bundle=829411021C544672C80B235A4AE56C12
22 latest_bundle=51C3FCC91493AC2C60D916C09EF5C2B3
23 last_validated_bundle=51C3FCC91493AC2C60D916C09EF5C2B3
24 last_bundle_validation_status=success
25 restart_required_apply_bundle=1
26 status=Restarting
27
28 idx3 5EC1F638-E8CC-48BC-9C4E-E1953BACDBC4 site2
29 active_bundle=829411021C544672C80B235A4AE56C12
30 latest_bundle=51C3FCC91493AC2C60D916C09EF5C2B3
31 last_validated_bundle=51C3FCC91493AC2C60D916C09EF5C2B3
32 last_bundle_validation_status=success
33 restart_required_apply_bundle=1
34 status=Up
35
36 idx4 676DC36E-DABC-410D-9A53-173208E62249 site2
37 active_bundle=829411021C544672C80B235A4AE56C12
38 latest_bundle=51C3FCC91493AC2C60D916C09EF5C2B3
39 last_validated_bundle=51C3FCC91493AC2C60D916C09EF5C2B3
40 last_bundle_validation_status=success
41 restart_required_apply_bundle=1
42 status=Up
43
44 idx1 A795DCB4-0B27-43CB-B461-836E132101D2 site1
45 active_bundle=51C3FCC91493AC2C60D916C09EF5C2B3
46 latest_bundle=51C3FCC91493AC2C60D916C09EF5C2B3
47 last_validated_bundle=51C3FCC91493AC2C60D916C09EF5C2B3
48 last_bundle_validation_status=success
49 restart_required_apply_bundle=0
50 status=Up
Note : Si la variable d'environnement $SPLUNK_HOME est bien paramétrée, il n'est pas obligatoire de mettre le PATH complet à la commande splunk.
Vérification sur un IDX :
1 $ sudo lsof -Pnni :9997
2 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
3 splunkd 6043 vagrant 69u IPv4 44241 0t0 TCP *:9997 (LISTEN)
Seach Head Cluster
Nous ne ferons pas d'affinité pour utiliser les 2 sites.
Via le Deployer us1 :
1 $ cd /opt/splunk/etc/shcluster/apps/
2
3 $ mkdir -p myappclustersearchbase/local
4
5 $ vi myappclustersearchbase/local/server.conf
6 [general]
7 #Disable affinity SH
8 site = site0
9
10 [clustering]
11 #Forcer les param qui sont à 3 pour le replication_factor
12 replication_factor=2
13 search_factor=2
14
15 multisite = true
16 manager_uri = https://us2.udmiot.lab:8089
17 mode = searchhead
18 pass4SymmKey = mysecuritykey2
Déployement sur les SHC
1 $ /opt/splunk/bin/splunk apply shcluster-bundle -target https://shc1.udmiot.lab:8089
Redémarrage de toutes les instances CM/IDX/SH :
1 $ sudo systemctl restart Splunkd
Envoie des logs des SH sur les IDX :
Depuis le Deployer us1 :
1 $ vi /opt/splunk/etc/shcluster/apps/myappclustersearchbase/local/outputs.conf
2 [tcpout:primary_indexers]
3 server = idx1.udmiot.lab:9997, idx2.udmiot.lab:9997,idx3.udmiot.lab:9997,idx4.udmiot.lab:9997
4
5 [tcpout]
6 defaultGroup = primary_indexers
7 forceTimebasedAutoLB = true
8 autoLBFrequency = 10
9 autoLBVolume = 512000
Déployement sur les SH
1 $ splunk apply shcluster-bundle -target https://shc1.udmiot.lab:8089
Envoie des logs des US sur les IDX :
Sur les US (Utility Server) us1 & us2.
1 $ cd /opt/splunk/etc/apps
2
3 $ mkdir -p myappforwardidx/local
4
5 $ vi myappforwardidx/local/outputs.conf
6 [tcpout:primary_indexers]
7 server = idx1.udmiot.lab:9997, idx2.udmiot.lab:9997,idx3.udmiot.lab:9997,idx4.udmiot.lab:9997
8
9 [tcpout]
10 defaultGroup = primary_indexers
11 forceTimebasedAutoLB = true
12 autoLBFrequency = 10
13 autoLBVolume = 512000
Note : en optimisation, on pourrait installer un DS (Deployement Server) pour simplifier.
Redémarrage de Splunk pour prise en compte :
1 $ sudo systemctl restart Splunkd
Vérifications :
Vérification que toutes les instances envoient bien leurs logs sur les IDX.
Sur une des SH, lancer une recherche SPL :
1 index=_internal | stats count by host
Il devrait y avoir les différents hosts IDX/SH/US.
Etat du cluster IDX, depuis le CM sur us2 :
1 $ splunk show cluster-status
2 Your session is invalid. Please login.
3 Splunk username: admin
4 Password:
5
6 Replication factor met
7 Search factor met
8 All data is searchable
9 Indexing Ready YES
10
11 idx2 15E8906A-A42A-4100-ACFF-36331EDAFBFB site1
12 Searchable YES
13 Status Up
14 Bucket Count=23
15
16 idx3 5EC1F638-E8CC-48BC-9C4E-E1953BACDBC4 site2
17 Searchable YES
18 Status Up
19 Bucket Count=35
20
21 idx4 676DC36E-DABC-410D-9A53-173208E62249 site2
22 Searchable YES
23 Status Up
24 Bucket Count=39
25
26 idx1 A795DCB4-0B27-43CB-B461-836E132101D2 site1
27 Searchable YES
28 Status Up
29 Bucket Count=33
Etat des bundles des IDX depuis le CM us2 :
1 $ splunk show cluster-bundle-status
2
3 master
4 cluster_status=None
5 active_bundle
6 checksum=51C3FCC91493AC2C60D916C09EF5C2B3
7 timestamp=1629578526 (in localtime=Sat Aug 21 22:42:06 2021)
8 latest_bundle
9 checksum=51C3FCC91493AC2C60D916C09EF5C2B3
10 timestamp=1629578526 (in localtime=Sat Aug 21 22:42:06 2021)
11 last_validated_bundle
12 checksum=51C3FCC91493AC2C60D916C09EF5C2B3
13 last_validation_succeeded=1
14 timestamp=1629578526 (in localtime=Sat Aug 21 22:42:06 2021)
15 last_check_restart_bundle
16 last_check_restart_result=restart not required
17 checksum=
18 timestamp=0 (in localtime=Thu Jan 1 01:00:00 1970)
19
20 idx2 15E8906A-A42A-4100-ACFF-36331EDAFBFB site1
21 active_bundle=51C3FCC91493AC2C60D916C09EF5C2B3
22 latest_bundle=51C3FCC91493AC2C60D916C09EF5C2B3
23 last_validated_bundle=51C3FCC91493AC2C60D916C09EF5C2B3
24 last_bundle_validation_status=success
25 restart_required_apply_bundle=0
26 status=Up
27
28 idx3 5EC1F638-E8CC-48BC-9C4E-E1953BACDBC4 site2
29 active_bundle=51C3FCC91493AC2C60D916C09EF5C2B3
30 latest_bundle=51C3FCC91493AC2C60D916C09EF5C2B3
31 last_validated_bundle=51C3FCC91493AC2C60D916C09EF5C2B3
32 last_bundle_validation_status=success
33 restart_required_apply_bundle=0
34 status=Up
35
36 idx4 676DC36E-DABC-410D-9A53-173208E62249 site2
37 active_bundle=51C3FCC91493AC2C60D916C09EF5C2B3
38 latest_bundle=51C3FCC91493AC2C60D916C09EF5C2B3
39 last_validated_bundle=51C3FCC91493AC2C60D916C09EF5C2B3
40 last_bundle_validation_status=success
41 restart_required_apply_bundle=0
42 status=Up
43
44 idx1 A795DCB4-0B27-43CB-B461-836E132101D2 site1
45 active_bundle=51C3FCC91493AC2C60D916C09EF5C2B3
46 latest_bundle=51C3FCC91493AC2C60D916C09EF5C2B3
47 last_validated_bundle=51C3FCC91493AC2C60D916C09EF5C2B3
48 last_bundle_validation_status=success
49 restart_required_apply_bundle=0
50 status=Up
Tests :
Faisons tomber le service Splunk sur l'IDX 1 et regardons l'état depuis le CM us2 :
1 $ splunk show cluster-status
2
3 Replication factor not met
4 Search factor not met
5 All data is searchable
6 Indexing Ready YES
7
8 idx2 15E8906A-A42A-4100-ACFF-36331EDAFBFB site1
9 Searchable YES
10 Status Up
11 Bucket Count=33
12
13 idx3 5EC1F638-E8CC-48BC-9C4E-E1953BACDBC4 site2
14 Searchable YES
15 Status Up
16 Bucket Count=35
17
18 idx4 676DC36E-DABC-410D-9A53-173208E62249 site2
19 Searchable YES
20 Status Up
21 Bucket Count=39
22
23 idx1 A795DCB4-0B27-43CB-B461-836E132101D2 site1
24 Searchable NO
25 Status ShuttingDown
26 Bucket Count=33
Le CM voit bien la perte de l'IDX1 et que le Réplication factor et Search factor ne sont plus satisfait.
Nous pouvons aussi le voir dans la GUI du CM, via le menu "Settings", "Indexer clustering" :
Si nous attendans quelques instants (suivant la volumétrie...) et que nous relançons la commande :
1 $ splunk show cluster-status
2
3 Replication factor met
4 Search factor met
5 All data is searchable
6 Indexing Ready YES
7
8 idx2 15E8906A-A42A-4100-ACFF-36331EDAFBFB site1
9 Searchable YES
10 Status Up
11 Bucket Count=44
12
13 idx3 5EC1F638-E8CC-48BC-9C4E-E1953BACDBC4 site2
14 Searchable YES
15 Status Up
16 Bucket Count=35
17
18 idx4 676DC36E-DABC-410D-9A53-173208E62249 site2
19 Searchable YES
20 Status Up
21 Bucket Count=39
22
23 idx1 A795DCB4-0B27-43CB-B461-836E132101D2 site1
24 Searchable NO
25 Status Stopped
26 Bucket Count=0
Le CM a fait le necessaire pour redistribuer les buckets manquants pour satisfaire le RF et SF.
Nous pouvons redémarrer le service Splunk de l'IDX 1 pour que tout revienne à la normale.
Dans le cadre de MAJ OS il peut être interessant de mettre en mode maintenance le CM pour qu'il n'effectue pas cette redistribution de buckets pour éviter un transfert de données important.