使用
uname -a
查看 Linux 系統(tǒng)內(nèi)核與版本,選擇對(duì)應(yīng)的安裝包,
下文以Linux x86_64 / Elasticsearch 8.7
為例,演示通過RPM
和壓縮包
兩種方式的安裝步驟。
1 下載與安裝
Download Elasticsearch
1.1 RPM
Install Elasticsearch with RPM
# 創(chuàng)建并切換目錄
mkdir /data/elastic
cd /data/elastic
# 下載
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-8.7.0-x86_64.rpm
# 安裝
rpm -ivh elasticsearch-8.7.0-x86_64.rpm
# 查看配置文件位置
rpm -qc kibana
安裝完畢后展示以下信息,記得保存安裝完畢后的 elastic 賬號(hào)密碼
--------------------------- Security autoconfiguration information ------------------------------
Authentication and authorization are enabled.
TLS for the transport and HTTP layers is enabled and configured.
The generated password for the elastic built-in superuser is : bLDOCJP2l5TmLegNt6BN
If this node should join an existing cluster, you can reconfigure this with
'/usr/share/elasticsearch/bin/elasticsearch-reconfigure-node --enrollment-token <token-here>'
after creating an enrollment token on your existing cluster.
You can complete the following actions at any time:
Reset the password of the elastic built-in superuser with
'/usr/share/elasticsearch/bin/elasticsearch-reset-password -u elastic'.
Generate an enrollment token for Kibana instances with
'/usr/share/elasticsearch/bin/elasticsearch-create-enrollment-token -s kibana'.
Generate an enrollment token for Elasticsearch nodes with
'/usr/share/elasticsearch/bin/elasticsearch-create-enrollment-token -s node'.
-------------------------------------------------------------------------------------------------
1.2 壓縮包
Install Elasticsearch from archive on Linux or MacOS
# 創(chuàng)建用戶 elastic,其中 -d 和 -m 選項(xiàng)用來為登錄名 elastic 產(chǎn)生一個(gè)主目錄 /home/elastic
useradd -d /home/elastic -m elastic
# 指定用戶 elastic 的口令
passwd elastic
# 創(chuàng)建安裝目錄
mkdir -p /app/elastic
# 更改目錄權(quán)限
chown -R elastic:elastic /app/elastic
# 切換用戶
sudo su - elastic
# 切換目錄
cd /app/elastic
# 下載安裝包
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-8.7.0-linux-x86_64.tar.gz
# 解壓安裝包
tar -zxvf elasticsearch-8.7.0-linux-x86_64.tar.gz
# 切換解壓后的目錄
cd /app/elastic/elasticsearch-8.7.0
2 配置
2.1 Linux 系統(tǒng)配置
Configure important system settings
2.1.1 打開文件句柄數(shù)
# 臨時(shí)會(huì)話生效
sudo ulimit -n 65535
# 永久生效
vim /etc/security/limits.conf
# 在上面配置文件中增加以下內(nèi)容
elasticsearch - nofile 65535
2.1.2 禁用交換
# 臨時(shí)會(huì)話生效,無需重啟
sudo swapoff -a
# 永久生效
vim /etc/fstab
# 在上面配置文件中注釋包含 swap 的所有行
2.1.3 虛擬內(nèi)存
# 臨時(shí)會(huì)話生效,無需重啟
sysctl -w vm.max_map_count=262144
# 永久生效
vim /etc/sysctl.conf
# 在上面配置文件中注釋以下內(nèi)容
vm.max_map_count = 262144
2.1.4 線程數(shù)
# 臨時(shí)會(huì)話生效,無需重啟
ulimit -u 4096
# 永久生效
vim /etc/security/limits.conf
# 在上面配置文件中注釋以下內(nèi)容
elasticsearch - nproc 4096
2.2 Elasticsearch 應(yīng)用配置
Configure important Elasticsearch settings
- RPM 安裝的配置文件路徑
vim /etc/elasticsearch/elasticsearch.yml
- 壓縮包 安裝的配置文件路徑
vim /../elasticsearch-8.7.0/config/elasticsearch.yml
# Use a descriptive name for your cluster:
cluster.name: elasticsearch-dev
# Use a descriptive name for the node:
node.name: dev-data-1
# Path to directory where to store the data (separate multiple locations by comma):
path.data: /var/lib/elasticsearch
# Path to log files:
path.logs: /var/log/elasticsearch
# By default Elasticsearch is only accessible on localhost. Set a different
# address here to expose this node on the network:
network.host: 172.16.32.2
# By default Elasticsearch listens for HTTP traffic on the first free port it
# finds starting at 9200. Set a specific HTTP port here:
http.port: 9200
# Pass an initial list of hosts to perform discovery when this node is started:
# The default list of hosts is ["127.0.0.1", "[::1]"]
discovery.seed_hosts: ["172.16.32.2"]
# Enable security features
xpack.security.enabled: true
xpack.security.enrollment.enabled: true
# Enable encryption for HTTP API client connections, such as Kibana, Logstash, and Agents
xpack.security.http.ssl:
enabled: true
keystore.path: certs/http.p12
# Enable encryption and mutual authentication between cluster nodes
xpack.security.transport.ssl:
enabled: true
verification_mode: certificate
keystore.path: certs/transport.p12
truststore.path: certs/transport.p12
# Create a new cluster with the current node only
# Additional nodes can still join the cluster later
cluster.initial_master_nodes: ["dev-data-1"]
# Allow HTTP API connections from anywhere
# Connections are encrypted and require user authentication
http.host: 0.0.0.0
# Allow other nodes to join the cluster from anywhere
# Connections are encrypted and mutually authenticated
transport.host: 0.0.0.0
3 啟動(dòng)與停止
3.1 RPM
# 配置系統(tǒng)啟動(dòng)時(shí)自動(dòng)啟動(dòng)
sudo /bin/systemctl daemon-reload
sudo /bin/systemctl enable elasticsearch.service
# 啟動(dòng)
service elasticsearch start
# 停止
service elasticsearch stop
# 檢查服務(wù)狀態(tài)
service elasticsearch status
# 查看日志
journalctl -u elasticsearch.service
3.2 壓縮包
命令行方式
文章來源:http://www.zghlxwxcb.cn/news/detail-458936.html
# 啟動(dòng)
/app/elastic/elasticsearch-8.7.0/bin/elasticsearch
# 停止
Ctrl-C
守護(hù)進(jìn)程方式
文章來源地址http://www.zghlxwxcb.cn/news/detail-458936.html
# 啟動(dòng)
/app/elastic/elasticsearch-8.7.0/bin/elasticsearch -d -p pid
# 停止
pkill -F pid
3.3 檢查是否啟動(dòng)成功
# 此處需要輸入安裝時(shí)生成的 elastic 賬號(hào)密碼
[root@*** /etc/kibana]# curl --cacert /etc/elasticsearch/certs/http_ca.crt -u elastic https://localhost:9200
Enter host password for user 'elastic':
{
"name" : "dev-data-1",
"cluster_name" : "elasticsearch-dev",
"cluster_uuid" : "Dumv3kP4TxGpNxBZaCuwYw",
"version" : {
"number" : "8.7.0",
"build_flavor" : "default",
"build_type" : "rpm",
"build_hash" : "09520b59b6bc1057340b55750186466ea715e30e",
"build_date" : "2023-03-27T16:31:09.816451435Z",
"build_snapshot" : false,
"lucene_version" : "9.5.0",
"minimum_wire_compatibility_version" : "7.17.0",
"minimum_index_compatibility_version" : "7.0.0"
},
"tagline" : "You Know, for Search"
}
4 常用命令
# 重置賬號(hào)密碼
/usr/share/elasticsearch/bin/elasticsearch-reset-password -u elastic
# 創(chuàng)建 kibana 注冊(cè)令牌
/usr/share/elasticsearch/bin/elasticsearch-create-enrollment-token -s kibana
# 創(chuàng)建 Elasticsearch Node 注冊(cè)令牌
/usr/share/elasticsearch/bin/elasticsearch-create-enrollment-token -s node
# 如果此節(jié)點(diǎn)應(yīng)加入現(xiàn)有群集,則可以使用重新配置
/usr/share/elasticsearch/bin/elasticsearch-reconfigure-node --enrollment-token <token-here>
到了這里,關(guān)于Elasticsearch [8.7] 安裝與配置的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!