镇江市建设招标网官方网站,网络企业做网站,作文网投稿,影响网站建设的关键点elasticsearch#xff08;集群#xff09;
案例版本#xff1a;elasticsearch 8.6.2
操作系统#xff1a;CentOS 7 注意#xff1a;全程使用普通用户操作。 0、节点信息
节点描述192.168.127.10master192.168.127.11slave…slave02
1、环境配置
1.1 修改文件 /etc/se…elasticsearch集群
案例版本elasticsearch 8.6.2
操作系统CentOS 7 注意全程使用普通用户操作。 0、节点信息
节点描述192.168.127.10master192.168.127.11slave…slave02
1、环境配置
1.1 修改文件 /etc/security/limits.conf
# 添加以下内容
* soft nofile 65536
* hard nofile 65536
* soft nproc 65536
* hard nproc 65536# 重启服务配置
systemctl daemon-reload1.2 修改文件 /etc/sysctl.conf
系统虚拟内存默认最大映射数为65530无法满足ES系统要求需要调整为262144以上。
vm.max_map_count655360
# 重新加载生效
sysctl -p1.3 调整JVM运行内存
修改使用的内存。可以视内存情况设定生产一般建议是机器内存的一半且不超过32G。
vi elasticsearch-8.6.2/config/jvm.options
# 新增
-Xms2g
-Xmx2g2、上传解压
# 所有节点上传安装目录并解压
tar -zxvf elasticsearch-6.8.23.tar.gz3、密码证书认证设置
3.1 生成证书
# 进入安装bin目录
cd elasticsearch-8.6.2/
./bin/elasticsearch-certutil ca
# 第一个是描述不填跳过第二是密码输入123456设置自己的密码
# 会生成elastic-stack-ca.p12的文件3.2 生成密钥
./bin/elasticsearch-certutil cert --ca elastic-stack-ca.p12
# 输入上一步的密码123456要输入路径直接回车生成在当前目录下3.3 迁移凭证地址到config目录下
# 创建目录
mkdir ./config/certs
# 移动凭证至指定目录下
mv ./elastic-certificates.p12 ./config/certs/# 移动凭证至集群其他节点
scp config/certs/elastic-certificates.p12 user192.168.127.11:/home/elasticsearch/elasticsearch-8.6.2/config/certs/3.4 各个集群节点都添加keystore密码
# 输入生成证书时的密码123456
./bin/elasticsearch-keystore add xpack.security.transport.ssl.keystore.secure_password
./bin/elasticsearch-keystore add xpack.security.transport.ssl.truststore.secure_password4、elasticsearch.yml配置
master配置
# 集群名称
cluster.name: my-application
# 结点名称 多个结点名称不同
node.name: node_1
# 日志和索引存储地址
path.data: /home/elasticsearch/es_data
path.logs: /home/elasticsearch/es_logs
# 服务器地址
network.host: 192.168.127.10
# 端口号
http.port: 9200
# 其他结点的路径
discovery.seed_hosts: [192.168.127.10, 192.168.127.11]
cluster.initial_master_nodes: [node_1, node_2]# 设置证书密码访问 下面会说怎么生成证书
xpack.security.enabled: true
xpack.security.transport.ssl.enabled: true
xpack.security.transport.ssl.verification_mode: certificate
xpack.security.transport.ssl.keystore.path: /home/elasticsearch/elasticsearch-8.6.2/config/certs/elastic-certificates.p12
xpack.security.transport.ssl.truststore.path: /home/elasticsearch/elasticsearch-8.6.2/config/certs/elastic-certificates.p12# 服务器启动会主动连接GeoLite2一种免费的IP地理位置数据库不需要时禁用不然会报错
ingest.geoip.downloader.enabled: falseslave配置如果多个节点根据需要同样配置多个就行
# 集群名称
cluster.name: my-application
# 结点名称 多个结点名称不同
node.name: node_2
# 日志和索引存储地址
path.data: /home/elasticsearch/es_data
path.logs: /home/elasticsearch/es_logs
# 服务器地址
network.host: 192.168.127.11
# 端口号
http.port: 9200
# 其他结点的路径
discovery.seed_hosts: [192.168.127.10, 192.168.1127.11]
cluster.initial_master_nodes: [node_1, node_2]# 设置证书密码访问
xpack.security.enabled: true
xpack.security.transport.ssl.enabled: true
xpack.security.transport.ssl.verification_mode: certificate
xpack.security.transport.ssl.keystore.path: /home/elasticsearch/elasticsearch-8.6.2/config/certs/elastic-certificates.p12
xpack.security.transport.ssl.truststore.path: /home/elasticsearch/elasticsearch-8.6.2/config/certs/elastic-certificates.p12# 服务器启动会主动连接GeoLite2一种免费的IP地理位置数据库不需要时禁用不然会报错
ingest.geoip.downloader.enabled: false5、启动ES服务
elasticsearch 不要用root用户启动。
cd elasticsearch-6.8.23/bin
./elasticsearch
# 后台启动
./elasticsearch -d6、设置集群访问密码
需要先正常启动ES服务。 会设置很多密码 elasticapm_systemkibanakibana_systemlogstash_systembeats_system这里全部设置成了123456
./bin/elasticsearch-setup-passwords interactive重置/更新密码 ./bin/elasticsearch-reset-password -u elastic7、浏览器访问
# 可以单独访问每台服务器
# 需要输入账号密码elastic 123456
http://192.168.127.10:9200
http://192.168.127.11:9200# 查看各节点情况
http://192.168.127.10:9200/_cat/nodeselasticsearch.yml 配置说明
# ---------------------------------- Cluster -----------------------------------
# 多台服务器同一集群名称要一致不同集群名称要保持唯一性。
cluster.name: my-application # 集群名称# ------------------------------------ Node ------------------------------------
# 同一集群下节点要保持唯一性。
node.name: node-1 # 节点名称# 主节点负责管理集群级别的任务例如对索引进行分片和副本分配以及协调节点之间的数据复制和恢复过程。当一个主节点失效时会重新选举一个新的主节点一个集群中最好只有少数几个主节点以避免过多的选举和资源浪费。
node.master: true # 是否可以被选举为主节点# 数据节点在一个集群中数据节点负责存储和处理数据即对文档增删改查、聚合等操作。
node.data: true # 是否可以存储数据
# 为了确保集群的稳定性和可靠性建议集群中至少设置3个节点。在这种情况下可以设置2个数据数据1个主节点。# ----------------------------------- Paths ------------------------------------
# 每个节点应该有一个独立的数据目录。如果要在多个节点建立集群应该为每个节点设置不同的数据目录。
# 这样可以通过在每个节点上设置不同的路径来实现。这样每个节点的数据都可以独立存储不会出现冲突如
# node1
# path.data: /data/es/node1/data
# node2:
# path.data: /data/es/node2/data
path.data: /path/to/data # 数据目录# 和数据目录一样每个节点应该有一个独立的日志目录。可以通过在每个节点上设置不同的路径来实现
path.logs: /path/to/logs # 日志目录
# 默认es的日志和数据存储放在es的安装目录这种在升级情况下很容易被删掉。推荐指定非安装目录的路径# ---------------------------------- Network -----------------------------------
# 设置为所在主机ip。帮助每个节点找到其他节点以便节点能够识别并通信从而建立集群
network.host: 192.168.0.1 # 节点绑定的IP或域名
#
# network.host: 0.0.0.0 会将节点绑定到所有的网络接口和IP地址上这可能导致安全和通信问题
# 安全问题
# ES将在所有可用的网络接口上公开使得它更容易遭受攻击。攻击者可直接通过任何可用的网络接口访问ES而不需要任何认证和授权。这可能导致数据泄露、损坏和其他问题。
# 通信问题
# 将ES绑定到所有可用的网络接口上可能导致网络问题。可能出现网络堵塞、延迟和其他通信问题从而影响集群的性能和可用性。
# 因此建议将network.host设置为节点的实际IP和主机名以确保节点绑定到正确的接口和地址。这样每个节点才能找到其他节点从而建立集群。# 如果同一台设备上运行多个ES则需要设置不同的值。
# 如果不想使用HTTP API可以设置 http.port: -1以禁用API。这将使ES只能通过Transport API进行通信。
# 但如果使用Kibana或其他工具与ES进行交互则需要启用HTTP API
http.port: 9200 # HTTP API监听的端口号。http请求端口# --------------------------------- Discovery ----------------------------------
# 集群中节点通信的端口。在构建集群通信时必须有这个配置否则无法建立通信
transport.tcp.port: 9300# 指定了要用于发现其他节点的主机列表。在建立集群时可以将已知的节点IP或主机名添加到此列表中
# 默认为空这意味着节点将不会主动发现其他节点。如果是建立集群需要设置此项包含其他节点以便在启动时找到其他节点。
discovery.seed_hosts: [host1, host2]
# 不需要设置端口因为在ES中节点之间通信默认使用9300端口传输、协调和9200端口用于HTTP REST API# 指定集群中初始主节点。在启动集群时必须指定一个或多个初始主节点。默认为“node-1”
# 指定多个节点时ES会在启动时会在其中选择一个初始主节点。
# 一般数量为奇数以便在发生故障时能够进行正确的投票和决策。
cluster.initial_master_nodes: [node-1, node-2]# ---------------------------------- Various -----------------------------------
# 默认为1。这意味着当集群中启动一个节点时就开始执行恢复操作。但如果集群节点数量太少则可能导致性能下降。因此可以指定启动多少个节点后才开始执行恢复操作这个设置可以优化集群的性能和可用性。
# 恢复操作是指节点重启或加入集群时ES自动恢复丢失或损坏的所以分片。索引分片是ES中的基本存储单元它将索引数据分成多个部分以便分布式存储和处理。
# 当一个节点重启或加入集群时它会丢失一部分索引分片导致数据不完整或不可用。为了解决这个问题ES会自动执行恢复操作将丢失的分片从其他节点复制回来。
gateway.recover_after_nodes: 3# --------------------------------------------------------------------------------
# 允许来自任何地方的HTTP API连接
# 连接是加密的需要用户认证
http.host: 0.0.0.0es部署–常见问题
1、更新地图数据库
1.1 问题
[ERROR][o.e.i.g.GeoIpDownloader] [node-1] exception during geoip databases updateorg.elasticsearch.ElasticsearchException: not all primary shards of [.geoip_databases] index are active解决
修改 elasticsearch.yml
# ES启动时会去更新地图的一些数据库直接禁掉即可
ingest.geoip.downloader.enabled: false2、启动后无法访问
2.1 浏览器无法访问
原因是Elasticsearch在Windows下开启了安全认证虽然started成功但访问http://localhost:9200/失败。
[WARN ][o.e.x.s.t.n.SecurityNetty4HttpServerTransport] [node-1] received
plaintext http traffic on an https channel, closing connection Netty4HttpChannel
{localAddress/172.168.102.183:9200, remoteAddress/172.168.161.66:49222}解决 修改 elasticsearch.yml
# 把安全认证开关从原先的true都改成false实现免密登录访问即可
xpack.security.enabled: false # 改成falsexpack.security.enrollment.enabled: true# Enable encryption for HTTP API client connections, such as Kibana, Logstash, and Agents
xpack.security.http.ssl:enabled: false # 改成falsekeystore.path: certs/http.p122.2 其他设备无法访问
本地 curl localhost:9200 成功访问其它机器通过ip无法访问。
$ vi elasticsearch-6.8.23/config/elasticsearch.yml
# 配置所有用户可访问
network.host: 0.0.0.03、启动报错
3.1 which: no java in
$ ./bin/elasticsearch
which: no java in (/opt/gvm/jdk1.8/bin:/bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/home/gvmuser/.local/bin:/home/gvmuser/bin:/home/gvmuser/jdk1.8/bin:/home/gvmuser/jdk1.8/jre/bin)
warning: Falling back to java on path. This behavior is deprecated. Specify JAVA_HOME
could not find java; set JAVA_HOME解决 安装jdk。
3.2、max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]
ERROR: [1] bootstrap checks failed
[1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65535]解决
vi /etc/security/limits.conf
# 追加以下内容
* soft nofile 65536
* hard nofile 65536
# 重启服务配置
systemctl daemon-reload
# 或修改后重新登录终端使其生效3.3、max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
系统虚拟内存默认最大映射数为65530无法满足ES系统要求需要调整为262144以上。
ERROR: [1] bootstrap checks failed
[1]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]解决
vi /etc/sysctl.conf
#添加参数
vm.max_map_count 262144#重新加载生效
sysctl -p4、GeoLite2-ASN.mmdb的数据库 遇到问题的版本elasticsearch-8.6.2 [ERROR][o.e.i.g.GeoIpDownloader ] [node-1] error downloading geoip database [GeoLite2-ASN.mmdb]
java.net.SocketTimeoutException: Connect timed out解决
GeoLite2/GeoIP全球ASN-IP离线定位库官网地址https://dev.maxmind.com/geoip/geolocate-an-ip?langen
现在并不需要这个库但是elasticsearch启动却需要连接这个库所以需要将这个连接的配置关闭让启动的时候不去连接这个库。
vim config/elasticsearch.yml
# 添加配置
ingest.geoip.downloader.enabled: false5、无法发现其他节点
master not discovered yet, this node has not previously joined a bootstrapped cluster, and this node must discover master-eligible nodes [node-1, node-2] to bootstrap a cluster: have discovered [{node-1}{l_KqE-gYTimBZbrvK9ijsQ}{2dYWd9TWTyqQToa-g8wB1w}{node-1}{192.168.127.10}{192.168.127.10:9300}{cdfhilmrstw}]; discovery will continue using [192.168.127.11:9300] from hosts providers and [{node-1}{l_KqE-gYTimBZbrvK9ijsQ}{2dYWd9TWTyqQToa-g8wB1w}{node-1}{192.168.127.10}{192.168.127.10:9300}{cdfhilmrstw}] from last-known cluster state; node term 0, last-accepted version 0 in term 0解决
# 查看防火墙状态
service firewalld status
# 发现防火墙是开着的 Active: active (running)# 关闭防火墙
service firewalld stop6、集群UUID
This node is a fully-formed single-node cluster with cluster UUID [ObqnTkiHQiGyFc5H2yywCQ], but it is configured as if to discover other nodes and form a multi-node cluster via the [discovery.seed_hosts[192.168.127.11]] setting. Fully-formed clusters do not attempt to discover other nodes, and nodes with different cluster UUIDs cannot belong to the same cluster. The cluster UUID persists across restarts and can only be changed by deleting the contents of the nodes data path(s). Remove the discovery configuration to suppress this message.解决 在新建集群之前启动过需删除data目录。
7、分词器不能使用
对应找不到 plugin-descriptor.properties文件。
java.lang.IllegalStateException: Could not load plugin descriptor for plugin directory [elasticsearch-analysis-ansj-8.3.3]
Likely root cause: java.nio.file.NoSuchFileException: /home/hd/elasticsearch-8.3.3/plugins/
elasticsearch-analysis-ansj-8.3.3/plugin-descriptor.properties解决 原因是压缩包的内容不够完整下载时应该在官网下载elasticsearch-analysis-ik-版本号.zip而不是source code.zip与elasticsearch-analysis-ansj-8.3.3.tar.gz。
传送门【部署ik分词器】 传送门【部署kibana可视化平台】