源代码安装ElasticSearch
软件名称 | 版本 |
---|---|
elasticsearch | 7.6.0 |
jdk | 1.8.0 |
Centos7.6 | CentOS-7-x86_64-Everything-1810 |
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
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自动设置密码
su elasticsearch
cd /usr/local/elasticsearch-7.6.0/bin
nohup ./elasticsearch -d &
rpm部署方式
地址 | 系统 |
---|---|
192.168.30.129 | Centos7.6 |
192.168.30.130 | Centos7.6 |
192.168.30.131 | Centos7.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
#
说明:分别在3个服务器部署
rpm -ivh elasticsearch-7.10.2-x86_64.rpm
systemctl daemon-reload
systemctl enable elasticsearch.service
systemctl start elasticsearch.service
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
说明: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 } } }'
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