創建網絡-拉取鏡像-啓動es
docker network create elastic
docker pull docker.elastic.co/elasticsearch/elasticsearch:8.7.1
docker run --name es-node01 --net elastic -p 9200:9200 -p 9300:9300 -t docker.elastic.co/elasticsearch/elasticsearch:8.7.1
第一次啓動es時會生成elastic用戶密碼和kibana密碼-在控制檯,注意保存
eg:
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✅ Elasticsearch security features have been automatically configured!
✅ Authentication is enabled and cluster connections are encrypted.
ℹ️ Password for the elastic user (reset with `bin/elasticsearch-reset-password -u elastic`):
UkshFkxayFHiVZaisZzp
ℹ️ HTTP CA certificate SHA-256 fingerprint:
7662d86bd72a75c868b279f04b8ac55ca03d05b7b67c83691c3427f41d64708e
ℹ️ Configure Kibana to use this cluster:
• Run Kibana and click the configuration link in the terminal when Kibana starts.
• Copy the following enrollment token and paste it into Kibana in your browser (valid for the next 30 minutes):
eyJ2ZXIiOiI4LjcuMSIsImFkciI6WyIxNzIuMTguMC4yOjkyMDAiXSwiZmdyIjoiNzY2MmQ4NmJkNzJhNzVjODY4YjI3OWYwNGI4YWM1NWNhMDNkMDViN2I2N2M4MzY5MWMzNDI3ZjQxZDY0NzA4ZSIsImtleSI6ImZXZE1QSWdCTWJoenoyMHU5d01TOmdaTWxTalNrU2VhOHRZVWNKRV9QdmcifQ==
ℹ️ Configure other nodes to join this cluster:
• Copy the following enrollment token and start new Elasticsearch nodes with `bin/elasticsearch --enrollment-token <token>` (valid for the next 30 minutes):
eyJ2ZXIiOiI4LjcuMSIsImFkciI6WyIxNzIuMTguMC4yOjkyMDAiXSwiZmdyIjoiNzY2MmQ4NmJkNzJhNzVjODY4YjI3OWYwNGI4YWM1NWNhMDNkMDViN2I2N2M4MzY5MWMzNDI3ZjQxZDY0NzA4ZSIsImtleSI6ImUyZE1QSWdCTWJoenoyMHU5Z1A1OlpVd2xsdjlrUWRLaG9lOTlGUU9QVGcifQ==
If you're running in Docker, copy the enrollment token and run:
`docker run -e "ENROLLMENT_TOKEN=<token>" docker.elastic.co/elasticsearch/elasticsearch:8.7.1`
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
測試es 是否啓動成功
訪問 https:localhost:9200 用戶名: elastic 密碼: UkshFkxayFHiVZaisZzp
如下,表示啓動成功
{
"name" : "cc6f963c54d6",
"cluster_name" : "docker-cluster",
"cluster_uuid" : "yPMHDO_WRbmITRhIJjtFZw",
"version" : {
"number" : "8.7.1",
"build_flavor" : "default",
"build_type" : "docker",
"build_hash" : "f229ed3f893a515d590d0f39b05f68913e2d9b53",
"build_date" : "2023-04-27T04:33:42.127815583Z",
"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"
}
安裝kibana
拉取kibana 鏡像-啓動kibana (注意kibana版本要與elasticsearch保持一致)
docker pull docker.elastic.co/kibana/kibana:8.7.1
docker run --name kib-01 --net elastic -p 5601:5601 docker.elastic.co/kibana/kibana:8.7.1
- 控制檯會生成一個訪問連接 點擊訪問
Go to http://0.0.0.0:5601/?code=724665 to get started.
訪問: http://0.0.0.0:5601/?code=724665 (code 每次會變)
輸入es啓動時保存的token (• Run Kibana and click the configuration link in the terminal when Kibana starts.)
ℹ️ Configure Kibana to use this cluster:
• Run Kibana and click the configuration link in the terminal when Kibana starts.
• Copy the following enrollment token and paste it into Kibana in your browser (valid for the next 30 minutes):
eyJ2ZXIiOiI4LjcuMSIsImFkciI6WyIxNzIuMTguMC4yOjkyMDAiXSwiZmdyIjoiNzY2MmQ4NmJkNzJhNzVjODY4YjI3OWYwNGI4YWM1NWNhMDNkMDViN2I2N2M4MzY5MWMzNDI3ZjQxZDY0NzA4ZSIsImtleSI6ImZXZE1QSWdCTWJoenoyMHU5d01TOmdaTWxTalNrU2VhOHRZVWNKRV9QdmcifQ==
輸入用戶名/密碼(用戶名: elastic 密碼: UkshFkxayFHiVZaisZzp)
-
導入測試數據 — 點擊 try sample data - other sample data sets -> add data;
-
查看數據-》 導航書籤欄找到DashBoard - 就可以查看你剛剛導入的測試數據了
安裝multi elasticsearch head 插件(谷歌商店)
-
谷歌商店搜索 elasticsearch head 會出現一個叫 Multi ElasticSearch Head 插件,添加到擴展程序,自行操作(github nmp編譯打包的插件還需要做一些配置,比較麻煩)
-
安裝好後,默認是http連接,new -> https://localhost:9200/?auth_user=elastic&auth_password=UkshFkxayFHiVZaisZzp ,連接es
/config/elasticsearch.yml 配置如下:
cluster.name: "docker-cluster"
network.host: 0.0.0.0
http.cors.allow-headers: Authorization,X-Requested-With,Content-Type,Content-Length
#----------------------- BEGIN SECURITY AUTO CONFIGURATION -----------------------
#
# The following settings, TLS certificates, and keys have been automatically
# generated to configure Elasticsearch security features on 21-05-2023 03:13:20
#
# --------------------------------------------------------------------------------
# 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: ["cc6f963c54d6"]
#----------------------- END SECURITY AUTO CONFIGURATION -------------------------
過程中常見錯誤以及解決方案
- 修改配置文件,命令找不到
1. bash: vim: command not found
- resolve
+ root 用戶進入容器
docker exec -ti --user root {容器名} /bin/bash
apt-get update
apt-get install vim
- 參考: