docker-compose安装elasticsearch集群实战

环境说明

  • linux:centos7
  • elasticsearch:5.6.4
  • elasticsearch-head:5
  • elasticsearch-head是es的一个可视化的客户端插件,可以直接对ES进行增删改查操作

目录结构

elasticsearch/
├── docker-compose.yml
├── head
└── node
    ├── es1
    │   ├── data
    │   └── elasticsearch.yml
    └── es2
        ├── data
        └── elasticsearch.yml

主节点elasticsearch.yml配置文件

elasticsearch/node/es1/elasticsearch.yml

network.bind_host: 0.0.0.0
cluster.name: elasticsearch_cluster
cluster.routing.allocation.disk.threshold_enabled: false
node.name: master
node.master: true
node.data: true
http.cors.enabled: true
http.cors.allow-origin: "*"
network.host: 0.0.0.0
discovery.zen.minimum_master_nodes: 1

从节点elasticsearch.yml配置文件

elasticsearch/node/es2/elasticsearch.yml

network.bind_host: 0.0.0.0
cluster.name: elasticsearch_cluster
cluster.routing.allocation.disk.threshold_enabled: false
node.name: node2
node.master: false
node.data: true
http.cors.enabled: true
http.cors.allow-origin: "*"
network.host: 0.0.0.0
discovery.zen.minimum_master_nodes: 1
discovery.zen.ping.unicast.hosts: es1

docker-compose.yml配置文件

version: '3.0'
services:
    elasticsearch-central:
        image: elasticsearch:5.6.4
        container_name: es1
        volumes:
           - /opt/modules/elasticsearch/node/es1/data:/usr/share/elasticsearch/data 
           - /opt/modules/elasticsearch/node/es1/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml
        environment:
           - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
           - ES_CLUSTERNAME=elasticsearch
        command: elasticsearch
        ports:
           - "9200:9200"
           - "9300:9300"
    elasticsearch-data:
        image: elasticsearch:5.6.4
        container_name: es2
        volumes:
           - /opt/modules/elasticsearch/node/es2/data:/usr/share/elasticsearch/data
           - /opt/modules/elasticsearch/node/es2/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml
        environment:
           - bootstrap.memory_lock=true
           - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
           - ES_CLUSTERNAME=elasticsearch
        command: elasticsearch
        ports:
           - "9201:9200"
           - "9301:9300"
        links:
           - elasticsearch-central:elasticsearch
    elasticsearch-head:
        image: mobz/elasticsearch-head:5
        container_name: head
        volumes:
           - /opt/modules/elasticsearch/head/Gruntfile.js:/usr/src/app/Gruntfile.js
           - /opt/modules/elasticsearch/head/_site/app.js:/usr/src/app/_site/app.js        
        ports:
           - "9100:9100"           
        links:
           - elasticsearch-central:elasticsearch

配置head

  • 下载elasticsearch-head
cd elasticsearch
git clone git://github.com/mobz/elasticsearch-head.git
mv elasticsearch-head head

解决: Linux – git: command not found
出错原因:服务器没有安装GIT,所以导致出错。解决方法:

Centos下使用:yum install git -y 或者 yum install -y git
Ubuntu/Debian下使用 : apt-get install git -y

下载下来的代码结构如下:

elasticsearch\head\Gruntfile.js修改以下片段

connect: {
	server: {
		options: {
		    /* 默认监控:127.0.0.1,修改为:0.0.0.0 */
			hostname: '0.0.0.0',
			port: 9100,
			base: '.',
			keepalive: true
		}
	}
}

elasticsearch\head\_site\app.js修改以下代码片段

* 修改localhost为elasticsearch集群地址,Docker部署中,一般是elasticsearch宿主机地址 4388行*/
this.base_uri = this.config.base_uri || this.prefs.get("app-base_uri") || "http://localhost:9200";

启动

  • 运行elasticsearch需要vm.max_map_count至少需要262144内存
切换到root用户修改配置sysctl.conf
vi /etc/sysctl.conf
在尾行添加以下内容   
vm.max_map_count=262144
并执行命令
sysctl -p

elk启动的时候可能会提示如下错误:
max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]

启动es

docker-compose up -d 启动
docker-compose down 关闭

测试

elasticsearch-head可视化页面:http://es所在机器IP:9100

源码包下载 提取码:ht3w

------------------------------------------------------------------------------------------------------------------------------

elasticsearch 查看集群状态 节点状态 和索引使用情况

查看集群总的状态
集群的监控包括二个方面:集群的健康状况和集群的运行状况
1、集群的健康状态,通过api获取:GET _cluster/health?pretty

2、集群的状况信息
集群状态信息主要包含整个集群的一些统计信息,例如文档数、分片数、资源使用情况等。集群状态信息可以由以下api获取:GET _cluster/stats?pretty

查看节点
节点监控主要针对各个节点,有很多指标对于保证ES集群的稳定运行非常重要。下面对节点监控指标进行介绍。节点指标可以通过以下api获取:GET /_nodes/stats?pretty

查看索引
索引监控指标注意针对单个索引,不过也可以通过"_all"对集群种所有索引进行监控,节点指标可以通过以下api获取:GET /_stats?pretty

详情跳转https://blog.csdn.net/star1210644725/article/details/109565434

1、所有文章未经授权禁止转载、摘编、复制或建立镜像,如有违反,追究法律责任。
2、本站文章部分来源注册用户发布或互联网收集而来,若有侵权,请邮件联系作者。
邮箱地址:wtao219@qq.com
THE END
分享
二维码
< <上一篇
下一篇>>