ES6集群环境搭建及相关建设方案

ES6集群

建设、环境搭建及调优(Centos7)

1.linux内核调整

1)vi /etc/security/limits.conf
* hard nofile 131072
* soft nofile 65536
* soft nproc 4096
* hard nproc 4096
* soft memlock unlimited
* hard memlock unlimited
2)vi /etc/sysctl.conf 
vm.max_map_count = 655360
fs.file-max = 1645037
3)执行 sysctl -p  确认更改

2.需要事先准备 jdk1.8及以上版本,安装head插件,node环境
安装jdk,node命令 tar -zxvf elasticsearch-6.8.9.tar.gz && elasticsearch-7.15.2-linux-x86_64.tar.gz && head-plugin.tar.gz && node-v6.10.2-linux-x64.tar.gz
3.配置环境变量及指定jdk版本

vi /etc/profile #配置的全局环境变量
#jdk8
export JAVA_HOME=/usr/local/java8#指定jdk放置的路径
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
#node
export NODE_PATH=/opt/ES6/head/node-v6.10.2-linux-x64#指定node放置的路径
export PATH=$NODE_PATH/bin:$PATH

#配置elasticsearch用户环境变量来指定启动jdk版本
	1. su - esuser
	2. vi ~/.bash_profile

PATH=$PATH:$HOME/.local/bin:$HOME/bin:/home/jdk1.8.0_111/bin
export PATH
export JAVA_HOME=/home/jdk1.8.0_111
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export JRE_HOME=$JAVA_HOME/jr

4.安装成功命令查看

[root@localhost ~]# node -v
v6.10.2
[root@localhost ~]# java -version
java version "1.8.0_231"
Java(TM) SE Runtime Environment (build 1.8.0_231-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.231-b11, mixed mode)

5.设置用户及目录权限

#创建用户组
groupadd elasticsearch
#创建用户并添加至用户组
useradd elasticsearch -g elasticsearch
#更改用户密码(输入 123456)
passwd elasticsearch
#修改目录权限
chown -R elasticsearch:elasticsearch /opt/ES6/elasticsearch/*  

6.es集群配置文件修改elasticsearch.yml
master节点
vi /opt/ES6/elasticsearch/config/elasticsearch.yml

cluster.name: my-application   #集群的名字,其他节点这里必须相同
node.name: node1   #节点名称,用于在日志中区分。节点名字不能相同
#指定该节点是否有资格被选举成为master节点,默认是true
#es是默认集群中的第一台机器为master,如果这台机挂了就会重新选举master
node.master: true
##允许该节点存储数据(默认开启)
node.data: true
path.data: /opt/ES6/elasticsearch/to/data  #数据的默认存放路径
path.logs: /opt/ES6/elasticsearch/to/logs  #日志的默认存放路径
#设置为true来锁住内存。因为内存交换到磁盘对服务器性能来说是致命的,
#当jvm开始swapping时es的效率会降低,所以要保证它不swap
bootstrap.memory_lock: true
network.host: 0.0.0.0    #当前节点的IP地址或者填0.0.0.0
http.port: 9200          #对外提供服务的端口,9300为集群服务的端口
##添加如下内容
#culster transport port
transport.tcp.port: 9300
transport.tcp.compress: true
#启用head插件必须配置,解决跨域访问问题(!!!必要)
http.cors.enabled: true
http.cors.allow-origin: "*"
#节点发现配置,主节点和其他节点都需要配置
discovery.zen.ping.unicast.hosts: ["IP","IP"]
##集群节点IP地址,也可以使用els、els.es2.com等名称,需要各节点能够解析
discovery.zen.minimum_master_nodes: 2   #避免脑裂,集群节点数最少为半数+1,至少是1

7.集群配置jvm.options
vi /opt/ES6/elasticsearch/config/jvm.options

################################################################
## IMPORTANT: JVM heap size
################################################################
## You should always set the min and max JVM heap
## size to the same value. For example, to set
## the heap to 4 GB, set:
## -Xms4g
## -Xmx4g
## See https://www.elastic.co/guide/en/elasticsearch/reference/current/heap-size.html
## for more information
################################################################
# Xms represents the initial size of total heap space
# Xmx represents the maximum size of total heap space
-Xms256m #根据服务器内存大小分配
-Xmx256m

8.node1节点配置:需要linux内核调整,安装jdk,node,配置环境变量,设置用户及目录权限

注意
​ 1.用scp拷贝到另外一台机器要把 data下的node删除
​ 2.node.master: true 不用配置

9.监控API

GET  /_cat

/_cat/health
/_cat/nodes
/_cat/master
/_cat/indices
/_cat/allocation 
/_cat/shards 
/_cat/shards/{index}
/_cat/thread_pool
/_cat/segments 
/_cat/segments/{index}

10.启动es集群,先启动主节点,在启动节点
cd /opt/ES6/elasticsearch/bin
./elasticsearch

11.head配置
​ 1.如果使用老版本的elasticsearch-head服务端的es会返回下面的错误信息,{“error”:“Content-Type header [application/x-www-form-urlencoded] is not supported”,“status”:406}。es6.0的版本不支持,浏览器请求头信息带Content-Type header [application/x-www-form-urlencoded], 需要修改 _site/vendor.js 。找到对应的行 if ( !s.crossDomain && !headers[“X-Requested-With”] ) { 的前面增加一行
​ headers[“Content-Type” ] = “application/json”
​ 2.默认es是不支持跨域访问的,如何解决es不支持跨域访问?
​ 在/etc/elasticsearch/elasticsearch.yml配置文件中加入以下内容,然后重启服务。

​ http.cors.enabled: true
​ http.cors.allow-origin: “*”
​ 3.在head插件目录下 cd /data/elasticsearch-head/
​ 后台行运grunt server &
4.修改head默认链接地址 vi elasticsearch-head/_site/app.js
​ 查找 ‘localhost’ or ‘prefs.get(“app-base_uri”)’ 将 app-base_uri 修改成节点地址,保存重启

12.访问集群
通过api查看该集群所有node
在这里插入图片描述
通过访问head查看
在这里插入图片描述

13.安全证书创建:每个节点都需添加配置 vi elasticsearch.yml
xpack.security.enabled: true
xpack.license.self_generated.type: basic
xpack.security.transport.ssl.enabled: true
xpack.security.transport.ssl.verification_mode: certificate
xpack.security.transport.ssl.keystore.path: elastic-certificates.p12
xpack.security.transport.ssl.truststore.path: elastic-certificates.p12

​ **1)**在bin下执行 bin/elasticsearch-certutil cert -out config/elastic-certificates.p12 -pass “”

​ 生成的证书在config下

成功如下显示

WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.bouncycastle.jcajce.provider.drbg.DRBG (file:/home/estestuser/elasticsearch-6.8.9/lib/tools/security-cli/bcprov-jdk15on-1.61.jar) to constructor sun.security.provider.Sun()
WARNING: Please consider reporting this to the maintainers of org.bouncycastle.jcajce.provider.drbg.DRBG
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
This tool assists you in the generation of X.509 certificates and certificate
signing requests for use with SSL/TLS in the Elastic stack.

The 'cert' mode generates X.509 certificate and private keys.
    * By default, this generates a single certificate and key for use
       on a single instance.
    * The '-multiple' option will prompt you to enter details for multiple
       instances and will generate a certificate and key for each one
    * The '-in' option allows for the certificate generation to be automated by describing
       the details of each instance in a YAML file

    * An instance is any piece of the Elastic Stack that requires a SSL certificate.
      Depending on your configuration, Elasticsearch, Logstash, Kibana, and Beats
      may all require a certificate and private key.
    * The minimum required value for each instance is a name. This can simply be the
      hostname, which will be used as the Common Name of the certificate. A full
      distinguished name may also be used.
    * A filename value may be required for each instance. This is necessary when the
      name would result in an invalid file or directory name. The name provided here
      is used as the directory name (within the zip) and the prefix for the key and
      certificate files. The filename is required if you are prompted and the name
      is not displayed in the prompt.
    * IP addresses and DNS names are optional. Multiple values can be specified as a
      comma separated string. If no IP addresses or DNS names are provided, you may
      disable hostname verification in your SSL configuration.

    * All certificates generated by this tool will be signed by a certificate authority (CA).
    * The tool can automatically generate a new CA for you, or you can provide your own with the
         -ca or -ca-cert command line options.

By default the 'cert' mode produces a single PKCS#12 output file which holds:
    * The instance certificate
    * The private key for the instance certificate
    * The CA certificate

If you specify any of the following options:
    * -pem (PEM formatted output)
    * -keep-ca-key (retain generated CA key)
    * -multiple (generate multiple certificates)
    * -in (generate certificates from an input file)
then the output will be be a zip file containing individual certificate/key files


Certificates written to /home/estestuser/elasticsearch-7.1.1/config/elastic-certificates.p12

This file should be properly secured as it contains the private key for 
your instance.

This file is a self contained file and can be copied and used 'as is'
For each Elastic product that you wish to configure, you should copy
this '.p12' file to the relevant configuration directory
and then follow the SSL configuration instructions in the product guide.

​ **2)**将生成好的证书拷贝到其他es的config下

scp elastic-certificates.p12 estestuser@ip:/home/estestuser/elasticsearch-6.8.9/config/

​ **3)**创建集群密码命令,设置完之后,数据会自动同步到其他节点。

 bin/elasticsearch-setup-passwords interactive

​ **4)**curl测试

curl --user elastic:passwd http://localhost:9200
14.同版本增加集群节点可横向扩容

在安装好的es环境下,将elastic-certificates.p12,elasticsearch.keystore拷贝到这个节点,依次重启es即可

如果一个数据节点不够或者集群界面报red或者yellow

可考虑数据节点扩容,在vi elasticsearch.yml中修改如下

node.data: true
15.供参考节点规划组合

node.master:该处设置为true,并不一定就是主节点,主节点由具有主节点选举资格,进行选举产生的,代表该节点是否具有主节点选举资格

node.data:该节点是否存储数据(默认开启)

node.ingest:Ingest 节点的基础原理,是:节点接收到数据之后,根据请求参数中指定的管道流 id,找到对应的已注册管道流,对数据进行处理,然后将处理过后的数据,按照 Elasticsearch 标准的 indexing 流程继续运行。

​ **1)**组合

node.master: true 
node.data: true 
node.ingest: true

这种组合表示这个节点既有成为主节点的资格,又可以存储数据,还可以作为预处理节点,这个时候如果某个节点被选举成为了真正的主节点,那么他还要存储数据,这样对于这个节点的压力就比较大了。
  elasticsearch 默认是:每个节点都是这样的配置,在测试环境下这样做没问题。实际工作中建议不要这样设置,这样相当于 主节点 和 数据节点 的角色混合到一块了。

​ **2)**组合

node.master: false 
node.data: true 
node.ingest: false

这种组合表示这个节点没有成为主节点的资格,也就不参与选举,只会存储数据。这个节点我们称为 data(数据)节点。在集群中需要单独设置几个这样的节点负责存储数据。后期提供存储和查询服务

​ **3)**组合

node.master: true 
node.data: false 
node.ingest: false

这种组合表示这个节点不会存储数据,有成为主节点的资格,可以参与选举,有可能成为真正的主节点。这个节点我们称为master节点

​ **4)**组合

node.master: false 
node.data: false 
node.ingest: true

这种组合表示这个节点即不会成为主节点,也不会存储数据,这个节点的意义是作为一个 client(客户端)节点,主要是针对海量请求的时候可以进行负载均衡。在新版 ElasticSearch5.x 之后该节点称之为:coordinate 节点,其中还增加了一个叫:ingest 节点,用于预处理数据(索引和搜索阶段都可以用到),当然,作为一般应用是不需要这个预处理节点做什么额外的预处理过程,那么这个节点和我们称之为 client 节点之间可以看做是等同的,我们在代码中配置访问节点就都可以配置这些 ingest 节点即可。

​ **5)**组合

node.master: false 
node.data: false 
node.ingest: false

这种配置为纯查询模式,节点只可以接受查询,对于查询数据量比较大的集群,配置这种节点可以有效的保护数据节点,防止datanode内存溢出。这种模式比模式四更节省资源,为纯查询模式!

总结

​ 默认情况下,每个节点都有成为主节点的资格,也会存储数据,还会处理客户端的请求。在一个生产集群中我们可以对这些节点的职责进行划分。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值