Linux CentOS7 单机部署elasticsearch-7.2.0 - Go语言中文社区

Linux CentOS7 单机部署elasticsearch-7.2.0


一、安装环境

[es@localhost bin]$ cat /etc/redhat-release 
CentOS Linux release 7.6.1810 (Core)

二、安装包

获取安装包

wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.2.0-linux-x86_64.tar.gz

在这里插入图片描述

三、修改配置文件

tar -zxvf elasticsearch-7.2.0-linux-x86_64.tar.gz -C /opt/
cd /opt/elasticsearch-7.2.0
vim config/elasticsearch.yml	#修改配置文件

修改内容:

cluster.name: my-application	#集群名
node.name: node-1	#节点名称
path.data: /data/es/data	#数据存储路径
path.logs: /data/es/logs	#日志存储路径
network.host: 192.168.110.112	#本机IP,可以写0.0.0.0
http.port: 9200	#访问端口
discovery.seed_hosts: ["127.0.0.1:9200"]	#通信地址
cluster.initial_master_nodes: ["node-1"]	#master节点名称
http.cors.enabled: true #是否支持跨域,默认为false
http.cors.allow-origin: "*"	#当设置允许跨域,默认为*,表示支持所有域名
mkdir -p /data/es/data	#创建data目录
mkdir -p /data/es/logs	#创建log目录
useradd es	#创建es用户
echo 123456| passwd --stdin es	#设置es密码
chown -R es:es /opt/elasticsearch-7.2.0	#将目录赋予es
chown -R es:es /data/es/	#将目录赋予es

分配系统资源

vim /etc/security/limits.conf

末尾追加以下内容

* soft nofile 65536
* hard nofile 65536
* soft nproc 4096
* hard nproc 4096
vim /etc/sysctl.conf

末尾追加以下内容

vm.max_map_count=655360

刷新

sysctl -p

配置文件示例

# ======================== 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: /data/elasticsearch/data
#
# Path to log files:
#
path.logs: /data/elasticsearch/log
#
# ----------------------------------- 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: 0.0.0.0
#
# 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 ["127.0.0.1", "[::1]"]
#
discovery.seed_hosts: ["0.0.0.0:9200"]
#
# Bootstrap the cluster using an initial set of master-eligible nodes:
#
cluster.initial_master_nodes: ["node-1"]
#
# 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
http.cors.enabled: true
http.cors.allow-origin: "*"                                    

四、启动

7.2版本自带JDK所以不用安装,要使用自己的Java版本,请设置JAVA_HOME环境变量。

su - es
sh /opt/elasticsearch-7.2.0/bin/elasticsearch

脚本

#! /bin/bash    
kill -9 $(ps -ef|grep elasticsearch-7.2.0/jdk/bin/java|grep -v grep |awk '{print $2}')
nohup bin/elasticsearch > ./log.out 2>&1 &
tail -f log.out

浏览器输入:http://192.168.110.112:9200/
在这里插入图片描述
启动成功

五、报错

1、bootstrap checks failed

详情: 一共有3个报错,都是系统资源分配不足导致的

[2019-07-01T17:48:05,527][INFO ][o.e.b.BootstrapChecks    ] [node-1] bound or publishing to a non-loopback address, enforcing bootstrap checks
ERROR: [3] bootstrap checks failed
[1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65535]
[2]: max number of threads [3795] for user [es] is too low, increase to at least [4096]
[3]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]

解决:

vim /etc/security/limits.conf

末尾追加以下内容

* soft nofile 65536
* hard nofile 65536
* soft nproc 4096
* hard nproc 4096
vim /etc/sysctl.conf

末尾追加以下内容

vm.max_map_count=655360

刷新

sysctl -p
版权声明:本文来源CSDN,感谢博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
原文链接:https://blog.csdn.net/qq_39680564/article/details/94399977
站方申明:本站部分内容来自社区用户分享,若涉及侵权,请联系站方删除。

0 条评论

请先 登录 后评论

官方社群

GO教程

猜你喜欢