【介紹頁】
https://www.elastic.co/cn/downloads/past-releases/elasticsearch-7-11-1
【下載地址】
https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.11.1-linux-x86_64.tar.gz
【目標】
1.讓ES對本機9200端口提供服務,即敲入curl localhost:9200能看到
{ "name" : "node-1", "cluster_name" : "hy-app322", "cluster_uuid" : "3uOf0MeGT06KHb1aODicpQ", "version" : { "number" : "7.11.0", "build_flavor" : "default", "build_type" : "tar", "build_hash" : "8ced7813d6f16d2ef30792e2fcde3e755795ee04", "build_date" : "2021-02-08T22:44:01.320463Z", "build_snapshot" : false, "lucene_version" : "8.7.0", "minimum_wire_compatibility_version" : "6.8.0", "minimum_index_compatibility_version" : "6.0.0-beta1" }, "tagline" : "You Know, for Search" }
這樣的反饋內容;
2.讓ES對ip:9200端口提供服務,如虛擬機ip為192.168.32.130,那么主機上瀏覽器通過192.168.32.130:9200端口可以得到上面這段反饋。
3.在本機或是主機上 能創建、查詢和刪除文檔。
以上三條中,頭兩條較容易實現,但不保證實現后第三條也能順利出來。
網上類似文檔多如牛毛,但基本只滿足了目標1和2,但這是不完全的。
ES能否實用,還得以第三條為檢驗標准。
【准備安裝的軟件】
elasticsearch-7.11.0-linux-x86_64.tar.gz
因為該版本自帶jdk,就不需另裝一個了。
執行命令:
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.11.1-linux-x86_64.tar.gz
【系統版本及內核】
CentOS Linux release 7.9.2009 (Core)
3.10.0-1160.el7.x86_64
【es解壓過程】
因為es不能以root執行,故創建用戶hy,然后以這個用戶來解壓
$tar -xvzf elasticsearch-7.11.0-linux-x86_64.tar.gz
解壓之后會出現目錄elasticsearch-7.11.0,
配置文件是elasticsearch-7.11.0/config/elasticsearch.yml,
執行文件是elasticsearch-7.11.0/bin/elasticsearch
【elasticsearch.yml的修改點】
cluster.name: hy-app322 # 集群名,多節點時節點扎堆就靠它,所以最好給個不易重復能獨立標識該群的名字
node.name: node-1 # 放開此節點即可
network.host: 0.0.0.0 # 改寫成0.0.0.0是讓本機和外網都能訪問
http.port: 9200 # 默認的服務端口 放開此節點即可
cluster.initial_master_nodes: ["node-1"] # 放開后,去掉其中的node-2,只留下node-1
【/etc/security/limits.conf的修改點】
切換到root用戶
vi /etc/security/limits.conf
在文件末尾,#End of file下書寫
* soft nofile 65535
* hard nofile 131072
* soft nproc 4096
* hard nproc 4096
保存退出
此項修改在再度切換為hy用戶才有效,因此不要一個普通賬戶hy開個窗口等着,一個root在另一個窗口改。
【/etc/sysctl.conf的修改點】
vi /etc/sysctl.conf
添加
vm.max_map_count=655360
保存后執行
sysctl -p
【系統防火牆的設置】
放開9200端口或是直接了當停止防火牆
#systemctl stop firewalld
【執行es】
切回hy賬戶,執行elasticsearch-7.11.0/bin/elasticsearch
【目標1的檢驗】
[hy@localhost ~]$ curl localhost:9200 { "name" : "node-1", "cluster_name" : "hy-app130", "cluster_uuid" : "OHQmV0p8QUCLutfepnipqQ", "version" : { "number" : "7.11.0", "build_flavor" : "default", "build_type" : "tar", "build_hash" : "8ced7813d6f16d2ef30792e2fcde3e755795ee04", "build_date" : "2021-02-08T22:44:01.320463Z", "build_snapshot" : false, "lucene_version" : "8.7.0", "minimum_wire_compatibility_version" : "6.8.0", "minimum_index_compatibility_version" : "6.0.0-beta1" }, "tagline" : "You Know, for Search" } [hy@localhost ~]$
【目標2的檢驗】
【目標3的檢驗】
待執行的語句:
# 創建兩條文檔 curl -H "Content-Type: application/json" -XPUT 'localhost:9200/google/emp/1?pretty' -d' {"name":"Andy","age":"21","salary":"30k","hdate":"2020-1-1T12:12:12"}' curl -H "Content-Type: application/json" -XPUT 'localhost:9200/google/emp/2?pretty' -d' {"name":"Bill","age":"22","salary":"60k","hdate":"2021-1-1T12:12:12"}' # 按ID查找 curl -XGET 'localhost:9200/google/emp/2?pretty' # 刪除 curl -XDELETE 'localhost:9200/google/emp/2?pretty' # 看是否刪掉了 curl -XGET 'localhost:9200/google/emp/2?pretty'
執行結果:
[hy@localhost ~]$ curl -H "Content-Type: application/json" -XPUT 'localhost:9200/google/emp/1?pretty' -d' {"name":"Andy","age":"21","salary":"30k","hdate":"2020-1-1T12:12:12"}' { "_index" : "google", "_type" : "emp", "_id" : "1", "_version" : 1, "result" : "created", "_shards" : { "total" : 2, "successful" : 1, "failed" : 0 }, "_seq_no" : 0, "_primary_term" : 1 } [hy@localhost ~]$ curl -H "Content-Type: application/json" -XPUT 'localhost:9200/google/emp/2?pretty' -d' {"name":"Bill","age":"22","salary":"60k","hdate":"2021-1-1T12:12:12"}' { "_index" : "google", "_type" : "emp", "_id" : "2", "_version" : 1, "result" : "created", "_shards" : { "total" : 2, "successful" : 1, "failed" : 0 }, "_seq_no" : 1, "_primary_term" : 1 } [hy@localhost ~]$ url -XGET 'localhost:9200/google/emp/2?pretty' bash: url: command not found... [hy@localhost ~]$ curl -XGET 'localhost:9200/google/emp/2?pretty' { "_index" : "google", "_type" : "emp", "_id" : "2", "_version" : 1, "_seq_no" : 1, "_primary_term" : 1, "found" : true, "_source" : { "name" : "Bill", "age" : "22", "salary" : "60k", "hdate" : "2021-1-1T12:12:12" } } [hy@localhost ~]$ curl -XDELETE 'localhost:9200/google/emp/2?pretty' { "_index" : "google", "_type" : "emp", "_id" : "2", "_version" : 2, "result" : "deleted", "_shards" : { "total" : 2, "successful" : 1, "failed" : 0 }, "_seq_no" : 2, "_primary_term" : 1 } [hy@localhost ~]$ curl -XGET 'localhost:9200/google/emp/2?pretty' { "_index" : "google", "_type" : "emp", "_id" : "2", "found" : false } [hy@localhost ~]$
如果執行和預期一致,則說明安裝成功。
END