Elasticsearch集群搭建

 

创建ES用户和组

因为使用root用户执行ES程序,将会出现错误,命令如下
#使用root用户
groupadd elsearch
useradd elsearch -g elsearch
chown -R elsearch:elsearch elasticsearch-6.3.2  #该命令是更改该文件夹下所属的用户组的权限

 

创建ES数据文件和日志文件

这个要和下一步配置的里面的路径相同
#使用root用户
mkdir /path
chown -R elsearch:elsearch /path/
su elsearch #切换用户
mkdir -p to/data
mkdir -p to/logs

 

修改ES配置文件

vi /usr/elasticsearch-6.3.2/config/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-1
node.master: true
node.data: true
#
# 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: /path/to/data
#
# Path to log files:
#
path.logs: /path/to/logs
#
# ----------------------------------- Memory -----------------------------------
#
# Lock the memory on startup:
#
# 解决错误:max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]
bootstrap.memory_lock: false
#
# 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: 192.168.10.151
#
# Set a custom port for HTTP:
#
http.port: 9200
transport.tcp.port: 9300

#
# 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: ["host1", "host2"]
discovery.zen.ping.unicast.hosts: ["192.168.10.151", "192.168.10.152", "192.168.10.153"]
#
# Prevent the "split brain" by configuring the majority of nodes (total number of master-eligible nodes / 2 + 1):
#
#discovery.zen.minimum_master_nodes: 
#
# 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

# ---------------------------------- Head plugins ----------------------------------- 
http.cors.enabled: true 
http.cors.allow-origin: "*"


使用服务器ip为,配置文件修改为对应的ip:
192.168.10.151 主节点 node-1
192.168.10.152 从节点 node-2
192.168.10.153 从节点 node-3

 

启动es

进入到bin 目录下执行 ./elasticsearch 命令,执行 ./elasticesrarch -d 是后台运行   
如果没有什么问题话,执行curl 'http://192.168.10.151:9200/' 命令,就出现下面的结果

Elasticsearch集群搭建

使用head插件连接

Elasticsearch集群搭建

 

错误整理

错误:max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]
1. vi /usr/elasticsearch-6.3.2/config/elasticsearch.yml
bootstrap.memory_lock: false #这个地方默认是true,改一下就好了;
2. vi /etc/security/limits.conf 添加以下:
* soft nofile 65536
* hard nofile 131072
* soft nproc 2048
* hard nproc 4096


错误:max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
执行命令:
sysctl -w vm.max_map_count=262144
查看结果:
sysctl -a|grep vm.max_map_count
永久修改,root用户
在 vi /etc/sysctl.conf文件最后添加一行
vm.max_map_count=262144

 

上一篇:linux/centos elasticsearch 环境搭建 安装 运行 使用


下一篇:elk安装与搭建