ElasticSearch7(ES)集群搭建(并配置密码)

ElasticSearch之分布式搜索引擎

一、简介

ElasticSearch官网

二、生产集群搭建

准备

  • 安装JDK的linux服务器三台(JDK版需要与ElasticSearch版本对应好)

下载

准备好ElasticSearch安装包,官网下载地址

创建用户组和用户

groupadd esuser---创建用户组
useradd -m -d /home/esuser -g esuser esuser---创建用户
passwd esuser---修改密码

创建目录

cd /opt
mkdir es   #创建安装目录
cd es
mkdir data logs #创建ElasticSearch数据目录和日志目录

解压

tar -zxvf elasticsearch-7.13.2-linux-x86_64.tar.gz -C /opt/es/

修改配置

cd /opt/es/elasticsearch-7.13.2/config/
vim elasticsearch.yml
# 集群配置
cluster.name: ES #修改集群名称,自定义即可
node.name: node01 #修改当前ES节点名称
node.master: true #作为master节点
node.data: true #作为node节点
path.data: /opt/es/data #修改数据保存目录
path.logs: /opt/es/logs #修改日志保存目录
network.host: 192.xxx.xxx.xxx #修改ES网络IP
discovery.seed_hosts: ["10.160.26.249:9300", "10.160.26.250:9300","10.160.26.251:9300"] #集群通信
cluster.initial_master_nodes: ["node01", "node02","node03"] #添加集群节点名称

# 密码配置
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 #证书位置

# head 插件需要这打开这两个配置
http.max_content_length: 200mb
http.cors.enabled: true
http.cors.allow-origin: "*"
http.cors.allow-headers: Authorization,X-Requested-With,Content-Length,Content-Type

#其他配置 按照需要即可
action.destructive_requires_name: true
gateway.recover_after_nodes: 2
network.tcp.keep_alive: true
network.tcp.no_delay: true
transport.tcp.compress: true

配置证书

cd /opt/es/elasticsearch-7.13.2
./bin/elasticsearch-certutil ca #在 /opt/es/elasticsearch-7.13.2目录下生成 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 '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 :  #直接回车
./bin/elasticsearch-certutil cert --ca elastic-stack-ca.p12 #在 /opt/es/elasticsearch-7.13.2目录下生成elastic-certificates.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 /opt/es/elasticsearch-7.13.2/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-stack-ca.p12  elastic-certificates.p12 到config目录下
mv elastic-stack-ca.p12 elastic-certificates.p12 config/  #与elasticsearch.yml中证书位置对应即可

拷贝安装目录

分发ElasticSearch目录到集群所有服务器,同时修改每个文件的node.name和network.host

启动

#切换root用户 修改/etc/security/limits.conf文件 添加以下内容
* soft nofile 65536
* hard nofile 131072
* soft nproc 2048
* hard nproc 4096
#修改 /etc/sysctl.conf 增加 vm.max_map_count=262145
#修改完成之后,使用sysctl -p命令刷新一下,再次切换到 esuser进行启动即可。
#切换ES用户后,启动集群
bin/elasticsearch -d

设置密码

#手动设置密码
/bin/elasticsearch-setup-passwords interactive
#手动设置密码
/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
#输入各用户密码即可
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]

恭喜ES集群搭建完成!!!

你可能感兴趣的:(ElasticSearch7(ES)集群搭建(并配置密码))