美文网首页
Elasticsearch集群、head插件搭建及配置(五)

Elasticsearch集群、head插件搭建及配置(五)

作者: 橡皮24 | 来源:发表于2018-11-09 15:55 被阅读46次

    1 环境

    需要java1.8以上,所以我们使用jdk1.8.0_172。并配置好环境变量。

    2 配置Elasticsearch

    elasticsearch下载地址:https://www.elastic.co/downloads/past-releases/elasticsearch-5-6-11
    下载源码解压。解压在/data/

    2.1 配置文件路径

    elasticsearch 配置目录:/data/elasticsearch/config/

    配置文件为:/data/elasticsearch/config/elasticsearch.yml

    2.2 配置文件详解

     [root@kafka11 config]# cat elasticsearch.yml
    cluster.name: elasticsearch_cluster #起名三个节点要一致
    node.name: node_master_11 #节点名:三个节点不一致
    node.master: true
    node.data: true
    path.data: /data/elasticsearch/data #数据目录(需要后期创建)
    path.logs: /data/elasticsearch/logs #日志目录(需要后期创建)
    bootstrap.memory_lock: true
    network.host: 10.10.4.11 #本机IP地址
    http.port: 9200 #端口
    discovery.zen.ping.unicast.hosts: ["10.10.4.11", "10.10.4.12", "10.10.4.13"]
    #集群地址
    http.cors.enabled: true
    http.cors.allow-origin: "*"
    

    2.3 创建用户、目录及修改目录权限

    由于Elasticsearch不能使用root权限运行,所以创建path.data和path.logs目录需要修改权限

    useradd elasticsearch
    chmod -R elasticsearch:elasticsearch /data/elasticsearch-5.6.11/
    mkdir -p /data/elasticsearch/data
    mkdir -p /data/elasticsearch/logs
    chmod -R /data/elasticsearch
    

    2.4 启动

    # su - elasticsearch
    $ /data/elasticsearch-5.6.11/bin/elasticsearch -d
    

    2.5 启动可能遇到问题

    [1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536] 意思是说你的进程不够用了

    解决方案: 切到root 用户:进入到security目录下的limits.conf;执行命令 vim /etc/security/limits.conf 在文件的末尾添加下面的参数值:

    * soft nofile 65536
    * hard nofile 131072
    * soft nproc 2048
    * hard nproc 4096
    

    前面的*符号必须带上,然后重新启动就可以了。执行完成后可以使用命令 ulimit -n 查看进程数

    [2]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144] 需要修改系统变量的最大值了

    解决方案:切换到root用户修改配置sysctl.conf 增加配置值: vm.max_map_count=655360执行命令 sysctl -p 这样就可以了,然后重新启动ES服务 就可以了

    5、查看状态

    [root@kafka11 ~]# netstat -ntlt
    tcp6 0 0 192.168.205.155:9200 :::* LISTEN    
    tcp6 0 0 192.168.205.155:9300 :::* LISTEN   
    

    9200是默认端口
    9300是集群通信端口

    3 相关命令

    1、检查Elasticsearch是否运行

    [root@kafka11 ~]# curl -X GET "10.10.4.11:9200/"
    
    {
    
     "name" : "node_master_11",
    
     "cluster_name" : "elasticsearch_cluster",
    
     "cluster_uuid" : "2BKMtG7tSBmaJqXQy1tzxg",
    
     "version" : {
    
     "number" : "5.6.11",
    
     "build_hash" : "bc3eef4",
    
     "build_date" : "2018-08-16T15:25:17.293Z",
    
     "build_snapshot" : false,
    
     "lucene_version" : "6.6.1"
    
     },
    
     "tagline" : "You Know, for Search"
    
    }
    

    2、查询集群状态

    [root@kafka11 ~]# curl -XGET 'http://10.10.4.11:9200/_cat/nodes' #任选一台机器执行
    
    10.10.4.11 16 91 0 0.24 0.09 0.06 mdi - node_master_11
    
    10.10.4.13 35 98 0 0.00 0.01 0.05 mdi * node_slave_13
    
    10.10.4.12 12 93 0 0.00 0.01 0.05 mdi - node_slave_12 #带*号的是自动选举出来的master
    
    [root@kafka11 ~]#curl -XGET 'http://10.10.4.11:9200/_cluster/state/nodes?pretty'
    
    {
    
     "cluster_name" : "elasticsearch_cluster", #名字
    
     "nodes" : {
    
     "0aOK3alCSAGQRYwMoB8-3A" : { #ID值
    
     "name" : "node_master_11", #node名字
    
     "ephemeral_id" : "Si4djzEERfqmFdbRDUA0WQ", #id
    
     "transport_address" : "10.10.4.11:9300", , #集群通讯地址
    
     "attributes" : { }
    
     },
    
     "JhxqBlI2RKeJx7HuvpkEAA" : {
    
     "name" : "node_slave_13",
    
     "ephemeral_id" : "wwfYQmiAR1qiHc0Cn-l3cA",
    
     "transport_address" : "10.10.4.13:9300",
    
     "attributes" : { }
    
     },
    
     "bkY8d3qkT9GO7P0lYpsjcw" : {
    
     "name" : "node_slave_12",
    
     "ephemeral_id" : "OUSmly1ITdKxai74NNYbbQ",
    
     "transport_address" : "10.10.4.12:9300",
    
     "attributes" : { }
    
     }
    
     }
    
    }
    

    3、查询集群中的master

    [root@kafka11 ~]# curl -XGET 'http://10.10.4.11:9200/_cluster/state/master_node?pretty'
    
    {
    
     "cluster_name" : "elasticsearch_cluster",
    
     "master_node" : "JhxqBlI2RKeJx7HuvpkEAA"
    
    }
    
    [root@kafka11 ~]# curl -XGET 'http://10.10.4.11:9200/_cat/master?v'
    
    id host ip node
    
    JhxqBlI2RKeJx7HuvpkEAA 10.10.4.13 10.10.4.13 node_slave_13
    

    4、查询集群的健康状态

    [root@kafka11 ~]# curl -XGET 'http://10.10.4.11:9200/_cat/health?v'
    
    epoch timestamp cluster         status node.total node.data shards pri relo init unassign pending_tasks max_task_wait_time active_shards_percent
    
    1538550748 15:12:28 elasticsearch_cluster green 3 3 437 221 0 0 0 0 -               100.0%
    

    ###Status下边是状态显示

    [root@kafka11 ~]# curl -XGET 'http://10.10.4.11:9200/_cluster/health?pretty'
    
    {
    
     "cluster_name" : "elasticsearch_cluster",
    
     "status" : "green", ##green代表正常
    
     "timed_out" : false,
    
     "number_of_nodes" : 3,
    
     "number_of_data_nodes" : 3,
    
     "active_primary_shards" : 221,
    
     "active_shards" : 437,
    
     "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
    
    }
    

    4 插件head安装及配置

    4.1 安装head

    1、下载解压

    wget https://github.com/mobz/elasticsearch-head/archive/master.zip

    unzip master.zip -d /data
    

    2、安装node.js

    执行head 插件,需要node.js 的支持,所以,下面先安装一node.js

    curl -sL https://rpm.nodesource.com/setup_8.x | bash -
    yum install -y nodejs nodejs-npm
    node –v ##验证是否安装
    

    3、安装grunt

    cd /data/elasticsearch-head-master/
    npm install grunt --save-dev
    npm install
    

    4、修改/etc/profile文件

    最后添加

    export NODE_HOME= /data/elasticsearch-head-master/node_modules/grunt
    export PATH=$PATH:$NODE_HOME/bin
    
    # source /etc/profile
    

    5、修改配置

    修改 vim _site/app.js 文件:修改head的连接地址

    6、修改elasticsearch配置文件elasticesearch.yml末端新增以下内容:

    http.cors.enabled: true
    
    http.cors.allow-origin: "*"
    

    7、启动head(要做head的目录里执行)

    grunt server &
    

    *****发现使用&加入后台,只要一退出shell就会无法访问,所以使用以下命令

    screen -dmLS head grunt server
    

    访问IP地址+9100即可出现图像。

    5 插件Bigdesk插件安装

    5.1 简介

    Bigdesk直接可以通过python提供的http服务器,python -m SimpleHTTPServer运行,服务器运行,端口号是8000,默认情况下linux系统下安装过了python,所以下载下来压缩包,直接运行服务就可以了。如果想修改端口直接在python -m SimpleHTTPServer 命令后添加端口号。

    官网地址:https://github.com/hlstudio/bigdesk

    5.2 安装

    wget http://yellowcong.qiniudn.com/bigdesk-master.zip
    

    进入到sit目录

    cd /data/bigdesk/_site/
    

    #启动web服务器
    #默认监听端口号是 8000,由于8000端口被占用启用8001端口

    python -m SimpleHTTPServer 8001
    

    Serving HTTP on 0.0.0.0 port 8001 ...

    5.3 使用

    访问IP+端口(8001)

    点击connect,出现各各节点,选中一个可以查看实时状态。和相关参数。

    5.4 插件cerebro安装

    5.4.1 安装配置

    es虽然不能再root下运行,但是cerebro 可以

    wget https://github.com/lmenezes/cerebro/releases/download/v0.6.5/cerebro-0.6.5.tgz
    tar zxvf cerebro-0.6.5.tgz
    cd cerebro-0.6.5/
    ##启动(默认是9000端口,如果想用其他端口使用-Dhttp.port=)
    bin/cerebro -Dhttp.port=1234
    

    如果在后台使用可以使用nohup ** & 命令。

    5.4.2 操作

    1、连接cerebro

    IP:port

    2、连接elasticsearch

    http://ip:9200 #此处一定要写http://

    相关文章

      网友评论

          本文标题:Elasticsearch集群、head插件搭建及配置(五)

          本文链接:https://www.haomeiwen.com/subject/iqsoxqtx.html