Docker安装es

# es 暴露的端口很多

# es 十分耗内存

# es 的数据一般需要放置到安全的目录!(通过挂载)

# 启动es
docker run -d --name elasticsearch --net somenetwork -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" elasticsearch:tag

# 解释
--net somenetwork  ? 网络配置 (后期学,先去掉)
"discovery.type=single-node" 集群单节点

[root@qiaoyanjie ~]# docker run -d --name elasticsearch01  -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" elasticsearch    #默认下载最新版本
Unable to find image 'elasticsearch:latest' locally
latest: Pulling from library/elasticsearch
05d1a5232b46: Pull complete 
5cee356eda6b: Pull complete 
89d3385f0fd3: Pull complete 
65dd87f6620b: Pull complete 
78a183a01190: Pull complete 
1a4499c85f97: Pull complete 
2c9d39b4bfc1: Pull complete 
1b1cec2222c9: Pull complete 
59ff4ce9df68: Pull complete 
1976bc3ee432: Pull complete 
5af49e8af381: Pull complete 
42c8b75ff7af: Pull complete 
7e6902915254: Pull complete 
99853874fa54: Pull complete 
596fbad6fcff: Pull complete 
Digest: sha256:a8081d995ef3443dc6d077093172a5931e02cdb8ffddbf05c67e01d348a9770e
Status: Downloaded newer image for elasticsearch:latest
5cfc15cf31a91e25674338960975736f9bd7d235a061d8eb30eaee3e1616742d
[root@qiaoyanjie ~]# docker ps -a    #最新版起不来
CONTAINER ID   IMAGE           COMMAND                  CREATED         STATUS                     PORTS                    NAMES
5cfc15cf31a9   elasticsearch   "/docker-entrypoint.…"   9 seconds ago   Exited (1) 8 seconds ago                            elasticsearch01
21d3be4a9e4c   tomcat          "catalina.sh run"        7 hours ago     Up 7 hours                 0.0.0.0:3345->8080/tcp   tomcat01
10987a6f0593   nginx           "/docker-entrypoint.…"   6 days ago      Up 6 hours                 0.0.0.0:3344->80/tcp     nginx01
[root@qiaoyanjie ~]# docker ps 
CONTAINER ID   IMAGE     COMMAND                  CREATED       STATUS       PORTS                    NAMES
21d3be4a9e4c   tomcat    "catalina.sh run"        7 hours ago   Up 7 hours   0.0.0.0:3345->8080/tcp   tomcat01
10987a6f0593   nginx     "/docker-entrypoint.…"   6 days ago    Up 6 hours   0.0.0.0:3344->80/tcp     nginx01
[root@qiaoyanjie ~]# docker rm -f 5cfc15cf31a9
5cfc15cf31a9
[root@qiaoyanjie ~]# docker images
REPOSITORY      TAG       IMAGE ID       CREATED        SIZE
nginx           latest    605c77e624dd   4 months ago   141MB
tomcat          latest    fb5657adc892   4 months ago   680MB
elasticsearch   latest    5acf0e8da90b   3 years ago    486MB
[root@qiaoyanjie ~]# docker run -d --name elasticsearch01  -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" elasticsearch
a10e3209ee777a80d44fc69091bf8a9596dd76a39aeed52fb38c820f0f59beda
[root@qiaoyanjie ~]# docker ps -a
CONTAINER ID   IMAGE           COMMAND                  CREATED         STATUS                     PORTS                    NAMES
a10e3209ee77   elasticsearch   "/docker-entrypoint.…"   9 seconds ago   Exited (1) 8 seconds ago                            elasticsearch01
21d3be4a9e4c   tomcat          "catalina.sh run"        7 hours ago     Up 7 hours                 0.0.0.0:3345->8080/tcp   tomcat01
10987a6f0593   nginx           "/docker-entrypoint.…"   6 days ago      Up 7 hours                 0.0.0.0:3344->80/tcp     nginx01
[root@qiaoyanjie ~]# docker logs -f a10e3209ee77    #查看日志,内存溢出
OpenJDK 64-Bit Server VM warning: INFO: os::commit_memory(0x0000000085330000, 2060255232, 0) failed; error='Cannot allocate memory' (errno=12)
#
# There is insufficient memory for the Java Runtime Environment to continue.
# Native memory allocation (mmap) failed to map 2060255232 bytes for committing reserved memory.
# An error report file with more information is saved as:
# /tmp/hs_err_pid1.log
[root@qiaoyanjie ~]# free -h
              total        used        free      shared  buff/cache   available
Mem:           1.8G        306M        206M        576K        1.3G        1.3G
Swap:            0B          0B          0B
[root@qiaoyanjie ~]# docker images    # 内存溢出???
REPOSITORY      TAG       IMAGE ID       CREATED        SIZE
nginx           latest    605c77e624dd   4 months ago   141MB
tomcat          latest    fb5657adc892   4 months ago   680MB
elasticsearch   7.6.2     f29a1ee41030   2 years ago    791MB
elasticsearch   latest    5acf0e8da90b   3 years ago    486MB
[root@qiaoyanjie ~]# docker run -d --name elasticsearch01  -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" elasticsearch:7.6.2
Unable to find image 'elasticsearch:7.6.2' locally
7.6.2: Pulling from library/elasticsearch
ab5ef0e58194: Pull complete 
c4d1ca5c8a25: Pull complete 
941a3cc8e7b8: Pull complete 
43ec483d9618: Pull complete 
c486fd200684: Pull complete 
1b960df074b2: Pull complete 
1719d48d6823: Pull complete 
Digest: sha256:1b09dbd93085a1e7bca34830e77d2981521a7210e11f11eda997add1c12711fa
Status: Downloaded newer image for elasticsearch:7.6.2
c4ac304a64a3205853ed8c240b9b375664e2b5f9f79a093856acf09fc22e918e
[root@qiaoyanjie ~]# docker ps -a    # 7.6.2版本可以启动成功
CONTAINER ID   IMAGE                 COMMAND                  CREATED          STATUS          PORTS                                            NAMES
c4ac304a64a3   elasticsearch:7.6.2   "/usr/local/bin/dock…"   47 seconds ago   Up 45 seconds   0.0.0.0:9200->9200/tcp, 0.0.0.0:9300->9300/tcp   elasticsearch01
21d3be4a9e4c   tomcat                "catalina.sh run"        7 hours ago      Up 7 hours      0.0.0.0:3345->8080/tcp                           tomcat01
10987a6f0593   nginx                 "/docker-entrypoint.…"   6 days ago       Up 7 hours      0.0.0.0:3344->80/tcp                             nginx01

# 测试一下 es 是否已经成功了
[root@qiaoyanjie ~]# curl localhost:9200
{
  "name" : "c4ac304a64a3",
  "cluster_name" : "docker-cluster",
  "cluster_uuid" : "WM3FfgN5TTKu0G1ManiIug",
  "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@qiaoyanjie ~]# curl localhost:9300    #9300不行
This is not an HTTP port[root@qiaoyanjie ~]#
# es十分耗内存,启动以后,linux(1核2G)就卡住了。  docker stats 查看 cpu 的状态

# es 启动时 cpu 状态
[root@qiaoyanjie ~]# docker stats    
CONTAINER ID   NAME              CPU %     MEM USAGE / LIMIT     MEM %     NET I/O           BLOCK I/O       PIDS
c4ac304a64a3   elasticsearch01   2.46%     1.25GiB / 1.795GiB    69.63%    0B / 0B           368MB / 696kB   42
21d3be4a9e4c   tomcat01          0.09%     124.2MiB / 1.795GiB   6.76%     8.77kB / 129kB    200MB / 0B      28
10987a6f0593   nginx01           0.00%     1.449MiB / 1.795GiB   0.08%     1.88kB / 1.97kB   2.84MB / 0B     2

# es 不启动时 cpu 状态
[root@qiaoyanjie ~]# docker stats 
CONTAINER ID   NAME       CPU %     MEM USAGE / LIMIT     MEM %     NET I/O           BLOCK I/O     PIDS
21d3be4a9e4c   tomcat01   0.12%     119.3MiB / 1.795GiB   6.49%     8.77kB / 129kB    202MB / 0B    28
10987a6f0593   nginx01    0.00%     1.449MiB / 1.795GiB   0.08%     1.88kB / 1.97kB   2.84MB / 0B   2

# 增加内存的限制,修改配置文件 -e 环境配置修改
[root@qiaoyanjie ~]# docker run -d --name elasticsearch02  -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" -e ES_JAVA_OPTS="-Xms64m -Xmx512m" elasticsearch:7.6.2
89af9d4d7f34585eec4344b2ea93e0fb7a8520e9292a8698d10189c89bec3d92
[root@qiaoyanjie ~]# docker ps -a
CONTAINER ID   IMAGE                 COMMAND                  CREATED          STATUS                        PORTS                                            NAMES
89af9d4d7f34   elasticsearch:7.6.2   "/usr/local/bin/dock…"   7 seconds ago    Up 6 seconds                  0.0.0.0:9200->9200/tcp, 0.0.0.0:9300->9300/tcp   elasticsearch02
c4ac304a64a3   elasticsearch:7.6.2   "/usr/local/bin/dock…"   22 minutes ago   Exited (143) 25 seconds ago                                                    elasticsearch01
21d3be4a9e4c   tomcat                "catalina.sh run"        7 hours ago      Up 7 hours                    0.0.0.0:3345->8080/tcp                           tomcat01
10987a6f0593   nginx                 "/docker-entrypoint.…"   6 days ago       Up 7 hours                    0.0.0.0:3344->80/tcp                             nginx01
[root@qiaoyanjie ~]# docker stats    # cpu 占用率明显减小
CONTAINER ID   NAME              CPU %     MEM USAGE / LIMIT     MEM %     NET I/O           BLOCK I/O        PIDS
89af9d4d7f34   elasticsearch02   97.84%    290.7MiB / 1.795GiB   15.82%    0B / 0B           97.3MB / 246kB   20
21d3be4a9e4c   tomcat01          0.09%     122.2MiB / 1.795GiB   6.65%     8.81kB / 129kB    288MB / 0B       28
10987a6f0593   nginx01           0.00%     1.445MiB / 1.795GiB   0.08%     1.92kB / 1.97kB   2.84MB / 0B      2
[root@qiaoyanjie ~]# curl localhost:9200    # 访问成功
{
  "name" : "89af9d4d7f34",
  "cluster_name" : "docker-cluster",
  "cluster_uuid" : "nuUXVWS1Q_iTgfLBOlrNDw",
  "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"
}

#  阿里云开放安全组,网页访问成功

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值