Elasticsearch - 部署集群
安装
elasticsearch 在新版本中已经自带了 jdk,不需要另外安装。
version="7.6.1"
cd $HOME
package_url="https://mirrors.huaweicloud.com/elasticsearch/${version}/elasticsearch-${version}-linux-x86_64.tar.gz"
wget -c ${package_url} || exit 1
tar zxvf elasticsearch-${version}-linux-x86_64.tar.gz
mv elasticsearch-${version} /opt/
cd /opt/
ln -sf elasticsearch-${version} elasticsearch
修改内核参数
echo vm.max_map_count=262144 >> /etc/sysctl.conf
sysct -p
修改句柄限制
echo "* soft nofile 65536" >> /etc/security/limits.conf
echo "* hard nofile 131072" >> /etc/security/limits.conf
创建数据目录
mkdir -p /data/elasticsearch/data
mkdir -p /data/elasticsearch/logs
创建运行用户
useradd elasticsearch
修改目录权限
chown -v elasticsearch:elasticsearch /opt/elasticsearch /opt/elasticsearch-${version} /data/elasticsearch/ -R
集群配置
集群,节点可以在同一台机器,也可以在不同的机器上。安装过程都是一样的。如果是在同一台机器,就安装到不同的目录即可。
实验机器 IP:
192.168.122.101
192.168.122.102
192.168.122.103
修改配置文件
cd /opt/elasticsearch/config
vim elasticsearch.yml
修改对应的配置(看备注)
# ======================== Elasticsearch Configuration =========================
#
# NOTE: Elasticsearch comes with reasonable defaults for most settings.
# Before you set out to tweak and tune the configuration, make sure you
# understand what are you trying to accomplish and the consequences.
#
# The primary way of configuring a node is via this file. This template lists
# the most important settings you may want to configure for a production cluster.
#
# Please consult the documentation for further information on configuration options:
# https://www.elastic.co/guide/en/elasticsearch/reference/index.html
#
# ---------------------------------- Cluster -----------------------------------
#
# Use a descriptive name for your cluster:
# 这里是集群名称,确定每个节点的配置的名称是一样的即可。
cluster.name: myes
#
# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:
# 节点名称,不同节点使用不同的名称
node.name: node-192.168.122.101
#
# Add custom attributes to the node:
#
#node.attr.rack: r1
#
# ----------------------------------- Paths ------------------------------------
#
# Path to directory where to store the data (separate multiple locations by comma):
# 数据目录
path.data: /data/elasticsearch/data
#
# Path to log files:
# 日志目录
path.logs: /data/elasticsearch/logs
#
# ----------------------------------- Memory -----------------------------------
#
# Lock the memory on startup:
#
#bootstrap.memory_lock: true
#
# Make sure that the heap size is set to about half the memory available
# on the system and that the owner of the process is allowed to use this
# limit.
#
# Elasticsearch performs poorly when the system is swapping the memory.
#
# ---------------------------------- Network -----------------------------------
#
# Set the bind address to a specific IP (IPv4 or IPv6):
# 设置当前的ip地址,通过指定相同网段的其他节点会加入该集群中,不同节点,填写节点通讯IP
network.host: 192.168.122.101
#
# Set a custom port for HTTP:
# 服务端口
http.port: 9200
#
# For more information, consult the network module documentation.
#
# --------------------------------- Discovery ----------------------------------
#
# Pass an initial list of hosts to perform discovery when this node is started:
# The default list of hosts is ["192.168.122.101", "[::1]"]
# 集群初始化查找列表
discovery.seed_hosts: ["192.168.122.101", "192.168.122.102", "192.168.122.103"]
#
# Bootstrap the cluster using an initial set of master-eligible nodes:
# 集群初始化节点
cluster.initial_master_nodes:
["node-192.168.122.101", "node-192.168.122.102", "node-192.168.122.103"]
#
# For more information, consult the discovery and cluster formation module documentation.
#
# ---------------------------------- Gateway -----------------------------------
#
# Block initial recovery after a full cluster restart until N nodes are started:
#
#gateway.recover_after_nodes: 3
#
# For more information, consult the gateway module documentation.
#
# ---------------------------------- Various -----------------------------------
#
# Require explicit names when deleting indices:
#
#action.destructive_requires_name: true
切换用户
运行的时候需要用普通用户去启动。
su - elasticsearch
启动服务
/opt/elasticearch/bin/elasticsearch -d
测试
创建索引
curl -XPUT http://192.168.122.101:9200/testindex
{"acknowledged":true,"shards_acknowledged":true,"index":"testindex"}
查看所有的索引
curl 'http://192.168.122.101:9200/_cat/indices?v'
health status index uuid pri rep docs.count docs.deleted store.size pri.store.size
yellow open testindex BliIJCoYQiW4TL_L_26zeg 1 1 1 0 0b 0b
删除索引
curl -X DELETE http://192.168.122.101:9200/testindex
{"acknowledged":true}
添加文档(如果索引不存在会自动创建索引)
curl -H "Content-Type: application/json" -XPUT 'http://192.168.122.101:9200/testindex/external/1' -d '{"name": "OPcai"}'
总结
可以安装 cerebro 查看集群的状态。
- 原文作者:Linux运维菜
- 原文链接:https://www.opcai.top/post/2020/2020-03/install_elasticsearch_cluster/
- 版权声明:本作品采用进行许可,非商业转载请注明出处(作者,原文链接),商业转载请联系作者获得授权。