Elasticsearch集群搭建

Elasticsearch集群搭建,第1张

Elasticsearch集群搭建 1.下载

地址:https://www.elastic.co/cn/downloads/past-releases/elasticsearch-6-4-3

2.es用户下创建目录
mkdir -p bin
mkdir -p data
mkdir -p logs
mkdir -p support
3.将6.4.3的包放入support目录下并且解压 4.修改配置
# ======================== 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: crm
#
# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:
#
node.name: node-1
#
# 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: /home/es/data
#
# Path to log files:
#
path.logs: /home/es/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):
#
network.host: 10.1.208.226
#
# Set a custom port for HTTP:
#
http.port: 9200
#
# For more information, consult the network module documentation.
#
# --------------------------------- Discovery ----------------------------------
# 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 new node is started:
# The default list of hosts is ["127.0.0.1", "[::1]"]
#
discovery.zen.ping.unicast.hosts: ["10.1.208.226","10.1.208.227","10.1.208.228"]
#
# Prevent the "split brain" by configuring the majority of nodes (total number of master-eligible nodes / 2 + 1):
#
discovery.zen.minimum_master_nodes: 2
#
# For more information, consult the zen discovery 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
http.cors.enabled: true
http.cors.allow-origin: "*"
transport.tcp.port: 9300            # 集群之间的通信端口
node.master: true                   #可选举为主节点
node.data: true                     #可用作数据节点 有的主节点配置为false 只做转发请求使用
5.启动脚本及停止脚本编写
es@server1 ~/bin $ cat start-es.sh
#!/bin/sh

cd ~/support/es/bin
./elasticsearch -d
es@server1 ~/bin $ cat stop-es.sh
#!/bin/sh

ps -ef | grep es | grep java | grep `whoami` | grep -v grep | awk '{print $2}' | while read pid
do
    kill -9 ${pid} 2>&1 >/dev/null
    echo "process id:${pid} shutdown successful!"
done
6.将es复制到其他节点 7.启动es报错


解决方法:删除安装es时设置的data文件夹,重新启动集群
由于是直接在一台单机模式配置好以后拷贝到另一台机器上的搭建的集群模式,原机器的单机模式是运行过一段时间后,又在这个基础上搭建的集群模式,存在data数据log等信息,拷贝到另一台机器上,这些文件没有删除,里面包含了一些唯一的id之类的信息,当启动集群时,id之类的冲突,因此报错,将集群中每台机器上的配置文件中指定的存放data的文件夹删除

8.删除/home/es/data 下面的文件重启即可 9.查看es集群状态

curl http://10.1.208.226:9200/_cluster/health?pretty 查看集群健康状态

curl http://ip:端口/_cat/nodes/pretty 查看集群节点

eshead查看

10.es相关集群信息命令
curl ip:端口/_cat
/_cat/allocation
/_cat/shards
/_cat/shards/{index}
/_cat/master
/_cat/nodes
/_cat/indices
/_cat/indices/{index}
/_cat/segments
/_cat/segments/{index}
/_cat/count
/_cat/count/{index}
/_cat/recovery
/_cat/recovery/{index}
/_cat/health
/_cat/pending_tasks
/_cat/aliases
/_cat/aliases/{alias}
/_cat/thread_pool
/_cat/plugins
/_cat/fielddata
/_cat/fielddata/{fields}
/_cat/nodeattrs
/_cat/repositories
/_cat/snapshots/{repository}

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5689025.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-17
下一篇 2022-12-17

发表评论

登录后才能评论

评论列表(0条)

保存