1.導入 Elasticsearch GPG KEY: rpm --import ./GPG-KEY-elasticsearch or apt-key add ./GPG-KEY-elasticsearch 2.添加elasticsearch的yum repo文件 vim /etc/yum.repo ...
1.導入 Elasticsearch GPG KEY:
rpm --import ./GPG-KEY-elasticsearch
or
apt-key add ./GPG-KEY-elasticsearch
2.添加elasticsearch的yum repo文件
vim /etc/yum.repos.d/elasticsearch.repo
[elasticsearch-7.x]
name=Elasticsearch repository for 7.x packages
baseurl=https://mirror.tuna.tsinghua.edu.cn/elasticstack/7.x/yum/
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=1
autorefresh=1
type=rpm-md
3.安裝elasticsearch
yum install elasticsearch
4.配置elasticsearch
vim /etc/elasticsearch/elasticsearch.yml
# 17行,設置集群名稱 cluster.name: my-cluster # 23行,設置節點名稱 node.name: es-node1 # 56行,允許外網訪問 network.host: 0.0.0.0 # 74行,配置集群master節點 cluster.initial_master_nodes: ["es-node1"]
# elasticsearch預設是不支持跨域的,在末尾添加如下兩行支持跨域
http.cors.enabled: true
http.cors.allow-origin: "*"
5.elasticsearch 預設需要4g的記憶體,這裡可以在適當修改,-Xms4g, 數字即為所占用記憶體
禁止 swap,一旦允許記憶體與磁碟的交換,會引起致命的性能問題。
可以通過在 elasticsearch.yml 中 bootstrap.memory_lock: true
,以保持 JVM 鎖定記憶體,保證 ES 的性能。
vim /etc/elasticsearch/jvm.options
-Xms1g -Xmx1g
6.elasticsearch不可以在root用戶下啟動,所以需要切換用戶
# 添加用戶,我這裡叫es adduser es # 給用戶設置密碼 passwd 123456 # 切換到es用戶下 su es
7.這時切換到es用戶下,又會報各種許可權不足,加上許可權就OK了
#./elasticsearch-env:行88: /etc/sysconfig/elasticsearch: 許可權不夠 chown -R es /etc/sysconfig/elasticsearch #bin/elasticsearch-env: 第 96 行:cd: /etc/elasticsearch: 許可權不夠 chown -R es /etc/elasticsearch #Exception in thread "main" java.nio.file.AccessDeniedException: /var/lib/elasticsearch #只要看到AccessDeniedException異常就給它許可權 chown -R es /var/lib/elasticsearch #Error opening log file '/var/log/elasticsearch/gc.log': Permission denied #將整個elasticsearch目錄許可權給它 chown -R es /var/log/elasticsearch #另外將安裝路徑的許可權給它,這裡目前還沒報錯,不過報錯是遲早的事 chown -R es /usr/share/elasticsearch
8.啟動es
cd /usr/share/elasticsearch/bin ./elasticsearch
9.測試
瀏覽器打開:http://ip:9200
如果開啟了防火牆,需要開啟9200埠,頁面信息顯示如下則啟動成功
{ "name" : "es-node1", "cluster_name" : "elasticsearch", "cluster_uuid" : "-IqD_alTS5SZ3xAtr2_qfQ", "version" : { "number" : "7.17.9", "build_flavor" : "default", "build_type" : "rpm", "build_hash" : "ef48222227ee6b9e70e502f0f0daa52435ee634d", "build_date" : "2023-01-31T05:34:43.305517834Z", "build_snapshot" : false, "lucene_version" : "8.11.1", "minimum_wire_compatibility_version" : "6.8.0", "minimum_index_compatibility_version" : "6.0.0-beta1" }, "tagline" : "You Know, for Search" }