美文网首页ELK
ES-安装部署篇

ES-安装部署篇

作者: 靈08_1024 | 来源:发表于2017-11-22 18:45 被阅读99次

    本篇主要讲述如何部署一个ES服务器。
    ES版本:5.6.0。
    服务器版本:centOS6.9,macOS。

    下载地址:ELK当前版本下载地址
    ELK旧版本下载

    ES是基于JAVA开发的,所以需要JDK(自行百度安装)。ES5.6.0需要JDK8。
    ES5.6.0只需要JDK的JRE即可,其JAVA_OPTS在内部有自定义的文件来处理。

    centos安装在前面,macOS安装在后面。

    centos安装:

    修改参数

    #1
    vim /etc/sysctl.conf
    #添加如下语句
    vm.max_map_count = 262144
    #2
    vim /etc/security/limits.conf
    #添加如下语句
    * soft nofile 65536
    * hard nofile 65536
    * soft nproc 2048
    * hard nproc 4096
    #3
    vim /etc/security/limits.d/90-nproc.conf
    #修改如下属性,该值原为1024,需要修改为2048
    *      soft    nproc    2048
    

    -----或者------
    还有一说:
    root执行以下脚本:

    #!/bin/bash 
    echo "* soft nofile 65536" >> /etc/security/limits.conf 
    echo "* hard nofile 65536" >> /etc/security/limits.conf 
    echo "* soft memlock unlimited" >> /etc/security/limits.conf 
    echo "* hard memlock unlimited" >> /etc/security/limits.conf 
    echo "vm.max_map_count = 262144" >> /etc/sysctl.conf 
    sysctl -p 
    ulimit -l unlimited
    

    防火墙设置

    vim /etc/sysconfig/iptables
    #在指定区域加入端口:
    iptables -I INPUT -p tcp --dport 9200 -j ACCEPT
    iptables -I INPUT -p tcp --dport 9300 -j ACCEPT
    #重启
    service iptables restart
    

    执行启动
    elasticSearch的启动需要用非root用户。

    如果没有用户,可以添加用户,下面的示例使用的是kindo用户,没有使用es用户,按需。es用户需要赋予读jdk目录的权限
    [root@kindoServer tools]# useradd es
    #赋予权限给kindo组的kindo
    [root@kindoServer tools]# chown -R es.es elasticsearch-5.6.0/
    #切换用户
    [root@kindoServer bin]# su - es
    #切换目录
    [es@kindoServer ~]$ cd /usr/local/elasticsearch-5.6.0/bin
    #前台启动
    [es@kindoServer bin]$ ./elasticsearch
    #后台启动
    [es@kindoServer bin]# ./elasticsearch -d
    #查看启动
    [es@kindoServer elasticsearch-5.6.0]$ jps
    3446 Elasticsearch
    3581 Jps
    #启动成功!
    

    Tips:

    • 有时我们的bin/elasticsearch文件不是加粗的(即不可用),需要执行:[es@kindoserver02 bin]$ chmod +x elasticsearch
    • 如果执行后台启动,一般在执行启动后10S后查看jps,此时ES已经启动稳定了。
    • 关闭ES,使用kill -9 JPS命令下ES的ID命令关闭。

    连接测试
    Linux服务器测试命令curl http://192.168.1.22:9200/_cluster/health?pretty或浏览器访问http://192.168.1.22:9200/_cluster/health?pretty查看ES的集群状态,出现如下界面,即成功:

    {
      "cluster_name" : "kindo",
      "status" : "green",
      "timed_out" : false,
      "number_of_nodes" : 2,
      "number_of_data_nodes" : 2,
      "active_primary_shards" : 5,
      "active_shards" : 10,
      "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
    }
    

    Tips:

         关于ES的重启或者停止,只有使用 ps -ef | grep elastic,杀死对应进程ID。
       默认 9300 是 Java 客户端的端口。9200 是支持 HTTP 的接口。

    elasticsearch 集群健康状况返回颜色取值

    颜色 意义
    green 所有分片和复制分片均可用
    yellow 所有主分片可用,部分或全部复制分片不可用
    red 主分片部分或全部不可用

    head插件的安装

    因为head插件是用nodejs写的,所以在安装head插件时,需要安装nodejs,grunt,Head插件。

    安装node:

    [root@kindoServer tools]# wget https://npm.taobao.org/mirrors/node/latest-v6.x/node-v6.11.1-linux-x64.tar.gz
    [root@kindoServer tools]# tar -zxvf node-v6.11.1-linux-x64.tar.gz
    #链接到local
    [root@kindoServer node-v6.11.1-linux-x64]# ln -s /home/kindo/data/tools/node-v6.11.1-linux-x64/bin/node  /usr/local/bin/node
    [root@kindoServer node-v6.11.1-linux-x64]# ln -s /home/kindo/data/tools/node-v6.11.1-linux-x64/bin/npm /usr/local/bin/npm
    #检查是否成功
    [root@kindoServer node-v6.11.1-linux-x64]# npm -v
    3.10.10
    [root@kindoServer node-v6.11.1-linux-x64]# node -v
    v6.11.1
    

    安装grunt:

    [root@kindoServer node-v6.11.1-linux-x64]# npm install -g grunt-cli
    

    /etc/profile文件中,添加以下:

    #上述完成后,配置grunt的环境变量
    GRUNT_HOME=/home/kindo/data/tools/node-v6.11.1-linux-x64/lib/node_modules/grunt-cli
    
    PATH = (以前的path):$GRUNT_HOME/bin
    
    export (以前的变量) GRUNT_HOME
    

    保存后,source /etc/profile立即刷新。使用grunt -V来进行测试。

    安装head

    安装git,然后下载并安装head。

    [root@kindoServer ~]# yum install git -y
    [root@kindoServer tools]# git clone git://github.com/mobz/elasticsearch-head.git
    #切换到elasticsearch-head目录下
    [root@kindoServer elasticsearch-head]# npm install && npm install grunt --save
    

    在上述命令执行完之后,会出现

    npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@^1.0.0 (node_modules/chokidar/node_modules/fsevents):
    npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.1.2: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
    npm WARN elasticsearch-head@0.0.0 license should be a valid SPDX license expression
    

    ,忽视掉即可。

    修改配置

    elasticsearch-head/Gruntfile.js文件中添加http: '*',,结果如下所示:

     connect: {
            server: {
                    options: {
                            http: '*',
                            port: 9100,
                            base: '.',
                            keepalive: true
                    }
            }
    

    如上片段所示位置在93行附近,编辑模式:93会跳转到93行。

    elasticsearch-head/_site/app.js中修改localhost为ES主机IP,结果如下所示:

    this.base_uri = this.config.base_uri || this.prefs.get("app-base_uri") || "http://192.168.1.22:9200";
    

    如上片段所示位置在4354行附近。

    elasticsearch-5.6.0/config/elasticsearch.yml文件中添加以下文字:

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

    开放9100端口:

     vim /etc/sysconfig/iptables
    #添加一下语句
     iptables -I INPUT -p tcp --dport 9100 -j ACCEPT
    #保存并重启
     service iptables restart
    

    启动head:
    在head主目录下执行下面命令启动:

    [root@kindoServer elasticsearch-head]# grunt server
    

    后台启动:

    nohup grunt server &
    

    以下全部是mac安装:

    macOS安装:

    xxxdeMacBook-Pro:local xxx$ brew update
    xxxdeMacBook-Pro:local xxx$ brew install elasticsearch
    #查看版本信息
    xxxdeMacBook-Pro:local xxx$ brew info elasticsearch
    #启动  加-d可以后台启动
    xxxdeMacBook-Pro:local xxx$ elasticsearch
    

    本人一口气也安装了logstash、kibana,ELK一家人要整整齐齐的嘛。

    查看进程:

    xxxdeMacBook-Pro:local xxx$ jps
    95777 Elasticsearch
    95779 Jps
    

    关闭进程kill -d 进程号

    安装head插件:

    mac安装

    git clone git://github.com/mobz/elasticsearch-head.git
    cd elasticsearch-head
    npm install
    npm run start
    

    修改跨域问题:在/usr/local/Cellar/elasticsearch/5.6.4/libexec/config/elasticsearch.yml文件尾部下添加:

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

    最后这条命令会启动head的。然后浏览器输入http://localhost:9100即可。

    相关文章

      网友评论

        本文标题:ES-安装部署篇

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