centos系统安装elasticsearch

本文档详细介绍了在CentOS系统上安装Elasticsearch 7.1.1的过程,包括安装JDK1.8,解压Elasticsearch压缩文件,创建新用户,配置文件权限和系统参数调整,解决max virtual memory areas和max file descriptors问题,以及成功访问Elasticsearch的验证方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.安装过程

  环境:软件xshell6,xftp6,JDK1.8安装文件,elasticsearch7.1.1zip.gz文件

1.1.安装JDK1.8

首先是上传JDK1.8的文件,这里通过xft6进行上传

修改JDK的环境变量,path ,JAVA_HOME ,classpath

在root用户下,修改配置文件

# vi /etc/profile

接下来在文件末尾增加如下代码:

export JAVA_HOME=/java/jdk1.8.0_131
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib

然后更新下,这样子不仅root用户的JDK 环境可以配置,elastic search环境也可以配置。(为安装elasticsearch 需要新增加用户做铺垫)

#  source /etc/profile

 

1.2解压文件

接下来解压,上传的elasticsearch压缩文件,这里选择的安装包是elasticsearch-7.1.1-linux-x86_64.tar.gz,

这里是在root环境下进行的解压(也只能如此,博主尝试在elastic用户解压,权限不予许),这里存放的路径是

/usr/local/software/elasticsearch-7.1.1

# tar -zxvf elasticsearch-7.1.1-linux-x86_64.tar.gz

1.3创建新的用户

# 创建用户组
groupadd es
# 创建用户
useradd -g es elastic
# 切换到elastic用户
su elastic
#设置用户密码 ,后续sudo的时候会用到
 passwd  elastic

1.4文件赋予权限

# 更改elasticsearch目录拥有者
chown elastic:es -R elasticsearch-7.1.1

1.5修改elastic配置文件

#编辑elasticsearch配置文件
#vi 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: 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: false
bootstrap.system_call_filter: 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: 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: ["host1", "host2"]
#
# 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: "*"

1)解决启动elasticsearch的时候,bootstrap的相关报错bootstrap checks failed

      bootstrap.memory_lock: false
      bootstrap.system_call_filter: false 

2)解决外部浏览器可以访问的问题

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

     network.host: 0.0.0.0 

3)重要设置

cluster.initial_master_nodes: ["node-1"]

2.安装碰到的问题

2.1报错max virtual memory areas vm.max_map_count [65530] is too low, increase to at least

etc/sysctl.conf 中添加上

vm.max_map_count=655360  保存然后执行

sysctl -p

2.2max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]

#切换到root用户修改
vim /etc/security/limits.conf

# 在最后面追加下面内容 *表示所有用户,记得其后有空格
* hard nofile 65536
* soft nofile 65536

2.3sudo命令的配置

# 配置文件位置
/etc/sudoers
## Allow root to run any commands anywhere 
root    ALL=(ALL)       ALL
#在这里添加,elsatic是普通用户
elastic ALL=(ALL)       ALL

 

3.成功的访问

curl 127.0.0.1:9200

以及外部浏览器的访问 http://202.79.163.123:9200/

成功截图

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值