ES7集群安装、配置、卸载

最新下载地址:https://www.elastic.co/cn/downloads/past-releases#elasticsearch

可选版本下载地址:https://www.elastic.co/downloads/past-releases

一、Linux系统参数设置:

文件句柄
vi /etc/security/limits.conf
* soft nofile 65536
* hard nofile 65536
* soft nproc 2048
* hard nproc 4096
#我选择锁住swapping因此需要在这个配置文件下再增加两行代码
* soft memlock unlimited
* hard memlock unlimited

虚拟内存设置
max_map_count定义了进程能拥有的最多内存区域
vi /etc/sysctl.conf
vm.max_map_count=655360
fs.file-max=655360

/sbin/sysctl -p

二、RPM安装方式:

rpm -ivh elasticsearch-7.3.2-x86_64.rpm

2.1、启动

#开机启动
systemctl enable elasticsearch
systemctl start elasticsearch
systemctl status elasticsearch

如果配置的日志目录,和data目录为root权限,需要设置为es的权限
chown -R elasticsearch:elasticsearch /home/elasticsearch/log
chown -R elasticsearch:elasticsearch /home/elasticsearch/data

2.2、卸载

[root@slave1 elasticsearch]# rpm -qa | grep elasticsearch
elasticsearch-7.1.1-1.x86_64
[root@slave1 elasticsearch]# rpm -e --nodeps elasticsearch-7.1.1-1.x86_64
Stopping elasticsearch service... OK
warning: file /var/run/elasticsearch: remove failed: No such file or directory
warning: /etc/elasticsearch/elasticsearch.yml saved as /etc/elasticsearch/elasticsearch.yml.rpmsave
Deleting log directory... OK

三、tar包安装方式

tar -zxvf elasticsearch-7.3.2-linux-x86_64.tar.gz 

cd elasticsearch-7.3.2/

3.1、目录结构说明

bin :脚本文件,包括 ES 启动 & 安装插件等等

config : elasticsearch.yml(ES 配置文件)、jvm.options(JVM 配置文件)、日志配置文件等等

JDK : 内置的 JDK,JAVA_VERSION="12.0.2"

lib : 类库

logs : 日志文件

modules : ES 所有模块,包括 X-pack 等

plugins : ES 已经安装的插件。默认没有插件

3.2、修改配置文件

vi config/elasticsearch.yml 
cluster.name: lanwon-es-cluster
node.name: node-1
node.master: true
node.data: true
#node.attr.rack: r1
path.data: /elasticsearch/data
path.logs: /elasticsearch/log
bootstrap.memory_lock: true
network.host: 172.16.14.184
http.port: 9200
transport.tcp.port: 9300
discovery.seed_hosts: ["172.16.14.184:9300","172.16.14.185:9300","172.16.14.186:9300"]
cluster.initial_master_nodes: ["172.16.14.184:9300", "172.16.14.185:9300","172.16.14.186:9300"]
#gateway.recover_after_nodes: 3
#action.destructive_requires_name: true
cluster.routing.allocation.cluster_concurrent_rebalance: 32
cluster.routing.allocation.node_concurrent_recoveries: 32
cluster.routing.allocation.node_initial_primaries_recoveries: 32
http.cors.enabled: true
http.cors.allow-origin: "*"
discovery.zen.minimum_master_nodes: 2
bootstrap.mlockall: true


cluster.name: lanwon-es-cluster
node.name: node-2
node.master: true
node.data: true
#node.attr.rack: r1
path.data: /elasticsearch/data
path.logs: /elasticsearch/log
bootstrap.memory_lock: true
network.host: 172.16.14.185
http.port: 9200
transport.tcp.port: 9300
discovery.seed_hosts: ["172.16.14.184:9300","172.16.14.185:9300","172.16.14.186:9300"]
cluster.initial_master_nodes: ["172.16.14.184:9300","172.16.14.185:9300","172.16.14.186:9300"]
#gateway.recover_after_nodes: 3
#action.destructive_requires_name: true
cluster.routing.allocation.cluster_concurrent_rebalance: 32
cluster.routing.allocation.node_concurrent_recoveries: 32
cluster.routing.allocation.node_initial_primaries_recoveries: 32
http.cors.enabled: true
http.cors.allow-origin: "*"
discovery.zen.minimum_master_nodes: 2
bootstrap.mlockall: true

cluster.name: lanwon-es-cluster
node.name: node-3
node.master: true
node.data: true
#node.attr.rack: r1
path.data: /elasticsearch/data
path.logs: /elasticsearch/log
bootstrap.memory_lock: true
network.host: 172.16.14.186
http.port: 9200
transport.tcp.port: 9300
discovery.seed_hosts: ["172.16.14.184:9300","172.16.14.185:9300","172.16.14.186:9300"]
cluster.initial_master_nodes: ["172.16.14.184:9300","172.16.14.185:9300","172.16.14.186:9300"]
#gateway.recover_after_nodes: 3
#action.destructive_requires_name: true
cluster.routing.allocation.cluster_concurrent_rebalance: 32
cluster.routing.allocation.node_concurrent_recoveries: 32
cluster.routing.allocation.node_initial_primaries_recoveries: 32
http.cors.enabled: true
http.cors.allow-origin: "*"
discovery.zen.minimum_master_nodes: 2
bootstrap.mlockall: true

sudo chown -R qyyx:qyyx /elasticsearch/log
sudo chown -R qyyx:qyyx /elasticsearch/data

3.3、启动

./bin/elasticsearch

3.4、tar包安装设置开机启动

sudo vi /etc/init.d/elasticsearch

#!/bin/sh
#chkconfig: 2345 80 05
#description: elasticsearch

export JAVA_HOME=/home/qyyx/tools/elasticsearch-7.3.2/jdk
export JAVA_BIN=/home/qyyx/tools/elasticsearch-7.3.2/jdk/bin
export PATH=$PATH:$JAVA_HOME/bin
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export JAVA_HOME JAVA_BIN PATH CLASSPATH

case "$1" in
start)
    su qyyx<<!
    cd /home/qyyx/tools/elasticsearch-7.3.2
    ./bin/elasticsearch -d
!
    echo "elasticsearch startup"
    ;;
stop)
    es_pid=`ps aux|grep elasticsearch | grep -v 'grep elasticsearch' | awk '{print $2}'`
    kill -9 $es_pid
    echo "elasticsearch stopped"
    ;;
restart)
    es_pid=`ps aux|grep elasticsearch | grep -v 'grep elasticsearch' | awk '{print $2}'`
    kill -9 $es_pid
    echo "elasticsearch stopped"
    su qyyx<<!
    cd /home/qyyx/tools/elasticsearch-7.3.2
    ./bin/elasticsearch -d
!
    echo "elasticsearch startup"
    ;;
*)
    echo "start|stop|restart"
    ;;
esac

exit $?

保存退出,赋予执行权限
chmod +x elasticsearch

sudo chmod +x /etc/init.d/elasticsearch

3.5、添加到开机启动任务

sudo chkconfig --add /etc/init.d/elasticsearch

如果不设置开机启动的话,也可以使用service elasticsearch start/stop/restart来操作

 

 

集群配置:

修改/config下的elasticsearch.yml

集群名称,必须一致,
cluster.name:elasticsearch

节点名称,不可以一样,这里按照node-1、node-2、node-3进行命名
node.name:node-1

path.data=/home/elasticsearch/data
path.log=/home/elasticsearch/log
注意:需要进行配置,如果使用默认配置是很危险的。当es被卸载,数据和日志将完全丢失。可以根据具体环境将数据目录和日志目录保存到其他路径下以确保数据和日志完整、安全。

discovery.seed_hosts: ["192.168.171.173:9301", "192.168.0.171:9301","192.168.0.174:9301"]
cluster.initial_master_nodes: ["192.168.171.173:9301", "192.168.0.171:9301","192.168.0.174:9301"]

把 bootstrap.memory_lock: false 注释放开
是否锁住内存。因为当jvm开始swapping时es的效率会降低,配置为true时要允许elasticsearch的进程可以锁住内存,同时一定要保证机器有足够的内存分配给es。如果不熟悉机器所处环境,建议配置为false。

添加 bootstrap.system_call_filter: false
Centos6不支持SecComp,而es5.2.0版本默认bootstrap.system_call_filter为true
禁用:在elasticsearch.yml中配置bootstrap.system_call_filter为false,注意要在Memory的后面配置该选项。

network.host: 192.168.171.173 
是本机ip,一般我们会使用192.168.1.55这种,这里用的虚拟机所以是10.9.39.13
http.port: 9200 设置端口为9200
transport.port: 9301

这里需要配置多个,为了演示非同一IP段,所以IP段不同
因为我们搭建了3台服务器用于演示,所以此处为三个服务器配置的network.host地址,
discovery.zen.ping.unicast.hosts: [“10.9.39.13”, “10.9.104.184”, “10.9.104.185”]

master集群中最小的master数量,集群都是过半投票制,所以3台服务器设置2个master节点,如果19台服务器可以设置5个master节点,因为设置的是最小master节点数量防止宕机过多。
#在Elasticsearch7.0版本已被移除,配置无效
#为了避免脑裂,集群的最少节点数量为,集群的总节点数量除以2加一
discovery.zen.minimum_master_nodes: 2

http.cors.enabled: true
http.cors.allow-origin: "*"

测试

查看集群主从分配

http://192.168.0.160:9200/_cat/nodes?v

ip            heap.percent ram.percent cpu load_1m load_5m load_15m node.role master name
192.168.0.160           35          97   0    0.04    0.23     0.22 di        -      node-3
192.168.0.160           15          97   0    0.04    0.23     0.22 dim       *      node-1
192.168.0.160           31          97   0    0.04    0.23     0.22 di        -      node-2

查看集群状态

http://192.168.0.160:9200/_cluster/health?pretty

{
  "cluster_name": "my-application",
  "status": "green",
  "timed_out": false,
  "number_of_nodes": 3,
  "number_of_data_nodes": 3,
  "active_primary_shards": 0,
  "active_shards": 0,
  "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
}

所有配置详解:

elasticsearch7.0配置文件详解 此文件不是集群生成所用到的文件,只是给大家讲解ES7配置文件的详细说明

vim /usr/local/elasticsearch-7.0.0/config/elasticsearch.yml
cluster.name: ES-Cluster
#ES集群名称,同一个集群内的所有节点集群名称必须保持一致

node.name: ES-master-10.150.55.94
#ES集群内的节点名称,同一个集群内的节点名称要具备唯一性

node.master: true
#允许节点是否可以成为一个master节点,ES是默认集群中的第一台机器成为master,如果这台机器停止就会重新选举

node.data: false
#允许该节点存储索引数据(默认开启)
#关于Elasticsearch节点的角色功能详解,请看:https://www.dockerc.com/elasticsearch-master-or-data/

path.data: /data/ES-Cluster/master/ES-master-10.150.55.94/data1,/data/ES-Cluster/master/ES-master-10.150.55.94/data2
#ES是搜索引擎,会创建文档,建立索引,此路径是索引的存放目录,如果我们的日志数据较为庞大,那么索引所占用的磁盘空间也是不可小觑的
#这个路径建议是专门的存储系统,如果不是存储系统,最好也要有冗余能力的磁盘,此目录还要对elasticsearch的运行用户有写入权限
#path可以指定多个存储位置,分散存储,有助于性能提升,以至于怎么分散存储请看详解https://www.dockerc.com/elk-theory-elasticsearch/

path.logs: /data/ES-Cluster/master/ES-master-10.150.55.94/logs
#elasticsearch专门的日志存储位置,生产环境中建议elasticsearch配置文件与elasticsearch日志分开存储

bootstrap.memory_lock: true
#在ES运行起来后锁定ES所能使用的堆内存大小,锁定内存大小一般为可用内存的一半左右;锁定内存后就不会使用交换分区
#如果不打开此项,当系统物理内存空间不足,ES将使用交换分区,ES如果使用交换分区,那么ES的性能将会变得很差

network.host: 10.150.55.94
#es绑定地址,支持IPv4及IPv6,默认绑定127.0.0.1;es的HTTP端口和集群通信端口就会监听在此地址上

network.tcp.no_delay: true
#是否启用tcp无延迟,true为启用tcp不延迟,默认为false启用tcp延迟

network.tcp.keep_alive: true
#是否启用TCP保持活动状态,默认为true

network.tcp.reuse_address: true
#是否应该重复使用地址。默认true,在Windows机器上默认为false

network.tcp.send_buffer_size: 128mb
#tcp发送缓冲区大小,默认不设置

network.tcp.receive_buffer_size: 128mb
#tcp接收缓冲区大小,默认不设置

transport.tcp.port: 9301
#设置集群节点通信的TCP端口,默认就是9300

transport.tcp.compress: true
#设置是否压缩TCP传输时的数据,默认为false

http.max_content_length: 200mb
#设置http请求内容的最大容量,默认是100mb

http.cors.enabled: true
#是否开启跨域访问

http.cors.allow-origin: "*"
#开启跨域访问后的地址限制,*表示无限制

http.port: 9201
#定义ES对外调用的http端口,默认是9200

discovery.zen.ping.unicast.hosts: ["10.150.55.94:9301", "10.150.55.95:9301","10.150.30.246:9301"]    #在Elasticsearch7.0版本已被移除,配置错误
#写入候选主节点的设备地址,来开启服务时就可以被选为主节点
#默认主机列表只有127.0.0.1和IPV6的本机回环地址
#上面是书写格式,discover意思为发现,zen是判定集群成员的协议,unicast是单播的意思,ES5.0版本之后只支持单播的方式来进行集群间的通信,hosts为主机
#总结下来就是:使用zen协议通过单播方式去发现集群成员主机,在此建议将所有成员的节点名称都写进来,这样就不用仅靠集群名称cluster.name来判别集群关系了

discovery.zen.minimum_master_nodes: 2           #在Elasticsearch7.0版本已被移除,配置无效
#为了避免脑裂,集群的最少节点数量为,集群的总节点数量除以2加一

discovery.zen.fd.ping_timeout: 120s             #在Elasticsearch7.0版本已被移除,配置无效
#探测超时时间,默认是3秒,我们这里填120秒是为了防止网络不好的时候ES集群发生脑裂现象

discovery.zen.fd.ping_retries: 6                #在Elasticsearch7.0版本已被移除,配置无效
#探测次数,如果每次探测90秒,连续探测超过六次,则认为节点该节点已脱离集群,默认为3次

discovery.zen.fd.ping_interval: 15s             #在Elasticsearch7.0版本已被移除,配置无效
#节点每隔15秒向master发送一次心跳,证明自己和master还存活,默认为1秒太频繁,

discovery.seed_hosts: ["10.150.55.94:9301", "10.150.55.95:9301","10.150.30.246:9301"]
#Elasticsearch7新增参数,写入候选主节点的设备地址,来开启服务时就可以被选为主节点,由discovery.zen.ping.unicast.hosts:参数改变而来

cluster.initial_master_nodes: ["10.150.55.94:9301", "10.150.55.95:9301","10.150.30.246:9301"]
#Elasticsearch7新增参数,写入候选主节点的设备地址,来开启服务时就可以被选为主节点

cluster.fault_detection.leader_check.interval: 15s 
#Elasticsearch7新增参数,设置每个节点在选中的主节点的检查之间等待的时间。默认为1秒

discovery.cluster_formation_warning_timeout: 30s 
#Elasticsearch7新增参数,启动后30秒内,如果集群未形成,那么将会记录一条警告信息,警告信息未master not fount开始,默认为10秒

cluster.join.timeout: 30s
#Elasticsearch7新增参数,节点发送请求加入集群后,在认为请求失败后,再次发送请求的等待时间,默认为60秒

cluster.publish.timeout: 90s 
#Elasticsearch7新增参数,设置主节点等待每个集群状态完全更新后发布到所有节点的时间,默认为30秒

cluster.routing.allocation.cluster_concurrent_rebalance: 32
#集群内同时启动的数据任务个数,默认是2个

cluster.routing.allocation.node_concurrent_recoveries: 32
#添加或删除节点及负载均衡时并发恢复的线程个数,默认4个

cluster.routing.allocation.node_initial_primaries_recoveries: 32
#初始化数据恢复时,并发恢复线程的个数,默认4个

https://www.cnblogs.com/lifengdi/archive/2019/09/16/11525648.html

 

  • 2
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值