Skip to content

Instantly share code, notes, and snippets.

@yonglai
Created October 7, 2017 22:29
Show Gist options
  • Save yonglai/7758761f5ef02971c26cc2cbeac7937b to your computer and use it in GitHub Desktop.
Save yonglai/7758761f5ef02971c26cc2cbeac7937b to your computer and use it in GitHub Desktop.
#! /bin/bash
echo Download the Elastic PGP key
rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch
elastic_repo=/etc/yum.repos.d/elastic_stack.repo
touch $elastic_repo
cat <<EOT > $elastic_repo
[elastic-5.x]
name=Elasticsearch repository for 5.x packages
baseurl=https://artifacts.elastic.co/packages/5.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=1
autorefresh=1
type=rpm-md
EOT
echo Install Elasticsearch
yum install elasticsearch -y
sed -i 's/#network.host:.*/network.host: localhost/g' /etc/elasticsearch/elasticsearch.yml
systemctl enable elasticsearch
systemctl start elasticsearch
echo Install Kibana
yum install kibana -y
sed -i 's/#server.host:/server.host:/g' /etc/kibana/kibana.yml
systemctl enable kibana
systemctl start kibana
echo Install Logstash
sudo yum install logstash
echo Install filebat
yum install filebeat -y
sudo chkconfig --add filebeat
echo Install heartbeat
yum install heartbeat -y
sudo chkconfig --add heartbeat
#echo Install X-Pack into Elasticsearch
#/usr/share/elasticsearch/bin/elasticsearch-plugin install x-pack -y
#echo Install X-Pack into Kibana
#/usr/share/kibana/bin/kibana-plugin install x-pack
echo Install nginx
yum install nginx httpd-tools -y
echo Remove default server setting
sed -i.bak -e "38,57d" /etc/nginx/nginx.conf
echo Setup nginx forwarding
elasticsearch_conf=/etc/nginx/conf.d/elasticsearch.conf
touch $elasticsearch_conf
cat <<EOT > $elasticsearch_conf
server {
listen 80;
server_name example.com;
location / {
proxy_pass http://localhost:9200;
proxy_http_version 1.1;
proxy_set_header Upgrade \$http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host \$host;
proxy_cache_bypass \$http_upgrade;
}
}
EOT
kibana_conf=/etc/nginx/conf.d/kibana.conf
touch $kibana_conf
cat <<EOT > $kibana_conf
server {
listen 81;
server_name example.com;
location / {
proxy_pass http://localhost:5601;
proxy_http_version 1.1;
proxy_set_header Upgrade \$http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host \$host;
proxy_cache_bypass \$http_upgrade;
}
}
EOT
echo Enable and start nginx
systemctl enable nginx
systemctl start nginx
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment