ElasticSearch部署手册

该文详细介绍了如何在CentOS7.6系统上部署Elasticsearch7.6.0的单节点和多节点集群,包括JDK的安装、系统参数配置、Elasticsearch的解压与权限设置、JVM内存配置、证书生成与安全设置、用户认证以及集群配置等步骤。此外,还提供了常用ES命令的示例。
摘要由CSDN通过智能技术生成

单节点部署

版本说明:

源代码安装ElasticSearch

软件名称版本
elasticsearch7.6.0
jdk1.8.0
Centos7.6CentOS-7-x86_64-Everything-1810

部署jdk

tar -xvf jdk-8u271-linux-x64.tar.gz -C /usr/local
#
vim /etc/profile
export JAVA_HOME=/usr/local/jdk1.8.0_271/
export PATH=$PATH:$JAVA_HOME/bin
source /etc/profile
java -version

系统配置

用户配置

useradd elasticsearch
echo “ElasticSearch” | passwd --stdin elasticsearch

系统参数配置

ulimit -n 65535
vim /etc/security/limits.conf
*  soft nproc 65536
*  hard nproc  65536
*  soft nofile  65536
*  hard nofile  65536
elasticsearch        soft    nproc           65536
elasticsearch        hard    nproc           65536
elasticsearch        soft    nofile          65536
elasticsearch        hard    nofile          65536
elasticsearch soft memlock unlimited
elasticsearch hard memlock unlimited
#
vim /etc/sysctl.conf
fs.file-max=655360
vm.max_map_count=262144
vm.swappiness = 1
sysctl -p
#

部署ElasticSearch

解压ElasticSearch

tar -xvf elasticsearch-7.6.0.tar.gz -C /usr/local/

修改用户权限

cd /usr/local
chown -R elasticsearch:elasticsearch elasticsearch-7.6.1

修改jvm内存
说明:根据内存大小修改

vim jvm.options
-Xms128m
-Xmx128m

生成证书

su elasticsearch
cd /usr/local/elasticsearch-7.6.0/bin
./elasticsearch-certutil ca
./elasticsearch-certutil cert --ca elastic-stack-ca.p12

说明:将证书文件移到config目录下,并赋予执行权限
配置elasticsearch.yml

cluster.name: my-application
node.name: localhost
node.master: true
bootstrap.memory_lock: true
bootstrap.system_call_filter: false
network.host: 0.0.0.0
http.port: 9200
http.cors.enabled: true
http.cors.allow-origin: "*"
xpack.security.enabled: true
xpack.security.transport.ssl.enabled: true
xpack.security.transport.ssl.verification_mode: certificate
xpack.license.self_generated.type: basic
xpack.security.transport.ssl.keystore.path: elastic-certificates.p12
xpack.security.transport.ssl.truststore.path: elastic-certificates.p12
http.cors.allow-headers: Authorization,X-Requested-With,Content-Length,Content-Type
discovery.seed_hosts: ["localhost"]
cluster.initial_master_nodes: ["localhost"]

配置认证用户

cd /usr/local/elasticsearch-7.6.0/bin
./elasticsearch-setup-passwords interactive

说明:interactive交互设置密码,auto自动设置密码

启动elasticsearch

su elasticsearch
cd /usr/local/elasticsearch-7.6.0/bin
nohup ./elasticsearch -d &

集群部署方式

环境

rpm部署方式

地址系统
192.168.30.129Centos7.6
192.168.30.130Centos7.6
192.168.30.131Centos7.6

系统配置

ulimit -n 65535
vim /etc/security/limits.conf
*  soft nproc 65536
*  hard nproc  65536
*  soft nofile  65536
*  hard nofile  65536
elasticsearch        soft    nproc           65536
elasticsearch        hard    nproc           65536
elasticsearch        soft    nofile          65536
elasticsearch        hard    nofile          65536
elasticsearch soft memlock unlimited
elasticsearch hard memlock unlimited
#
vim /etc/sysctl.conf
fs.file-max=655360
vm.max_map_count=262144
vm.swappiness = 1
sysctl -p
#

部署ElasticSearch

说明:分别在3个服务器部署

rpm -ivh elasticsearch-7.10.2-x86_64.rpm 
systemctl daemon-reload
systemctl enable elasticsearch.service
systemctl start elasticsearch.service

配置elasticsearch.yml

192.168.30.129配置

#集群名称
cluster.name: ES-MY
#节点名称,每个节点的名称不能重复
node.name: node-1
#每个节点的地址不能重复
network.host: 192.168.30.129
#是否有资格成为主节点
node.master: true
node.data: true
http.port: 9250
transport.tcp.port: 9350
#head插件需要打开这两个配置
http.cors.enabled: true
http.cors.allow-origin: "*"
http.max_content_length: 200mb
#es7.x之后新增配置,初始化一个新的集群时需要配置来选举master
cluster.initial_master_nodes: ["node-1"]
#es7.x之后新增配置,节点发现
discovery.seed_hosts: ["192.168.30.129:9350", "192.168.30.130:9350", "192.168.30.131:9350"]
gateway.recover_after_nodes: 2
network.tcp.keep_alive: true
network.tcp.no_delay: true
transport.tcp.compress: true
#集群内同时启动的数据任务个数,默认是2个
cluster.routing.allocation.cluster_concurrent_rebalance: 16
#添加或删除节点及负载均衡时并发恢复的线程个数,默认4个
cluster.routing.allocation.node_concurrent_recoveries: 16

启动elasticsearch

systemctl restart elasticsearch

查看ES集群列表

[root@localhost ~]# curl http://192.168.30.129:9250/_cat/nodes
192.168.30.129 24 86  1 0.04 0.12 0.13 cdfhilmrstw * node-1

192.168.30.130配置

#集群名称
cluster.name: ES-MY
#节点名称,每个节点的名称不能重复
node.name: node-2
#每个节点的地址不能重复
network.host: 192.168.30.130
#是否有资格成为主节点
node.master: true
node.data: true
http.port: 9250
transport.tcp.port: 9350
#head插件需要打开这两个配置
http.cors.enabled: true
http.cors.allow-origin: "*"
http.max_content_length: 200mb
#es7.x之后新增配置,初始化一个新的集群时需要配置来选举master
cluster.initial_master_nodes: ["node-1"]
#es7.x之后新增配置,节点发现
discovery.seed_hosts: ["192.168.30.129:9350", "192.168.30.130:9350", "192.168.30.131:9350"]
gateway.recover_after_nodes: 2
network.tcp.keep_alive: true
network.tcp.no_delay: true
transport.tcp.compress: true
#集群内同时启动的数据任务个数,默认是2个
cluster.routing.allocation.cluster_concurrent_rebalance: 16
#添加或删除节点及负载均衡时并发恢复的线程个数,默认4个
cluster.routing.allocation.node_concurrent_recoveries: 16

启动elasticsearch

systemctl restart elasticsearch

查看ES集群列表

[root@localhost ~]# curl http://192.168.30.129:9250/_cat/nodes
192.168.30.129 24 86  1 0.04 0.12 0.13 cdfhilmrstw * node-1
192.168.30.130 12 85 59 0.66 0.41 0.24 cdfhilmrstw - node-2

192.168.30.131配置

#集群名称
cluster.name: ES-MY
#节点名称,每个节点的名称不能重复
node.name: node-3
#每个节点的地址不能重复
network.host: 192.168.30.131
#是否有资格成为主节点
node.master: true
node.data: true
http.port: 9250
transport.tcp.port: 9350
#head插件需要打开这两个配置
http.cors.enabled: true
http.cors.allow-origin: "*"
http.max_content_length: 200mb
#es7.x之后新增配置,初始化一个新的集群时需要配置来选举master
cluster.initial_master_nodes: ["node-1"]
#es7.x之后新增配置,节点发现
discovery.seed_hosts: ["192.168.30.129:9350", "192.168.30.130:9350", "192.168.30.131:9350"]
gateway.recover_after_nodes: 2
network.tcp.keep_alive: true
network.tcp.no_delay: true
transport.tcp.compress: true
#集群内同时启动的数据任务个数,默认是2个
cluster.routing.allocation.cluster_concurrent_rebalance: 16
#添加或删除节点及负载均衡时并发恢复的线程个数,默认4个
cluster.routing.allocation.node_concurrent_recoveries: 16

启动elasticsearch

systemctl restart elasticsearch

查看ES集群列表

[root@localhost ~]# curl http://192.168.30.129:9250/_cat/nodes
192.168.30.131 23 86 18 0.74 0.30 0.19 cdfhilmrstw - node-3
192.168.30.130 12 85 59 0.66 0.41 0.24 cdfhilmrstw - node-2
192.168.30.129 24 86  1 0.04 0.12 0.13 cdfhilmrstw * node-1

认证配置

生成证书

cd /usr/share/elasticsearch/bin
./elasticsearch-certutil ca
./elasticsearch-certutil cert --ca elastic-stack-ca.p12

说明:将证书文件移到/etc/elasticsearch目录下,并赋予执行权限,同时将证书文件同步到192.168.30.130和192.168.30.131

启动x-pack配置

说明:192.168.30.129 192.168.30.130 192.168.30.131服务器的elasticsearch.yml同步追加x-pack配置,然后分别重启elasticsearch服务

#开启安全认证登录
xpack.security.enabled: true
xpack.security.transport.ssl.enabled: true
xpack.security.authc.accept_default_password: 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

配置密码

cd /usr/share/elasticsearch/bin
./elasticsearch-setup-passwords auto|interactive #或者将auto替换为interactive进行手动修改

修改分片数

说明:报错:this cluster currently has [14030]/[1000] maximum shards open
注释掉elasticsearch.yml中x-pack配置,撤销认证操作重启es集群,修改默认分片数(默认1000)

curl -XPUT -H "Content-Type:application/json" http://192.168.30.131:9200/_cluster/settings -d '{ "persistent": { "cluster": { "max_shards_per_node": 10000 } } }'

修改ES密码

curl -XPOST -u elastic "192.168.30.131:9200/_security/user/elastic/_password" -H 'Content-Type: application/json' -d'{"password" : "elastic123456"}'

常用ES命令

curl http://192.168.30.129:9250/_cat?pretty
=^.^=
/_cat/allocation
/_cat/shards
/_cat/shards/{index}
/_cat/master
/_cat/nodes
/_cat/tasks
/_cat/indices
/_cat/indices/{index}
/_cat/segments
/_cat/segments/{index}
/_cat/count
/_cat/count/{index}
/_cat/recovery
/_cat/recovery/{index}
/_cat/health
/_cat/pending_tasks
/_cat/aliases
/_cat/aliases/{alias}
/_cat/thread_pool
/_cat/thread_pool/{thread_pools}
/_cat/plugins
/_cat/fielddata
/_cat/fielddata/{fields}
/_cat/nodeattrs
/_cat/repositories
/_cat/snapshots/{repository}
/_cat/templates
/_cat/ml/anomaly_detectors
/_cat/ml/anomaly_detectors/{job_id}
/_cat/ml/trained_models
/_cat/ml/trained_models/{model_id}
/_cat/ml/datafeeds
/_cat/ml/datafeeds/{datafeed_id}
/_cat/ml/data_frame/analytics
/_cat/ml/data_frame/analytics/{id}
/_cat/transforms
/_cat/transforms/{transform_id}
#
#  *号表示为当前节点为主节点的意思
curl http://192.168.30.129:9250/_cat/nodes
192.168.30.131 45 86 0 0.01 0.06 0.12 cdfhilmrstw - node-3
192.168.30.130 40 87 0 0.00 0.01 0.09 cdfhilmrstw * node-2
192.168.30.129 20 88 0 0.00 0.01 0.05 cdfhilmrstw - node-1
#
curl http://192.168.30.129:9250/_cat/health?v
epoch      timestamp cluster status node.total node.data shards pri relo init unassign pending_tasks max_task_wait_time active_shards_percent
1642347463 15:37:43  ES-MY   green           3         3      6   3    0    0        0             0
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

gswcfl

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值