Docker部署ES(增加内存限制启动)


Docker部署ES(增加内存限制启动)

背景:

  1. ES暴露端口很多
  2. ES十分耗内存
  3. ES的数据一般需要放置到安全目录
#官方启动
[root@aliyun ~]# docker run -d --name elasticsearch -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
3f65a0f235ef69b5b89de17a5437c56414006e6d826afa413944863657445926

#启动之后,虚拟机就变得十分卡(可用docker stats查看cpu状态)
#docker stats查看cpu
[root@aliyun ~]# docker stats 3f65a0f235ef
CONTAINER ID   NAME            CPU %     MEM USAGE / LIMIT     MEM %     NET I/O       BLOCK I/O       PIDS
3f65a0f235ef   elasticsearch   2.63%     1.255GiB / 1.795GiB   69.96%    598B / 996B   785MB / 729kB   42

#测试ES是否安装成功
[root@aliyun ~]# curl localhost:9200
{
  "name" : "3f65a0f235ef",
  "cluster_name" : "docker-cluster",
  "cluster_uuid" : "cBdzRwfnTlyxbMjMlNqh4g",
  "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"
}
#关闭ES
[root@aliyun ~]# docker stop 3f65a0f235ef
[root@aliyun ~]# docker ps -a
CONTAINER ID   IMAGE                 COMMAND                  CREATED        STATUS                      PORTS     NAMES
3f65a0f235ef   elasticsearch:7.6.2   "/usr/local/bin/dock…"   13 hours ago   Exited (143) 13 hours ago             elasticsearch
#增加内存限制重新启动
[root@aliyun ~]# docker run -d --name limit_es -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" -e ES_JAVA_OPTS="-Xms64m -Xmx512m" elasticsearch:7.6.2
b44c0788a5aa27d3ce60f8d504a218baafd3b07f24672fbbff62d63ec8f4a7ea
#启动非常快,而且虚拟机不卡
#验证
[root@aliyun ~]# docker ps 
CONTAINER ID   IMAGE                 COMMAND                  CREATED         STATUS         PORTS                                            NAMES
b44c0788a5aa   elasticsearch:7.6.2   "/usr/local/bin/dock…"   4 seconds ago   Up 3 seconds   0.0.0.0:9200->9200/tcp, 0.0.0.0:9300->9300/tcp   limit_es
[root@aliyun ~]# curl localhost:9200
{
  "name" : "b44c0788a5aa",
  "cluster_name" : "docker-cluster",
  "cluster_uuid" : "_yYjIItLSWOiRks6Ry4zGw",
  "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@aliyun ~]# docker stats
CONTAINER ID   NAME       CPU %     MEM USAGE / LIMIT     MEM %     NET I/O       BLOCK I/O       PIDS
b44c0788a5aa   limit_es   0.36%     399.2MiB / 1.795GiB   21.72%    524B / 942B   121MB / 729kB   43
#发现内存消耗比不加内存限制要低得多

原创文章,作者:jamestackk,如若转载,请注明出处:https://blog.ytso.com/244938.html

(0)
上一篇 2022年4月18日
下一篇 2022年4月18日

相关推荐

发表回复

登录后才能评论