《Elastic Stack 实战手册》——三、产品能力——3.4.入门篇——3.4.1.Elastic Stack 安装部署—— 3.4.1.1.安装Elasticsearch(本地及docker)(3) https://developer.aliyun.com/article/1231511
镜像校验
docker images
[root@esteam7002 elasticsearch]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE docker.io/elasticsearch 7.10.1 558380375f1a 4 months ago 774 MB
最简启动
命令:
docker run -it \ --rm \ -p 9200:9200 \ -p 9300:9300 \ -e "discovery.type=single-node" \ --name elasticsearch \ elasticsearch:7.10.1 \ bin/elasticsearch
如果需要开启包括禁止交换区、文件句柄限制等设置:
1、内存锁定:--ulimit memlock=-1:-1
2、打开文件上限:--ulimit nofile=655350:655350
3、关闭交换区:-e "bootstrap.memory_lock=true"
4、后台运行:-d
5、完整命令:
docker run -it \ -d \ --rm \ --ulimit memlock=-1:-1 \ --ulimit nofile=655350:655350 \ -e "bootstrap.memory_lock=true" \ -p 9200:9200 \ -p 9300:9300 \ -e "discovery.type=single-node" \ --name elasticsearch \ elasticsearch:7.10.1 \
6、通过命令查看日志 docker logs -f elasticsearch
7、出现以下日志内容代表启动成功:
{"type": "server", "timestamp": "2021-04-19T09:58:55,399Z", "level": "INFO", "component": "o.e.n.Node", "cluster.name": "docker-cluster", "node.name": "adbdcd016771", "message": "initialized" } -> 节点初始化开始 {"type": "server", "timestamp": "2021-04-19T09:58:55,400Z", "level": "INFO", "component": "o.e.n.Node", "cluster.name": "docker-cluster", "node.name": "adbdcd016771", "message": "starting ..." } {"type": "server", "timestamp": "2021-04-19T09:58:55,657Z", "level": "INFO", "component": "o.e.t.TransportService", "cluster.name": "docker-cluster", "node.name": "adbdcd016771", "message": "publish_address {172.17.0.2:9300}, bound_addresses {[::]:9300}" } -> 节点集群内部数据传输接口开启 {"type": "server", "timestamp": "2021-04-19T09:58:56,259Z", "level": "INFO", "component": "o.e.c.c.Coordinator", "cluster.name": "docker-cluster", "node.name": "adbdcd016771", "message": "setting initial configuration to VotingConfiguration{ScWOitRNSime0vB24lcmcA}" } -> 初始化投票配置 {"type": "server", "timestamp": "2021-04-19T09:58:56,605Z", "level": "INFO", "component": "o.e.c.s.MasterService", "cluster.name": "docker-cluster", "node.name": "adbdcd016771", "message": "elected-as-master ([1] nodes joined)[{adbdcd016771}{ScWOitRNSime0vB24lcmcA}{pKCm7iZTR3eihceRySdZvA}{172.17.0.2}{172.17.0.2:9300}{cdhilmrstw}{ml.machine_memory=1927176192, xpack.installed=true, transform.node=true, ml.max_open_jobs=20} elect leader, _BECOME_MASTER_TASK_, _FINISH_ELECTION_], term: 1, version: 1, delta: master node changed {previous [], current [{adbdcd016771}{ScWOitRNSime0vB24lcmcA}{pKCm7iZTR3eihceRySdZvA}{172.17.0.2}{172.17.0.2:9300}{cdhilmrstw}{ml.machine_memory=1927176192, xpack.installed=true, transform.node=true, ml.max_open_jobs=20}]}" } -> 同集群节点发现 {"type": "server", "timestamp": "2021-04-19T09:58:56,838Z", "level": "INFO", "component": "o.e.c.c.CoordinationState", "cluster.name": "docker-cluster", "node.name": "adbdcd016771", "message": "cluster UUID set to [Of1IoqfaRMis216Bmgd5CQ]" } -> 集群Id初始化 {"type": "server", "timestamp": "2021-04-19T09:58:56,940Z", "level": "INFO", "component": "o.e.c.s.ClusterApplierService", "cluster.name": "docker-cluster", "node.name": "adbdcd016771", "message": "master node changed {previous [], current [{adbdcd016771}{ScWOitRNSime0vB24lcmcA}{pKCm7iZTR3eihceRySdZvA}{172.17.0.2}{172.17.0.2:9300}{cdhilmrstw}{ml.machine_memory=1927176192, xpack.installed=true, transform.node=true, ml.max_open_jobs=20}]}, term: 1, version: 1, reason: Publication{term=1, version=1}" } -> 集群选主完成 {"type": "server", "timestamp": "2021-04-19T09:58:57,039Z", "level": "INFO", "component": "o.e.h.AbstractHttpServerTransport", "cluster.name": "docker-cluster", "node.name": "adbdcd016771", "message": "publish_address {172.17.0.2:9200}, bound_addresses {[::]:9200}", "cluster.uuid": "Of1IoqfaRMis216Bmgd5CQ", "node.id": "ScWOitRNSime0vB24lcmcA" } -> 节点restful监听接口开启 {"type": "server", "timestamp": "2021-04-19T09:58:57,040Z", "level": "INFO", "component": "o.e.n.Node", "cluster.name": "docker-cluster", "node.name": "adbdcd016771", "message": "started", "cluster.uuid": "Of1IoqfaRMis216Bmgd5CQ", "node.id": "ScWOitRNSime0vB24lcmcA" } -> 节点初始完成
ES启动状态校验
同上
节点停机
通过命令 docker ps -as 找到对应的 docker container
[root@esteam7002 elasticsearch]# docker ps -as CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES SIZE adbdcd016771 elasticsearch:7.10.1 "/tini -- /usr/loc..." 2 hours ago Up 2 hours 0.0.0.0:9200->9200/tcp, 0.0.0.0:9300->9300/tcp elasticsearch 132 kB (virtual 774 MB)
关掉对应的 container docker stop elasticsearch
[root@esteam7002 elasticsearch]# docker stop elasticsearch elasticsearch
Docker-compose 安装
1、下载镜像、校验等同 docker 安装 小结,本节略
2、创建配置文件 vi docker-compose.yml
# 声明docker-compose版本,Mac等环境可以使用3,但是在一些Linux环境中只支持到2 version: "2.2" # 声明节点使用的网络空间 networks: bigdata: driver: bridge # 声明节点使用的,从宿主机挂载进去的数据目录 volumes: es-data-01: driver: local # 声明ES节点 services: # docker container es-node-01: # 使用的镜像及版本 image: elasticsearch:7.10.1 # container 是否自动重启 restart: always # container 名称 container_name: es-node-01 # 环境参数 environment: - node.name=es-node-01 - cluster.name=docker-cluster - cluster.initial_master_nodes=es-node-01 - discovery.seed_hosts=es-node-01 - bootstrap.memory_lock=true - "ES_JAVA_OPTS=-Xms512m -Xmx512m" # 系统级别限制属性 ulimits: memlock: soft: -1 hard: -1 # 宿主机挂载到container里的目录 volumes: - es-data-01:/usr/share/elasticsearch/data # 开放端口映射 ports: - 9200:9200 - 9300:9300 # 使用docker网络名称 networks: - bigdata
《Elastic Stack 实战手册》——三、产品能力——3.4.入门篇——3.4.1.Elastic Stack 安装部署—— 3.4.1.1.安装Elasticsearch(本地及docker)(5) https://developer.aliyun.com/article/1231509