網(wǎng)站建設(shè)容易嗎seo自媒體培訓(xùn)
警告:請(qǐng)勿將這些說(shuō)明用于生產(chǎn)部署
本頁(yè)上的說(shuō)明僅適用于本地開(kāi)發(fā)。請(qǐng)勿將此配置用于生產(chǎn)部署,因?yàn)樗话踩?。?qǐng)參閱部署選項(xiàng)以獲取生產(chǎn)部署選項(xiàng)列表。
使用 start-local 腳本在 Docker 中快速設(shè)置 Elasticsearch 和 Kibana 以進(jìn)行本地開(kāi)發(fā)或測(cè)試。
此設(shè)置附帶一個(gè)月的試用許可證,其中包括所有 Elastic 功能。試用期過(guò)后,許可證將恢復(fù)為免費(fèi)和開(kāi)放 - Basic。有關(guān)更多信息,請(qǐng)參閱 Elastic 訂閱。
更多閱讀:Elasticsearch:如何在 Docker 上運(yùn)行 Elasticsearch 8.x 進(jìn)行本地開(kāi)發(fā)
先決條件
- 如果你尚未安裝 Docker,請(qǐng)下載并安裝適用于你的操作系統(tǒng)的Docker Desktop。
- 如果你使用的是 Microsoft Windows,請(qǐng)安裝適用于 Linux 的 Windows 子系統(tǒng) (WSL)。
運(yùn)行 start-local
start-local 腳本可以在地址進(jìn)行下載 GitHub - elastic/start-local: Try Elasticsearch and Kibana locally。要在本地設(shè)置 Elasticsearch 和 Kibana,請(qǐng)運(yùn)行 start-local 腳本。
curl -fsSL https://elastic.co/start-local | sh
此腳本創(chuàng)建一個(gè) elastic-start-local 文件夾,其中包含:
- docker-compose.yml:Elasticsearch 和 Kibana 的 Docker Compose 配置
- .env:環(huán)境設(shè)置,包括 Elasticsearch 密碼
- start.sh 和 stop.sh:用于啟動(dòng)和停止 Elasticsearch 和 Kibana 的腳本
- uninstall.sh:用于卸載 Elasticsearch 和 Kibana 的腳本
$ pwd
/Users/liuxg/data/start-local
$ curl -fsSL https://elastic.co/start-local | sh______ _ _ _ | ____| | | | (_) | |__ | | __ _ ___| |_ _ ___ | __| | |/ _` / __| __| |/ __|| |____| | (_| \__ \ |_| | (__ |______|_|\__,_|___/\__|_|\___|
-------------------------------------------------
🚀 Run Elasticsearch and Kibana for local testing
-------------------------------------------------?? Do not use this script in a production environment?? Setting up Elasticsearch and Kibana v8.15.3...- Generated random passwords
- Created the elastic-start-local folder containing the files:- .env, with settings- docker-compose.yml, for Docker services- start/stop/uninstall commands
- Running docker compose up --wait[+] Running 24/24? kibana 13 layers [?????????????] 0B/0B Pulled 62.0s ? 23987c61699b Pull complete 5.6s ? 8915ba981ca3 Pull complete 4.0s ? 4c8b24782cfe Pull complete 33.1s ? 807b2cadbcb1 Pull complete 5.3s ? aea2eb4e3b10 Pull complete 9.4s ? ab757075fe94 Pull complete 7.1s ? 4ca545ee6d5d Pull complete 8.5s ? 7e3665e2de31 Pull complete 9.8s ? c3055b6e09f0 Pull complete 10.9s ? ec8a64bd5a5f Pull complete 11.1s ? dfd6d27a36fe Pull complete 12.5s ? 17173b4bfc67 Pull complete 13.3s ? 2b1cd59a6503 Pull complete 14.1s ? kibana_settings 8 layers [????????] 0B/0B Pulled 66.3s ? 4253e52d2237 Pull complete 16.8s ? e436db77a937 Pull complete 15.4s ? 0f431d485a97 Pull complete 57.7s ? 8673bfa492b1 Pull complete 18.4s ? fab125f6f236 Pull complete 19.8s ? 43ad26ccf7ea Pull complete 21.8s ? fb6208a6757b Pull complete 23.1s ? 500133bff266 Pull complete 24.9s ? elasticsearch Pulled 66.3s
[+] Building 0.0s (0/0) docker:desktop-linux
[+] Running 6/6? Network elastic-start-local_default Created 0.0s ? Volume "elastic-start-local_dev-elasticsearch" Created 0.0s ? Volume "elastic-start-local_dev-kibana" Cre... 0.0s ? Container es-local-dev Healthy 2.1s ? Container kibana_settings Exited 0.1s ? Container kibana-local-dev Healthy 0.0s 🎉 Congrats, Elasticsearch and Kibana are installed and running in Docker!🌐 Open your browser at http://localhost:5601Username: elasticPassword: wuRd1MYj🔌 Elasticsearch API endpoint: http://localhost:9200
🔑 API key: MDBQWUpKTUJDMldQM2xRTVlqM1A6N2FyUE9WRVpSSFc4d25QNWZTYThMQQ==Learn more at https://github.com/elastic/start-local
我們首先查看一下生成的文件:
$ pwd
/Users/liuxg/data/start-local
$ ls
elastic-start-local
它創(chuàng)建了一個(gè)叫做 elastic-start-local 的目錄。我們進(jìn)入該目錄進(jìn)行查看:
$ cd elastic-start-local/
$ ls -al
total 40
drwxr-xr-x 7 liuxg staff 224 Nov 13 17:24 .
drwxr-xr-x 3 liuxg staff 96 Nov 13 17:24 ..
-rw-r--r-- 1 liuxg staff 419 Nov 13 17:26 .env
-rw-r--r-- 1 liuxg staff 2434 Nov 13 17:24 docker-compose.yml
-rwxr-xr-x 1 liuxg staff 1450 Nov 13 17:24 start.sh
-rwxr-xr-x 1 liuxg staff 189 Nov 13 17:24 stop.sh
-rwxr-xr-x 1 liuxg staff 1099 Nov 13 17:24 uninstall.sh
從上面,我們可以看到所生成的文件。我們來(lái)查看一下 .env 的文件:
.env
ES_LOCAL_VERSION=8.15.3
ES_LOCAL_CONTAINER_NAME=es-local-dev
ES_LOCAL_PASSWORD=wuRd1MYj
ES_LOCAL_URL=http://localhost:9200
ES_LOCAL_PORT=9200
ES_LOCAL_HEAP_INIT=128m
ES_LOCAL_HEAP_MAX=2g
KIBANA_LOCAL_CONTAINER_NAME=kibana-local-dev
KIBANA_LOCAL_PORT=5601
KIBANA_LOCAL_PASSWORD=N6IOHrSA
KIBANA_ENCRYPTION_KEY=V2Q2IKYiH5YgXgeXuokzBuuZ1wuB7ygE
ES_LOCAL_API_KEY=MDBQWUpKTUJDMldQM2xRTVlqM1A6N2FyUE9WRVpSSFc4d25QNWZTYThMQQ==
從上面的配置中,我們可以看出來(lái),修改?ES_LOCAL_VERSION 可以改變 Elasticsearch 及 Kibana 的版本。在上面,我們也可以看到它配置的密碼 ES_LOCAL_PASSWORD。
我們使用如下的命令來(lái)進(jìn)行查看:
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
4b50f85bddd3 docker.elastic.co/kibana/kibana:8.15.3 "/bin/tini -- /usr/l…" 7 minutes ago Up 7 minutes (healthy) 127.0.0.1:5601->5601/tcp kibana-local-dev
a89056d65008 docker.elastic.co/elasticsearch/elasticsearch:8.15.3 "/bin/tini -- /usr/l…" 7 minutes ago Up 7 minutes (healthy) 127.0.0.1:9200->9200/tcp, 9300/tcp es-local-dev
我們可以看到有兩個(gè)容器正在運(yùn)行中。
我們?cè)跒g覽器中打開(kāi) http://localhost:9200:
我們也可以使用如下的命令來(lái)進(jìn)行查看:
$ curl -u elastic:wuRd1MYj http://localhost:9200
{"name" : "a89056d65008","cluster_name" : "docker-cluster","cluster_uuid" : "T4kEFaxvTkC8R9j4wW4A3w","version" : {"number" : "8.15.3","build_flavor" : "default","build_type" : "docker","build_hash" : "f97532e680b555c3a05e73a74c28afb666923018","build_date" : "2024-10-09T22:08:00.328917561Z","build_snapshot" : false,"lucene_version" : "9.11.1","minimum_wire_compatibility_version" : "7.17.0","minimum_index_compatibility_version" : "7.0.0"},"tagline" : "You Know, for Search"
}
我們也可以在瀏覽器中打入地址 http://localhost:5601:
我們成功地進(jìn)入到 Kibana 的界面了。
警告:HTTPS 已禁用,并且對(duì) Elasticsearch 使用基本身份驗(yàn)證。此配置僅用于本地測(cè)試。出于安全考慮,Elasticsearch 和 Kibana 只能通過(guò) localhost 訪問(wèn)。
API keys
生成 Elasticsearch 的 API 密鑰并將其作為 ES_LOCAL_API_KEY 存儲(chǔ)在 .env 文件中。使用此密鑰通過(guò) Elastic SDK 或 REST API 連接到 Elasticsearch。
在 elastic-start-local 文件夾中使用 curl 檢查與 Elasticsearch 的連接:
source .env
curl $ES_LOCAL_URL -H "Authorization: ApiKey ${ES_LOCAL_API_KEY}"
$ source .env
$ curl $ES_LOCAL_URL -H "Authorization: ApiKey ${ES_LOCAL_API_KEY}"
{"name" : "a89056d65008","cluster_name" : "docker-cluster","cluster_uuid" : "T4kEFaxvTkC8R9j4wW4A3w","version" : {"number" : "8.15.3","build_flavor" : "default","build_type" : "docker","build_hash" : "f97532e680b555c3a05e73a74c28afb666923018","build_date" : "2024-10-09T22:08:00.328917561Z","build_snapshot" : false,"lucene_version" : "9.11.1","minimum_wire_compatibility_version" : "7.17.0","minimum_index_compatibility_version" : "7.0.0"},"tagline" : "You Know, for Search"
}
啟動(dòng)及停止服務(wù)
你可以使用 elastic-start-local 文件夾中提供的 start 和 stop 命令。
要停止 Elasticsearch 和 Kibana Docker 服務(wù),請(qǐng)使用 stop?命令:
cd elastic-start-local
./stop.sh
$ pwd
/Users/liuxg/data/start-local/elastic-start-local
$ ls
docker-compose.yml start.sh stop.sh uninstall.sh
$ ./stop.sh
[+] Stopping 3/3? Container kibana-local-dev Stopped 0.2s ? Container kibana_settings Stopped 0.0s ? Container es-local-dev Stopped 2.6s
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
要啟動(dòng) Elasticsearch 和 Kibana Docker 服務(wù),請(qǐng)使用 start 命令:
cd elastic-start-local
./start.sh
$ pwd
/Users/liuxg/data/start-local/elastic-start-local
$ ls
docker-compose.yml start.sh stop.sh uninstall.sh
$ ./start.sh
[+] Building 0.0s (0/0) docker:desktop-linux
[+] Running 3/3? Container es-local-dev Healthy 0.0s ? Container kibana_settings Exited 0.0s ? Container kibana-local-dev Healthy 0.0s
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
4b50f85bddd3 docker.elastic.co/kibana/kibana:8.15.3 "/bin/tini -- /usr/l…" 19 minutes ago Up 23 seconds (healthy) 127.0.0.1:5601->5601/tcp kibana-local-dev
a89056d65008 docker.elastic.co/elasticsearch/elasticsearch:8.15.3 "/bin/tini -- /usr/l…" 19 minutes ago Up 34 seconds (healthy) 127.0.0.1:9200->9200/tcp, 9300/tcp es-local-dev
從上面,我們可以看到容器已經(jīng)被成功運(yùn)行。
如果你需要配置 HTTPS,你需要閱讀文章 “如何在 Linux,MacOS 及 Windows 上進(jìn)行安裝 Elasticsearch”。