Reference: https://www.elastic.co/guide/en/elasticsearch/reference/current/install-elasticsearch.html
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java8-installer
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/5.x/apt stable main" | sudo tee -a /etc/apt/sources.list.d/elastic-5.x.list
apt update
apt install elasticsearch
- SysV init (Ubuntu 14)
sudo /bin/systemctl daemon-reload
sudo /bin/systemctl enable elasticsearch.service
-
SystemD (Ubuntu 16)
update-rc.d elasticsearch defaults 95 10
-
Bind elasticsearch to accept requets from loopback only
Edit /etc/elasticsearch/elasticsearch.yml
network.host: 127.0.0.1
-
Install nginx and apache-utils
apt install nginx apache2-utils
Apache-utils is needed in this case to give us the 'htpasswd' command -
Generate a .htpasswd file
htpasswd -c /etc/nginx/elasticsearchuser.pwd username
-
Edit the default nginx vhost
server {
listen 9222;
server_name localhost;
location / {
rewrite ^/(.*) /$1 break;
proxy_ignore_client_abort on;
proxy_pass http://localhost:9200;
proxy_redirect http://localhost:9200 http://localhost/;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
auth_basic "Elasticsearch Authentication";
auth_basic_user_file /etc/nginx/elasticsearchuser.pwd;
}
}