elasticsearch集群搭建记录

一、集群服务器配置信息

服务器IP配置
10.110.25.134节点1
10.110.25.151节点2
10.110.25.226节点3
10.110.15.43节点4
10.110.15.46节点5

二、安装 JDK

链接: JDK安装.

三、下载 ElasticSearch 安装包和中文分词器并解压

下载地址:
链接: elasticsearch-7-6-1.
链接: ik分词器.

添加用户:

useradd es

下载es安装包和中文分词器上传到三台服务器上解压:

cd /home/es
chown es elasticsearch-7.6.1-linux-x86_64.tar.gz
chown es elasticsearch-analysis-ik-7.6.1.zip
su - es
tar -zxvf elasticsearch-7.6.1-linux-x86_64.tar.gz
unzip elasticsearch-analysis-ik-7.6.1.zip -d /home/es/elasticsearch-7.6.1/plugins/ik

四、创建用于存放数据与日志的目录

mkdir -p /home/es/data
mkdir -p /home/es/log

五、集群配置

5.1 节点1配置

echo '' > /home/es/elasticsearch-7.6.1/config/elasticsearch.yml
vim /home/es/elasticsearch-7.6.1/config/elasticsearch.yml
cluster.name: fuxy_es_cluster
#节点名称,要唯⼀
node.name: es_node_1
#数据存放位置
path.data: /home/es/data
#⽇志存放位置
path.logs: /home/es/log
#es绑定的ip地址,开放⽹卡地址
network.host: 10.110.25.134
#是否开启master ⻆⾊选举
node.master: true
# 是否开启数据节点⻆⾊
node.data: true
#是否锁住内存,避免交换(swapped)带来的性能损失,默认值是: false
bootstrap.memory_lock: true
#以下两项是外部访问http需要开启的项
#启⽤跨域资源共享
http.cors.enabled: true
http.cors.allow-origin: "*"
# 开放端⼝号
http.port: 9200
# 集群间传输端⼝号
transport.tcp.port: 9300
# 集群主节点配置
discovery.seed_hosts: ["10.110.25.134","10.110.25.151","10.110.25.226"]
# 集群初始化 master 节点。只填备选主节点,初始化时读取。
cluster.initial_master_nodes: ["es_node_1","es_node_2","es_node_3"]

5.2 其他节点配置

仅修改:
node.name
network.host
4和5不参与选举
node.master: false

六、JVM 配置

 vim /home/es/elasticsearch-7.6.1/config/jvm.options

1、log4j2漏洞缓解方案

-Dlog4j2.formatMsgNoLookups=true

七、修改系统配置

注意>>是追加,>是覆盖,不要弄错。

7.1 针对bootstrap.memory_lock: true的系统设置

1、切换root,修改/etc/security/limits.conf

exit
vim /etc/security/limits.conf

文件最后添加以下内容:

* soft nofile 65536
* hard nofile 65536
* soft nproc 32000
* hard nproc 32000
* hard memlock unlimited
* soft memlock unlimited

2、修改/etc/systemd/system.conf

vim /etc/systemd/system.conf

分别修改以下内容:

DefaultLimitNOFILE=65536
DefaultLimitNPROC=32000
DefaultLimitMEMLOCK=infinity

说明:

* soft nofile 65536
* hard nofile 65536

此设置修改后需要重新登录用户,才会生效。登录后使用 ulimit -S -n 和 /ulimit -H -n 查看参数。

若不修改会报错:

max file descriptors [4096] for elasticsearch process is too low, increase to at least [65535]

7.2 max_map_count、file-max、swappiness

max_map_count文件包含限制一个进程可以拥有的VMA(虚拟内存区域)的数量。
如不修改会报错:

max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]

file-max是设置 系统所有进程一共可以打开的文件数量。
vm.swappiness=0意味用于在任何情况下都不要发生内存交换。需改为1.
使用root用户执行:

echo -e 'vm.max_map_count=655360 \nfs.file-max=655360 \nvm.swappiness=1' >> /etc/sysctl.conf
sysctl -p #使修改生效

如报错:

sysctl: cannot stat /proc/sys/–p: No such file or directory

先执行:

modprobe br_netfilter
ls /proc/sys/net/bridge

八、启动

su - es
/home/es/elasticsearch-7.6.1/bin/elasticsearch -d
tail -100f /home/es/log/fuxy_es_cluster.log

九、其他

查看集群健康状态
http://10.110.25.134:9200/_cluster/health?pretty=true

十、常用DSL

#分词
GET /_analyze
{
  "text":"宁智显",
  "analyzer":"ik_smart"
}

#查看索引列表
GET /_cat/indices?v

#查看索引结构
GET /索引名

#查询所有数据
# track_total_hits 显示总数,false时大于10000后只显示10000
# explain 显示数据在哪个分片
GET /索引名/_search
{
  "track_total_hits":true,
  "explain": true, 
  "query": {
    "match_all": {}
  }
}
#按条件查询
GET /索引名/_search
{
  "query": {
    "match": {
      "filed": "value"
    }
  }
}


#删除索引库
DELETE /索引名

# 创建索引
# analyzer 分词器,中文分词器有ik_smart 粗粒度、ik_max_word 最细粒度
# number_of_shards 主分片数
# number_of_replicas 从分片数
PUT /fxy_bic_psn
{
  "mappings": {
    "properties": {
      "psnNo":{
        "type": "keyword"
      },
      "psnMgtcode":{
        "type": "keyword"
      },
      "psnName":{
        "type": "text",
        "analyzer": "ik_smart" 
      },
      "certNo":{
        "type": "keyword"
      },
      "psnCertType":{
        "type": "keyword"
      },
      "ver":{
        "type": "keyword"
      },
      "crteTime":{
        "type": "keyword"
      },
      "updtTime":{
        "type": "keyword"
      }
    }
  },
  "settings": {
    "number_of_shards": 5,#主分片数
    "number_of_replicas": 4#从分片数
  }
}

十一、单机版安装记录

安装版本8.2.3

配置文件

cluster.name: fuxy_es_cluster
#节点名称,要唯⼀
node.name: es_node_1
##数据存放位置
path.data: /software/elk/es/data
##⽇志存放位置
path.logs: /software/elk/es/log
##es绑定的ip地址,开放⽹卡地址
network.host: 192.168.52.128
#是否锁住内存,避免交换(swapped)带来的性能损失,默认值是: false
bootstrap.memory_lock: true
##以下两项是外部访问http需要开启的项
##启⽤跨域资源共享
http.cors.enabled: true
http.cors.allow-origin: "*"
## 开放端⼝号
http.port: 9200

8版本执行启动后会在配置文件后追加以下配置,同时需要使用https访问。

#----------------------- BEGIN SECURITY AUTO CONFIGURATION -----------------------
#
# The following settings, TLS certificates, and keys have been automatically    
# generated to configure Elasticsearch security features on 04-08-2022 10:15:12
#
# --------------------------------------------------------------------------------

# Enable security features
xpack.security.enabled: true

xpack.security.enrollment.enabled: true

# Enable encryption for HTTP API client connections, such as Kibana, Logstash, and Agents
xpack.security.http.ssl:
  enabled: true
  keystore.path: certs/http.p12

# Enable encryption and mutual authentication between cluster nodes
xpack.security.transport.ssl:
  enabled: true
  verification_mode: certificat
  keystore.path: certs/transport.p12
  truststore.path: certs/transport.p12
# Create a new cluster with the current node only
# Additional nodes can still join the cluster later
cluster.initial_master_nodes: ["es_node_1"]

#----------------------- END SECURITY AUTO CONFIGURATION -------------------------

调整以下配置后再启动,不使用https。

xpack.security.enabled: false
xpack.security.enrollment.enabled:: false
verification_mode: none

十二、密码设置

设置密码有两种方式:自动设置密码,手动设置密码。

12.1 手动设置密码

1.在elasticsearch.yml 中添加如下配置,开启x-pack认证。

xpack.security.enabled: true
xpack.security.transport.ssl.enabled: true

2.重启es。在es bin目录下,执行手动设置密码命令:./elasticsearch-setup-passwords interactive。如图3-39所示。设置完后需重启。
在这里插入图片描述

12.2 自动设置密码

1.同手动设置密码第一步操作相同。
2.在es bin目录下,执行自动设置密码命令:./elasticsearch-setup-passwords auto。
在这里插入图片描述

12.3 修改密码

修改密码命令如下:

curl -H "Content-Type:application/json" -XPOST -u elastic 'http://127.0.0.1:9200/_xpack/security/user/elastic/_password' -d '{"password":"222222"}'
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值