AWS EC2 安裝ElasticSearch/Kibana

搞了一下午,build了兩個版本的memo

EC2 ver :2018.03-release

ElasticSearch:6.4.2/6.2.4

Kibana:6.4.2/6.2.4

ik:6.4.2/6.2.4


安裝ElasticSearch

ES/Kibana/ik安裝部分 流程擷取自同事Derek大大的按圖施工保證成功(XD

這邊做一些版本差異修改及流程詳解

  1. 更新套件以及java 1.8.0

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    $ sudo yum update

    $ sudo yum install java-1.8.0-openjdk.x86_64

    $ sudo alternatives --config java

    > There are 2 programs which provide 'java'.
    > Selection Command
    > -----------------------------------------------
    > *+ 1 /usr/lib/jvm/jre-1.7.0-openjdk.x86_64/bin/java
    > 2 /usr/lib/jvm/jre-1.8.0-openjdk.x86_64/bin/java

    Enter to keep the current selection[+], or type selection number:2
  2. 安裝ElasticSearch,注意對應版號

1
2
3
4
5
$ mkdir ~/src
$ cd ~/src
$ wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.4.2.rpm

$ sudo rpm --install elasticsearch-6.4.2.rpm
  1. 修改jvm使用記憶體大小
1
2
3
4
5
6
7
8
$ sudo su
$ nano /etc/elasticsearch/jvm.options

/etc/elasticsearch/jvm.options
#-Xms1g
#-Xmx1g
-Xms256m
-Xmx256m
  1. 修改ElasticSearch Host
    

這邊使用EC2 PrviteIP

Docker好像是使用elasticsearch(見Reference)

1
2
3
4
5
6
7
8
$ nano /etc/elasticsearch/elasticsearch.yml

/etc/elasticsearch/elasticsearch.yml
・・・
network.host: 10.0.0.0
transport.host: localhost

sudo -i service elasticsearch start

安裝Kibana

版本需要對應ElasticSearch

解壓縮/設定完後在目錄下執行./bin/kibana就可啟動kibana及監聽

1
2
3
4
5
6
7
8
9
10
11
12
wget https://artifacts.elastic.co/downloads/kibana/kibana-6.4.2-linux-x86_64.tar.gz

tar -xzvf kibana-6.4.2-linux-x86_64.tar.gz

cd kibana-6.4.2-linux-x86_64

nano config/kibana.yml

server.port: 5601
server.host: "0.0.0.0"

./bin/kibana

安裝ik分詞模組

版本也須對應ElasticSratch

其中

1
cp -R /usr/share/elasticsearch/plugins/ik/elasticsearch/* /usr/share/elasticsearch/plugins/ik/

如果版本比6.4.2低的話則有可能會多出現這個目錄 需要執行cp

6.4.2解壓出來無多此目錄

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
wget https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v6.4.2/elasticsearch-analysis-ik-6.4.2.zip

sudo mkdir /usr/share/elasticsearch/plugins/ik

sudo mv elasticsearch-analysis-ik-6.4.2.zip /usr/share/elasticsearch/plugins/ik

cd /usr/share/elasticsearch/plugins/ik/

sudo unzip elasticsearch-analysis-ik-6.4.2.zip

sudo rm elasticsearch-analysis-ik-6.4.2.zip

#cp -R /usr/share/elasticsearch/plugins/ik/elasticsearch/* /usr/share/elasticsearch/plugins/ik/

sudo service elasticsearch restart

掛載字典檔

可以自行擴充字典檔。IK Plugin 字典檔放在 /usr/share/elasticsearch/plugins/ik/config/main.dic 這個路徑,可以自行更換。為了獲得更好的搜尋效果,我們先更換為「超齊百萬字典檔」,這是之前特地製作的字典檔,內容包含 UTF-8 繁體與簡體字碼 (目前有 11x 萬詞),有需要的請自行下載使用。替換以後重新啟動服務 (IK 也支援熱字典檔擴充)

直接替換原有的ik預設字典檔

1
2
3
4
5
6
7
cd /usr/share/elasticsearch/plugins/ik/config/

sudo wget https://github.com/samejack/sc-dictionary/raw/master/main.txt

sudo mv main.dic main.dic.cn

sudo mv main.txt main.dic

設定Nginx轉發

server name 設定domain name

proxy_pass 設定EC2 Privite Ip

很多教學都用public cname,是也可以..

kibana一樣設定 使用不同domain改Port為5601即可

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
server {

listen 80;
server_name domain.com.tw;

#error logging

error_log /var/log/nginx/elasticsearch_error.log;

location / {

proxy_set_header Connection "Keep-Alive";
proxy_set_header Proxy-Connection "Keep-Alive";
proxy_set_header Authorization "";

proxy_pass http://10.0.0.0:9200/;


}
#ELB Health Checks

location /status {
root /usr/share/nginx/html/;
}

}

EC2 Security Group

Security Group要記得開對應機器的ip以及80,9200,5601

如果是要打進ElasticSearch則需要開80,9200


Reference

Elastic

Nginx Reverse Proxy for Elasticsearch and Kibana 5 on AWS

nginx as HTTPS proxy for Elasticsearch (Docker setting)

超齊百萬字典檔