Elasticsearch 的安裝與啓動
1.1 下載 Elasticsearch 7.6.0
下載地址:https://www.elastic.co/cn/downloads/elasticsearch
下載對應需要的 ES 。我這邊是 Linux 的系統。另外 ES 支持 Docker 方式啓動。另外,ES 7.x 不需要本地 JDK 環境支持:
- ES 5,安裝需要 JDK 8 以上
- ES 6.5,安裝需要 JDK 11 以上
- ES 7.2.1,內置了 JDK 12
1.2 啓動 Elasticsearch 7.6.0
1
2
3
4
|
[root@localhost ~] # su elsearch # 切換用戶
[elsearch@localhost ~] # cd elasticsearch-7.6.0/
[elsearch@localhost ~] # bin/elasticsearch # 正常啓動命令
[elsearch@localhost ~] # bin/elasticsearch -d # 守護進程啓動
|
1.3 驗證 Elasticsearch 7.6.0 是否啓動成功
驗證方式1:打開瀏覽器,輸入 http://localhost:9200/ 地址,然後可以得到下面的信息:
驗證方式2:命令行輸入:curl 127.0.0.1:9200。或者輸入:curl localhost:9200
1
2
3
4
5
6
7
8
9
10
|
{
"name" : "VM_0_9_centos" , # 默認啓動的時候指定了 ES 實例名稱.
"cluster_name" : "elasticsearch" , # 默認名爲 elasticsearch
"cluster_uuid" : "noTo0yvOQBeMtZXh9D0frQ" ,
"version" : { # 版本信息
"number" : "7.6.0" ,
......
},
"tagline" : "You Know, for Search"
}
|
打開瀏覽器,通過 http://localhost:9200/_cat/nodes?v 地址,可以看到當前節點信息,如下:
命令行輸入:curl 127.0.0.1:9200/_cat/nodes?v。或者輸入:curl localhost:9200/_cat/nodes?v。
1
2
|
ip heap.percent ram .percent cpu load_1m load_5m load_15m node.role master name
127.0.0.1 45 83 1 0.00 0.01 0.08 dilm * VM_0_9_centos
|
1.4 設置 Elasticsearch 7.6.0 可以外網訪問
1. elasticsearch默認端口9200,需要開啓服務器端口才可以外網訪問。
2. 修改elasticsearch.yml配置文件,將ip改爲0.0.0.0,如果需要特定ip可以訪問,可以設定爲固定的ip。
3. 啓動elasticsearch,發現無法啓動會出現報錯信息。
1
2
3
|
ERROR: [2] bootstrap checks failed
[1]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
[2]: the default discovery settings are unsuitable for production use; at least one of [discovery.seed_hosts, discovery.seed_providers, cluster.initial_master_nodes] must be configured
|
錯誤1解決:修改 /etc/sysctl.conf 配置文件,添加一行配置:vm.max_map_count=360000
錯誤2解決:修改elasticsearch.yml配置文件,放開註釋即可:cluster.initial_master_nodes: ["node-1", "node-2"]
Elasticsearch 的配置
1. 配置文件位於 /elasticsearch-7.6.0/config 目錄下面
- elasticsearch.yml es的相關配置
- jvm.options jvm的相關參數(內存大小等)
- log4j2.properties 日誌相關配置
2. elasticsearch.yml關鍵配置說明
1
2
3
4
5
6
7
8
9
10
11
12
13
|
# ---------------------------------- Cluster ---------------------------------------------------
cluster.name: my-application ES集羣名稱,以此作爲是否同一集羣的判斷條件,相同集羣內的節點設置相同的集羣名。
# ----------------------------------- Node -----------------------------------------------------
node.name: node-1 ES節點名稱,以此作爲集羣中不同節點的區分條件,即實例名。
# ----------------------------------- Paths ----------------------------------------------------
path.data: /path/to/data 數據存儲地址,指定了存儲文檔數據目錄
path.logs: /path/to/logs 日誌存儲地址,注意這裏要改成實際路徑
# ---------------------------------- Network ---------------------------------------------------
network.host: 127.0.0.1 網絡地址和端口,用於 http 和 transport 服務使用
http.port: 9200
|
3. elasticsearch的兩種模式:Development 與 Production 模式說明:
- 以 transport 的地址是否綁定在 localhost 爲標準判斷 network.host。
- Development 模式下在啓動時會以warning的方式提示配置檢查異常。
- Production 模式下在啓動時會以error的方式提示配置檢查異常並退出。
4. 參數修改的第二種方式
1
|
[elsearch@localhost ~] # bin/elasticsearch -Ehttp.port=19200
|
Elasticsearch 本地啓動集羣的方式:即單機集羣多個 ES 實例
1. 單機多個 ES 實例,形成一個 ES 單機僞集羣,啓動腳本如下:
1
2
3
4
5
|
[elsearch@localhost ~] # bin/elasticsearch
[elsearch@localhost ~] # bin/elasticsearch -E http.port=7200 -E path.data=node2
[elsearch@localhost ~] # bin/elasticsearch -E http.port=8200 -E path.data=node3
# [elsearch@localhost ~]# bin/elasticsearch -E node.name=node01 -E cluster.name=bysocket_es_cluster -E path.data=node01_data -d
# [elsearch@localhost ~]# bin/elasticsearch -E node.name=node02 -E cluster.name=bysocket_es_cluster -E path.data=node02_data -d
|
2. 查看多個 ES 實例啓動情況
打開瀏覽器,輸入 http://localhost:9200/_cat/nodes?v 地址,可以看到啓動情況:master的值爲*,則爲當前 master 節點。
相關查看地址:http://IP:3120/_cat/nodes, http://IP:3120/_cat/nodes?v, http://IP:3120/_cluster/stats。
3. 關閉集羣中的 ES 實例,可以使用簡單的命令實現
1
2
|
[root@localhost ~] # ps -ef | grep elasticsearch # 找到elasticsearch線程
[root@localhost ~] # kill -9 pid # 殺死elasticsearch線程
|