Elasticsearch是一个高度可扩展的开源全文搜索和分析引擎。它允许你快速、近实时地存储、搜索和分析大量的数据。Elasticsearch通常用于日志分析、全文搜索、安全智能、业务分析等场景中。它基于Lucene库构建,提供了一个分布式多用户能力的全文搜索引擎,具有HTTP web接口和无模式的JSON文档。
一、安装配置docker环境
首先,本地需要安装好docker 环境。
然后,创建docker网络:
docker network create elastic
二、获取ES镜像
获取 Elasticsearch 镜像:
docker pull docker.elastic.co/elasticsearch/elasticsearch:8.12.0
三、启动ES容器
启动Elasticsearch容器:
docker run --name es01 --net elastic -p 9200:9200 -it -m 1GB docker.elastic.co/elasticsearch/elasticsearch:8.12.0
使用 -m 参数设置容器的内存限制。
该命令打印出Elastic用户密码和用于Kibana的注册令牌。
复制生成的Elastic密码和注册令牌。这些凭据仅在首次启动Elasticsearch时显示。
我们也可以使用以下命令重新生成凭据。
docker exec -it es01 /usr/share/elasticsearch/bin/elasticsearch-reset-password -u elastic
docker exec -it es01 /usr/share/elasticsearch/bin/elasticsearch-create-enrollment-token -s kibana
我们建议将Elastic密码存储为shell中的环境变量。例如:
export ELASTIC_PASSWORD="your_password"
比如,这里的password为:w-G5=A4tJt7-eMa6CqPC
通过浏览器访问:https://localhost:9200,输入用户名和对应的密码,如图所示:
返回Elasticsearch集群的信息,包括名称和Elasticsearch 版本号等等。
四、配置密码和证书
建议存储elastic的密码作为环境变量:
export ELASTIC_PASSWORD="w-G5=A4tJt7-eMa6CqPC"
从容器中复制http_ca.crt SSL证书到本地目录,执行命令:
docker cp es01:/usr/share/elasticsearch/config/certs/http_ca.crt .
在容器运行的情况下,调用Elasticsearch的REST API,执行命令:
curl --cacert http_ca.crt -u elastic:$ELASTIC_PASSWORD https://localhost:9200
如下是返回结果:
{
"name" : "8cff19167c6a",
"cluster_name" : "docker-cluster",
"cluster_uuid" : "JzVAFzjvQd-raJBXyaxV5g",
"version" : {
"number" : "8.12.0",
"build_flavor" : "default",
"build_type" : "docker",
"build_hash" : "1665f706fd9354802c02146c1e6b5c0fbcddfbc9",
"build_date" : "2024-01-11T10:05:27.953830042Z",
"build_snapshot" : false,
"lucene_version" : "9.9.1",
"minimum_wire_compatibility_version" : "7.17.0",
"minimum_index_compatibility_version" : "7.0.0"
},
"tagline" : "You Know, for Search"
}
下一篇介绍使用Docker安装Kibana。