$ docker pull splunk/universalforwarder:latest
$ docker run -d -p 9997:9997 -e 'SPLUNK_START_ARGS=--accept-license' -e 'SPLUNK_PASSWORD=<password>' splunk/universalforwarder:latest
docker exec -it <container-id> /bin/bash
./splunk add forward-server <host name or ip address>:<listening port> ./splunk add monitor /var/log ./splunk restart
$ docker run -it -p 9997:9997 -e 'SPLUNK_START_ARGS=--accept-license' -e 'SPLUNK_PASSWORD=password' splunk/universalforwarder:latest PLAY [Run default Splunk provisioning] ******************************************************************************************************************************************************************************************************* Tuesday 09 April 2019 13:40:38 +0000 (0:00:00.096) 0:00:00.096 ********* TASK [Gathering Facts] *********************************************************************************************************************************************************************************************************************** ok: [localhost] Tuesday 09 April 2019 13:40:39 +0000 (0:00:01.520) 0:00:01.616 ********* TASK [Get actual hostname] ******************************************************************************************************************************************************************************************************************* changed: [localhost] Tuesday 09 April 2019 13:40:40 +0000 (0:00:00.599) 0:00:02.215 ********* Tuesday 09 April 2019 13:40:40 +0000 (0:00:00.054) 0:00:02.270 ********* TASK [set_fact] ****************************************************************************************************************************************************************************************************************************** ok: [localhost] Tuesday 09 April 2019 13:40:40 +0000 (0:00:00.075) 0:00:02.346 ********* Tuesday 09 April 2019 13:40:40 +0000 (0:00:00.067) 0:00:02.413 ********* Tuesday 09 April 2019 13:40:40 +0000 (0:00:00.060) 0:00:02.473 ********* Tuesday 09 April 2019 13:40:40 +0000 (0:00:00.051) 0:00:02.525 ********* Tuesday 09 April 2019 13:40:40 +0000 (0:00:00.056) 0:00:02.582 ********* Tuesday 09 April 2019 13:40:41 +0000 (0:00:00.216) 0:00:02.798 ********* included: /opt/ansible/roles/splunk_common/tasks/change_splunk_directory_owner.yml for localhost Tuesday 09 April 2019 13:40:41 +0000 (0:00:00.087) 0:00:02.886 ********* TASK [splunk_common : Update Splunk directory owner] ***************************************************************************************************************************************************************************************** ok: [localhost] Tuesday 09 April 2019 13:40:41 +0000 (0:00:00.324) 0:00:03.210 ********* included: /opt/ansible/roles/splunk_common/tasks/get_facts.yml for localhost Tuesday 09 April 2019 13:40:41 +0000 (0:00:00.094) 0:00:03.305 ********* ...
# FROM centos:7 # , ENV SPLUNK_HOME /splunkforwarder ENV SPLUNK_ROLE splunk_heavy_forwarder ENV SPLUNK_PASSWORD changeme ENV SPLUNK_START_ARGS --accept-license # # wget - # expect - Splunk # jq - , RUN yum install -y epel-release \ && yum install -y wget expect jq # , , RUN wget -O splunkforwarder-7.2.4-8a94541dcfac-Linux-x86_64.tgz 'https://www.splunk.com/bin/splunk/DownloadActivityServlet?architecture=x86_64&platform=linux&version=7.2.4&product=universalforwarder&filename=splunkforwarder-7.2.4-8a94541dcfac-Linux-x86_64.tgz&wget=true' \ && wget -O docker-18.09.3.tgz 'https://download.docker.com/linux/static/stable/x86_64/docker-18.09.3.tgz' \ && tar -xvf splunkforwarder-7.2.4-8a94541dcfac-Linux-x86_64.tgz \ && tar -xvf docker-18.09.3.tgz \ && rm -f splunkforwarder-7.2.4-8a94541dcfac-Linux-x86_64.tgz \ && rm -f docker-18.09.3.tgz # shell , inputs.conf, splunkclouduf.spl first_start.sh . source . COPY [ "inputs.conf", "docker-stats/props.conf", "/splunkforwarder/etc/system/local/" ] COPY [ "docker-stats/docker_events.sh", "docker-stats/docker_inspect.sh", "docker-stats/docker_stats.sh", "docker-stats/docker_top.sh", "/splunkforwarder/bin/scripts/" ] COPY splunkclouduf.spl /splunkclouduf.spl COPY first_start.sh /splunkforwarder/bin/ # , RUN chmod +x /splunkforwarder/bin/scripts/*.sh \ && groupadd -r splunk \ && useradd -r -m -g splunk splunk \ && echo "%sudo ALL=NOPASSWD:ALL" >> /etc/sudoers \ && chown -R splunk:splunk $SPLUNK_HOME \ && /splunkforwarder/bin/first_start.sh \ && /splunkforwarder/bin/splunk install app /splunkclouduf.spl -auth admin:changeme \ && /splunkforwarder/bin/splunk restart # COPY [ "init/entrypoint.sh", "init/checkstate.sh", "/sbin/" ] # . /, . VOLUME [ "/splunkforwarder/etc", "/splunkforwarder/var" ] HEALTHCHECK --interval=30s --timeout=30s --start-period=3m --retries=5 CMD /sbin/checkstate.sh || exit 1 ENTRYPOINT [ "/sbin/entrypoint.sh" ] CMD [ "start-service" ]
#!/usr/bin/expect -f set timeout -1 spawn /splunkforwarder/bin/splunk start --accept-license expect "Please enter an administrator username: " send -- "admin\r" expect "Please enter a new password: " send -- "changeme\r" expect "Please confirm new password: " send -- "changeme\r" expect eof
/splunkforwarder/bin/splunk install app /splunkclouduf.spl -auth admin:changeme
start() { trap teardown EXIT if [ -z $SPLUNK_INDEX ]; then echo "'SPLUNK_INDEX' env variable is empty or not defined. Should be 'dev' or 'prd'." >&2 exit 1 else sed -e "s/@index@/$SPLUNK_INDEX/" -i ${SPLUNK_HOME}/etc/system/local/inputs.conf fi sed -e "s/@hostname@/$(cat /etc/hostname)/" -i ${SPLUNK_HOME}/etc/system/local/inputs.conf sh -c "echo 'starting' > /tmp/splunk-container.state" ${SPLUNK_HOME}/bin/splunk start watch_for_failure }
version: '2' services: splunk-forwarder: image: "${IMAGE_REPO}/docker-stats-splunk-forwarder:${IMAGE_VERSION}" environment: SPLUNK_INDEX: ${ENVIRONMENT} volumes: - /etc/hostname:/etc/hostname:ro - /var/log:/var/log - /var/run/docker.sock:/var/run/docker.sock:ro
Source: https://habr.com/ru/post/447402/
All Articles