1
0
mirror of https://github.com/krislamo/graylog_demo synced 2026-01-11 22:03:15 +00:00

21 Commits
tls ... master

Author SHA1 Message Date
86fcc23047 Add fault-tolerant file buffers for logs 2021-03-23 12:03:56 -04:00
b4e33f4b41 Use built-in TLS forwarding support 2020-07-24 11:56:06 -04:00
651a26584a Quickly forward data to Graylog 2020-07-01 15:45:44 -04:00
e7caff95de Fix indentation 2020-07-01 15:15:46 -04:00
8cca097e66 Format log and update buffer settings 2020-07-01 15:13:44 -04:00
be5f069cdb Set td-agent flush_interval to 0 seconds 2020-07-01 14:32:02 -04:00
3ae07d16f4 Bump version of Graylog related Docker containers 2020-07-01 12:31:37 -04:00
3c896e40b1 Update README to reflect the multi-machine setup 2020-03-25 13:21:34 -04:00
b5ab0d95bc Log all containers and syslogs' 2020-03-25 10:58:29 -04:00
9f78958df4 Remove routing labels and expose WP container 2020-03-24 14:58:54 -04:00
9815a86386 Secure forward to td-agent on Graylog server 2020-03-24 14:04:25 -04:00
eac9696e19 Remove old Docker network 2020-03-20 18:56:44 -04:00
c95cbdbaa6 Refactoring to divide services among two boxes 2020-03-20 15:40:14 -04:00
d9139b715a Create multiple VMs 2020-03-20 15:40:08 -04:00
79980fde84 Prevent error if /var/log/containers folder exists 2020-03-20 15:40:02 -04:00
Bob Belnap
e509d3bad6 defer the parsing of httpd messages until after the message is stored (this allows the whole message to appear in graylog, as well as being parsed) 2020-03-20 10:44:38 -04:00
550aaafa4f Give td-agent permission to /var/log 2020-03-05 16:18:07 -05:00
15f1d8bb32 Install td-agent plugins and update graylog host 2020-03-04 16:09:50 -05:00
802a2d4e10 Remove bind mount log paths 2020-03-04 11:35:39 -05:00
4a0d92fa97 Remove fluentd container and minor reorganization 2020-03-04 11:28:29 -05:00
a233c8c043 Install and enable td-agent daemon 2020-03-04 10:51:28 -05:00
10 changed files with 325 additions and 213 deletions

1
.gitignore vendored
View File

@@ -1 +1,2 @@
.vagrant .vagrant
tmp

View File

@@ -1,22 +1,21 @@
# Graylog Demo # Graylog Demo
This is a demonstration of Graylog, a centralized log management system featuring a shell provisioned CentOS 7 Vagrant box. To illustrate various log collection methods `httpd`, `rsyslog` and `docker` are installed and a simple WordPress instance is deployed via Docker Compose. Log collection incorporates Fluentd to ship logs into a Graylog instance from containers, the syslog, and arbitrary filesystem logs. This is a demonstration of Graylog, a centralized log management system featuring a shell provisioned CentOS 7 Vagrant box. To illustrate various log collection methods `httpd`, `rsyslog` and `docker` are installed and a simple WordPress instance is deployed via Docker Compose. Log collection incorporates td-agent (a version of Fluentd) to ship logs into a Graylog instance from containers, the syslog, and arbitrary filesystem logs.
This demonstration assumes you are familiar with using Vagrant + VirtualBox to automate the installation of virtual machines, although you can reference the Vagrantfile's shell provisioning sections to manually set up a system if you so desire. Please install these prerequisites before attempting the quick start below. This demonstration assumes you are familiar with using Vagrant + VirtualBox to automate the installation of virtual machines, although you can reference the Vagrantfile's shell provisioning sections to manually set up a system if you so desire. Please install these prerequisites before attempting the quick start below.
#### Notes about setup #### Notes about setup
- This demonstration uses Traefik for routing and the [xip.io](http://xip.io/) wildcard DNS service. If DNS fails to resolve for whatever reason you may want to set the domains to the IP inside your operating system's hosts file, e.g. - This demonstration uses Traefik for some routing and the [xip.io](http://xip.io/) wildcard DNS service. If DNS fails to resolve for whatever reason you may want to set the domains to the IP inside your operating system's hosts file, e.g.
``` ```
172.28.128.30 traefik.172.28.128.30.xip.io 172.28.128.30 traefik.172.28.128.30.xip.io
172.28.128.30 graylog.172.28.128.30.xip.io 172.28.128.30 graylog.172.28.128.30.xip.io
172.28.128.30 wordpress.172.28.128.30.xip.io
``` ```
- Vagrant will provision a virtual machine with a static private Class B address (specifically `172.28.128.30`). If you would like to change this IP address to something different you will need to change the `PRIVATE_NET_IP` variable and the scripted API calls in the `Vagrantfile`. You'll also need to modify the few wildcard DNS references to it in the two `docker-compose.yml` files. - Vagrant will provision two virtual machines with two consecutive private Class B addresses (starting from `172.28.128.30`). If you would like to change this base IP address to something different you will need to look through the project and find various references. Unfortunately, this is not a simple variable you can set for the entire project.
- Vagrant is set to allocate 4 cores and 4 GB of RAM, you may need to adjust this for your machine if necessary. - Vagrant is set to allocate 4 cores and 4 GB of RAM per machine (this is 8 cores / 8 GB of memory total) you may need to adjust this for your machine if necessary.
- After deploying, Graylog takes the longest to become available and it may take 30 seconds to a few minutes to bring it up depending on your machine. - After deploying, Graylog takes the longest to become available and it may take 30 seconds to a few minutes to bring it up depending on your machine.
@@ -26,7 +25,7 @@ This demonstration assumes you are familiar with using Vagrant + VirtualBox to a
## Quick Start ## Quick Start
_This section assumes you will be using the default `172.28.128.30` IP address_ _This section assumes you will be using the default `172.28.128.30` and `172.28.128.31` IP addresses_
1. Clone the repository and navigate inside its directory 1. Clone the repository and navigate inside its directory
2. Create and provision the VM using `vagrant up` 2. Create and provision the VM using `vagrant up`
3. Navigate to [http://graylog.172.28.128.30.xip.io:8080/](http://graylog.172.28.128.30.xip.io:8080/) 3. Navigate to [http://graylog.172.28.128.30.xip.io:8080/](http://graylog.172.28.128.30.xip.io:8080/)
@@ -36,13 +35,13 @@ _This section assumes you will be using the default `172.28.128.30` IP address_
7. Press the start button on the top right to start updating the feed every second 7. Press the start button on the top right to start updating the feed every second
#### Docker Test #### Docker Test
- Generate Docker logs by simply navigating to the WordPress install page [http://wordpress.172.28.128.30.xip.io:8080/](http://wordpress.172.28.128.30.xip.io:8080/) - Generate Docker logs by simply navigating to the WordPress install page: [http://172.28.128.31:8080](http://172.28.128.31:8080/wp-admin/install.php)
#### File Test #### File Test
- Collect logs from Apache's `access_log` file by going to [http://172.28.128.30/](http://172.28.128.30/) - Collect logs from Apache's `access_log` file by going to [http://172.28.128.31/](http://172.28.128.31/)
#### Syslog Test #### Syslog Test
1. Go back to the terminal inside the project's directory and type `vagrant ssh` 1. Go back to the terminal inside the project's directory and type `vagrant ssh systems` or `vagrant ssh graylog`
2. You can test Syslog collection with `logger` e.g. `logger -t test Hello world` (or just wait for some to appear) 2. You can test Syslog collection with `logger` e.g. `logger -t test Hello world` (or just wait for some to appear)
### Copyrights and Licenses ### Copyrights and Licenses

108
Vagrantfile vendored
View File

@@ -1,28 +1,38 @@
# vi: set ft=ruby : # vi: set ft=ruby :
PRIVATE_NET_IP = "172.28.128.30" PRIVATE_NET_IP = "172.28.128."
Vagrant.configure("2") do |config| Vagrant.configure("2") do |config|
config.vm.box = "centos/7"
config.vm.network "private_network", ip: PRIVATE_NET_IP
config.vm.synced_folder ".", "/vagrant", type: "nfs"
config.vm.provider "virtualbox" do |vbox| vmservers = ["graylog", "systems"]
last_octet = 30
vmservers.each do |server|
config.vm.define "#{server}" do |node|
node.vm.box = "centos/7"
node.vm.hostname = "#{server}"
node.vm.network "private_network", ip: PRIVATE_NET_IP + last_octet.to_s
node.vm.synced_folder ".", "/vagrant", type: "nfs"
last_octet = last_octet + 1
node.vm.provider "virtualbox" do |vbox|
vbox.memory = 4096 vbox.memory = 4096
vbox.cpus = 4 vbox.cpus = 4
end end
config.vm.provision "shell", inline: <<-SHELL # Common provision
node.vm.provision "shell", inline: <<-SHELL
# Set SELinux to permissive # Set SELinux to permissive
setenforce 0 setenforce 0
sed -i "s/SELINUX=enforcing/SELINUX=permissive/g" /etc/selinux/config sed -i "s/SELINUX=enforcing/SELINUX=permissive/g" /etc/selinux/config
# Import GPG keys # Import GPG keys
curl -s https://download.docker.com/linux/centos/gpg -o docker-key rpm --import \
rpm --import docker-key \
/etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 \ /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 \
http://download.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-7 https://download.docker.com/linux/centos/gpg \
http://download.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-7 \
https://packages.treasuredata.com/GPG-KEY-td-agent
# Install Docker Community Edition # Install Docker Community Edition
yum-config-manager --add-repo \ yum-config-manager --add-repo \
@@ -35,15 +45,6 @@ Vagrant.configure("2") do |config|
# Convenience # Convenience
yum install -y vim yum install -y vim
# Install jq
yum install -y epel-release
yum install -y jq
# Install apache
yum install -y httpd
systemctl start httpd
systemctl -q enable httpd
# Install rsyslog # Install rsyslog
yum install -y rsyslog yum install -y rsyslog
systemctl start rsyslog systemctl start rsyslog
@@ -55,19 +56,49 @@ Vagrant.configure("2") do |config|
systemctl restart rsyslog systemctl restart rsyslog
fi fi
# Setup TLS
if [ ! -f /vagrant/tmp/ca_key.pem ]; then
echo "Generating TLS certificates..."
cd /vagrant/tmp
openssl req -newkey rsa:4096 \
-x509 \
-sha256 \
-days 3650 \
-nodes \
-out ca_cert.pem \
-keyout ca_key.pem \
-subj "/C=US/ST=Local/L=Local/O=Org/OU=IT/CN=example.com" \
2> /dev/null
fi
# Install td-agent
cp /vagrant/td-agent.repo /etc/yum.repos.d/
yum check-update
yum install -y td-agent
td-agent-gem install fluent-plugin-gelf-hs gelf
systemctl -q enable td-agent
SHELL SHELL
# Install newest docker-compose # Commmon provision: install docker-compose
config.vm.provision "shell", path: "install-compose.sh" node.vm.provision "shell", path: "install-compose.sh"
# Start compose services and add default input # Graylog specific provision
config.vm.provision "shell", inline: <<-SHELL if server == "graylog"
# Bring up containers node.vm.provision "shell", inline: <<-SHELL
cp /vagrant/td-agent-server.conf /etc/td-agent/td-agent.conf
mkdir -p /var/log/graylog_buffer
chown -R td-agent:td-agent /var/log/graylog_buffer
systemctl restart td-agent
# Install jq
yum install -y epel-release
yum install -y jq
# Start Graylog
cd /vagrant cd /vagrant
/usr/local/bin/docker-compose up -d 2> /dev/null /usr/local/bin/docker-compose up -d 2> /dev/null
cd /vagrant/wordpress
/usr/local/bin/docker-compose up -d 2> /dev/null
cd /vagrant
# Wait 120 seconds for Graylog to come online # Wait 120 seconds for Graylog to come online
SECONDS=0 SECONDS=0
@@ -117,6 +148,31 @@ Vagrant.configure("2") do |config|
-u admin:admin \ -u admin:admin \
"http://graylog.172.28.128.30.xip.io:8080/api/system/inputs" \ "http://graylog.172.28.128.30.xip.io:8080/api/system/inputs" \
-d @GELFTCPInput.json -d @GELFTCPInput.json
SHELL
elsif server == "systems"
node.vm.provision "shell", inline: <<-SHELL
# Install apache
yum install -y httpd
systemctl start httpd
systemctl -q enable httpd
# Configure td-agent
cp /vagrant/td-agent.conf /etc/td-agent/td-agent.conf
mkdir -p /var/log/containers /var/log/fluentd_buffer
chown -R td-agent:td-agent /var/log/containers /var/log/fluentd_buffer
chmod -R 755 /var/log
systemctl restart td-agent
# Bring up WordPress test containers
cd /vagrant/wordpress
/usr/local/bin/docker-compose up -d 2> /dev/null
SHELL SHELL
end end
end
end
end

View File

@@ -3,7 +3,7 @@ version: '3.7'
services: services:
traefik: traefik:
image: traefik:2.1.4 image: traefik:2.2.1
restart: always restart: always
networks: networks:
- traefik-net - traefik-net
@@ -24,27 +24,27 @@ services:
- "traefik.enable=true" - "traefik.enable=true"
volumes: volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro - /var/run/docker.sock:/var/run/docker.sock:ro
logging:
fluentd: driver: "fluentd"
build: ./fluentd options:
restart: always fluentd-address: "tcp://127.0.0.1:24224"
volumes: fluentd-async-connect: "true"
- /var/log:/var/log/hostlogs tag: traefik
networks:
- graylog
ports:
- 24224:24224
- 24224:24224/udp
- 5140:5140/udp
mongo: mongo:
image: mongo:4.2.2 image: mongo:4.2.8
restart: always restart: always
networks: networks:
- graylog - graylog
logging:
driver: "fluentd"
options:
fluentd-address: "tcp://127.0.0.1:24224"
fluentd-async-connect: "true"
tag: graylog.db
elasticsearch: elasticsearch:
image: elasticsearch:6.8.6 image: elasticsearch:6.8.10
restart: always restart: always
environment: environment:
- http:host=0.0.0.0 - http:host=0.0.0.0
@@ -57,9 +57,15 @@ services:
hard: -1 hard: -1
networks: networks:
- graylog - graylog
logging:
driver: "fluentd"
options:
fluentd-address: "tcp://127.0.0.1:24224"
fluentd-async-connect: "true"
tag: graylog.elasticsearch
graylog: graylog:
image: graylog/graylog:3.2.2 image: graylog/graylog:3.3.2
restart: always restart: always
environment: environment:
- GRAYLOG_PASSWORD_SECRET=LongerPassword01 - GRAYLOG_PASSWORD_SECRET=LongerPassword01
@@ -88,6 +94,12 @@ services:
- 12201:12201 - 12201:12201
# GELF UDP # GELF UDP
- 12201:12201/udp - 12201:12201/udp
logging:
driver: "fluentd"
options:
fluentd-address: "tcp://127.0.0.1:24224"
fluentd-async-connect: "true"
tag: graylog
networks: networks:
traefik-net: traefik-net:

View File

@@ -1,10 +0,0 @@
FROM fluent/fluentd:v1.9.0-debian-1.0
USER root
RUN apt-get update \
&& apt-get -y install --no-install-recommends wget \
&& rm -rf /var/lib/apt/lists/*
RUN gem install fluent-plugin-rewrite-tag-filter
RUN gem install gelf
RUN cd /fluentd/plugins \
&& wget -q https://raw.githubusercontent.com/emsearcy/fluent-plugin-gelf/master/lib/fluent/plugin/out_gelf.rb
COPY fluent.conf /fluentd/etc/

View File

@@ -1,49 +0,0 @@
<source>
@type forward
port 24224
</source>
<source>
@type syslog
port 5140
tag system
</source>
<source>
@type tail
path /var/log/hostlogs/httpd/access_log
pos_file /var/log/hostlogs/httpd/access_log.pos
tag httpd.access
<parse>
@type apache2
</parse>
</source>
<match devel.*>
@type copy
<store>
@type file
path /var/log/hostlogs/containers/${tag}
append true
<buffer tag>
timekey 5s
flush_mode immediate
</buffer>
</store>
<store>
@type rewrite_tag_filter
<rule>
key container_name
pattern /\/(.+)/
tag ${tag}.$1
</rule>
</store>
</match>
<match **>
@type gelf
protocol tcp
host vagrant_graylog_1
port 12201
flush_interval 5s
</match>

42
td-agent-server.conf Normal file
View File

@@ -0,0 +1,42 @@
<source>
@type forward
port 2514
<transport tls>
version TLSv1_2
insecure true
cert_path /vagrant/tmp/ca_cert.pem
private_key_path /vagrant/tmp/ca_key.pem
</transport>
</source>
<source>
@type forward
port 24224
</source>
<source>
@type syslog
port 5140
tag system.local
</source>
<filter httpd.access>
@type parser
key_name message
reserve_data true
<parse>
@type apache2
</parse>
</filter>
<match **>
@type gelf
protocol tcp
host localhost
port 12201
<buffer>
@type file
path /var/log/graylog_buffer
flush_interval 0s
</buffer>
</match>

62
td-agent.conf Normal file
View File

@@ -0,0 +1,62 @@
<source>
@type forward
port 24224
</source>
<source>
@type syslog
port 5140
tag system
</source>
<source>
@type tail
path /var/log/httpd/access_log
pos_file /var/log/td-agent/access_log.pos
tag httpd.access
<parse>
@type none
</parse>
</source>
<match devel.*>
@type copy
<store>
@type file
path /var/log/containers/${tag}
append true
<buffer tag>
@type file
path /var/log/containers/buffer
flush_interval 0s
</buffer>
<format>
@type single_value
message_key log
</format>
</store>
<store>
@type rewrite_tag_filter
<rule>
key container_name
pattern /\/(.+)/
tag ${tag}.$1
</rule>
</store>
</match>
<match **>
@type forward
transport tls
tls_cert_path /vagrant/tmp/ca_cert.pem
<server>
name example.com
host 172.28.128.30
port 2514
</server>
<buffer>
@type file
path /var/log/fluentd_buffer
flush_interval 0s
</buffer>
</match>

5
td-agent.repo Normal file
View File

@@ -0,0 +1,5 @@
[treasuredata]
name=TreasureData
baseurl=http://packages.treasuredata.com/3/redhat/$releasever/$basearch
gpgcheck=1
gpgkey=https://packages.treasuredata.com/GPG-KEY-td-agent

View File

@@ -11,26 +11,25 @@ services:
MYSQL_USER: wordpress MYSQL_USER: wordpress
MYSQL_PASSWORD: Password1 MYSQL_PASSWORD: Password1
MYSQL_RANDOM_ROOT_PASSWORD: '1' MYSQL_RANDOM_ROOT_PASSWORD: '1'
networks: logging:
- default driver: "fluentd"
options:
fluentd-address: "tcp://127.0.0.1:24224"
fluentd-async-connect: "true"
tag: devel.kris.db
wordpress: wordpress:
depends_on: depends_on:
- db - db
image: wordpress:latest image: wordpress:latest
restart: always restart: always
ports:
- 8080:80
environment: environment:
WORDPRESS_DB_HOST: db:3306 WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wordpress WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: Password1 WORDPRESS_DB_PASSWORD: Password1
WORDPRESS_DB_NAME: wordpress WORDPRESS_DB_NAME: wordpress
networks:
- default
- traefik-net
labels:
- "traefik.http.routers.wordpress.rule=Host(`wordpress.172.28.128.30.xip.io`)"
- "traefik.docker.network=vagrant_traefik-net"
- "traefik.enable=true"
logging: logging:
driver: "fluentd" driver: "fluentd"
options: options:
@@ -38,10 +37,5 @@ services:
fluentd-async-connect: "true" fluentd-async-connect: "true"
tag: devel.kris tag: devel.kris
networks:
traefik-net:
external:
name: vagrant_traefik-net
volumes: volumes:
db_data: {} db_data: {}