【Docker】docker 安装 elasticsearch

本文详细介绍了如何在Docker中安装Elasticsearch7.16.3版本,包括拉取镜像、启动容器、端口映射、JVM内存设置、单节点模式、挂载数据和配置文件,以及安全设置如xpack.security和SSL。同时提到了ik分词插件和Kibana的安装方法。
摘要由CSDN通过智能技术生成

Docker 安装 ElasticSearch

获取镜像(elasticsearch:7.16.3)

# 拉取镜像
docker pull elasticsearch:7.16.3
# 查看本地镜像
docker images

启动容器

启动参数:

-d 后台启动运行
--name 容器名称
restart=always docker启动后保持运行状态
-p 9200:9200 http访问端口映射
-p 9300:9300 服务间访问端口映射
-e ES_JAVA_OPTS="-Xms512m -Xmx512m"  JVM内存大小
-e "discovery.type=single-node"  单节点启动
-v 指定挂载目录,需准备好挂载路径:`/gonait/docker-mount/elastic-search`,并需要指定文件夹读写权限`chmod -R 777 elastic-search`
elasticsearch:7.16.3  指定启动镜像
首次启动不指定挂载目录
docker run -d \
--name=elastic-search \
--restart=always \
-e ES_JAVA_OPTS="-Xms512m -Xmx512m" \
-e "discovery.type=single-node"  \
-p 9200:9200 \
-p 9300:9300 \
elasticsearch:7.16.3
# 查看容器是否启动成功
docker ps | grep elastic-search
# 进入容器查看
docker exec -it elastic-search /bin/bash
# 复制容器中的配置文件
docker cp -a elastic-search:/usr/share/elasticsearch/config /gonait/docker-mount/elastic-search/config
# 修改配置文件:/gonait/docker-mount/elastic-search/config/elasticsearch.yml
vim elasticsearch.yml
# elasticsearch.yml 配置文件
cluster.name: "elastic-search"
network.host: 0.0.0.0

#----------------------- BEGIN SECURITY AUTO CONFIGURATION -----------------------
#
# The following settings, TLS certificates, and keys have been automatically
# generated to configure Elasticsearch security features on 16-10-2023 14:13:22
#
# --------------------------------------------------------------------------------

# Enable security features
# xpack.security.enabled: true 改为 xpack.security.enabled: false,这样就可以直接 使用http访问,并且不>需要账号密码鉴权,这个设置看个人情况,如果是生产环境建议开始开启 https和账号密码鉴权
# xpack.security.enabled: true
xpack.security.enabled: false
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
#----------------------- END SECURITY AUTO CONFIGURATION -------------------------
http.host: 0.0.0.0
path.repo: /usr/share/elasticsearch/data/elastic-backup

# 强制删除正在运行的容器
docker rm -f elastic-search
再次启动指定挂载目录
docker run -d \
--name=elastic-search \
--restart=always \
-e ES_JAVA_OPTS="-Xms512m -Xmx512m" \
-e "discovery.type=single-node"  \
-p 9200:9200 \
-p 9300:9300 \
-v /gonait/docker-mount/elastic-search/data:/usr/share/elasticsearch/data \
-v /gonait/docker-mount/elastic-search/plugins:/usr/share/elasticsearch/plugins \
-v /gonait/docker-mount/elastic-search/config:/usr/share/elasticsearch/config \
-v /gonait/docker-mount/elastic-search/logs:/usr/share/elasticsearch/logs \
elasticsearch:7.16.3

查看容器是否启动成功

# 宿主机浏览器访问
http://{linux_ip}:9200/
# 正常响应结果
{
  "name": "df8caecf562d",
  "cluster_name": "docker-cluster",
  "cluster_uuid": "wiwctpzhTtu0F3LWsCyinA",
  "version": {
    "number": "7.16.3",
    "build_flavor": "default",
    "build_type": "docker",
    "build_hash": "4e6e4eab2297e949ec994e688dad46290d018022",
    "build_date": "2022-01-06T23:43:02.825887787Z",
    "build_snapshot": false,
    "lucene_version": "8.10.1",
    "minimum_wire_compatibility_version": "6.8.0",
    "minimum_index_compatibility_version": "6.0.0-beta1"
  },
  "tagline": "You Know, for Search"
}

访问失败可能原因:

  • 查看docker容器是否启动成功,docker logs elastic-search,如果出现以下报错日志,说明文件夹logs读写权限没配置,chmod -R 777 elastic-search
    [0.001s][error][logging] Error opening log file 'logs/gc.log': Permission denied
    [0.001s][error][logging] Initialization of output 'file=logs/gc.log' using options 'filecount=32,filesize=64m' failed.
    error:
    Invalid -Xlog option '-Xlog:gc*,gc+age=trace,safepoint:file=logs/gc.log:utctime,pid,tags:filecount=32,filesize=64m', see error log for details.
    Error: Could not create the Java Virtual Machine.
    Error: A fatal exception has occurred. Program will exit.
    	at org.elasticsearch.tools.launchers.JvmOption.flagsFinal(JvmOption.java:119)
    	at org.elasticsearch.tools.launchers.JvmOption.findFinalOptions(JvmOption.java:81)
    	at org.elasticsearch.tools.launchers.JvmErgonomics.choose(JvmErgonomics.java:38)
    	at org.elasticsearch.tools.launchers.JvmOptionsParser.jvmOptions(JvmOptionsParser.java:135)
    	at org.elasticsearch.tools.launchers.JvmOptionsParser.main(JvmOptionsParser.java:86)
    
  • 查看是否关闭防火墙:systemctl status firewalld,如果不是以下状态,则需要关闭系统防火墙,systemctl stop firewalld
    [root@easy-cloud-node-206 config]# systemctl status firewalld
    ● firewalld.service - firewalld - dynamic firewall daemon
       Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
       Active: inactive (dead)
         Docs: man:firewalld(1)
    
  • 其他可能情况,需结合实际查看相应解决办法

安装elastic-search插件及其他相关组件

练习资料:30万+唐诗宋词

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值