Elasticsearch单机多实例

团队新购服务器,为避免‘大材小用’采用实体跑多实例方案。本文介绍ES单机多集群多实例部署,以两台服务器为例,详述下载、创建目录、拷贝配置文件等部署步骤,还提及Elasticsearch 7.x系列配置要点,如防止相同切片、配置实例数量。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

前言

团队新采购一批大内存服务器作为Elasticsaerch节点。根据ES官网文档,单机单实例最多不超64G内存,这批服务器用于单机单实例有些"大材小用" .由于之前用docker做ES集群碰到过坑, 所以这次采用实体跑多实例的方案。

环境

ES单机多实例有两种情况,一种为单集群多实例,另外一种为多集群多实例。 本篇主要介绍单机多集群多实例的情况。

由于大多节点配置等信息都雷同,本文用两台服务器做为示例

需求架构图

es.png

部署过程

下载

node1,node2

curl -O https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.0.0-x86_64.rpm
rpm -ivh elasticsearch-7.0.0-x86_64.rpm 

创建目录

node1,node2

mkdir -p /data/elasticsearch/{t2,t1}/{data,repo,log}
chown elasticsearch. elasticsearch/ -R

拷贝配置文件

node1,node2

cd /etc/
cp -avP elasticsearch/ t1es/
cp -avP elasticsearch/ t2es/

配置文件

node1

/etc/t2es/elasticsearch.yml


cluster:
    name: t2es
    routing:
        allocation:
            same_shard.host: true
    initial_master_nodes:
        - t2-node-70
        - t2-node-71
        - ...
node:
    name: t2-node-70
    master: true
    data: true
    max_local_storage_nodes: 2
path:
    data: /data/elasticsearch/t2/data
    logs: /data/elasticsearch/t2/log
    repo: /data/elasticsearch/t2/repo
network:
    host: t2-node-70
http:
    port: 9200
transport.tcp.port: 9300
discovery.zen.ping.unicast.hosts: ["t2-node-70:9300","t2-node-71:9300" ...]
discovery.zen.fd.ping_timeout: "10s"
discovery.zen.fd.ping_retries: 10
reindex.remote.whitelist: "192.168.1.*:*"

/etc/t1es/elasticsearch.yml

cluster:
    name: t1es
    routing:
        allocation:
            same_shard.host: true
    initial_master_nodes:
        - t1-node-70
        - t1-node-71
        - ...
node:
    name: t1-node-70
    master: true
    data: true
    max_local_storage_nodes: 2
path:
    data: /data/elasticsearch/t1/data
    logs: /data/elasticsearch/t1/log
    repo: /data/elasticsearch/t1/repo
network:
    host: t1-node-70
http:
    port: 9201
transport.tcp.port: 9301
discovery.zen.ping.unicast.hosts: ["t1-node-70:9301","t1-node-71:9301" ...]
discovery.zen.fd.ping_timeout: "10s"
discovery.zen.fd.ping_retries: 10
reindex.remote.whitelist: "192.168.1.*:*"

node2

/etc/t2es/elasticsearch.yml

...

network:
    host: t1-node-70
http:
    port: 9201
transport.tcp.port: 9301
...

/etc/t1es/elasticsearch.yml

...

network:
    host: t1-node-70
http:
    port: 9201
transport.tcp.port: 9301

...

启动服务配置

node1,node2

cd /usr/lib/systemd/system
cp -avp elasticsearch.service  t2es.service
cd /etc/sysconfig
cp -avp cp -avP elasticsearch  t2es
cp -avp cp -avP elasticsearch  t1es

修改启动服务配置

node1,node2

/usr/lib/systemd/system/t2es

[Unit]
Description=t2-Elasticsearch
Documentation=http://www.elastic.co
Wants=network-online.target
After=network-online.target

[Service]
RuntimeDirectory=elasticsearch
PrivateTmp=true
Environment=ES_HOME=/usr/share/elasticsearch
Environment=ES_PATH_CONF=/etc/t2es
Environment=PID_DIR=/var/run/elasticsearch
Environment=ENV_PATH=/etc/sysconfig/t2es 
# EnvironmentFile=-/etc/sysconfig/elasticsearch  
WorkingDirectory=/usr/share/elasticsearch
User=elasticsearch
Group=elasticsearch
ExecStart=/usr/share/elasticsearch/bin/elasticsearch -p ${PID_DIR}/t2es.pid --quiet
StandardError=inherit
LimitNOFILE=65535
LimitNPROC=4096
LimitAS=infinity
LimitFSIZE=infinity
TimeoutStopSec=0
KillSignal=SIGTERM
KillMode=process
SendSIGKILL=no
SuccessExitStatus=143

[Install]
WantedBy=multi-user.target

/usr/lib/systemd/system/t1es


...
Environment=ES_PATH_CONF=/etc/t2es
Environment=PID_DIR=/var/run/elasticsearch
Environment=ENV_PATH=/etc/sysconfig/t2es 
# EnvironmentFile=-/etc/sysconfig/elasticsearch  
WorkingDirectory=/usr/share/elasticsearch
User=elasticsearch
Group=elasticsearch
ExecStart=/usr/share/elasticsearch/bin/elasticsearch -p ${PID_DIR}/t2es.pid --quiet
...

编辑/usr/share/elasticsearch/bin/elasticsearch-env

修改 source /etc/sysconfig/elasticsearch

if [ ! -z ${ENV_PATH} ]
then
    source ${ENV_PATH} 
else
    source /etc/sysconfig/elasticsearch
fi

/etc/sysconfig/t2es

所有参数配置可以在这里面加

ES_PATH_CONF=/etc/t2es
ES_STARTUP_SLEEP_TIME=5

启动

node1,node2

systemctl t1es start
systemctl t2es start

总结

  • Elasticsearch 7.x系列需要配置initial_master_nodes.
  • cluster.routing.allocation.same_shard.host防止一台主机存在多个相同切片.
  • node.max_local_storage_nodes配置一台主机可以存在的实例数量.

转载于:https://blog.51cto.com/maoyao/2400596

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值