elasticsearch集群搭建

1、准备三台服务,ip如下

192.168.37.40
192.168.37.141
192.168.37.48

2、系统设置
将/etc/fstab文件中所有设置为swap的设备关闭

swapoff -a
free -h

注释/etc/fstab的swap行

vi /etc/fstab
注释swap行

设置Linux内核参数

vi /etc/sysctl.conf
vm.swappiness=1
fs.file-max=655360
vm.max_map_count=262144
net.ipv4.tcp_retries2=5

生效/etc/sysctl.conf配置文件

sysctl -p

设置资源限制配置文件

vi /etc/security/limits.conf
* soft nofile 65535
* hard nofile 65535
* soft nproc  4096
* hard nproc  4096
* soft memlock unlimited
* hard memlock unlimited

3、设置防火墙
es检索服务应限制访问ip,将集群节点和需要访问es的ip添加到trusted区域

安装、启动防火墙

yum install firewalld.noarch
systemctl enable firewalld.service
systemctl start firewalld.service

不同的服务器执行不同的命令
(1)192.168.37.40服务器

firewall-offline-cmd --zone=trusted --add-source=192.168.37.141
firewall-offline-cmd --zone=trusted --add-source=192.168.37.48
systemctl reload firewalld
firewall-cmd --list-all-zones

(2)192.168.37.141服务器

firewall-offline-cmd --zone=trusted --add-source=192.168.37.40
firewall-offline-cmd --zone=trusted --add-source=192.168.37.48
systemctl reload firewalld
firewall-cmd --list-all-zones

(3)192.168.37.48服务器

firewall-offline-cmd --zone=trusted --add-source=192.168.37.40
firewall-offline-cmd --zone=trusted --add-source=192.168.37.141
systemctl reload firewalld
firewall-cmd --list-all-zones

4、es集群搭建
将elasticsearch-7.12.1-linux-aarch64.tar.gz文件上传到/home/elastic/software目录

解压

tar -zxvf elasticsearch-7.12.1-linux-aarch64.tar.gz

JVM配置

vi config/jvm.options.d/java.options
-Xms31g
-Xmx31g
-Dlog4j2.formatMsgNoLookups=true

主要配置,不同的服务器设置不同的参数

(1)192.168.37.40服务器

vi config/elasticsearch.yml
cluster.name: hypersearch
node.name: node-1
bootstrap.memory_lock: true
bootstrap.system_call_filter: false
network.host: 192.168.37.40,127.0.0.1
discovery.seed_hosts: ["192.168.37.40", "192.168.37.141", "192.168.37.48"]
cluster.routing.allocation.same_shard.host: true
cluster.initial_master_nodes: node-1

(2)192.168.37.141服务器

vi config/elasticsearch.yml
cluster.name: hypersearch
node.name: node-2
bootstrap.memory_lock: true
bootstrap.system_call_filter: false
network.host: 192.168.37.141,127.0.0.1
discovery.seed_hosts: ["192.168.37.40", "192.168.37.141", "192.168.37.48"]
cluster.routing.allocation.same_shard.host: true
cluster.initial_master_nodes: node-1

(3)192.168.37.48服务器

vi config/elasticsearch.yml
cluster.name: hypersearch
node.name: node-3
bootstrap.memory_lock: true
bootstrap.system_call_filter: false
network.host: 192.168.37.48,127.0.0.1
discovery.seed_hosts: ["192.168.37.40", "192.168.37.141", "192.168.37.48"]
cluster.routing.allocation.same_shard.host: true
cluster.initial_master_nodes: node-1

新增账户(不要使用root账户运行服务)

useradd elastic
passwd elastic
elastic123456
chmod -R 777 /home/elastic/software/elasticsearch-7.12.1
su elastic

启动服务

bin/elasticsearch -d

5、查看集群状态

curl http://192.168.37.40:9200/_cluster/health?pretty
{
  "cluster_name" : "hypersearch",
  "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
}

你可能感兴趣的:(Elasticsearch,elasticsearch)