• ElasticSearch6.5.1集群部署


    一、环境准备

    1.1、基础环境优化

    (1) 修改系统内核参数(/etc/sysctl.conf)

    [root@node1 ~]# mv /etc/sysctl.conf /etc/sysctl.conf_bak
    [root@node1 ~]# cat > /etc/sysctl.conf <<EOF
    fs.file-max = 655350
    net.ipv4.tcp_max_tw_buckets = 1000000
    net.ipv4.tcp_fin_timeout = 30
    net.ipv4.tcp_keepalive_time = 1200
    net.ipv4.tcp_keepalive_probes = 3
    net.ipv4.tcp_keepalive_intvl = 30
    net.ipv4.tcp_syncookies = 1
    net.ipv4.tcp_tw_reuse = 1
    net.ipv4.tcp_tw_recycle = 1
    net.ipv4.ip_local_port_range = 5000 65000
    net.ipv4.tcp_mem = 786432 1048576 1572864
    net.ipv4.ip_forward = 1
    net.ipv4.conf.default.rp_filter = 1
    net.ipv4.conf.default.accept_source_route = 0
    net.bridge.bridge-nf-call-ip6tables = 0
    net.bridge.bridge-nf-call-iptables = 0
    net.bridge.bridge-nf-call-arptables = 0
    net.core.wmem_max = 873200
    net.core.rmem_max = 873200
    net.ipv4.tcp_wmem = 8192 436600 873200
    net.ipv4.tcp_rmem = 32768 436600 873200
    net.core.somaxconn = 10240
    net.core.netdev_max_backlog = 20480
    net.ipv4.tcp_max_syn_backlog = 20480
    net.ipv4.tcp_retries2 = 5
    net.ipv4.conf.lo.arp_ignore = 0
    net.ipv4.conf.lo.arp_announce = 0
    net.ipv4.conf.all.arp_ignore = 0
    kernel.msgmnb = 65536
    kernel.msgmax = 65536
    kernel.shmmax = 68719476736
    kernel.shmall = 4294967296
    kernel.sysrq = 0
    kernel.core_uses_pid = 1
    vm.overcommit_memory = 1
    fs.file-max = 655350
    vm.max_map_count = 655350
    EOF

    (2) 修改资源限制配置文件(/etc/security/limits.conf)

    [root@node1 ~]# mv /etc/security/limits.conf /etc/security/limits.conf_bak
    [root@node1 ~]# cat > /etc/security/limits.conf <<EOF
    * soft noproc 20480
    * hard noproc 20480
    root soft nofile 655350
    root hard nofile 655350
    * soft nofile 655350
    * hard nofile 655350
    EOF

    1.2、安装JDK

    (1) 下载JDK1.8,要求JDK版本1.8以上

    [root@node1 ~]# ll jdk-8u251-linux-x64.tar.gz 
    -rw-r--r-- 1 root root 195132576 Jun 4 14:10 jdk-8u251-linux-x64.tar.gz

    (2) 解压安装包并配置环境变量

    [root@node1 ~]# vim jdk_install.sh
    #!/bin/bash
    dir=`pwd`
    mkdir -p /usr/java
    tar -zxvf ${dir}/jdk-8u112-linux-x64.tar.gz -C /usr/java/ &>/dev/null
    echo 'export JAVA_HOME=/usr/java/jdk1.8.0_112' >> /etc/profile
    echo 'export PATH=$JAVA_HOME/bin/:$PATH' >> /etc/profile
    echo 'export CLASSPATH=.:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar:$CLASSPAT' >> /etc/profile
    source /etc/profile
    java -version

    (3) 验证是否安装成功

    [root@node1 ~]# source /etc/profile
    [root@node1 ~]# java -version
    java version "1.8.0_112"
    Java(TM) SE Runtime Environment (build 1.8.0_112-b15)
    Java HotSpot(TM) 64-Bit Server VM (build 25.112-b15, mixed mode)

    1.3、创建普通用户

    [root@node1 ~]# mkdir /u01
    #挂载磁盘,一定要将系统最大的磁盘挂载到/u01目录下;或者将普通用户的家目录放在最大的分区下面
    [root@node1 ~]# useradd isi -b /u01
    [root@node1 ~]# echo 'isi%2020' | passwd --stdin isi 

    1.4、node环境部署

    1.4.1、源码安装

    [root@node1 ~]# wget https://nodejs.org/download/release/v12.16.1/node-v12.16.1.tar.xz
    [root@node1 ~]# tar -xf node-v12.16.1.tar.gz
    [root@node1 ~]# cd node-v12.16.1
    [root@node1 ~]# ./configure
    [root@node1 ~]# make && make install
    [root@node1 ~]# node -v
    [root@node1 ~]# npm -v

    1.4.2、yum安装

    [root@node1 ~]# rpm -ivh https://mirrors.tuna.tsinghua.edu.cn/epel/7/x86_64/Packages/e/epel-release-7-12.noarch.rpm
    [root@node1 ~]# curl --silent --location https://rpm.nodesource.com/setup_10.x | bash -
    [root@node1 ~]# yum -y install nodejs
    [root@node1 ~]# node -v
    [root@node1 ~]# npm -v

    1.4.3、二进制安装(推荐使用)

    [root@node1 ~]# wget https://nodejs.org/download/release/v12.16.1/node-v12.16.1-linux-x64.tar.xz
    [root@node1 ~]# ll node-v12.16.1-linux-x64.tar.xz 
    -rw-r--r-- 1 root root 14591852 May 15 16:29 node-v12.16.1-linux-x64.tar.xz
    [root@node1 ~]# tar -xf node-v12.16.1-linux-x64.tar.xz -C /usr/local/
    [root@node1 ~]# cd /usr/local/
    [root@node1 local]# mv node-v12.16.1-linux-x64 node-v12.16.1
    [root@node1 local]# echo 'export NODE_HOME=/usr/local/node-v12.16.1' >> /etc/profile
    [root@node1 local]# echo 'export PATH=$NODE_HOME/bin/:$PATH' >> /etc/profile
    [root@node1 local]# source /etc/profile
    [root@node1 local]# node -v
    v12.16.1
    [root@node1 local]# npm -v
    6.13.4
    #npm国内源配置
    [root@node1 local]# npm config set registry --registry=https://registry.npm.taobao.org
    #永久性配置
    npm config set registry --registry=https://registry.npm.taobao.org
    #临时配置
    npm install -g grunt-cli --registry=https://registry.npm.taobao.org # -g表示全局安装
    npm install express --registry=https://registry.npm.taobao.org

    安装脚本install.sh:

    #!/bin/bash
    dir_path=`pwd`
    cd $dir_path
    tar -xf node-v12.16.1-linux-x64.tar.xz -C /usr/local
    cd /usr/local
    mv node-v12.16.1-linux-x64 node-v12.16.1
    echo 'export NODE_HOME=/usr/local/node-v12.16.1' >> /etc/profile
    echo 'export PATH=$NODE_HOME/bin/:$PATH' >> /etc/profile
    source /etc/profile
    node -v
    npm config set registry --registry=https://registry.npm.taobao.org

    二、安装elasticsearch6.5.1

    (1) 下载安装包

    [root@node1 ~]# wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.5.1.tar.gz
    [root@node1 ~]# ll elasticsearch-6.5.1.tar.gz 
    -rw-r--r-- 1 root root 113317061 Jul 16 19:28 elasticsearch-6.5.1.tar.gz

    (2) 创建安装目录并解压

    [root@node1 ~]# mkdir -p /u01/isi/application/component
    [root@node1 ~]# tar -xf elasticsearch-6.5.1.tar.gz -C /u01/isi/application/component/

    (3) 修改配置文件

    [root@node1 ~]# cd /u01/isi/application/component/elasticsearch-6.5.1/
    [root@node1 elasticsearch-6.5.1]# grep -Ev "^#|^$" config/elasticsearch.yml 
    cluster.name: my-cluster
    node.name: 192.168.145.27
    node.master: true
    node.data: true
    network.host: 0.0.0.0
    http.port: 9200
    transport.tcp.port: 9300
    discovery.zen.ping.unicast.hosts: ["192.168.145.27", "192.168.145.57"]
    discovery.zen.minimum_master_nodes: 1
    http.cors.enabled: true
    http.cors.allow-origin: "*"

    配置说明:

    cluster.name:     #它指代的是集群的名字,一个集群的名字必须唯一,节点根据集群名字加入到集群中;
    node.name:     #节点名称,可以是自定义的方便分辨的名字,记住master也是一个节点;
    node.master: true/false   #是否可以作为集群中的主节点;
    node.data: true/false   #是否可以作为集群中的数据节点;
    node.ingest: false   #非数据预处理节点;
    bootstrap.memory_lock: false   #禁止锁定内存;由于当jvm开始swapping时es的效率会降低,所以要保证它不swap,可以把ES_MIN_MEM和ES_MAX_MEM两个环境变量设置成同一个值,并且保证机器有足够的内存分配给es。同时也要允许elasticsearch的进程可以锁住内存,linux下可以通过ulimit -l unlimited命令;
    bootstrap.system_call_filter: false   #禁用系统调用过滤器;
    path.log:     #节点的日志保存路径;
    path.data:    #节点的数据保存路径;
    network.host:   #设置network.bind_host 和 publish_host的默认值,这里设置成127.0.0.1和主机ip是有区别的,设置为0.0.0.0表示任何主机可以连接此机器。你可以使用curl -XGET “http://network.host/9200"看到结果;
    transport.tcp.port:   #集群之间的端口;
    http.port:   #node节点的服务端口;
    http.cors.enabled: true   #为开通head的配置;
    http.cors.allow-origin: "*"   #为开通head的配置;
    xpack.ml.enabled: false   #设置为false以禁用X-Pack机器学习功能;
    gateway.recover_after_nodes: 1    #设置集群中N个节点启动时进行数据恢复,默认为1;
    discovery.zen.minimum_master_nodes: 1    #设置这个参数来保证集群中的节点可以知道其它N个有master资格的节点。默认为1,对于大的集群来说,可以设置大一点的值(2-4);
    discovery.zen.ping.unicast.hosts: ["host1", "host2:port"]   #设置集群中master节点的初始列表,可以通过这些节点来自动发现新加入集群的节点;这里是一组IP,表示用于加入集群,一般是使用ip:port,该port为集群内通信的端口
    discovery.zen.ping.multicast.enabled:false   #设置是否打开多播发现节点,默认是true;
    discovery.zen.ping.timeout: 3s   #设置集群中自动发现其它节点时ping连接超时时间,默认为3秒,对于比较差的网络环境可以高点的值来防止自动发现时出错;

    (4) 修改jvm配置

    [root@node1 elasticsearch-6.5.1]# vim config/jvm.options
    #修改以下两项即可
    -Xms1g    #jvm最小内存,建议设置为本机器内存的一半
    -Xmx1g    #jvm最大内存,建议设置为本机器内存的一半

    (5) 启动服务

    [root@node1 ~]# cd /u01/isi/application/component/elasticsearch-6.5.1/
    [root@node1 elasticsearch-6.5.1]# chown -R isi:isi /u01/isi/application/component/elasticsearch-6.5.1/
    [root@node1 elasticsearch-6.5.1]# su isi
    [isi@node1 elasticsearch-6.5.1]$ nohup ./bin/elasticsearch &
    启动脚本start.sh
    #!/bin/bash
    nohup bin/elasticsearch &
    停止脚本stop.sh
    #!/bin/bash
    kill -9 `ps -ef | grep /u01/isi/application/component/elasticsearch-6.5.1/ | grep -v grep | awk '{print $2}'`

    (6) 验证

    [isi@node1 elasticsearch-6.5.1]$ ps -ef|grep elasticsearch
    [isi@node1 elasticsearch-6.5.1]$ ss -nlt|grep 9200
    [isi@node1 elasticsearch-6.5.1]$ curl http://192.168.145.27:9200
    {
    "name" : "192.168.145.27",
    "cluster_name" : "my-cluster",
    "cluster_uuid" : "PoIf3bPjRxe6Aip89q02Pw",
    "version" : {
    "number" : "6.5.1",
    "build_flavor" : "default",
    "build_type" : "tar",
    "build_hash" : "8c58350",
    "build_date" : "2018-11-16T02:22:42.182257Z",
    "build_snapshot" : false,
    "lucene_version" : "7.5.0",
    "minimum_wire_compatibility_version" : "5.6.0",
    "minimum_index_compatibility_version" : "5.0.0"
    },
    "tagline" : "You Know, for Search"
    }

    三、安装elasticsearch插件

    由于head和sql插件均依赖于node环境,所以安装前必须先安装好node环境

    3.1、安装head插件(离线安装)

     es-head是ElasticSearch的一个插件,提供了es 的可视化操作界面。在es 2.X版本后,该插件不在支持es的插件安装方式安装及启动,而是使用grunt方式启动;同时,5.0以上elasticsearch-head 不能放在elasticsearch的 plugins、modules 目录下,否则elasticsearch启动会报错。

    (1) 下载head插件安装包

    [root@node1 ~]# cd /u01/isi/application/component/elasticsearch-6.5.1/
    [root@node1 elasticsearch-6.5.1]# wget https://codeload.github.com/mobz/elasticsearch-head/zip/master wget https://github.com/mobz/elasticsearch-head/archive/master.zip wget https://github.com/mobz/elasticsearch-head

    (2) 解压并安装

    [root@node1 elasticsearch-6.5.1]# unzip master.zip
    [root@node1 elasticsearch-6.5.1]# mv elasticsearch-head-master elasticsearch-head
    [root@node1 elasticsearch-6.5.1]# cd elasticsearch-head/
    [root@node1 elasticsearch-head]# npm install -g grunt-cli
    #如果npm安装程序提示npm ERR! code ECONNREFUSED,则使用 npm config set proxy null 清除代理再使用上面的命令
    [root@node1 elasticsearch-head]# cd ..
    [root@node1 elasticsearch-6.5.1]# chown -R isi:isi elasticsearch-head

    (3) 修改elasticsearch.yml文件,增加跨域的配置(需要重启elasticsearch才能生效)

    [root@node1 elasticsearch-6.5.1]# vim config/elasticsearch.yml 
    #添加以下两行
    http.cors.enabled: true
    http.cors.allow-origin: "*"

    (4) 重启elasticsearch,再启动es-head

    #重启elasticsearch
    [root@node1 elasticsearch-6.5.1]# su isi
    [isi@node1 elasticsearch-6.5.1]$ ./stop.sh
    #再启动es-head [isi@node1 elasticsearch-6.5.1]$ cd elasticsearch-head/ [isi@node1 elasticsearch-head]$ nohup grunt server &
    #编写es-head启动脚本start_head.sh [isi@node1 elasticsearch-head]$ vim start_head.sh #!/bin/bash cd /u01/isi/application/component/elasticsearch-6.5.1/elasticsearch-head nohup grunt server &

    #编写es-head停止脚本stop_head.sh [isi@node1 elasticsearch-head]$ vim stop_head.sh #!/bin/bash kill -9 `ps -ef | grep grunt | grep -v grep | awk '{print $2}'`
    [isi@node1 elasticsearch-head]$ chmod +x start_head.sh stop_head.sh 
    #如不能联网,可以使用联网机器或虚拟机上的node_modules中的grunt启动es-head
    
    [isi@node1 elasticsearch-head]$ find ./ -name grunt
    ./node_modules/grunt-cli/bin/grunt
    ./node_modules/grunt
    ./node_modules/grunt/bin/grunt
    ./node_modules/grunt/lib/grunt
    ./node_modules/grunt/node_modules/grunt-cli/bin/grunt
    ./node_modules/grunt/node_modules/.bin/grunt
    ./node_modules/.bin/grunt
    [isi@node1 elasticsearch-head]$ vim start_head.sh 
    #!/bin/bash
    cd /u01/isi/application/component/elasticsearch-6.5.1/elasticsearch-head
    nohup node_modules/grunt/node_modules/grunt-cli/bin/grunt server &

    3.2、安装es-sql插件

    (1) 下载es-sql插件安装包

    [root@node1 elasticsearch-6.5.1]# pwd
    /u01/isi/application/component/elasticsearch-6.5.1
    [root@node1 elasticsearch-6.5.1]# wget https://github.com/NLPchina/elasticsearch-sql/archive/6.5.1.0.tar.gz

    (2) 解压并安装

    [root@node1 elasticsearch-6.5.1]# ll 6.5.1.0.tar.gz 
    -rw-r--r-- 1 root root 3651419 Aug 6 17:37 6.5.1.0.tar.gz
    [root@node1 elasticsearch-6.5.1]# tar -xf 6.5.1.0.tar.gz 
    [root@node1 elasticsearch-6.5.1]# cd elasticsearch-sql-6.5.1.0/
    [root@node1 elasticsearch-sql-6.5.1.0]# npm config set registry --registry=https://registry.npm.taobao.org
    [root@node1 elasticsearch-sql-6.5.1.0]# npm config set proxy null
    [root@node1 elasticsearch-sql-6.5.1.0]# npm install express -save

    (3) 修改site-server/site_configuration.json配置文件中的服务端口

    [root@node1 elasticsearch-sql-6.5.1.0]# cd src/site-server
    [root@node1 site-server]# vim site_configuration.json 
    #将端口号由8080改为9101
    {
    "port":9101
    }
    [root@node1 elasticsearch-sql-6.5.1.0]# cd ../../../
    [root@node1 elasticsearch-6.5.1]# chown -R isi:isi elasticsearch-sql-6.5.1.0/

    (4) 重启elasticsearch,再启动es-sql

    #重启elasticsearch
    [root@node1 elasticsearch-6.5.1]# su isi
    [isi@node1 elasticsearch-6.5.1]$ ./stop.sh
    #再启动es-sql [root@node1 elasticsearch-6.5.1]# pwd /u01/isi/application/component/elasticsearch-6.5.1 [root@node1 elasticsearch-6.5.1]# su isi [isi@node1 elasticsearch-6.5.1]# cd elasticsearch-sql-6.5.1.0/src/site-server [isi@node1 site-server]$ nohup node node-server.js &
    #编写es-sql启动脚本start_sql.sh [isi@node1 elasticsearch-sql-6.5.1.0]$ vim start_sql.sh #!/bin/bash cd /u01/isi/application/component/elasticsearch-6.5.1/elasticsearch-sql-6.5.1.0/src/site-server nohup node node-server.js &

    #编写es-sql启动脚本stop_sql.sh
    [isi@node1 elasticsearch-sql-6.5.1.0]$ vim stop_sql.sh
    #
    !/bin/bash
    kill -9 `ps -ef|grep node-server.js | grep -v grep |awk '{print $2}'`

    [isi@node1 elasticsearch
    -sql-6.5.1.0]$ chmod +x start_sql.sh stop_sql.sh

    四、安装cerebro监控

    (1) 下载安装包

    [root@node1 ~]# wget https://github.com/lmenezes/cerebro/releases/download/v0.8.1/cerebro-0.8.1.tgz
    [root@node1 ~]# tar -xf cerebro-0.8.1.tgz -C /u01/isi/application/component/

    (2) 启动

    [root@node1 ~]# chown -R isi:isi /u01/isi/application/component/
    [root@node1 cerebro-0.8.1]# su isi
    [isi@node1 cerebro-0.8.1]$ ./bin/cerebro    #前台启动
    #编写启动脚本
    [isi@node1 cerebro-0.8.1]$ vim start.sh
    #!/bin/bash
    cd /u01/isi/application/component/cerebro-0.8.1
    #nohup ./bin/cerebro -Dhttp.port=16002 -Dhttp.address=192.168.145.27 &    #监听到指定端口与地址
    nohup ./bin/cerebro &
    #编写停止脚本
    [isi@node1 cerebro-0.8.1]$ vim stop.sh
    #!/bin/bash
    kill -9 `ps -ef |grep cerebro |grep -v grep |awk '{print $2}'`

    (3) 测试

     浏览器访问 http://ip:9000

    (4) 相关配置

    #配置登录验证,支持LDAP和basic再种方式
    #以下为基本验证的配置
    [isi@node1 cerebro-0.8.1]$ vim conf/application.conf 
    #找到以下行,取消注释即可
    type: basic
    settings: {
    username = "admin"
    password = "1234"
    }
    #配置服务器
    #非必须,如果经常使用的话,可以先在conf/application.conf中配置好ElasticSearch服务器地址
    [isi@node1 cerebro-0.8.1]$ vim conf/application.conf
    # A list of known hosts
    hosts = [
    {
    host = "http://localhost:9200"
    name = "Some Cluster"
    },
    # Example of host with authentication
    #{
    # host = "http://some-authenticated-host:9200"
    # name = "Secured Cluster"
    # auth = {
    # username = "username"
    # password = "secret-password"
    # }
    #}
    ]
  • 相关阅读:
    Rose2003执行出现 -2147417848 (80010108)&#39;:Automation 错误
    Xcode 证书生成、设置、应用
    关于数组中加入相同的view的试验
    XCode 项目配置说明
    ios申请真机调试( xcode 5)详细解析
    CAShapeLayer--备用
    手把手教你 iOS通过自己的服务器实现应用分发
    iOS最新上线流程+续费 2015-7-20更新
    iOS8的一些控件的变更
    iOS8上放大缩小的动画
  • 原文地址:https://www.cnblogs.com/hovin/p/14822595.html
Copyright © 2020-2023  润新知