上一篇:
(一)Elasticsearch、head、kibana环境介绍及下载 --- Elasticsearch 集群搭建
目录
1.新增es用户。
用户名:es 密码:elasticsearch
[root@es-64-02 local]# adduser es
[root@es-64-02 local]# passwd es
更改用户 es 的密码 。
新的 密码:
重新输入新的 密码:
passwd: 所有的身份验证令牌已经成功更新。
[root@es-64-02 local]# chown -R es:es /usr/local/
[root@es-64-02 local]# su es
Ps:一定要切换 用户,千万别用 root,因为es官方规定不能root用户启动es。chown -R es:es xxx 为es用户赋予权限,一定要注意,自己的文件夹。我这里是存放在 /url/local 下面的。
2.上传解压、重命名、删除es。
[es@es-64-01 local]$ pwd
/usr/local
[es@es-64-01 local]$ tar -zxvf elasticsearch-6.2.4.tar.gz
省略.........................
elasticsearch-6.2.4/modules/parent-join/parent-join-6.2.4.jar
elasticsearch-6.2.4/logs/
elasticsearch-6.2.4/plugins/
[es@es-64-01 local]$ rm -rf elasticsearch-6.2.4.tar.gz
[es@es-64-01 local]$ mv elasticsearch-6.2.4 elasticsearch
3.修改es配置。
编辑文档:
[es@es-64-02 config]$ pwd
/usr/local/elasticsearch/config
[es@es-64-02 config]$ vi elasticsearch.yml
配置解释:
#集群名称 cluster.name: es-cluster #节点名称 node.name: es-hadoop11 #数据文件存储路径 path.data: /home/es/elasticsearch-5.4.0/data #log文件存储路径 path.logs: /home/es/elasticsearch-5.4.0/logs # ip地址 network.host: 192.168.200.11 #连接端口 http.port: 9200 #这个参数来保证集群中的节点可以知道其它N个有master资格的节点。默认为1,对于大的集群来说,可以设置大一点的值(2-4) discovery.zen.minimum_master_nodes: 2 #集群中master节点的初始列表,可以通过这些节点来自动发现新加入集群的节点。 discovery.zen.ping.unicast.hosts: [“192.168.7.126”, “192.168.7.125”] discovery.zen.ping_timeout: 120s bootstrap.system_call_filter: false http.cors.enabled: true http.cors.allow-origin: “*”
10.0.1.91 配置:
# ======================== 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: my-application cluster.name: es-cluster # # ------------------------------------ Node ------------------------------------ # # Use a descriptive name for the node: # #node.name: node-1 node.name: es-91 # # 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: /usr/local/elasticsearch/data # # Path to log files: # #path.logs: /path/to/logs path.logs: /usr/local/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): # #network.host: 192.168.0.1 network.host: 10.0.1.91 # # Set a custom port for HTTP: # #http.port: 9200 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: ["10.0.1.91:9300", "192.168.5.101:9300"] discovery.zen.minimum_master_nodes: 2 # 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 discovery.zen.ping_timeout: 120s bootstrap.system_call_filter: false http.cors.enabled: true http.cors.allow-origin: "*"
10.0.1.92 配置:
# ======================== 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: es-cluster # # ------------------------------------ Node ------------------------------------ # # Use a descriptive name for the node: # node.name: es-92 # # 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: /usr/local/elasticsearch/data # # Path to log files: # path.logs: /usr/local/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): # network.host: 10.0.1.92 transport.tcp.port: 9300 # # 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.0.1.91:9300", "192.168.5.101:9300"] # # 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 discovery.zen.ping_timeout: 120s bootstrap.system_call_filter: false http.cors.enabled: true http.cors.allow-origin: "*"
192.168.5.101 配置:
# ======================== 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: my-application # # ------------------------------------ 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: /path/to/data # # Path to log files: # #path.logs: /path/to/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: 192.168.0.1 # # 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: ["host1", "host2"] # # 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 discovery.zen.ping_timeout: 120s bootstrap.system_call_filter: false http.cors.enabled: true http.cors.allow-origin: "*" discovery.zen.ping.unicast.hosts: ["10.0.1.91:9300", "192.168.5.101:9300"] discovery.zen.minimum_master_nodes: 2 http.port: 9200 transport.tcp.port: 9300 network.host: 192.168.5.101 path.logs: /home/hba/elasticsearch/logs path.data: /home/hba/elasticsearch/data node.name: es-101 cluster.name: es-cluster
4.es报错问题解决。
首先,切换到 root用户下,su root
max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]
解决办法:
vi /etc/security/limits.conf
追加配置:
* soft nofile 65536 * hard nofile 65536
max number of threads [1024] for user [es] is too low, increase to at least [4096]
解决办法:
vi /etc/security/limits.d/90-nproc.conf
把 2048 换成 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
vi /etc/sysctl.conf
最后追加一行:
vm.max_map_count=262144
5.es 启动、停止。查看
首先,启动时 切换到 es 用户,su es ,注意:绝对不能用 root 用户启动。
启动命令:
[root@es-64-01 elasticsearch]# su es [es@es-64-01 elasticsearch]$ bin/elasticsearch
后台启动
bin/elasticsearch -d
查看进程
ps -ef | grep elasticsearch
杀死进程,结束es
kill -9 pid
启动不报错,稍微等一会。启动完成:
10.0.1.91
10.0.1.92
192.168.5.101
6.集群验证。
浏览器分别访问,显示结果。
集群状态:
Ok,没什么问题。
(零)linux 从零开始搭建虚拟机集群,安装jdk,ssh免密登录 -- 小白教程
(一)Elasticsearch、head、kibana环境介绍及下载 --- Elasticsearch 集群搭建
(二)elasticsearch集群搭建及启动报错问题解决 --- Elasticsearch 集群搭建
(三)elasticsearch 安装插件 kibana 及 后台启动 --- Elasticsearch 集群搭建
(四)安装elasticsearch-head 后台启动 --- Elasticsearch 集群搭建
(五)elasticsearch 集群扩展 --- Elasticsearch 集群搭建
(六)elasticsearch 集群 网络超时解决方案 --- Elasticsearch 集群搭建