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. Go语言系列之标准库fmt

    fmt包实现了类似C语言printf和scanf的格式化I/O.主要分为向外输出内容和获取输入内容两大部分. 向外输出 标准库fmt提供了以下几种输出相关函数. Print Print系列函数会将内容 ...

  2. Mybatis-Plus的引用

    一.依赖 <dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus-b ...

  3. Kube-OVN1.5.0新版本发布,支持鲲鹏云平台网络平面部署

    近日,Kube-OVN发布了最新的1.5.0版本.自2019年4月开源以来,Kube-OVN经历了15次重要版本迭代,以及社区成立,建设者贡献代码,稳定性测试,国内外用户开始在生产环境中投入使用,企业 ...

  4. 【记录一个问题】android opencl c++: 使用event.SetCallBack()方法后,在回调函数中要再使用event.wait()才能得到profile信息

    如题:希望执行完成后得到各个阶段的执行时间,但是通过回调发现start, end, submit, queued等时间都是0 因此要在回调函数中再使用一次event.wait(),然后才能获得prof ...

  5. vue学习10-计算属性

    计算属性 1 <!DOCTYPE html> 2 <html lang='en'> 3 <head> 4 <meta charset='UTF-8'> ...

  6. gin框架中项目的初始化

    核心知识点 json配置文件解析成结构体 将路由对应的接口抽离到单独的文件中,main函数中直接注册路由即可 项目目录图 项目代码 app.json代码 { "app_name": ...

  7. jsp FN 标签库的使用方法

    1.   在jsp  导入标签库 <%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="f ...

  8. JavaScript与java语法区别

    网页中各种技术的作用 感谢大佬:https://blog.csdn.net/RookiexiaoMu_a/article/details/89052768 HTML 制作网页的结构 CSS 美化网页 ...

  9. UITabBarController的基本使用

  10. nginx启动失败:Redirecting to /bin/systemctl start nginx.service Failed to start nginx.service: Unit not found.

    解决方法: 是因为nginx没有有添加到系统服务,手动手动添加一个即可. 在 /etc/init.d/下创建名为nginx的启动脚本即可,内容如下: #!/bin/bash # # chkconfig ...