美文网首页
ES安装及插件head的使用

ES安装及插件head的使用

作者: 黑客不黑_ | 来源:发表于2019-04-03 16:01 被阅读0次

    一、ES安装向导:

    • elasticsearch是什么有什么用,简单点说它可以提供搜索功能,像商城搜索商品等。

    1、环境要求

    JDK  node
    

    2、下载

    elasticsearch
    

    3、下载插件

    elasticsearch-head  git clone [https://github.com/mobz/elasticsearch-head.git](https://github.com/mobz/elasticsearch-head.git)
    

    4、创建非root用户权限管控,必须非root用户启动

    useradd es  
    passwd es  
    chown -R es:root elasticsearch-6.5.4  
    ll  
    [root@iZwz99kz2oogerp784tbxiZ service]# ll  
    total 199300  
    drwxr-xr-x 9 es root 4096 Jan 11 11:56 elasticsearch-6.5.4  
    drwxr-xr-x 8 root root 4096 Jan 11 12:08 elasticsearch-head  
    su es
    

    5、启动elasticsearch

    su es  cd /home/service/elasticsearch-6.5.4/bin  可以先看启动会不会报错,不报错就后台启动。  ./elasticsearch  后台启动  nohup ./elasticsearch &
    

    6、启动elasticsearch-head

    二、elasticsearch中head插件的使用

    1、安装

    • 插件官网地址https://github.com/mobz/elasticsearch-head

    • 由于插件时托管在github中,要从github中直接下载所以需要先安装git

    • 安装插件时又使用到了npm,所以npm同时都安装上(注意:npm在epel源中)yum install git npm

      npm在epel源中

    git clone [https://github.com/mobz/elasticsearch-head.git](https://github.com/mobz/elasticsearch-head.git) 
    # 安装过程需要连接互联网  
    cd elasticsearch-head 
    # git clone后会自动生成的一个目录  
    npm install  
    npm run start  
    后台启动  
    nohup npm run start &
    

    2、测试

    使用浏览器打开http://192.168.10.2:9200。如果能正常打开说明head插件安装正确 现在集群健康状态哪里显示未连接,这是因为head插件没有权限获取集群节点的信息,接下来设置权限

    image.png

    3、权限设定

    如果想查询集群健康信息,那么需要在elasticsearch配置文件中授权

    vim /etc/elasticsearch/elasticsearch.yml  http.cors.enabled: true # elasticsearch中启用CORS  http.cors.allow-origin: "*" # 允许访问的IP地址段,* 为所有IP都可以访问
    

    4、测试

    • 填入测试索引
        curl -XPUT '192.168.10.2:9100/book'
    
    • 打开浏览器,再次通过浏览器打开,填入已经授权节(上面的两行配置)点IP地址,点击链接,就可以看到集群健康信息与测试索引的分片信息。

    • 点数据浏览就可以查看到所有的信息,不过这里没有插入数据也就看不到。接下来的文章会记录如何输入、输出、过滤数据


      image.png

    三、启动elasticsearch报错

    • [1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]
      编辑 /etc/security/limits.conf,追加以下内容;
    soft nofile 65536
     hard nofile 65536
    

    此文件修改后需要重新登录用户,才会生效

    • [2]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
      编辑 /etc/sysctl.conf,追加以下内容:
    vm.max_map_count=655360
    

    保存后,执行名利

    sysctl -p
    

    重新启动,成功。
    bin/elasticsearch &

    四、设置elasticsearch-head允许外网访问

    修改elasticsearch.yml配置文件

    vim config/elasticsearch.yml
    增加
    network.host: 0.0.0.0
    

    五、优化内存配置

    [root@localhost config]# ls
    elasticsearch.keystore  elasticsearch.yml  jvm.options  log4j2.properties  role_mapping.yml  roles.yml  users  users_roles
    [root@localhost config]# vim jvm.options 
    [root@localhost config]# pwd
    /home/service/elasticsearch-6.5.4/config
    

    elasticsearch使用java的jvm默认是使用1G的内存的,这里我们修改一下内存,直接把内存改到200m


    image.png

    修改内容

    -Xms200m
    -Xmx200m
    

    相关文章

      网友评论

          本文标题:ES安装及插件head的使用

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