Skip to content

Instantly share code, notes, and snippets.

@gogojimmy
Last active September 12, 2019 11:10
Show Gist options
  • Save gogojimmy/52e0a7e4971825283c99ee723f182a15 to your computer and use it in GitHub Desktop.
Save gogojimmy/52e0a7e4971825283c99ee723f182a15 to your computer and use it in GitHub Desktop.
Install ELK stack for elk 7.x
#!/bin/bash
# Checking whether user has enough permission to run this script
sudo -n true
if [ $? -ne 0 ]
then
echo "This script requires user to have passwordless sudo access"
exit
fi
dependency_check_deb() {
java -version
if [ $? -ne 0 ]
then
# Installing Java 8 if it's not installed
sudo apt-get install openjdk-8-jre-headless -y
# Checking if java installed is less than version 7. If yes, installing Java 7. As logstash & Elasticsearch require Java 7 or later.
elif [ "`java -version 2> /tmp/version && awk '/version/ { gsub(/"/, "", $NF); print ( $NF < 1.8 ) ? "YES" : "NO" }' /tmp/version`" == "YES" ]
then
sudo apt-get install openjdk-8-jre-headless -y
fi
}
dependency_check_rpm() {
java -version
if [ $? -ne 0 ]
then
#Installing Java 8 if it's not installed
sudo yum install jre-1.8.0-openjdk -y
# Checking if java installed is less than version 7. If yes, installing Java 8. As logstash & Elasticsearch require Java 7 or later.
elif [ "`java -version 2> /tmp/version && awk '/version/ { gsub(/"/, "", $NF); print ( $NF < 1.8 ) ? "YES" : "NO" }' /tmp/version`" == "YES" ]
then
sudo yum install jre-1.8.0-openjdk -y
fi
}
debian_elk() {
# resynchronize the package index files from their sources.
sudo apt-get update
# Download and install the public signing key:
wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add -
sudo apt-get install apt-transport-https
echo "deb https://artifacts.elastic.co/packages/7.x/apt stable main" | sudo tee -a /etc/apt/sources.list.d/elastic-7.x.list
# Install the Elasticsearch Debian package
sudo apt-get update && sudo apt-get install -y openjdk-11-jre-headless elasticsearch kibana logstash
# Starting The Services
sudo systemctl daemon-reload
sudo systemctl enable logstash.service
sudo systemctl start logstash.service
sudo systemctl enable elasticsearch.service
sudo systemctl start elasticsearch.service
sudo systemctl enable kibana.service
sudo systemctl start kibana.service
}
# Installing ELK Stack
if [ "$(grep -Ei 'debian|buntu|mint' /etc/*release)" ]
then
echo " It's a Debian based system"
dependency_check_deb
debian_elk
elif [ "$(grep -Ei 'fedora|redhat|centos' /etc/*release)" ]
then
echo "It's a RedHat based system."
dependency_check_rpm
rpm_elk
else
echo "This script doesn't support ELK installation on this OS."
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment