Elasticsearch-7.15.2 集群搭建

準(zhǔn)備工作:

1、準(zhǔn)備3臺(tái)服務(wù)器,確?;ハ嘀澳躳ing通
172.30.12.215
172.30.12.218
172.30.13.201
2、系統(tǒng):centos7.4
3、機(jī)器已經(jīng)安裝好jdk

一、下載 es

官網(wǎng)下載地址:https://www.elastic.co/cn/downloads/elasticsearch

image.png

二、安裝 es

1、將es解壓到 /opt目錄下

tar -zxvf elasticsearch-7.15.2-linux-x86_64.tar.gz -C /opt

2、重命名(可忽略)

mv elasticsearch-7.15.2 elasticsearch

3、創(chuàng)建目錄

mkdir /opt/elasticsearch/data

三、修改配置文件

#集群名字,三臺(tái)集群的集群名字都必須一致
cluster.name: es
#指定主節(jié)點(diǎn)  7.1版本后不配置會(huì)報(bào)錯(cuò)master not discovered yet
cluster.initial_master_nodes: ["node-1"]
#當(dāng)前節(jié)點(diǎn)名字
node.name: node-1
#該節(jié)點(diǎn)是否有資格選舉為master
node.master: true
#存儲(chǔ)索引數(shù)據(jù),三臺(tái)都設(shè)為true即可
node.data: true
#數(shù)據(jù)位置
path.data: /opt/elasticsearch/data
#日志位置
path.logs: /opt/elasticsearch/logs
#鎖住物理內(nèi)存,不使用swap內(nèi)存,有swap內(nèi)存的可以開啟此項(xiàng)
bootstrap.memory_lock: false
bootstrap.system_call_filter: false
network.host: 0.0.0.0
http.port: 9200
transport.tcp.port: 9300
#設(shè)置集群的初始節(jié)點(diǎn)列表,集群互通端口為9300
discovery.zen.ping.unicast.hosts: ["172.30.13.201:9300","172.30.12.215:9300","172.30.12.218:9300"]
#集群最小主節(jié)點(diǎn)數(shù)目
discovery.zen.minimum_master_nodes: 2
#發(fā)現(xiàn)超時(shí)時(shí)間
discovery.zen.ping_timeout: 3s

將配置好的es分發(fā)到其他兩臺(tái)服務(wù)器上:

scp -r /opt/elasticsearch root@172.30.12.215:/opt/
scp -r /opt/elasticsearch root@172.30.12.218:/opt/

四、調(diào)優(yōu)

1、jvm調(diào)優(yōu)

vim /opt/elasticsearch/config/jvm.options

-Xms1g   修改為 ===>  -Xms4g
-Xmx1g   修改為 ===>  -Xmx4g

設(shè)置為物理內(nèi)存一半最佳,可根據(jù)服務(wù)器內(nèi)存去選擇調(diào)

2、操作系統(tǒng)調(diào)優(yōu)(必須配置,否則ES起不來)

  • 在/etc/sysctl.conf添加如下內(nèi)容
fs.file-max=655360
vm.max_map_count=655360

sysctl -p生效

解釋:
(1)fs.file-max=655360
系統(tǒng)最大打開文件描述符數(shù)
(2)vm.max_map_count=655360
限制一個(gè)進(jìn)程擁有虛擬內(nèi)存區(qū)域的大小
不修改可能啟動(dòng)報(bào)錯(cuò):

max file descriptors [65535] for elasticsearch process is too low, increase to at least [65536]
  • 編輯 /etc/security/limits.conf,追加以下內(nèi)容;
* soft nofile 65536
* hard nofile 65536

解釋:nofile-最大打開文件描述符
不修改可能啟動(dòng)報(bào)錯(cuò):

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

此文件修改后需要重新登錄用戶,才會(huì)生效

五、創(chuàng)建普通用戶

因?yàn)閑s不允許root用戶啟動(dòng)

groupadd es
useradd es -g es -p es
chown -R es:es /opt/elasticsearch
su es

六、啟動(dòng)

三臺(tái)服務(wù)上依次啟動(dòng)es

/opt/elasticsearch/bin/elasticsearch

瀏覽器訪問:http://172.30.13.201:9200/_cat/nodes?v
如果節(jié)點(diǎn)都啟動(dòng)成功,會(huì)顯示:

image.png

七、設(shè)置最大分頁(yè)數(shù)

查看當(dāng)前設(shè)置

curl -XGET 127.0.0.1:9200/索引名/_settings

返回

{
    "scorpus": {
        "settings": {
            "index": {
                "routing": {
                    "allocation": {
                        "include": {
                            "_tier_preference": "data_content"
                        }
                    }
                },
                "refresh_interval": "1s",
                "number_of_shards": "5",
                "provided_name": "scorpus",
                "creation_date": "1655454636590",
                "store": {
                    "type": "fs"
                },
                "number_of_replicas": "1",
                "uuid": "7_0BCh28QxWUoiehWRb62w",
                "version": {
                    "created": "7150299"
                }
            }
        }
    }
}

這里沒有 max_result_window配置,es采用的是默認(rèn)的10000。使用以下命令修改

curl -XPUT 127.0.0.1:9200/scorpus/_settings -H 'content-Type:application/json' -d '{"index.max_result_window":"1000000"}'

修改成功后返回

{"acknowledged":true}

再次查看設(shè)置,就能看到設(shè)置的最大值

{
    "scorpus": {
        "settings": {
            "index": {
                "routing": {
                    "allocation": {
                        "include": {
                            "_tier_preference": "data_content"
                        }
                    }
                },
                "refresh_interval": "1s",
                "number_of_shards": "5",
                "provided_name": "scorpus",
                "max_result_window": "1000000",
                "creation_date": "1655454636590",
                "store": {
                    "type": "fs"
                },
                "number_of_replicas": "1",
                "uuid": "7_0BCh28QxWUoiehWRb62w",
                "version": {
                    "created": "7150299"
                }
            }
        }
    }
}

注意:
1、此方法是設(shè)置單索引,如果需要更改索引需要將scorpus換成_all
2、即使換成_all,對(duì)于新增的索引,還是默認(rèn)的10000

八、常用命令

#查看所有索引
http://127.0.0.1:9200/_cat/indices
#刪除所有索引
curl -X DELETE 'http://localhost:9200/_all'

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容