本文将介绍用docker的方式安装elasticsearch和kibana,并用浏览器访问elasticsearch。这里的elasticsearch主要给测试环境使用,因此不会设置https和密码。kibana是elasticsearch的前端,可以用来访问elasticsearch,展示数据图表、搜索数据等等。下文以Ubuntu22.04为例。
在root目录下,用root执行(下同):vim docker-compose.yml
,内容如下
services:
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:8.1.1
container_name: elastic811
ulimits:
memlock:
soft: -1
hard: -1
nofile:
soft: 65535
hard: 65535
ports:
- "9200:9200"
- "9300:9300"
volumes:
- /data/docker/es811_data/data:/usr/share/elasticsearch/data # 映射数据文件
networks:
- elastic
environment:
# 设置适当的内存占用
- "ES_JAVA_OPTS=-Xms512m -Xmx4096m"
restart: always
kibana:
image: docker.elastic.co/kibana/kibana:8.1.1
container_name: kibana811
ports:
- "5601:5601"
networks:
- elastic
depends_on:
- elasticsearch
restart: always
networks:
elastic:
driver: bridge
创建数据目录:mkdir -pv /data/docker/es811_data/data
启动docker容器:docker-compose up -d
(如果遇到问题,可能是系统open files不够,把宿主机的nofile soft和hard设置为至少65535,自行百度)
在root目录下,执行命令 vim elasticsearch.yml
,内容如下
cluster.name: "docker-cluster"
network.host: 0.0.0.0
# 新增这一行,设为单点模式
discovery.type: "single-node"
#----------------------- BEGIN SECURITY AUTO CONFIGURATION -----------------------
#
# The following settings, TLS certificates, and keys have been automatically
# generated to configure Elasticsearch security features on 18-05-2024 02:47:05
#
# --------------------------------------------------------------------------------
# Enable security features
# 关闭安全验证
xpack.security.enabled: false
# 关闭enrollment安全验证
xpack.security.enrollment.enabled: false
# Enable encryption for HTTP API client connections, such as Kibana, Logstash, and Agents
xpack.security.http.ssl:
enabled: false # 关闭
keystore.path: certs/http.p12
# Enable encryption and mutual authentication between cluster nodes
xpack.security.transport.ssl:
enabled: false # 关闭
verification_mode: none # 设为none
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: ["237fa9594e49"]
#----------------------- END SECURITY AUTO CONFIGURATION -------------------------
执行如下命令:
# 先停止容器
docker-compose stop
# 拷贝配置文件
docker cp elasticsearch.yml elastic811:/usr/share/elasticsearch/config/elasticsearch.yml
# 启动容器
docker-compose start
http://172.16.2.233:5601/
172.16.2.233 是宿主机的ip地址。