利用 docker 部署 elasticsearch 集群(单节点多实例)
文章目录
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 集群(单节点多实例)的更多相关文章
- Docker部署Elasticsearch集群
http://blog.sina.com.cn/s/blog_8ea8e9d50102wwik.html Docker部署Elasticsearch集群 参考文档: https://hub.docke ...
- Centos8 Docker部署ElasticSearch集群
ELK部署 部署ElasticSearch集群 1.拉取镜像及批量生成配置文件 # 拉取镜像 [root@VM-24-9-centos ~]# docker pull elasticsearch:7. ...
- 利用docker部署redis集群
目录 一.首先配置redis.conf文件,... 1 1.获取配置文件... 1 2.修改各配置文件的参数... 2 二.下载redis镜像.启动容器... 2 1.创建网络... 2 2.拉取镜像 ...
- 使用Elasticsearch Operator快速部署Elasticsearch集群
转载自:https://www.qikqiak.com/post/elastic-cloud-on-k8s/ 随着 kubernetes 的快速发展,很多应用都在往 kubernetes 上面迁移,现 ...
- Azure vm 扩展脚本自动部署Elasticsearch集群
一.完整过程比较长,我仅给出Azure vm extension script 一键部署Elasticsearch集群的安装脚本,有需要的同学,可以邮件我,我给你完整的ARM Template 如果你 ...
- Centos8 部署 ElasticSearch 集群并搭建 ELK,基于Logstash同步MySQL数据到ElasticSearch
Centos8安装Docker 1.更新一下yum [root@VM-24-9-centos ~]# yum -y update 2.安装containerd.io # centos8默认使用podm ...
- 日志分析系统 - k8s部署ElasticSearch集群
K8s部署ElasticSearch集群 1.前提准备工作 1.1 创建elastic的命名空间 namespace编排文件如下: elastic.namespace.yaml --- apiVers ...
- laravel项目利用twemproxy部署redis集群的完整步骤
Twemproxy是一个代理服务器,可以通过它减少Memcached或Redis服务器所打开的连接数.下面这篇文章主要给大家介绍了关于laravel项目利用twemproxy部署redis集群的相关资 ...
- Elasticsearch使用系列-Docker搭建Elasticsearch集群
Elasticsearch使用系列-ES简介和环境搭建 Elasticsearch使用系列-ES增删查改基本操作+ik分词 Elasticsearch使用系列-基本查询和聚合查询+sql插件 Elas ...
随机推荐
- LINUX学习-Mysql集群-一主多从
新建一台服务器 192.168.88.40 yum -y install mysql mysql-server 编辑etc下的配置文件 vim /etc/my.cnf 输入 bin-log=mysql ...
- Linux防止文件被误删除或修改
chattr简介 Linux没有回收站,一旦文件或文件夹被误删除,要寻找回来很麻烦,不如事先对一些重要的文件做一些保护,这时我们需要一个命令chattr,其使用格式为 chattr 操作符 属性 文件 ...
- ASP.NET 内联代码、内联表达式、数据绑定表达式使用方法罗列(形式就是常说的尖括号 百分号 等于号 井号)
今天在做渭南电脑维修网的一个小功能时遇到了一些问题,因此特别列出,以备他日之用. 首先对ASP.NET 内联代码.内联表达式.数据绑定表达式的概念进行罗列,详细概念以及基本的用法我就不在这里罗嗦了,请 ...
- 外观模式(Facade模式)
外观模式的定义与特点 外观(Facade)模式又叫作门面模式,是一种通过为多个复杂的子系统提供一个一致的接口,而使这些子系统更加容易被访问的模式.该模式对外有一个统一接口,外部应用程序不用关心内部子系 ...
- golang中goroutine协程调度器设计策略
goroutine与线程 /* goroutine与线程1. 可增长的栈os线程一般都有固定的栈内存,通常为2MB,一个goroutine的在其声明周期开始时只有很小的栈(2KB),goroutine ...
- 使用 Dapr 缩短软件开发周期
Microsoft DevOps 文档里的文章(https://docs.microsoft.com/zh-cn/azure/devops/report/dashboards/cycle-time-a ...
- rsync实时备份监控命令(详细大全)
目录 一:rsync介绍 1.rsync简介 2.rsync特性 3.rsync应用场景 4.rsync的传输方式 5.Rsync传输模式 二:RSYNC使用参数 三:参数使用案例 一:rsync介绍 ...
- Android性能优化之Android 10+ dex2oat实践
作者:字节跳动终端技术--郭海洋 背景 对于Android App的性能优化来说,方式方法以及工具都有很多,而dex2oat作为其中的一员,却可能不被大众所熟知.它是Android官方应用于运行时,针 ...
- 你需要的Grid布局入门教程
一.Grid布局概述 首先,Grid 布局与 Flex布局 有一定的相似性,都可以指定容器内部多个项目的位置.但是,Grid 布局远比 Flex 布局强大! Flex 布局是轴线布局,只能指定&quo ...
- web.xml 配置文件?
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http:// ...