The Splunk Universal Forwarder (UF) is managed via the command line using the splunk binary located in the bin directory of the installation. To perform basic configuration, you primarily use the splunk add forward-server command to point the UF to an indexer and splunk add monitor to specify which logs to collect. This allows for headless installation and automation across multiple servers without needing a GUI.
What You'll Need
- A downloaded Splunk Universal Forwarder installation package (.msi for Windows, .rpm or .deb for Linux).
- Administrative or root-level access to the target machine.
- The IP address or hostname and the receiving port (usually 9997) of your Splunk Indexer or Intermediate Forwarder.
- Network connectivity between the forwarder and the indexer on the specified port.
Step-by-Step
- Navigate to the Bin Directory: Open your terminal or command prompt and change the directory to where the Splunk binary resides.
- Linux: Typically
/opt/splunkforwarder/bin - Windows: Typically
C:\Program Files\SplunkUniversalForwarder\bin
- Linux: Typically
- Accept the License: If this is a first-time run, you must accept the license agreement to initialize the software. Run:
./splunk start --accept-license(Linux) orsplunk.exe start --accept-license(Windows). - Set an Admin Password: During the first start, the CLI will prompt you to create an administrator username and password. Enter these credentials and save them securely; they are required for most subsequent configuration changes.
- Configure the Indexer (Forward Server): Tell the forwarder where to send the data. Use the following command, replacing the bracketed information with your actual server details:
./splunk add forward-server [indexer-ip]:9997. - Add Data Inputs: Specify which files or directories the UF should monitor.
- To monitor a specific file:
./splunk add monitor /var/log/syslog - To monitor an entire directory:
./splunk add monitor /var/log/apache2/ - To monitor a Windows event log:
./splunk add monitor WinEventLog:Application
- To monitor a specific file:
- Verify the Connection: Check the status of the forwarder to ensure it is running and communicating. Use
./splunk statusto verify the process is active. - Restart the Service: Whenever you make significant configuration changes via the CLI, it is a best practice to restart the service to ensure all settings are applied:
./splunk restart.
Common Mistakes
- Wrong Permissions: Running the
splunkcommand as a standard user when the service was installed as root/system. This often results in "Permission Denied" errors when trying to modifyinputs.conforoutputs.conf. - Incorrect Port: Attempting to send data to the Splunk Web port (8000) instead of the indexing port (9997). The UF cannot communicate via the web interface port.
- Path Errors: Using relative paths for log files. Always use absolute paths (e.g.,
/var/log/app.loginstead of./app.log) to ensure the forwarder finds the file regardless of the current working directory. - Forgetting the License: Attempting to run configuration commands before running the
--accept-licensecommand, which prevents the binary from executing.
Tips
- Use Silent Installation: For large-scale deployments, use the
-sor--silentflag during installation to bypass interactive prompts. - Check the Internal Logs: If data isn't appearing in Splunk, check the local internal logs on the forwarder located in
/var/log/splunk/splunkd.logto see connection errors. - Environment Variables: Add the
/bindirectory of the Splunk UF to your system's PATH environment variable so you can runsplunkfrom any directory without typing the full path. - Use a Deployment Server: For more than five forwarders, avoid manual CLI configuration and use a Splunk Deployment Server to push configuration bundles automatically.
Troubleshooting
If the Universal Forwarder is not sending data to your indexer, follow these steps in order:
- Verify Service Status: Run
./splunk status. If it is not running, run./splunk start. - Test Network Connectivity: Use a tool like
telnetornc(netcat) to see if the forwarder can reach the indexer on port 9997. Example:nc -zv [indexer-ip] 9997. If this fails, check your firewall settings. - Check Indexer Listening Status: Ensure the receiving port is actually enabled on the Splunk Indexer. In the Indexer's web UI, navigate to Settings > Forwarding and receiving > Receive data and ensure port 9997 is listed and active.
- Review Local Logs: Search the
splunkd.logfile for keywords like "TcpOutputProc" or "Connection refused" to identify the exact cause of the communication failure. - Re-add the Forward Server: If the connection is unstable, try removing the server and adding it again:
./splunk remove forward-server [indexer-ip]:9997followed by theadd forward-servercommand.
Frequently Asked Questions
Does the Universal Forwarder require a license?
The Universal Forwarder is generally free to use and does not count against your Splunk indexing license quota, regardless of the volume of data it sends.
Can I monitor multiple indexers for redundancy?
Yes. You can run the splunk add forward-server command multiple times with different IP addresses. The UF will then load-balance the data across the available indexers.
How do I stop the Universal Forwarder via CLI?
Use the command ./splunk stop. This gracefully shuts down the data collection processes and closes network connections.
Can I change the receiving port from 9997?
Yes, but the port must be changed on both the Indexer (to listen on the new port) and the Forwarder (to send to the new port) using the add forward-server [ip]:[new-port] command.
How do I update the admin password via command line?
Use the command ./splunk edit user admin -password [new-password] to update the credentials for the administrator account.