Docker安装elasticsearch 1:不用数据卷

本文介绍了如何在Docker中安装和配置Elasticsearch,包括设置内存限制、解决IPv4转发警告以及通过curl进行健康检查。同时强调了Elasticsearch对内存的需求和数据安全,以及在容器内监控资源使用情况的重要性。
摘要由CSDN通过智能技术生成

0.注意事项

es暴露的端口很多
es很占内存,默认1g
es的数据需要放到安全目录,要做数据挂载
es集群,需要docker网络

1.官方启动es(不推荐,没设置es内存大小)

docker run -d --name elasticsearch -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" elasticsearch:7.7.0

curl查看是否启动成功

[root@localhost haokai]#  curl locallhost:9200
curl: (6) Could not resolve host: locallhost; Unknown error
[root@localhost haokai]#  curl localhost:9200
{
  "name" : "64353fa05644",
  "cluster_name" : "docker-cluster",
  "cluster_uuid" : "Lg4AuNSISjC_E3ztBBZbTg",
  "version" : {
    "number" : "7.6.2",
    "build_flavor" : "default",
    "build_type" : "docker",
    "build_hash" : "ef48eb35cf30adf4db14086e8aabd07ef6fb113f",
    "build_date" : "2020-03-26T06:34:37.794943Z",
    "build_snapshot" : false,
    "lucene_version" : "8.4.0",
    "minimum_wire_compatibility_version" : "6.8.0",
    "minimum_index_compatibility_version" : "6.0.0-beta1"
  },
  "tagline" : "You Know, for Search"
}
[root@localhost haokai]#

2.docker stats查看容器占用状态

这个命令也比较耗费内存,因为是实施刷新的,所以不看了要ctrl + c关掉

docker stats

3.docker -e增加内存限制

-e ES_JAVA_OPS=“Xms64m Xmx=128”

内存指定:最小64M,最大128M,看自己需要,一般不超过物理内存的50%。

docker run --name elasticsearch -d -e ES_JAVA_OPTS="-Xms512m -Xmx512m" -e "discovery.type=single-node" -p 9200:9200 -p 9300:9300 elasticsearch:7.7.0
[root@localhost jdk1.8.0_261]# docker stats
CONTAINER ID   NAME            CPU %     MEM USAGE / LIMIT     MEM %     NET I/O           BLOCK I/O        PIDS
9bb52e7b7711   elasticsearch   0.38%     733.6MiB / 1.777GiB   40.32%    656B / 0B         370MB / 2.43MB   54
533124d2559a   tomcat01        0.24%     62.11MiB / 1.777GiB   3.41%     17.8kB / 172kB    2.99GB / 49MB    36
aca793e8d0cc   nginx01         0.00%     1.883MiB / 1.777GiB   0.10%     8.64kB / 6.78kB   22.4MB / 0B      5
CONTAINER ID   NAME            CPU %     MEM USAGE / LIMIT     MEM %     NET I/O           BLOCK I/O        PIDS
9bb52e7b7711   elasticsearch   0.38%     733.6MiB / 1.777GiB   40.32%    656B / 0B         370MB / 2.43MB   54
533124d2559a   tomcat01        0.24%     62.11MiB / 1.777GiB   3.41%     17.8kB / 172kB    2.99GB / 49MB    36
aca793e8d0cc   nginx01         0.00%     1.883MiB / 1.777GiB   0.10%     8.64kB / 6.78kB   22.4MB / 0B      5
CONTAINER ID   NAME            CPU %     MEM USAGE / LIMIT     MEM %     NET I/O           BLOCK I/O        PIDS
9bb52e7b7711   elasticsearch   0.43%     733.1MiB / 1.777GiB   40.29%    656B / 0B         370MB / 2.43MB   54
533124d2559a   tomcat01        0.32%     61.75MiB / 1.777GiB   3.39%     17.8kB / 172kB    2.99GB / 49MB    36
aca793e8d0cc   nginx01         0.00%     1.883MiB / 1.777GiB   0.10%     8.64kB / 6.78kB   22.4MB / 0B      5
CONTAINER ID   NAME            CPU %     MEM USAGE / LIMIT     MEM %     NET I/O           BLOCK I/O        PIDS
9bb52e7b7711   elasticsearch   0.43%     733.1MiB / 1.777GiB   40.29%    656B / 0B         370MB / 2.43MB   54
533124d2559a   tomcat01        0.32%     61.75MiB / 1.777GiB   3.39%     17.8kB / 172kB    2.99GB / 49MB    36
aca793e8d0cc   nginx01         0.00%     1.883MiB / 1.777GiB   0.10%     8.64kB / 6.78kB   22.4MB / 0B      5
CONTAINER ID   NAME            CPU %     MEM USAGE / LIMIT     MEM %     NET I/O           BLOCK I/O        PIDS
9bb52e7b7711   elasticsearch   8.27%     733.4MiB / 1.777GiB   40.31%    656B / 0B         381MB / 2.43MB   54
533124d2559a   tomcat01        0.20%     61.75MiB / 1.777GiB   3.39%     17.8kB / 172kB    2.99GB / 49MB    36
aca793e8d0cc   nginx01         0.00%     1.883MiB / 1.777GiB   0.10%     8.64kB / 6.78kB   22.4MB / 0B      5
CONTAINER ID   NAME            CPU %     MEM USAGE / LIMIT     MEM %     NET I/O           BLOCK I/O        PIDS
9bb52e7b7711   elasticsearch   8.27%     733.4MiB / 1.777GiB   40.31%    656B / 0B         381MB / 2.43MB   54
533124d2559a   tomcat01        0.20%     61.75MiB / 1.777GiB   3.39%     17.8kB / 172kB    2.99GB / 49MB    36
aca793e8d0cc   nginx01         0.00%     1.883MiB / 1.777GiB   0.10%     8.64kB / 6.78kB   22.4MB / 0B      5
CONTAINER ID   NAME            CPU %     MEM USAGE / LIMIT     MEM %     NET I/O           BLOCK I/O        PIDS
9bb52e7b7711   elasticsearch   0.31%     733.4MiB / 1.777GiB   40.31%    656B / 0B         381MB / 2.43MB   54
533124d2559a   tomcat01        0.26%     61.75MiB / 1.777GiB   3.39%     17.8kB / 172kB    2.99GB / 49MB    36
aca793e8d0cc   nginx01         0.00%     1.883MiB / 1.777GiB   0.10%     8.64kB / 6.78kB   22.4MB / 0B      5
^C
[root@localhost jdk1.8.0_261]#

在这里插入图片描述

4.WARNING: IPv4 forwarding is disabled. Networking will not work.

启动镜像,可能会遇到WARNING: IPv4 forwarding is disabled. Networking will not work,提示没有网络,因为没有开启转发,网桥配置完后,需要开启转发,不然容器启动后,就会没有网络,配置/etc/sysctl.conf,添加net.ipv4.ip_forward=1

命令含义:

vim /etc/sysctl.conf

#配置转发
net.ipv4.ip_forward=1

#重启服务,让配置生效
systemctl restart network

#查看是否成功,如果返回为“net.ipv4.ip_forward = 1”则表示成功

sysctl net.ipv4.ip_forward
[root@localhost haokai]# vim /etc/sysctl.conf
[root@localhost haokai]# systemctl restart network
[root@localhost haokai]# sysctl net.ipv4.ip_forward
net.ipv4.ip_forward = 1

5.curl测试

[root@localhost jdk1.8.0_261]# curl localhost:9200
{
  "name" : "9bb52e7b7711",
  "cluster_name" : "docker-cluster",
  "cluster_uuid" : "Y2vYqWaOSo68OT3Vaogc6g",
  "version" : {
    "number" : "7.7.0",
    "build_flavor" : "default",
    "build_type" : "docker",
    "build_hash" : "81a1e9eda8e6183f5237786246f6dced26a10eaf",
    "build_date" : "2020-05-12T02:01:37.602180Z",
    "build_snapshot" : false,
    "lucene_version" : "8.5.1",
    "minimum_wire_compatibility_version" : "6.8.0",
    "minimum_index_compatibility_version" : "6.0.0-beta1"
  },
  "tagline" : "You Know, for Search"
}
[root@localhost jdk1.8.0_261]#
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值