Linux(Centos7) 搭建 Elasticsearch-7.7.0 环境(单机)

环境

  • Linux(Centos 7)
  • ElasticSerach 7.7.0
  • JDK 1.8

安装ES

切换到 root 用户
su root
进入到 /opt 下 创建 /es 文件夹
cd /opt 
mkdir es
进入到es文件夹内下载 elasticsearch-7.7.0

下载

[root@localhost es]# wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.7.0-linux-x86_64.tar.gz

解压elasticsearch安装包

[root@localhost es]# tar -xf elasticsearch-7.7.0-linux-x86_64.tar.gz

修改配置文件 elasticsearch.yml :

[root@localhost es]# vim elasticsearch-7.7.0/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: 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):
# 可以定义为0.0.0.0,表示允许所有ip访问。但是这样不太安全,可以定义为当前虚拟机的ip
# 如果是桥接模式的话,ip可能会变,虚拟机建议使用0.0.0.0
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:
#  与node.name对应
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

修改堆栈内存建议为机器内存的50%(当然也可以不改)

[root@localhost bin]# vim /opt/es/elasticsearch-7.7.0/config/jvm.options

-Xms1g
-Xmx1g
改为:
-Xms256m
-Xmx256m

修改每个进程最大同时打开文件数 limits.conf 文件

[root@localhost ~]# vim /etc/security/limits.conf

esuser           hard    nofile          65536
esuser           soft    nofile          65536
*                soft    nproc           4096
*                hard    nproc           4096


可以查看当前系统同时打开进程数的默认值:

    ulimit -Hn
    ulimit -Sn

修改 elasticsearch用户拥有的内存权限大小 sysctl.conf文件

[root@localhost ~]# vim /etc/sysctl.conf

文件最后添加一行内容:
vm.max_map_count=655360

添加完毕之后,执行命令:
sysctl -p

启动ES

注意: 启动es服务的时候,是不允许使用超级管理员root账户 那么接下来,我们需要创建一个普通用户

[root@localhost es]# adduser esuser
[root@localhost es]# passwd esuser

给esuser用户赋权限
[root@localhost es]# chown -R esuser /opt/es/elasticsearch-7.7.0

切换用户
[root@localhost es]# su - esuser

启动ES
[esuser@localhost ~]$ cd /opt/es/elasticsearch-7.7.0/bin/
[esuser@localhost bin]$ ./elasticsearch -d

判断是否启动成功,可执行如下命令,查看是否启用9200端口即可

[root@localhost es]# ss -tanl

或者访问9200端口是否是以下内容

[esuser@localhost es] curl 127.0.0.1:9200

{
  "name" : "nYjxCs3",
  "cluster_name" : "my-application",
  "cluster_uuid" : "_4ODdDaESQatC4LU9AzSVQ",
  "version" : {
    "number" : "6.6.1",
    "build_flavor" : "default",
    "build_type" : "tar",
    "build_hash" : "1fd8f69",
    "build_date" : "2019-02-13T17:10:04.160291Z",
    "build_snapshot" : false,
    "lucene_version" : "7.6.0",
    "minimum_wire_compatibility_version" : "5.6.0",
    "minimum_index_compatibility_version" : "5.0.0"
  },
  "tagline" : "You Know, for Search"
}
  • 如果显示如上信息,则代表Linux下ES已经搭建完毕(单机)
  • 若是es的后台运行,则用kill -9 进程号 来停止。(可通过jps命令,查看es进程号)

重启ES

ps -ef | grep elastic

kill -9 18578
cd /opt/es/elasticsearch-7.7.0/bin/
./elasticsearch

报错合集:

  1. max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]
  2. max number of threads [3818] for user [es] is too low, increase to at least [4096]
  3. max virtual memory areas vm.max_map_count [6530] is too low, increase to at least [262144]
  4. java.lang.RuntimeException: can not run elasticsearch as root
  5. java.lang.IllegalStateException: failed to obtain node locks, tried [[/home/test/elasticsearch-7.7.0/data]] with lock id [0]; maybe these locations are not writable or multiple nodes were started without increasing [node.max_local_storage_nodes] (was [1])?
  6. future versions of Elasticsearch will require Java 11; your Java version from [/home/klbp/java-se-8u41-ri/jre] does not meet this requirement
  7. could not find java in JAVA_HOME at /usr/lib/jvm/java-11-openjdk-11.0.8.10-0.el7_8.x86_64/bin/java
  8. OpenJDK 64-Bit Server VM warning: If the number of processors is expected to increase from one, then you should configure the number of parallel GC threads appropriately using -XX:ParallelGCThreads=N

报错内容1,2解决方法,新增配置:

vim /etc/security/limits.conf

* soft nofile 65536
* hard nofile 65536
* soft nproc 4096
* hard nproc 4096

报错内容3解决方法,新增配置

vim /etc/sysctl.conf

vm.max_map_count=262144

报错6是ES与JDK版本不匹配导致,这里显示的是需要JDK11版本,所有需要换JDK

先查找 JDK
rpm -qa|grep jdk


删除JDK
sudo yum -y remove java-1.8.0-openjdk-1.8.0.222.b03-1.el7.x86_64


搜索JDK11
yum search java-11-openjdk


安装JDK11
sudo yum install java-11-openjdk-headless.x86_64


检查是否安装成功
java -version

安装JDK环境

先查找 JDK ,我这里有两个版本,1.7和1.8都删除,换成JDK11

[root@localhost ~]# rpm -qa|grep jdk

java-1.8.0-openjdk-headless-1.8.0.222.b03-1.el7.x86_64
java-1.7.0-openjdk-headless-1.7.0.221-2.6.18.1.el7.x86_64
copy-jdk-configs-3.3-10.el7_5.noarch
java-1.8.0-openjdk-1.8.0.222.b03-1.el7.x86_64
java-1.7.0-openjdk-1.7.0.221-2.6.18.1.el7.x86_64


删除JDK
[root@localhost ~]# yum -y remove java-1.8.0-openjdk-headless-1.8.0.222.b03-1.el7.x86_64
[root@localhost ~]# yum -y remove java-1.7.0-openjdk-headless-1.7.0.221-2.6.18.1.el7.x86_64

安装JDK

搜索JDK11
[root@localhost ~]# yum search java-11-openjdk

安装JDK11
[root@localhost ~]# yum install java-11-openjdk-headless.x86_64

检查是否安装成功

[root@localhost ~]# java -version

# 此时已经是JDK11版本
openjdk version "11.0.9" 2020-10-20 LTS
OpenJDK Runtime Environment 18.9 (build 11.0.9+11-LTS)
OpenJDK 64-Bit Server VM 18.9 (build 11.0.9+11-LTS, mixed mode, sharing)

修改JDK环境变量

[root@localhost ~]# vim /etc/profile
 
JAVA_HOME=/usr/lib/jvm/java-11-openjdk-11.0.8.10-0.el7_8.x86_64  # 注意版本
JRE_HOME=$JAVA_HOME/jre
CLASS_PATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib
PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin
export JAVA_HOME JRE_HOME CLASS_PATH PATH

注意: 修改文件后运行# source /etc/profile, 或者重启虚拟机。

报错7的解决办法: 连接 或者安装JDK的时候不要用root用户安装

报错8解决办法: 将虚拟机改完2个或以上处理器

注意ES与JDK的对应版本要求

 

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值