淘先锋技术网

首页 1 2 3 4 5 6 7

Elasticsearch实战——环境搭建

1. 环境准备

准备三台虚拟机,分别为:

$vim /etc/hosts
192.168.1.122 node1
192.168.1.127 node2
192.168.1.126 node3

修改内核参数配置

$vim /etc/security/limits.conf

添加下面的参数:

#文件描述符配置
* soft nofile 65536
* hard nofile 65536
#最大线程数检查
* soft nproc unlimited
* hard nproc unlimited
#最大虚拟内存检查
* soft as unlimited
* hard as unlimited
#最大文件大小检查
* soft fsize unlimited
* hard fsize unlimited
#内存锁定
* soft memlock unlimited
* hard memlock unlimited

最大线程数据检查

$vim /etc/security/limits.d/%s-nproc.conf
* soft nproc unlimited

虚拟内存区域最大数据检查

$vim /etc/sysctl.conf

添加

vm.max_map_count=262144

然后重启

2. jdk安装

$tar -zvxf jdk-13.0.1_linux-x64_bin.tar.gz
$mv jdk-13.0.1 jdk
$vim /etc/profile
export JAVA_HOME=/java/jdk
export PATH=$PATH:$JAVA_HOME/bin
$source /etc/profile
$vim ~/.base_profile
export JAVA_HOME=/java/jdk
export PATH=$PATH:$JAVA_HOME/bin
$source /etc/profile

3. 安装elasticsearch

$tar -zvxf elasticsearch-7.5.1-linux-x86_64.tar.gz
$mv elasticsearch-7.5.1 elasticsearch
$vim elasticsearch/config/jvm.options

修改垃圾回收器为G1,因为jdk版本需要jdk10以上的,不支持CMS垃圾回收器

-XX:+UseG1GC
-XX:G1ReservePercent=25
-XX:InitiatingHeapOccupancyPercent=60
$vim elasticsearch/config/elasticsearch.yml
cluster.name: syg
node.name: node-2
node.attr.rack: r1
path.data: /home/syg/elasticsearch/index
path.logs: /home/syg/elasticsearch/logs

# Lock the memory on startup:
bootstrap.memory_lock: true
network.host: 0.0.0.0
http.port: 9200

#集群参数
#Elasticsearch7新增参数,写入候选主节点的设备地址,开启服务时就可以被选为主节点由discovery.zen.ping.unicast.hosts参数改变而来
discovery.seed_hosts: ["192.168.0.122", "192.168.0.127","192.168.0.126"]
#Elasticsearch7新增参数,写入候选主节点的设备地址
cluster.initial_master_nodes: ["192.168.0.122", "192.168.0.127","192.168.0.126"]
#Elasticsearch7新增参数,设置每个节点在选中的主节点的检查之间等待的时间。默认为1秒
cluster.fault_detection.leader_check.interval: 15s
#Elasticsearch7新增参数,启动后30秒内,如果集群未形成,那么将会记录一条警告信息,警告信息未master not fount开始,默认为10秒
discovery.cluster_formation_warning_timeout: 30s
#Elasticsearch7新增参数,节点发送请求加入集群后,在认为请求失败后,再次发送请求的等待时间,默认为60秒
cluster.join.timeout: 30s
#Elasticsearch7新增参数,设置主节点等待每个集群状态完全更新后发布到所有节点的时间,默认为30秒
cluster.publish.timeout: 90s
#集群内同时启动的数据任务个数,默认是2个
cluster.routing.allocation.cluster_concurrent_rebalance: 2

#
# ---------------------------------- Gateway -----------------------------------
#三个节点启动后才开始恢复索引
gateway.recover_after_nodes: 3
#三个节点启动后5分钟后开始恢复索引
gateway.recover_after_time: 5m
gateway.expected_nodes: 3

#初始化数据恢复时,并发恢复线程的个数,默认4个
cluster.routing.allocation.node_initial_primaries_recoveries: 4
#添加或删除节点及负载均衡时并发恢复的线程个数,默认4个
cluster.routing.allocation.node_concurrent_recoveries: 4
#恢复数据时,限制的宽带流量,如果是0就是无限制
indices.recovery.max_bytes_per_sec: 20mb

#action.destructive_requires_name: true
http.cors.enabled: true
http.cors.allow-origin: "*"

启动

$./elasticsearch/bin/elasticsearch -d

4. 关注我

搜索微信公众号:java架构强者之路
在这里插入图片描述