首页 > 其他 > 详细

Elasticsearch单机多实例

时间:2019-05-28 11:06:28      阅读:171      评论:0      收藏:0      [点我收藏+]
前言

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

环境

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

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

需求架构图

技术分享图片

部署过程

下载

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配置一台主机可以存在的实例数量.

Elasticsearch单机多实例

原文:https://blog.51cto.com/maoyao/2400596

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!