美文网首页elasticsearch
CentOS6.X,部署elasticsearch5.6详细步骤

CentOS6.X,部署elasticsearch5.6详细步骤

作者: 迟凝丶捏米么 | 来源:发表于2017-11-07 15:50 被阅读96次

    标签(空格分隔): elasticsearch head kibana jdk Linux升级


    目录.png

    安装说明

    本次为裸机安装单机版的elasticsearch5.6,由此会涉及到很多不可避免的,或者说多余的部分,请自行忽略。操作系统Linux内核版本,jdk版本,elasticsearch5.6需要 Java8。

    这里说明一下,因为后面会安装head插件,对Linux的内核要求在3.5以上,默认安装的Linux版本的内核为2.6。参见截图。jdk1.8是安装在elasticsearch用户下的,在root用户下java -version就会显示-bash: java: command not found

    见官方文档:Elasticsearch requires at least Java 8. Specifically as of this writing, it is recommended that you use the Oracle JDK version 1.8.0_131.

    系统参数 系统参数

    Linux插件安装

    root用户下,".xz"文件解压

    说明:安装解压xz,是在安装elasticsearch的head插件的时候,需要用到node.js,同时需要Linux需要可以连接internet网络

    1.下载地址 https://tukaani.org/xz/
    要选择.bz2的,别选.xz的,否则还是解压不了

    image.png

    2.解压包
    tar -zxvf xz-5.2.3.tar.gz
    cd xz-5.2.3
    ./configure --prefix=/usr/local/xz
    这里会遇到问题,在configure时就是各种找不到,没有gcc等,于是输入以下命令
    yum install update -y
    yum install upgrade -y
    这个过程有点久,等完成后,再安装gcc
    yum install gcc
    这样安装好后
    cd xz-5.0.3/
    ./configure
    make
    make install
    之后就可以愉快地解压tar.xz文件啦!基本是参见文档内容,请见谅。

    3.解压xz包
    xz -d ***.tar.xz

    4.解压tar包
    tar -xvf ***.tar

    安装wget

    yum -y install wget

    安装vim

    yum -y install vim

    Linux的常用支持库

    在CentOS安装软件的时候,可能缺少一部分支持库,而报错。这里首先安装系统常用的支持库。那么在安装的时候就会减少很多的错误的出现。

    yum install -y gcc gdb strace gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs patch e2fsprogs-devel krb5-devel libidn libidn-devel openldap-devel nss_ldap openldap-clients openldap-servers libevent-devel libevent uuid-devel uuid mysql-devel 
    

    jdk1.8安装

    说明:这里切换到elasticsearch用户进行安装,不是一种全局jdk配置方式

    1.新建用户
    useradd elasticsearch,这时默认用户主目录在 /home/elasticsearch

    2.su - elasticsearch,切换到elasticsearch用户

    3.ls -al,可以查看到隐藏文件,见图片红色框部分

    新建用户下的目录.png

    4.修改.bashrc文件,切记 :wq 后,执行source .bashrc,进行保存生效
    export JAVA_HOME="/home/elasticsearch/jdk1.8.0_144"
    export JRE_HOME=${JAVA_HOME}/jre
    export PATH=${JAVA_HOME}/bin:$PATH
    export CLASSPATH=.:${JAVA_HOME}/lib/dt.jar:${JAVA_HOME}/lib/tools.jar
    export JAVA_HOME JRE_HOME CLASSPATH PATH

    .bashrc文件配置.png

    5.这时再查看java版本,发现已经为1.8了

    jdk1.8.png

    elasticsearch5.6安装以及配置修改

    1.下载地址
    https://www.elastic.co/downloads/elasticsearch#ga-release

    elasticsearch下载.png

    2.解压压缩文件
    tar -zxvf elasticsearch-5.6.3.tar.gz

    3.修改elasticsearch.yml配置文件

    配置文件位置.png

    修改参数如下,注意该配置##顺序分先后##

    • 集群名称:cluster.name: jt_sap5
    • 节点名称:node.name: single-node(集群中的各个节点名称都不能相同)
    • 数据目录:path.data: /path/to/data(若没有特殊数据路径,注释掉该参数,默认使用ES_HOME/data)
    • 日志目录:#path.logs: /path/to/logs(若没有特殊数据路径,注释掉该参数,默认使用ES_HOME/logs)
    • 锁定物理内存设置:bootstrap.memory_lock: false(注释掉该参数,默认使用false)
    • 系统过滤器调用设置:bootstrap.system_call_filter: false
    • 节点主机IP:network.host: 10.0.1.215
    • 节点端口:http.port: 9200
    • 数据传输端口:transport.tcp.port: 9300
    • 集群节点获取类型:discovery.type: single-node(注意该配置只在单节点集群中使用,多节点集群不能使用,使用默认类型)
    • 集群节点列表:discovery.zen.ping.unicast.hosts: ["host1:port1", "host2: port2"](该配置在多节点集群中使用,单节点不适用该配置。其中,host表示集群中其他节点的ip地址,port表示集群中其他节点的数据传输端口)
    • 集群有效节点最小值:discovery.zen.minimum_master_nodes: 3(该配置在多借点集群中使用,单节点不适用。其中,该配置的值不能大于总节点数量,建议使用 [节点数量/2 + 1] 来计算该配置值)
    • 是否允许跨源 REST 请求:http.cors.enabled: true
    • 允许跨源REST请求的地址:http.cors.allow-origin: ""(在开启允许跨源REST请求之后,才使用该配置,不然不能使用,其中“”标识允许所有的跨源访问)
    • 最大的http请求长度:http.max_initial_line_length: 10m

    备注:
    1.bootstrap.system_call_filter参数配置,默认为true,这里更改为false,放在bootstrap.memory_lock后面,同时设定bootstrap.memory_lock为false,主要可能的原因是由于CentOS6.X内核版本为2.6,不支持bootstrap.memory_lock参数的开启,就会引出下面的内核升级问题。
    2.官方文档中提到bootstrap.memory_lock: true的诸多配置,在后文添加。
    3.注意 “:”,后面需要加空格

    内核版本问题报错.png

    4.elasticsearch启动错误处理方法,以及必须的配置

    [elasticsearch@localhost bin]$ ./elasticsearch
    ... ...
     
    ERROR: 
    [5] bootstrap checks failed
    [1]: max file descriptors [65535] for elasticsearch process is too low, increase to at least [65536]
    [2]: max number of threads [1024] for user [elasticsearch] is too low, increase to at least [2048]
    [3]: max virtual memory areas vm.max_map_count [256000] is too low, increase to at least [262144]
    [4]: system call filters failed to install; check the logs and fix your configuration or disable system call filters at your own risk
     
    ... ...
    

    (1)针对错误[1],[2],可以采取如下配置:

    修改/etc/security/limits.conf配置文件:

    #[root@www config]$ vim /etc/security/limits.conf
    
    #增加5行,修改最大句柄数和单进程的最大线程数:
    *  -  nofile  65536
    * soft memlock   unlimited
    * hard memlock   unlimited
    * soft nproc 2048
    * hard nproc 2048
    

    (此处代表所有用户都适用,可以根据自身需要设定特定用户句柄)
    如果系统中存在/etc/security/limits.d/90-nproc.conf,修改
    soft nproc 1024为* soft nproc 10240,将所有用户句柄最大值调整为10240。

    #[root@www config]$ vim /etc/security/limits.d/90-nproc.conf
    修改如下配置:
    
    # Default limit for number of user's processes to prevent
    # accidental fork bombs.
    # See rhbz #432903 for reasoning.
    
    *          soft    nproc     10240
    root       soft    nproc     unlimited
    

    修改完成后,重新登录elasticsearch账户,查看设置是否生效。

    [elasticsearch@www config]$ ulimit -n
    65536
    [elasticsearch@www config]$ ulimit -u
    2048
    

    官方文档:
    Elasticsearch使用了大量的文件描述符或者文件句柄。文件描述符将要被用完时会导致灾难性的后果,并且非常可能引起数据丢失。确保增加运行Elasticsearch的用户打开文件描述符的数量至少为65,536或者更高。
    Elasticsearch使用多个线程池来进行不同类型的操作。当需要时能够创建新线程是很重要的。确保Elasticsearch用户能创建的线程数最少为2048个。

    你可以检查每个节点的max_file_descriptors配置情况:

    GET _nodes/stats/process?filter_path=**.max_file_descriptors

    (2)针对错误[3],可以采取如下方式:
    修改/etc/sysctl.conf文件配置项:

    [root@www ~]# vim /etc/sysctl.conf
    # 一个进程可以拥有的VMA(虚拟内存区域)的数量:
    vm.max_map_count=262144
     
    # 调用虚拟内存的阈值数:
    vm.swappiness=1 
    
    [root@www ~]# sysctl -p
    

    (3)针对错误[4][5],可以采取如下方式:

    出现错误的原因:是因为centos6.x操作系统不支持SecComp,而elasticsearch 5.x,默认bootstrap.system_call_filter为true进行检测,所以导致检测失败,失败后直接导致ES不能启动。但是为了禁止内存交换,这两个参数最好设置为true。

    在elasticsearch.yml中添加配置项:bootstrap.system_call_filter为false:

    bootstrap.memory_lock: false
    bootstrap.system_call_filter: false
    

    官方文档:大多数操作系统会用尽可能多的内存用于文件系统缓存和及早换出无用的应用内存。这可能导致一部分JVM内存被交换到硬盘上。这种内存交换非常不利于性能和节点的稳定性。应该竭尽所能来避免这种情况。它能引起垃圾回收持续长达数分钟而不是几毫秒并且能导致节点响应缓慢甚至与集群失去联系。由此,最好的方式就是禁止内存交换。

    禁止内存交换的三种方式

    • 启用 bootstrap.memory_lock
    • 暂时禁用,Linux系统执行命令sudo swapoff -a,如果要永久禁用,则需要编辑/etc/fstab文件,然后注释掉所有包含swap的行。
    • vim /etc/sysctl.conf,正如上面提到的vm.swappiness=1,这样子只会在正常情况下减少内存交换,但在紧急情况中依然存在。

    警告:mlockall如果尝试分配超过了可用的内存,可能会引起JVM 或者 shell session退出。在启动Elasticsearch后,你可以检查下设置是否生效了,可以通过检查下面请求响应中的mlockall值:

    `GET _nodes?filter_path=**.mlockall`
    or
    `GET _nodes/process?pretty`
    

    (4)优化JVM的Head内存大小
    说明:该配置适用于ES服务器负载较高时,通过提高JVM的Heap内存,可以提高ES的处理速度。

    # vim $ES_HOME/config/jvm.options
    
    #这个值不能超过可用物理内存的50%,甚至更小。
    修改以下两处配置:
    -Xms4g
    -Xmx4g
    
    #如果内存配置超过6G请修改如下配置。把回收期修改为G1 GC
    ## GC configuration
    -XX:+UseConcMarkSweepGC
    -XX:CMSInitiatingOccupancyFraction=75
    -XX:+UseCMSInitiatingOccupancyOnly
    修改后
    ## GC configuration
    -XX:+UseG1GC
    -XX:MaxGCPauseMillis=200
    

    5.启动和关闭elasticsearch
    以elasticsearch用户登录

    启动:
    # cd $ES_HOME
    # ./bin/elasticsearch –d –p pid
    关闭:
    # cd $ES_HOME
    # kill -9 `pid`
    

    浏览器打开:http://127.0.0.1:9200

    Head插件安装

    1.安装git
    需要从github上面下载代码,因此先要安装git

    yum -y install git
    

    安装完成后,就可以直接下载代码了:

    git clone git://github.com/mobz/elasticsearch-head.git
    

    或者在windows下载
    下载地址:https://github.com/mobz/elasticsearch-head,下载后上传到Linux系统中。

    2.安装node
    由于head插件本质上还是一个nodejs的工程,因此需要安装node,使用npm来安装依赖的包。(npm可以理解为maven)
    去官网下载nodejs,https://nodejs.org/en/download/

    node官网.png

    下载下来的jar包是xz格式的,一般的linux可能不识别,但我们前面以及安装了xz解压工具了哦!

    xz -d node*.tar.xz
    tar -xvf node*.tar
    

    解压完node的安装文件后,需要配置下环境变量,root用户编辑/etc/profile,注意要修改node路径,添加

    vim /etc/profile
    
    export NODE_HOME=/home/elasticsearch/node-v8.9.0-linux-x64
    export PATH=$PATH:$NODE_HOME/bin
    export NODE_PATH=$NODE_HOME/lib/node_modules
    
    #在命令行输入:source /etc/profile,让配置文件生效。
    

    在命令行输入:node -v,查看node.js的版本。

    node版本号.png

    3.安装grunt
    grunt是一个很方便的构建工具,可以进行打包压缩、测试、执行等等的工作,5.0里的head插件就是通过grunt启动的。因此需要安装一下grunt:

    npm install grunt-cli
    
    安装完成后检查一下:
    [root@www elasticsearch-head-master]# grunt -version
    grunt-cli v1.2.0
    grunt v1.0.1
    

    4.修改head源码

    查看当前head插件目录下有无node_modules/grunt目录,没有的话,执行命令创建:npm install grunt --save

    (1)修改服务器监听地址:增加hostname属性,设置为*
    目录:head/Gruntfile.js

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

    (2)检查head根目录下是否存在base文件夹
    要是没有的话,将 _site下的base文件夹及其内容复制到head根目录下

    (3)修改连接地址:
    目录:head/_site/app.js

    修改head的连接地址:
    this.base_uri = this.config.base_uri || this.prefs.get("app-base_uri") || "http://localhost:9200";
    
    把localhost修改成你es的服务器地址,如:
    this.base_uri = this.config.base_uri || this.prefs.get("app-base_uri") || "http://10.0.0.78:9200";
    

    5.运行head
    首先启动elasticsearch,然后在head目录中,执行npm install下载依赖的包
    如果速度较慢或者安装失败,可以使用国内镜像 npm install -g cnpm --registry=https://registry.npm.taobao.org

    #后台启动grunt server命令
    nohup grunt server &exit
    
    #如果想关闭head插件,使用[Linux](http://lib.csdn.net/base/linux)查找进程命令:
    ps aux|grep head
    
    #结束进程:
    kill -9 'pid'
    

    访问head插件:
    http://10.0.0.78:9100(启动后会有提示:Started connect web server on http://10.0.0.78:9100)

    Kibana安装

    Kibana是一个开源的分析与可视化平台,设计出来用于和Elasticsearch一起使用的。你可以用kibana搜索、查看、交互存放在Elasticsearch索引里的数据,使用各种不同的图表、表格、地图等kibana能够很轻易地展示高级数据分析与可视化。
    1.下载kibana-5.6.3-linux-x86_64.tar.gz
    下载地址为:https://www.elastic.co/downloads/kibana

    image.png

    2.修改配置文件
    进入kibana解压目录,修改配置文件config/kibana.yml。

    • kibana服务器端口号:server.port: 5601
    • kibana服务器ip地址:server.host: "10.10.10.102"
    • kibana服务器连接ES地址:elasticsearch.url: "http://10.10.10.102:9200"

    3.启动 kibana

    nohup  bin/kibana &>/dev/null&
    

    4.查看是否启动成功
    打开浏览器,访问:http://IP:5601即可

    Linux内核2.6升级3.10

    背景说明:CentOS 7 的内核一般都是3.10的,而CentOS 6.X 的内核一般都是2.6,在2.6的内核下,elasticsearch5.x下bootstrap.system_call_filter启动会出现问题,要求为内核3.5以上。
    升级内核的方式,网上有很多方法是下载内核然后编译,这样需要安装很多必备的环境和工具,比较麻烦,但是也有助于我们了解内核的编译,这里采取较为简单的快速的升级方式。

    1.查看当前内核版本(升级后)

    [root@www home]# more /etc/issue
    Red Hat Enterprise Linux Server release 6.5 (Santiago)
    Kernel \r on an \m
    
    [root@www home]# uname -a
    Linux www 3.10.107-1.el6.elrepo.x86_64 #1 SMP Tue Jun 27 10:57:54 EDT 2017 x86_64 x86_64 x86_64 GNU/Linux
    
    

    2.导入public key

    rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
    

    3.安装ELRepo到CentOS
    http://elrepo.org/tiki/tiki-index.php 选择要安装的ELRepo

    ELRepo官网.png
    rpm -Uvh http://www.elrepo.org/elrepo-release-6-8.el6.elrepo.noarch.rpm
    

    4.安装kernel-lt(lt=long-term)

    yum --enablerepo=elrepo-kernel install kernel-lt -y
    

    或者 安装kernel-ml(ml=mainline)

    yum --enablerepo=elrepo-kernel install kernel-ml -y
    

    5.编辑grub.conf文件,修改Grub引导顺序

    vim /etc/grub.conf
    

    因为一般新安装的内核在第一个位置,所以设置default=0,表示启动新内核

    image.png

    6.重启
    查看此时内核版本

    [root@www home]# uname -r
    3.10.107-1.el6.elrepo.x86_64
    

    [THE END]

    参考文档:

    linux的tar.xz文件解压以及xz工具安装
    centos安装wget 及配置
    Linux中必备常用支持库的安装(CentOS-6.5)
    Elasticsearch用户指南 二 安装
    如何在Linux下源码安装node.js
    Elasticsearch5 及 head插件 安装说明
    centos7下Elasticsearch5.2.2和head 插件环境搭建
    Elasticsearch 5.0 —— Head插件部署指南(Head目前支持5.0了!请不要看本篇文章了)
    CentOS6.X 升级内核 至 3.10
    Welcome to the ELRepo Project

    相关文章

      网友评论

        本文标题:CentOS6.X,部署elasticsearch5.6详细步骤

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