2020-01-22 15:09:57 +00:00
|
|
|
# vi: set ft=ruby :
|
|
|
|
|
2020-01-27 20:44:38 +00:00
|
|
|
PRIVATE_NET_IP = "172.28.128.30"
|
|
|
|
|
2020-01-22 15:09:57 +00:00
|
|
|
Vagrant.configure("2") do |config|
|
|
|
|
config.vm.box = "centos/7"
|
2020-01-27 20:44:38 +00:00
|
|
|
config.vm.network "private_network", ip: PRIVATE_NET_IP
|
2020-01-22 19:57:33 +00:00
|
|
|
config.vm.synced_folder ".", "/vagrant", type: "nfs"
|
|
|
|
|
|
|
|
config.vm.provider "virtualbox" do |vbox|
|
|
|
|
vbox.memory = 4096
|
|
|
|
vbox.cpus = 4
|
|
|
|
end
|
2020-01-22 16:44:41 +00:00
|
|
|
|
2020-01-22 15:09:57 +00:00
|
|
|
config.vm.provision "shell", inline: <<-SHELL
|
|
|
|
|
2020-01-28 20:42:48 +00:00
|
|
|
# Set SELinux to permissive
|
|
|
|
setenforce 0
|
|
|
|
sed -i "s/SELINUX=enforcing/SELINUX=permissive/g" /etc/selinux/config
|
|
|
|
|
2020-01-22 15:09:57 +00:00
|
|
|
# Import GPG keys
|
|
|
|
curl -s https://download.docker.com/linux/centos/gpg -o docker-key
|
2020-02-26 18:38:24 +00:00
|
|
|
rpm --import docker-key \
|
|
|
|
/etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 \
|
|
|
|
http://download.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-7
|
2020-01-22 15:09:57 +00:00
|
|
|
|
|
|
|
# Install Docker Community Edition
|
|
|
|
yum-config-manager --add-repo \
|
|
|
|
https://download.docker.com/linux/centos/docker-ce.repo
|
|
|
|
yum install -y docker-ce docker-ce-cli containerd.io
|
|
|
|
systemctl start docker
|
2020-01-22 16:07:04 +00:00
|
|
|
systemctl -q enable docker
|
2020-01-22 15:09:57 +00:00
|
|
|
usermod -aG docker vagrant
|
|
|
|
|
2020-01-22 21:14:43 +00:00
|
|
|
# Convenience
|
|
|
|
yum install -y vim
|
|
|
|
|
2020-02-26 18:38:24 +00:00
|
|
|
# Install jq
|
|
|
|
yum install -y epel-release
|
|
|
|
yum install -y jq
|
|
|
|
|
2020-02-11 21:25:20 +00:00
|
|
|
# Install apache
|
|
|
|
yum install -y httpd
|
|
|
|
systemctl start httpd
|
|
|
|
systemctl -q enable httpd
|
|
|
|
|
2020-01-22 21:14:43 +00:00
|
|
|
# Install rsyslog
|
|
|
|
yum install -y rsyslog
|
|
|
|
systemctl start rsyslog
|
|
|
|
systemctl -q enable rsyslog
|
|
|
|
|
2020-01-27 20:44:38 +00:00
|
|
|
# Add rsyslog forwarding option if it does not exist
|
2020-02-10 21:17:24 +00:00
|
|
|
if ! grep -q "127.0.0.1:5140" /etc/rsyslog.conf; then
|
|
|
|
echo "*.* @127.0.0.1:5140" >> /etc/rsyslog.conf
|
2020-01-27 20:44:38 +00:00
|
|
|
systemctl restart rsyslog
|
|
|
|
fi
|
|
|
|
|
2020-01-22 15:09:57 +00:00
|
|
|
SHELL
|
|
|
|
|
2020-01-22 15:20:11 +00:00
|
|
|
# Install newest docker-compose
|
|
|
|
config.vm.provision "shell", path: "install-compose.sh"
|
|
|
|
|
2020-02-26 18:38:24 +00:00
|
|
|
# Start compose services and add default input
|
2020-01-22 19:57:33 +00:00
|
|
|
config.vm.provision "shell", inline: <<-SHELL
|
2020-03-02 16:51:51 +00:00
|
|
|
# Remove old keys and create directories
|
|
|
|
mkdir -p /vagrant/pki
|
|
|
|
rm -r /vagrant/pki/*
|
|
|
|
mkdir -p /vagrant/pki/{fluentd,graylog}
|
|
|
|
|
2020-02-26 18:38:24 +00:00
|
|
|
# Bring up containers
|
2020-01-22 19:57:33 +00:00
|
|
|
cd /vagrant
|
2020-02-19 18:46:52 +00:00
|
|
|
/usr/local/bin/docker-compose up -d 2> /dev/null
|
|
|
|
cd /vagrant/wordpress
|
|
|
|
/usr/local/bin/docker-compose up -d 2> /dev/null
|
2020-02-25 20:44:12 +00:00
|
|
|
cd /vagrant
|
2020-02-26 18:38:24 +00:00
|
|
|
|
|
|
|
# Wait 120 seconds for Graylog to come online
|
2020-03-02 16:51:51 +00:00
|
|
|
INSTALL_INPUT=0
|
2020-02-26 18:38:24 +00:00
|
|
|
SECONDS=0
|
|
|
|
while true
|
|
|
|
do
|
|
|
|
GRAYLOG_STATE=$(
|
|
|
|
docker inspect vagrant_graylog_1 \
|
|
|
|
| jq --raw-output '.[] | .State.Health.Status')
|
|
|
|
|
|
|
|
if [[ "$GRAYLOG_STATE" == "healthy" ]]; then
|
|
|
|
echo "Graylog is available."
|
2020-03-02 16:51:51 +00:00
|
|
|
INSTALL_INPUT=1
|
2020-02-26 18:38:24 +00:00
|
|
|
sleep 5
|
|
|
|
break
|
2020-02-27 18:45:49 +00:00
|
|
|
elif [[ "$GRAYLOG_STATE" != "starting" ]]; then
|
2020-02-26 18:38:24 +00:00
|
|
|
echo "Something is wrong with Graylog. Aborting."
|
2020-03-02 16:51:51 +00:00
|
|
|
break
|
2020-02-26 18:38:24 +00:00
|
|
|
elif [[ $SECONDS -le 120 ]]; then
|
|
|
|
echo "Waiting for Graylog ($SECONDS/120 seconds)"
|
|
|
|
sleep 10
|
|
|
|
else
|
|
|
|
echo "Waiting on Graylog timed out. Aborting."
|
2020-03-02 16:51:51 +00:00
|
|
|
break
|
2020-02-26 18:38:24 +00:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2020-02-27 18:45:49 +00:00
|
|
|
# Check for existing GELF TCP Input
|
2020-02-26 18:38:24 +00:00
|
|
|
INPUTSTATE=$(
|
|
|
|
curl -s -X GET \
|
|
|
|
-H "Content-Type: application/json" \
|
|
|
|
-H "X-Requested-By: cli" \
|
|
|
|
-u admin:admin \
|
|
|
|
"http://graylog.172.28.128.30.xip.io:8080/api/system/inputstates")
|
|
|
|
|
|
|
|
INPUT_TYPES=$(echo $INPUTSTATE | jq --raw-output '.states | .[] | .message_input.type')
|
|
|
|
|
|
|
|
for TYPE in $INPUT_TYPES; do
|
2020-02-27 18:45:49 +00:00
|
|
|
if [[ "$TYPE" == "org.graylog2.inputs.gelf.tcp.GELFTCPInput" ]]; then
|
|
|
|
echo "Found GELF TCP input in Graylog, aborting input installation."
|
2020-03-02 16:51:51 +00:00
|
|
|
INPUT_INSTALL=1
|
|
|
|
break
|
2020-02-26 18:38:24 +00:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2020-02-27 18:45:49 +00:00
|
|
|
# Install GELF TCP Input
|
2020-03-02 16:51:51 +00:00
|
|
|
if [[ $INSTALL_INPUT -eq 1 ]]; then
|
|
|
|
echo "Installing GELF TCP input"
|
|
|
|
curl -i -s -X POST \
|
|
|
|
-H "Content-Type: application/json" \
|
|
|
|
-H "X-Requested-By: cli" \
|
|
|
|
-u admin:admin \
|
|
|
|
"http://graylog.172.28.128.30.xip.io:8080/api/system/inputs" \
|
|
|
|
-d @GELFTCPInput.json
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Generate and install TLS keys
|
|
|
|
cd /vagrant/pki
|
|
|
|
|
|
|
|
# Generate Graylog's CA
|
|
|
|
openssl genrsa -out rootCA.key 4096 2> /dev/null
|
|
|
|
openssl req -x509 -new -nodes -key rootCA.key -sha256 -days 1024 \
|
|
|
|
-out rootCA.crt -subj "/C=US/ST=GA/O=MyOrg/CN=localhost" 2> /dev/null
|
|
|
|
|
|
|
|
# Generate Fluentd's keys
|
|
|
|
openssl genrsa -out fluentd.key 4096 2> /dev/null
|
|
|
|
openssl req -new -sha256 -key fluentd.key \
|
|
|
|
-subj "/C=US/ST=GA/O=MyOrg/CN=localhost" -out fluentd.csr 2> /dev/null
|
|
|
|
|
|
|
|
# Sign Fluentd's certificate
|
|
|
|
openssl x509 -req -in fluentd.csr -CA rootCA.crt -CAkey rootCA.key \
|
|
|
|
-CAcreateserial -out fluentd-signed.crt -days 500 -sha256 2> /dev/null
|
|
|
|
|
|
|
|
mv fluentd*.* fluentd/
|
|
|
|
mv root*.* graylog/
|
|
|
|
|
2020-01-22 19:57:33 +00:00
|
|
|
SHELL
|
|
|
|
|
2020-01-22 15:09:57 +00:00
|
|
|
end
|