版本號 | 作者 | 服務器版本號 | 備註 | |
---|---|---|---|---|
v0.0.1 | 飛豺 | 8416837 | CENTOS8 |
安裝
CENTOS 8
安裝包安裝
# 下載略
sudo tar xvzf elasticsearch-7.6.1-linux-x86_64.tar.gz -C /home/app/ElasticSearch
cd /home/app/ElasticSearch/elasticsearch-7.6.1/
# 啓動命令
bin/elasticsearch
# 提示:future versions of Elasticsearch will require Java 11; your Java version from [/usr/lib/jvm/jdk1.8.0_241/jre] does not meet this requirement - 將來的版本要求java11
# 平時使用jdk8
# 報錯:不能使用root java.lang.RuntimeException: can not run elasticsearch as root
# 切換用戶
su lilei
bin/elasticsearch
# 報錯:Exception in thread "main" java.nio.file.AccessDeniedException: /home/app/ElasticSearch/elasticsearch-7.6.1/config/jvm.options 說明權限不夠,命令前加上sudo # 若配置了權限,就不需要sudo
/home/app/ElasticSearch/elasticsearch-7.6.1/bin/elasticsearch
# 繼續報錯:java.lang.RuntimeException: can not run elasticsearch as root 沒關係,解決就是。說明賬戶lilei也是root角色呀。
# 添加新的用戶組
sudo groupadd elsearch;sudo useradd elsearch -g elsearch;sudo passwd elsearch
# 要求輸入新的密碼
# 輸入lileiel作爲密碼
# passwd: all authentication tokens updated successfully.
# 繼續執行。報錯:elsearch is not in the sudoers file. This incident will be reported 當前使用的賬戶elsearch不屬於sudoer
# 添加sudoer
su root
echo 'elsearch ALL=(ALL) ALL' >> /etc/sudoers
su elsearch # 切換回去
# 錯錯錯,當然不對了,上文把elsearch變成了root用戶!
# 正解見下文:
su root
sudo chown -R elsearch:elsearch elasticsearch-7.6.1/
# 將權限賦給elsearch。不要加sudo
# 執行jps,顯示:8277 Elasticsearch 啓動成功
- 訪問
curl -X GET http://localhost:9200/
{
"name" : "localhost.localdomain",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "vdJlG_JuSreD3wZROjqorw",
"version" : {
"number" : "7.6.1", // es版本號
"build_flavor" : "default",
"build_type" : "tar",
"build_hash" : "aa751e09be0a5072e8570670309b1f12348f023b",
"build_date" : "2020-02-29T00:15:25.529771Z",
"build_snapshot" : false,
"lucene_version" : "8.4.0", // lucene版本號
"minimum_wire_compatibility_version" : "6.8.0",
"minimum_index_compatibility_version" : "6.0.0-beta1"
},
"tagline" : "You Know, for Search" // 宣傳詞
}
- 配置網絡訪問,首先確保防火牆開啓了端口或者防火牆關閉
vim /home/app/ElasticSearch/elasticsearch-7.6.1/config/elasticsearch.yml
# 配置ip和端口
啓動,報錯:max file descriptors [4096] for elasticsearch process is too low, increase to at least [65535] 可能一直報錯,需要增加配置,直到不報錯
su root
sudo vim /etc/security/limits.conf
添加內容:
#切換到root用戶修改
sudo vim /etc/security/limits.conf
# 更改linux的最大文件描述限制要求
* soft nofile 262144
* hard nofile 262144
es soft nofile 262144
es hard nofile 262144
* soft nproc 2048
* hard nproc 4096
es soft nproc 2048
es hard nproc 4096
#更改linux的鎖內存限制要求
es soft memlock unlimited
es hard memlock unlimited
#然後 logout 重新登錄 (7.6.1好像不重登錄,不執行下述命令也行)
ulimit -Hn
262144
繼續修改:sudo vim /etc/security/limits.d/90-nproc.conf
內容:
# 使用root
# vim /etc/security/limits.d/90-nproc.conf
* soft nproc 2048
root soft nproc 2048
再修改:sudo vim /etc/security/limits.conf
內容:
es soft nproc 4096
es hard nproc 4096
再修改:sudo vim /etc/sysctl.conf
內容:
#使用root
# vim /etc/sysctl.conf
#添加下面配置:
vm.max_map_count=655360
#更改linux禁用swapping,添加或修改如下:
vm.swappiness = 1
#並執行命令:
sysctl -p
繼續修改:sudo vim config/elasticsearch.yml
增加:cluster.initial_master_nodes: ["node-1"]
- 上述修改了那麼多,終於啓動成功了:
ps:與底層同時跑,🐂🍺啊,——在中央倉庫看到lucene的最新版本是8.4.1
- 查看jdk與es版本對應
demo
命令行
用命令行建索引並查詢
- 索引
curl -XPUT 'http://192.168.191.6:9200/twitter/_doc/1?pretty' -H 'Content-Type: application/json' -d '
{
"user": "kimchy",
"post_date": "2009-11-15T13:12:00",
"message": "Trying out Elasticsearch, so far so good?"
}'
索引結果:
{
"_index" : "twitter",
"_type" : "_doc",
"_id" : "1",
"_version" : 1,
"result" : "created",
"_shards" : {
"total" : 2,
"successful" : 1, // 成功
"failed" : 0
},
"_seq_no" : 0,
"_primary_term" : 1
}
- 查看
curl -XGET 'http://192.168.191.6:9200/twitter/_doc/1?pretty=true'
# 或者
curl -XGET 'http://192.168.191.6:9200/twitter/_search?pretty=true' -H 'Content-Type: application/json' -d '
{
"query" : {
"match" : { "user": "kimchy" }
}
}'
結果:
{
"_index" : "twitter",
"_type" : "_doc",
"_id" : "1",
"_version" : 1,
"_seq_no" : 0,
"_primary_term" : 1,
"found" : true,
"_source" : {
"user" : "kimchy",
"post_date" : "2009-11-15T13:12:00",
"message" : "Trying out Elasticsearch, so far so good?"
}
}
- 搜索
搜索twitter目錄下的文檔
curl -XGET 'http://192.168.191.6:9200/twitter/_search?q=user:kimchy&pretty=true'
響應:
{
"took" : 136,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 1,
"relation" : "eq"
},
"max_score" : 0.2876821,
"hits" : [
{
"_index" : "twitter",
"_type" : "_doc",
"_id" : "1",
"_score" : 0.2876821,
"_source" : {
"user" : "kimchy",
"post_date" : "2009-11-15T13:12:00",
"message" : "Trying out Elasticsearch, so far so good?"
}
}
]
}
}
圖形界面
分詞器
中文
IK
ik,起先做solr的時候也用的這個,記得當時還有其它收費分詞器。
歷史版本下載
安裝kibana
- 腳本
sudo tar xvzf kibana-7.6.1-linux-x86_64.tar.gz -C /home/app/Kibana/
cd /home/app/Kibana/kibana-7.6.1-linux-x86_64
# 目錄授權
sudo chown -R elsearch:elsearch kibana-7.6.1-linux-x86_64/
# 安裝sense
# 切換非root賬戶
su elsearch
sh bin/kibana plugin --install elastic/sense # 5+以後不需要安裝.在界面點Dev Tools
# 啓動kibana 默認5601
# run
# run es
/home/app/apache-elasticsearch/elasticsearch-2.4.4/bin/elasticsearch
# run k 可能有點慢 【注意】第一次啓動報錯: FATAL Error: EACCES: permission denied, stat '.i18nrc.json' 無權限 國際化文件無權限錯誤 ;第二次啓動,就成功了
/home/app/Kibana/kibana-7.6.1-linux-x86_64/bin/kibana # 注意es的ip
# 訪問.應先在配置文件配置ip訪問
curl http://192.168.191.6:5601/app/sense
# 控制檯
http://192.168.191.6:5601/app/kibana #/dev_tools/console # 選擇Dev Tools(扳手logo|icon) 進入控制檯
- 效果