m6米乐安卓版下载-米乐app官网下载
暂无图片
1
暂无图片
暂无图片
暂无图片

elasticsearch 7.13.2 多节点集群(含配置xpack及创建设置证书和私钥)安装部署指南 -m6米乐安卓版下载

原创 尚雷 2023-05-19
746

1.1 操作系统兼容性

elasticsearch不同版本对操作系统有兼容性要求,可参照如下官方链接查看es和操作系统兼容需求列表。

产品和操作系统: https://www.elastic.co/cn/support/matrix#matrix_os

1.2 jvm兼容性

elasticsearch不同版本对jvm有兼容性要求,可参照如下官方链接查看es和jvm兼容需求列表。

产品和jvm: https://www.elastic.co/cn/support/matrix#matrix_jvm

2.1 环境列表

服务器ip 主机名称 角色 端口号 操作系统版本
10.110.7.39 xsky-node1 master 9200、9201 centos linux release 7.9.2009 (core)
10.110.7.40 xsky-node2 master 9200、9201 centos linux release 7.9.2009 (core)
10.110.7.41 xsky-node3 master 9200、9201 centos linux release 7.9.2009 (core)

2.2 关闭防火墙

-- root 用户执行,所有节点
systemctl stop firewalld && systemctl disable firewalld
systemctl status firewalld

2.3 设置内核参数

-- root 用户执行,所有节点
sed -e '/^vm.max_map_count/d' \
       -i.bak \
       /etc/sysctl.conf; \
sed -e '$a vm.max_map_count=655360' \
      -i.bak \
      /etc/sysctl.conf; \
sed -e '/^* soft nofile/d' \
    -e '/^* hard nofile/d' \
    -e '/^elasticsearch soft nofile/d' \
    -e '/^elasticsearch hard nofile/d' \
    -e '/^* soft memlock/d' \
    -e '/^* hard memlock/d' \
    -e '/^elasticsearch soft memlock/d' \
    -e '/^elasticsearch hard memlock/d' \
    -i.bak \
    /etc/security/limits.conf; \
sed -e '$a * soft nofile 655350' \
    -e '$a * hard nofile 655350' \
    -e '$a elasticsearch soft nofile 655350' \
    -e '$a elasticsearch hard nofile 655350' \
    -e '$a * soft memlock unlimited' \
    -e '$a * hard memlock unlimited' \
    -e '$a elasticsearch soft memlock unlimited' \
    -e '$a elasticsearch hard memlock unlimited' \
    -i.bak \
    /etc/security/limits.conf; \
sysctl -p

2.4 关闭交换分区

-- root 用户执行,所有节点
swapoff -a;
# 注释/etc/fstab文件swap信息
# /dev/mapper/centos-swap swap                    swap    defaults        0 0

2.5 安装jdk

# root 用户执行,所有节点
wget https://download.java.net/openjdk/jdk11/ri/openjdk-11 28_linux-x64_bin.tar.gz
tar -zxvf openjdk-11 28_linux-x64_bin.tar.gz
chown -r root:root /usr/java
# 编辑/etc/profile文件,文件末尾添加如下内容
export java_home=/usr/java/jdk-11
export es_java_home=/usr/java/jdk-11
export path=$es_java_home/bin:$path
export path=$java_home/bin:$path
# 执行source /etc/profile使其生效

2.6 创建用户

# elasticsearch 7启动需要使用普通用户
# 使用root用户创建esuser用户
groupadd esuser
useradd -g esuser esuser

2.7 创建目录

# 使用root用户,所有节点都操作
# 创建存放数据及日志目录
# 生产环境建议单独挂载目录
mkdir -p /path/to
chown -r esuser:esuser /path

3.1 下载二进制安装包

# esuser用户 
mkdir /home/esuser/deploy
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.13.2-linux-x86_64.tar.gz /home/soft
tar -zxvf /home/soft/elasticsearch-7.13.2-linux-x86_64.tar.gz -c /home/esuser/deploy
chown -r esuser:esuser /home/esuser/deploy
su - esuser
mv /home/esuser/deploy/elasticsearch-7.13.2 /home/esuser/deploy/elasticsearch-7.13.2-9300
cp -a /home/esuser/deploy/elasticsearch-7.13.2-9300 /home/esuser/deploy/elasticsearch-7.13.2-9301

3.2 配置elasticsearch.yml

分别在每个节点配置9300和9301两个目录elasticsearch.yml文件,内容分别如下:

9300目录elasticsearch.yml

-- esuser用户,所有节点
-- 注意每个节点需该对应配置文件信息
cd elasticsearch-7.13.2-9300/config
cat elasticsearch.yml 内容如下(过滤#)
# ======================== elasticsearch configuration =========================
cluster.name: es-cluster
# ------------------------------------ node ------------------------------------
node.name: node-7.39-9300  # node.name要根据对应节点进行修改,不能相同
node.attr.rack: r1
node.attr.type: hot
node.master: true
node.data: true
node.ingest: false
node.ml: false
cluster.remote.connect: false
thread_pool.write.queue_size: 1000
# ----------------------------------- paths ------------------------------------
path.data: /path/to/data-9300
path.logs: /path/to/logs-9300
# ----------------------------------- memory -----------------------------------
bootstrap.memory_lock: true 
bootstrap.system_call_filter: false
# ---------------------------------- network -----------------------------------
network.host: 10.110.7.39   # network.host要和物理服务器ip对应,不能相同
http.port: 9200
transport.tcp.port: 9300
# --------------------------------- discovery ----------------------------------
cluster.initial_master_nodes: ["node-7.39-9300", "node-7.39-9301", "node-7.40-9300", "node-7.40-9301", "node-7.41-9300", "node-7.41-9301"]
discovery.zen.ping.unicast.hosts: ["10.110.7.39:9300","10.110.7.39:9301", "10.110.7.40:9300","10.110.7.40:9301", "10.110.7.41:9300","10.110.7.41:9301"]
discovery.zen.minimum_master_nodes: 3 
discovery.zen.fd.ping_timeout: 60s
discovery.zen.fd.ping_retries: 3
discovery.zen.fd.ping_interval: 10s
# ---------------------------------- gateway -----------------------------------
# ---------------------------------- various -----------------------------------
xpack.security.enabled: true
xpack.security.transport.ssl.enabled: true
xpack.security.transport.ssl.verification_mode: certificate 
xpack.security.transport.ssl.keystore.path: certs/elastic-certificates.p12 
xpack.security.transport.ssl.truststore.path: certs/elastic-certificates.p12
xpack.security.http.ssl.supported_protocols: [ "tlsv1.3", "tlsv1.2", "tlsv1.1", "tlsv1" ]
http.cors.enabled: true
http.cors.allow-origin: "*"
http.cors.allow-headers: authorization,x-requested-with,content-length,content-type
http.max_content_length: 1000mb
action.destructive_requires_name: true
xpack.security.audit.enabled: true
xpack.security.audit.logfile.events.exclude: ["access_granted"]
xpack:
  security:
    authc:
      realms:
        native:
            native11:
                order: 0
        ldap.ldap1:
          order: 1
          url: ["ldap://authldap.vemic.com:389","ldap://ldap-proxy.vemic.com:389"]
          cache:
            ttl: 60m
          user_dn_templates:
            - "cn={0},cn=users,dc=xxx,dc=com"
          group_search:
            base_dn: "cn=users,dc=focuschina,dc=com"
          unmapped_groups_as_roles: false
xpack.notification.email:
    default_account: 110
    account:
        110:
            profile: standard
            smtp:
                auth: true
                host: 192.168.16.190
                user: 110@xxx.com

9301目录elasticsearch.yml

-- 注意每个节点需该对应配置文件信息
cd elasticsearch-7.13.2-9301/config
# ======================== elasticsearch configuration =========================
cluster.name: es-cluster
# ------------------------------------ node ------------------------------------
node.name: node-7.39-9301  # node.name要根据节点进行对应修改
node.attr.rack: r1
node.attr.type: hot
node.master: true
node.data: true
node.ingest: false
node.ml: false
cluster.remote.connect: false
thread_pool.write.queue_size: 1000
# ----------------------------------- paths ------------------------------------
path.data: /path/to/data-9300
path.logs: /path/to/logs-9300
# ----------------------------------- memory -----------------------------------
bootstrap.memory_lock: true 
bootstrap.system_call_filter: false
# ---------------------------------- network -----------------------------------
network.host: 10.110.7.39   # network.host要和物理服务器ip对应
http.port: 9201
transport.tcp.port: 9301
# --------------------------------- discovery ----------------------------------
cluster.initial_master_nodes: ["node-7.39-9300", "node-7.39-9301", "node-7.40-9300", "node-7.40-9301", "node-7.41-9300", "node-7.41-9301"]
discovery.zen.ping.unicast.hosts: ["10.110.7.39:9300","10.110.7.39:9301", "10.110.7.40:9300","10.110.7.40:9301", "10.110.7.41:9300","10.110.7.41:9301"]
discovery.zen.minimum_master_nodes: 3 
discovery.zen.fd.ping_timeout: 60s
discovery.zen.fd.ping_retries: 3
discovery.zen.fd.ping_interval: 10s
# ---------------------------------- gateway -----------------------------------
# ---------------------------------- various -----------------------------------
xpack.security.enabled: true
xpack.security.transport.ssl.enabled: true
xpack.security.transport.ssl.verification_mode: certificate 
xpack.security.transport.ssl.keystore.path: certs/elastic-certificates.p12 
xpack.security.transport.ssl.truststore.path: certs/elastic-certificates.p12
xpack.security.http.ssl.supported_protocols: [ "tlsv1.3", "tlsv1.2", "tlsv1.1", "tlsv1" ]
http.cors.enabled: true
http.cors.allow-origin: "*"
http.cors.allow-headers: authorization,x-requested-with,content-length,content-type
http.max_content_length: 1000mb
action.destructive_requires_name: true
xpack.security.audit.enabled: true
xpack.security.audit.logfile.events.exclude: ["access_granted"]
xpack:
  security:
    authc:
      realms:
        native:
            native11:
                order: 0
        ldap.ldap1:
          order: 1
          url: ["ldap://authldap.vemic.com:389","ldap://ldap-proxy.vemic.com:389"]
          cache:
            ttl: 60m
          user_dn_templates:
            - "cn={0},cn=users,dc=xxx,dc=com"
          group_search:
            base_dn: "cn=users,dc=focuschina,dc=com"
          unmapped_groups_as_roles: false
xpack.notification.email:
    default_account: 110
    account:
        110:
            profile: standard
            smtp:
                auth: true
                host: 192.168.16.190
                user: 110@xxx.com

3.2 配置jvm.options

分别配置9300和9301两个目录jvm.options文件,内容如下:

-xms8g
-xmx8g
-xx: useconcmarksweepgc
-xx:cmsinitiatingoccupancyfraction=75
-xx: usecmsinitiatingoccupancyonly
-des.networkaddress.cache.ttl=60
-des.networkaddress.cache.negative.ttl=10
-xx: alwayspretouch
-xss1m
-djava.awt.headless=true
-dfile.encoding=utf-8
-djna.nosys=true
-xx:-omitstacktraceinfastthrow
-dio.netty.nounsafe=true
-dio.netty.nokeysetoptimization=true
-dio.netty.recycler.maxcapacityperthread=0
-dlog4j.shutdownhookenabled=false
-dlog4j2.disable.jmx=true
-djava.io.tmpdir=${es_tmpdir}
-xx: heapdumponoutofmemoryerror
-xx:heapdumppath=data
-xx:errorfile=logs/hs_err_pid%p.log
8:-xx: printgcdetails
8:-xx: printgcdatestamps
8:-xx: printtenuringdistribution
8:-xx: printgcapplicationstoppedtime
8:-xloggc:logs/gc.log
8:-xx: usegclogfilerotation
8:-xx:numberofgclogfiles=32
8:-xx:gclogfilesize=64m
9-:-xlog:gc*,gc age=trace,safepoint:file=logs/gc.log:utctime,pid,tags:filecount=32,filesize=64m
9-:-djava.locale.providers=compat
10-:-xx:useavx=2

3.3 开启安全认证

3.3.1 生成节点证书

– 只需在一个节点生成凭证即可

3.3.1.1 创建证书办法机构ca

# esuser用户操作,在其中一节点操作
cd /home/esuser/deploy/elasticsearch-7.13.2-9300
[esuser@xsky-node1 elasticsearch-7.13.2-9300]$ ./bin/elasticsearch-certutil ca
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 'ca' mode generates a new 'certificate authority'
this will create a new x.509 certificate and private key that can be used
to sign certificate when running in 'cert' mode.
use the 'ca-dn' option if you wish to configure the 'distinguished name'
of the certificate authority
by default the 'ca' mode produces a single pkcs#12 output file which holds:
    * the ca certificate
    * the ca's private key
if you elect to generate pem format certificates (the -pem option), then the output will
be a zip file containing individual files for the ca certificate and private key
please enter the desired output file [elastic-stack-ca.p12]: # 按回车
enter password for elastic-stack-ca.p12 : # 按回车
# 该命令默认在当前目录生成elastic-stack-ca.p12 单个证书文件,该文件是pkcs#12密钥库   
# 其中包含ca的公共证书和用于对每个节点的证书签名的私钥

3.3.1.2 生成证书和私钥

# esuser用户操作,在其中一节点操作
[esuser@xsky-node1 elasticsearch-7.13.2-9300]$ ./bin/elasticsearch-certutil cert --ca elastic-stack-ca.p12 
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 an 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)
      unless the --self-signed command line option is specified.
      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
enter password for ca (elastic-stack-ca.p12) :    # 按回车
please enter the desired output file [elastic-certificates.p12]: # 按回车
enter password for elastic-certificates.p12 : # 按回车
certificates written to /home/esuser/deploy/elasticsearch-7.13.2-9300/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.
for client applications, you may only need to copy the ca certificate and
configure the client to trust this certificate.
# 命令执行完后会在当前目录生成elastic-certificates.p12文件,此文件是各个节点通信凭证

3.3.1.3 移动凭证到指定目录

# esuser用户,每个节点都需操作
# 创建目录
mkdir ~$es_home/config/certs
# 移动凭证到指定目录
mv elastic-certificates.p12 ~$es_home/config/certs
mv elastic-stack-ca.p12 ~$es_home/config/certs
# 设置权限
chmod 777 ~$es_home/config/certs/elastic*.p12

3.3.2 拷贝文件

# 当以上操作完成后,我们可以将在10.110.7.39上的deploy打包拷贝到其它物理服务器,并对每台物理服务器上的elasticsearch.yml文件进行对应修改
# 只需调整 node.name、network.host,要分别和当前节点对应
[root@xsky-node1 ~]# su - esuser
[esuser@xsky-node1 ~]$ tar -cf deploy.tar ./deploy
[esuser@xsky-node1 ~]$ scp deploy.tar 10.110.7.40:/home/esuser
[esuser@xsky-node1 ~]$ scp deploy.tar 10.110.7.41:/home/esuser
# 然后分别使用esuser用户在10.110.7.40/41解压deploy.tar,修改对应节点的elasticsearch.yml文件

3.3.3 启动验证

-- 10.110.7.39
[root@xsky-node1 ~]# su esuser
[esuser@xsky-node1 root]$ cd /home/esuser/deploy
[esuser@xsky-node1 deploy]$ ./elasticsearch-7.13.2-9300/bin/elasticsearch
[esuser@xsky-node1 deploy]$ ./elasticsearch-7.13.2-9301/bin/elasticsearch
-- 10.110.7.40
[root@xsky-node1 ~]# su esuser
[esuser@xsky-node2 root]$ cd /home/esuser/deploy
[esuser@xsky-node2 deploy]$ ./elasticsearch-7.13.2-9300/bin/elasticsearch
[esuser@xsky-node2 deploy]$ ./elasticsearch-7.13.2-9301/bin/elasticsearch
-- 10.110.7.41
[root@xsky-node1 ~]# su esuser
[esuser@xsky-node3 root]$ cd /home/esuser/deploy
[esuser@xsky-node3 deploy]$ ./elasticsearch-7.13.2-9300/bin/elasticsearch
[esuser@xsky-node3 deploy]$ ./elasticsearch-7.13.2-9301/bin/elasticsearch

此时,待启动日志里不再报 master not discovered yet, this node has not previously joined a bootstrapped (v7 ) cluster,其它节点已加入集群,再进行设置密码操作。

3.3.4 设置密码

使用esuser用户,只需在其中一个节点执行

# esuser用户
[root@xsky-node1 ~]# su - esuser
[esuser@xsky-node1 elasticsearch-7.13.2-9300]$ ./bin/elasticsearch-setup-passwords interactive
initiating the setup of passwords for reserved users elastic,apm_system,kibana,kibana_system,logstash_system,beats_system,remote_monitoring_user.
you will be prompted to enter passwords as the process progresses.
please confirm that you would like to continue [y/n]y # 输入y,按回车
enter password for [elastic]: 
reenter password for [elastic]: 
enter password for [apm_system]: 
reenter password for [apm_system]: 
enter password for [kibana_system]: 
reenter password for [kibana_system]: 
enter password for [logstash_system]: 
reenter password for [logstash_system]: 
enter password for [beats_system]: 
reenter password for [beats_system]: 
enter password for [remote_monitoring_user]: 
reenter password for [remote_monitoring_user]: 
changed password for user [apm_system]
changed password for user [kibana_system]
changed password for user [kibana]
changed password for user [logstash_system]
changed password for user [beats_system]
changed password for user [remote_monitoring_user]
changed password for user [elastic]
# 还可以使用auto命令自动创建密码,如下所示:
-rw-r--r--  1 esuser esuser   2710 jun 11  2021 readme.asciidoc
[esuser@xsky-node1 elasticsearch-7.13.2-9300]$ ./bin/elasticsearch-setup-passwords auto
initiating the setup of passwords for reserved users elastic,apm_system,kibana,kibana_system,logstash_system,beats_system,remote_monitoring_user.
the passwords will be randomly generated and printed to the console.
please confirm that you would like to continue [y/n]y
changed password for user apm_system
password apm_system = aczcjwvf3po9p0ntkw2g
changed password for user kibana_system
password kibana_system = 3v9pxfd0x0c7hwud7dyw
changed password for user kibana
password kibana = 3v9pxfd0x0c7hwud7dyw
changed password for user logstash_system
password logstash_system = 4dnp3g7wljaft0arqnka
changed password for user beats_system
password beats_system = paumkgng10iz5ln8hi9a
changed password for user remote_monitoring_user
password remote_monitoring_user = tcezxcmupyzx43gst9cs
changed password for user elastic
password elastic = 8sliypbkixfvd3kx8de9

3.3.5 浏览器查看验证

1) 方式一

打开浏览器,输入 http://10.110.7.39:9200, 注意账号是 elastic,而非自己创建的普通用户,密码是设置的密码

image.png

输出结果如下:

{
  "name" : "node-7.39-9300",
  "cluster_name" : "es-cluster",
  "cluster_uuid" : "yjietmj4qa6djze4j4ba1q",
  "version" : {
    "number" : "7.13.2",
    "build_flavor" : "default",
    "build_type" : "tar",
    "build_hash" : "4d960a0733be83dd2543ca018aa4ddc42e956800",
    "build_date" : "2021-06-10t21:01:55.251515791z",
    "build_snapshot" : false,
    "lucene_version" : "8.8.2",
    "minimum_wire_compatibility_version" : "6.8.0",
    "minimum_index_compatibility_version" : "6.0.0-beta1"
  },
  "tagline" : "you know, for search"
}

2)方式二

curl -xget -u elastic:password http://:端口号/_cluster/health?pretty

[root@xsky-node1 ~]# curl -xget -u elastic:esuser123 http://10.110.7.39:9200/_cluster/health?pretty
{
  "cluster_name" : "es-cluster",
  "status" : "green",
  "timed_out" : false,
  "number_of_nodes" : 6,
  "number_of_data_nodes" : 6,
  "active_primary_shards" : 1,
  "active_shards" : 2,
  "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
}
最后修改时间:2023-05-22 09:52:23
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
1人已赞赏
【米乐app官网下载的版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

文章被以下合辑收录

评论

网站地图