1、环境介绍

Linux:~ # cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)

2、拉取 elasticserach 镜像

Linux:~ # docker pull elasticsearch
"不加版本,表示拉取最新版本"

3、创建 elasticsearch 数据目录

Linux:~ # mkdir -p /opt/elasticsearch/{es1,es2,es3}/{config,data,logs}
Linux:~ # tree /opt/elasticsearch/
/opt/elasticsearch/
|-- es1
| |-- config
| |-- data
| `-- logs
|-- es2
| |-- config
| |-- data
| `-- logs
`-- es3
|-- config
|-- data
`-- logs 12 directories, 0 files

4、创建 elasticsearch 配置文件

  • 注意将下列内容中的 本机IP 字段,替换成自己机器的IP地址
Linux:~ # cat > /opt/elasticsearch/es1/config/elasticsearch.yml <<EOF
cluster.name: elasticsearch-cluster
node.name: es-node1
network.bind_host: 0.0.0.0
network.publish_host: 本机IP
http.port: 9200
transport.tcp.port: 9300
http.cors.enabled: true
http.cors.allow-origin: "*"
node.master: true
node.data: true
discovery.zen.ping.unicast.hosts: ["本机IP:9300","本机IP:9301","本机IP:9302"]
discovery.zen.minimum_master_nodes: 1
EOF Linux:~ # cat > /opt/elasticsearch/es2/config/elasticsearch.yml <<EOF
cluster.name: elasticsearch-cluster
node.name: es-node2
network.bind_host: 0.0.0.0
network.publish_host: 本机IP
http.port: 9201
transport.tcp.port: 9301
http.cors.enabled: true
http.cors.allow-origin: "*"
node.master: true
node.data: true
discovery.zen.ping.unicast.hosts: ["本机IP:9300","本机IP:9301","本机IP:9302"]
discovery.zen.minimum_master_nodes: 1
EOF Linux:~ # cat > /opt/elasticsearch/es3/config/elasticsearch.yml <<EOF
cluster.name: elasticsearch-cluster
node.name: es-node3
network.bind_host: 0.0.0.0
network.publish_host: 本机IP
http.port: 9202
transport.tcp.port: 9302
http.cors.enabled: true
http.cors.allow-origin: "*"
node.master: true
node.data: true
discovery.zen.ping.unicast.hosts: ["本机IP:9300","本机IP:9301","本机IP:9302"]
discovery.zen.minimum_master_nodes: 1
EOF

5、配置JVM线程数量限制

Linux:~ # echo "vm.max_map_count=262144" >> /etc/sysctl.conf
Linux:~ # sysctl -p
  • 注:这一步是为了防止启动容器时,报出如下错误:
    bootstrap checks failed max virtual memory areas vm.max_map_count [65530] likely too low, increase to at least [262144]*

6、启动 elasticsearch docker 集群

#!/bin/bash
xms='-Xms256m'
xmx='-Xmx256m'
portes=(
9200
9201
9202
) portcluster=(
9300
9301
9302
) espath='/opt/elasticsearch'
dockerespath='/usr/share/elasticsearch'
image='elasticsearch:latest' num=1
portc=0
for port in ${portes[*]}
do
portc=$(( ${num} - 1 ))
docker run -d -e ES_JAVA_OPTS=""${xms}" "${xmx}"" \
-p ${port}:${port} \
-p ${portcluster[$portc]}:${portcluster[$portc]} \
-v ${espath}/es${num}/config/elasticsearch.yml:${dockerespath}/config/elasticsearch.yml \
-v ${espath}/es${num}/data:${dockerespath}/data \
-v ${espath}/es${num}/logs:${dockerespath}/logs \
--name es-0${num} ${image} let num++
done

7、验证 elasticsearch 集群

"因为是在公有云服务器上部署的,ip不方便透露,就用localhostip代替了"
Linux:~ # curl "http://localhostip:9200/_cat/nodes"
localhostip 31 96 2 0.15 1.12 1.06 mdi - es-node2
localhostip 36 96 2 0.15 1.12 1.06 mdi - es-node1
localhostip 32 96 2 0.15 1.12 1.06 mdi * es-node3
Linux:~ # curl "http://localhostip:9200/_cluster/health?pretty"
{
"cluster_name" : "elasticsearch-cluster",
"status" : "green",
"timed_out" : false,
"number_of_nodes" : 3,
"number_of_data_nodes" : 3,
"active_primary_shards" : 0,
"active_shards" : 0,
"relocating_shards" : 0,
"initializing_shards" : 0,
"unassigned_shards" : 0,
"delayed_unassigned_shards" : 0,
"number_of_pending_tasks" : 0,
"number_of_in_flight_fetch" : 0,
"task_max_waiting_in_queue_millis" : 0,
"active_shards_percent_as_number" : 100.0
}

8、插入以及查看 elasticsearch 索引信息

"插入索引"
Linux:~ # curl -XPUT "http://localhostip:9200/2021-01-21/myelasticsearch/1?pretty" -H "Content-type: application/json" -d '{"name": "bandian", "country": "China", "age": "25", "birthday": "1995-03-20", "sex": "gentleman", "style":"tie han han"}'
{
"_index" : "2021-01-21",
"_type" : "myelasticsearch",
"_id" : "1",
"_version" : 1,
"result" : "created",
"_shards" : {
"total" : 2,
"successful" : 2,
"failed" : 0
},
"created" : true
}
"查看索引"
Linux:~ # curl -XGET "http://localhostip:9200/2021-01-21/myelasticsearch/1?pretty" -H "Content-type: application/json"
{
"_index" : "2021-01-21",
"_type" : "myelasticsearch",
"_id" : "1",
"_version" : 1,
"found" : true,
"_source" : {
"name" : "bandian",
"country" : "China",
"age" : "25",
"birthday" : "1995-03-20",
"sex" : "gentleman",
"style" : "tie han han"
}
}
"从这里可以看出,索引的创建模板格式:_index,_type,_id,_version,found,_source"

利用 docker 部署 elasticsearch 集群(单节点多实例)的更多相关文章

  1. Docker部署Elasticsearch集群

    http://blog.sina.com.cn/s/blog_8ea8e9d50102wwik.html Docker部署Elasticsearch集群 参考文档: https://hub.docke ...

  2. Centos8 Docker部署ElasticSearch集群

    ELK部署 部署ElasticSearch集群 1.拉取镜像及批量生成配置文件 # 拉取镜像 [root@VM-24-9-centos ~]# docker pull elasticsearch:7. ...

  3. 利用docker部署redis集群

    目录 一.首先配置redis.conf文件,... 1 1.获取配置文件... 1 2.修改各配置文件的参数... 2 二.下载redis镜像.启动容器... 2 1.创建网络... 2 2.拉取镜像 ...

  4. 使用Elasticsearch Operator快速部署Elasticsearch集群

    转载自:https://www.qikqiak.com/post/elastic-cloud-on-k8s/ 随着 kubernetes 的快速发展,很多应用都在往 kubernetes 上面迁移,现 ...

  5. Azure vm 扩展脚本自动部署Elasticsearch集群

    一.完整过程比较长,我仅给出Azure vm extension script 一键部署Elasticsearch集群的安装脚本,有需要的同学,可以邮件我,我给你完整的ARM Template 如果你 ...

  6. Centos8 部署 ElasticSearch 集群并搭建 ELK,基于Logstash同步MySQL数据到ElasticSearch

    Centos8安装Docker 1.更新一下yum [root@VM-24-9-centos ~]# yum -y update 2.安装containerd.io # centos8默认使用podm ...

  7. 日志分析系统 - k8s部署ElasticSearch集群

    K8s部署ElasticSearch集群 1.前提准备工作 1.1 创建elastic的命名空间 namespace编排文件如下: elastic.namespace.yaml --- apiVers ...

  8. laravel项目利用twemproxy部署redis集群的完整步骤

    Twemproxy是一个代理服务器,可以通过它减少Memcached或Redis服务器所打开的连接数.下面这篇文章主要给大家介绍了关于laravel项目利用twemproxy部署redis集群的相关资 ...

  9. Elasticsearch使用系列-Docker搭建Elasticsearch集群

    Elasticsearch使用系列-ES简介和环境搭建 Elasticsearch使用系列-ES增删查改基本操作+ik分词 Elasticsearch使用系列-基本查询和聚合查询+sql插件 Elas ...

随机推荐

  1. console.log(a)和console.log(window.a)的区别?

    console.log(window.l); //undefined console.log(l); //Uncaught ReferenceError: l is not defined js对于未 ...

  2. Git 基础指令

    Git 基础指令 Git 基础指令 获取 Git 仓库 在已存在目录中初始化仓库 克隆现有的仓库 记录仓库与仓库的更新 仓库的记录 检查当前文件状态 三部曲 跟踪新文件 提交更新 移除文件 推送到远程 ...

  3. 动静分离、Rewirte、HTTPS

    目录 Nginx动静分离技术 示例搭建步骤 部署NFS 静态资源共享 部署代理服务器 Rewrite(重点) Rewrite基本概述 rewrite语法 rewrite标记Flag last和brea ...

  4. R语言:关于rJava包的安装

    R语言:关于rJava包的安装  盐池里的萝卜 2014-09-14 00:53:33 在做文本挖掘的时候,会发现分词时候rJava是必须要迈过去的坎儿,所以进行了总结: 第一步:安装rJava和jd ...

  5. (2)用Micropython将ESP32数据上云

    之前我们尝试过直接把LED点亮并且闪烁. 今天尝试一下将LED的开关状态上云,并可以通过云来进行数据下发. 数据要上云,首先开发板要联网. 首先我们会用 Python的network 库, 在netw ...

  6. 【记录一个问题】golang的xorm组件更新数据库未生效

    代码中使用了类似的方式来更新数据库: func (writer *dbWriter) updateVersion(ctx context.Context, IP string, version str ...

  7. windows10双系统删除linux

    问题 在这里删除后会发现有残留一个引导区,几百m(下图已经删除完),而且启动会进linux引导,然后必须f12进入选择启动项才可以启动windows 解决方法 使用删除引导就可以了 再使用傲梅分区助手 ...

  8. Android开发之事件

    当按下一个按钮时,有两种事件促发的方式,一种是通过回调,一种是通过事件监听. 回调: xml中: 只要设置android:onclick="回调函数名字" '主函数中重写回调函数即 ...

  9. golang中的RPC开发-2

    RPC简介 远程过程调用(Remote Procedure Call,RPC)是一个计算机通信协议 该协议允许运行于一台计算机的程序调用另一台计算机的子程序,而程序员无需额外地为这个交互作用编程 如果 ...

  10. Servlet-请求的分发处理

    1,HelloServlet类中 2,a.html中