在centos下安装elasticsearch

准备工作

安装jdk 见我之前的文章 在Centos下安装jdk

ES不能使用root用户执行,故新建一个角色

创建用户:elasticsearch
adduser elasticsearch

创建用户密码(8位以上符合要求的密码,共需输入两次)
passwd elasticsearch

将ES文件夹的权限赋给新用户
chown -R elasticsearch /usr/elasticsearch/elasticsearch-7.3.0

切换到新用户
su elasticsearch

新建存放的文件夹
mkdir /usr/elasticsearch

安装

将es安装包上传到服务器

解压安装包
tar -zxvf elasticsearch-7.3.0-linux-x86_64.tar.gz

进入安装目录
cd elasticsearch-7.3.0/config/

打开配置文件
vim elasticsearch.yml

cluster.name配置集群,如果是集群式分布的话,集群名字要相同

node配置节点名称与主节点配置

path配置,配置数据与日志的存储位置

es优化配置,本次先不做

网关与端口配置

在实际配置中,发现本次不涉及到集群等概念,于是关掉了集群的配置。在配置中也遇到了一些问题,具体如下:
1、本机使用curl + ip + port命令可以正确获取到json,但是外网不行。
解决:修改network.host: 0.0.0.0

2、报错failed to obtain node locks,节点绑定失败导致的启动失败,原因是有其他的es没有正常关闭。
解决:ps -ef | grep elasticsearch查到进程


使用kill -9 进程号命令可以将异常进程杀掉

3、报错信息如下:

ERROR: [2] bootstrap checks failed
[1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]

[2]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]

解决:

[1]: max file descriptors [65535] for elasticsearch process is too low, increase to at least [65536]

编辑 /etc/security/limits.conf,追加以下内容;

* soft nofile 65536
* hard nofile 65536

需要重新登录用户才会生效

[2]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]

编辑 /etc/sysctl.conf,追加以下内容:
vm.max_map_count=655360
保存后,执行:
sysctl -p

4、配置文件结尾需要加上这些代码之后,浏览器也可以访问了

http.cors.enabled: true
http.cors.allow-origin: "*"
http.cors.allow-headers: Authorization

配置完成后保存退出,进入bin目录,运行bin下的脚本,命令如下
nohup ./elasticsearch > es-start.log 2>&1 &

打开浏览器局域网内其他计算机的浏览器,输入ip:port可以看到如下页面,证明启动成功。

本次完成配置文件如下:

# ======================== 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.master: true
#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: 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: ["127.0.0.1", "192.168.9.99"]
#
# 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: "*"
http.cors.allow-headers: Authorization
#xpack.security.enabled: true
#xpack.security.transport.ssl.enabled: true

文中需要的es包地址如下:

链接:https://pan.baidu.com/s/1suM454mPYa_41IimaWVCOQ
提取码:dvdb

在centos下安装jdk

上一篇

linux 搭建 showdoc

下一篇
评论
发表评论 说点什么
还没有评论
117
1