Getting Data In

Simple installation script for Universal Forwarder

lguinn2
Legend

When you have more than a few forwarders to maintain, it becomes tedious (and error-prone) to install them one-by-one. Using the Deployment Server is great for keeping the configurations up-to-date and consistent.

But I want to script the installation. This isn't really a Splunk problem, it's more of a scripting problem.

Any great scripts out there? All answers welcome, especially Linux and Windows.

Tags (2)
1 Solution

lguinn2
Legend

With some updates that were created (and tested!) by rroberts. Thanks Mr R; you are the best!
If you cut-and-paste this script - watch out for the line wraps! You will need to correct these before your script will run.

#!/bin/sh

# This EXAMPLE script shows how to deploy the Splunk universal forwarder
# to many remote hosts via ssh and common Unix commands.
# For "real" use, this script needs ERROR DETECTION AND LOGGING!!

# --Variables that you must set -----

# Populate this file with a list of hosts that this script should install to,
# with one host per line. This must be specified in the form that should
# be used for the ssh login, ie. username@host
#
# Example file contents:
# splunkuser@10.20.13.4
# splunkker@10.20.13.5
HOSTS_FILE="$HOME/whereToInstallUF"

# This should be a WGET command that was *carefully* copied from splunk.com!!
# Sign into splunk.com and go to the download page, then look for the wget
# link near the top of the page (once you have selected your platform)
# copy and paste your wget command between the ""
WGET_CMD="wget -O splunkforwarder..."

# Set the install file name to the name of the file that wget downloads
# (the second argument to wget)
INSTALL_FILE="splunkforwarder..."

# After installation, the forwarder will become a deployment client of this
# host.  Specify the host and management (not web) port of the deployment server
# that will be managing these forwarder instances.
DEPLOY_SERVER="xxx.xxx.xxx.xxx:8089"

# Set the new Splunk admin password
PASSWORD="newpassword"

# ----------- End of user settings -----------

# create script to run remotely. Watch out for line wraps, esp. in the "set deploy-poll" line below.  
# the remote script assumes that 'splunkuser' (the login account) has permissions to write to the
# /opt directory (this is not generally the default in Linux)
REMOTE_SCRIPT="
cd /opt
$WGET_CMD
tar -xzf $INSTALL_FILE
# /opt/splunkforwarder/bin/splunk enable boot-start -user splunkusername
/opt/splunkforwarder/bin/splunk start --accept-license --answer-yes --auto-ports --no-prompt
/opt/splunkforwarder/bin/splunk set deploy-poll \"$DEPLOY_SERVER\" --accept-license --answer-yes --auto-ports --no-prompt  -auth admin:changeme
/opt/splunkforwarder/bin/splunk edit user admin -password $PASSWORD -auth admin:changeme
/opt/splunkforwarder/bin/splunk restart
"    
echo "In 5 seconds, will run the following script on each remote host:"
echo
echo "===================="
echo "$REMOTE_SCRIPT"
echo "===================="
echo
sleep 5
echo "Reading host logins from $HOSTS_FILE"
echo
echo "Starting."

for DST in `cat "$HOSTS_FILE"`; do
  if [ -z "$DST" ]; then
    continue;
  fi
  echo "---------------------------"
  echo "Installing to $DST"

  # run script on remote host - you will be prompted for the password
  ssh "$DST" "$REMOTE_SCRIPT"

done  
echo "---------------------------"
echo "Done"

View solution in original post

rwells
Engager

What does DST mean in this scrip and what does it do?

0 Karma

lguinn2
Legend

DST is a variable. On each iteration of the loop, DST is set to the next host in the HOSTS_FILE.
So at any given point, DST should contain the IP address where the universal forwarder is to be installed.

0 Karma

lguinn2
Legend

Another script posting - also good

Forwarder Installation Script

0 Karma

rmorlen
Splunk Employee
Splunk Employee

Thanks for the script.

We have found Splunk incredibly easy to install and upgrade. Much easier that most products. We have UF's installed on 3000+ servers.

0 Karma

dwaddle
SplunkTrust
SplunkTrust

A couple of comments:

[1] Nothing keeps you from running a purely-internal yum repository to distribute Splunk install images to your servers. Then, "yum update" even works...
[2] Rather than setting the admin password directly, there's always user-seed.conf, which works well for that purpose.
[3] It's not terribly difficult to spin out your own RPM that includes splunk as a dependency - let that RPM (and its included scriplets) deal with post-install configuration

bilhays
Engager

ssbarnea, that's a bit harsh. We're talking about on the fly configuration, which is not trivial, and this kind of script is very helpful (at least to oldschoolers like myself). Thanks lguinn, this one answers 3-4 questions I had while writing something similar.

ssbarnea
Explorer

Thanks, the above script is a proof of the splunk inability to create easy to install and deploy products. I just hope that they will fix the current silly URL download tricks and provide a solution like this, maybe even RPM and DEB repositories.

lguinn2
Legend

Documentation here, including another example script...

0 Karma

jviteka
Explorer

Do I need to create a share for this?

0 Karma

lguinn2
Legend

If you cut-and-paste this script, watch out for the line wrap on the lines that start with
/opt/splunkforwarder

lguinn2
Legend

This was the shortest script that I could come up with that wasn't completely lame. It is based on a much more sophisticated script that is now part of the documentation.

Get Updates on the Splunk Community!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...