教程集 www.jiaochengji.com
教程集 >  Golang编程  >  golang教程  >  正文 centos8安装elasticsearch

centos8安装elasticsearch

发布时间:2022-12-11   编辑:jiaochengji.com
教程集为您提供centos8安装elasticsearch等资源,欢迎您收藏本站,我们将为您提供最新的centos8安装elasticsearch资源

centos8安装elasticsearch

  • 一、elasticsearch简介
  • 二、elasticsearch下载及安装
      • 1. 安装jdk1.8
      • 2. 下载、传输并解压
  • 三、配置开机启动以及远程访问
      • 1. 配置开机启动
      • 2. 配置远程访问
  • 四、elasticsearch-head的安装和配置
      • 1. elasticsearch-head下载
      • 2. 插件的安装和配置

一、elasticsearch简介

来自百度百科:
ElasticSearch是一个基于Lucene的搜索服务器。它提供了一个分布式多用户能力的全文搜索引擎,基于RESTful web接口。Elasticsearch是用Java语言开发的,并作为Apache许可条款下的开放源码发布,是一种流行的企业级搜索引擎。ElasticSearch用于云计算中,能够达到实时搜索,稳定,可靠,快速,安装使用方便。

二、elasticsearch下载及安装

1. 安装jdk1.8

centos下安装jdk1.8

2. 下载、传输并解压

  1. es7.4.2下载链接。
  2. 使用Xftp传输到linux中。
  3. 解压下载后的安装包。
tar xzvf elasticsearch-7.4.2-linux-x86_64.tar.gz
  1. 解压完成后进入到bin文件夹下,并启动elasticsearch。
cd /usr/local/elasticsearch-7.4.2/bin/
su es 			    # 使用创建的账户进行启动
./elasticsearch     # 启动elasticsearch


5. 测试是否启动成功

curl 127.0.0.1:9200


可能会出现以下错误
1)jdk版本不对应

解决:

 vim  /usr/local/elasticsearch-7.4.2/bin/elasticsearch     # 编辑启动文件
 文件:
 #配置自己的jdk1.8
export JAVA_HOME=/usr/local/jdk1.8                        #安装的jdk位置
export PATH=$JAVA_HOME/bin:$PATH
#添加jdk判断
if [ -x "$JAVA_HOME/bin/java" ]; then
   JAVA="/usr/local/jdk1.8/bin/java"							   #安装的jdk位置
else
   JAVA=`which java`
fi

文件全文:

#!/bin/bash
  
# CONTROLLING STARTUP:
#
# This script relies on a few environment variables to determine startup
# behavior, those variables are:
#
#   ES_PATH_CONF -- Path to config directory
#   ES_JAVA_OPTS -- External Java Opts on top of the defaults set
#
# Optionally, exact memory values can be set using the `ES_JAVA_OPTS`. Note that
# the Xms and Xmx lines in the JVM options file must be commented out. Example
# values are "512m", and "10g".
#
#   ES_JAVA_OPTS="-Xms8g -Xmx8g" ./bin/elasticsearch
#配置自己的jdk1.8
export JAVA_HOME=/usr/local/jdk1.8
export PATH=$JAVA_HOME/bin:$PATH

source "`dirname "$0"`"/elasticsearch-env

if [ -z "$ES_TMPDIR" ]; then
  ES_TMPDIR=`"$JAVA" -cp "$ES_CLASSPATH" org.elasticsearch.tools.launchers.TempDirectory`
fi

ES_JVM_OPTIONS="$ES_PATH_CONF"/jvm.options
JVM_OPTIONS=`"$JAVA" -cp "$ES_CLASSPATH" org.elasticsearch.tools.launchers.JvmOptionsParser "$ES_JVM_OPTIONS"`
ES_JAVA_OPTS="${JVM_OPTIONS//\$\{ES_TMPDIR\}/$ES_TMPDIR}"

if [ -x "$JAVA_HOME/bin/java" ]; then
   JAVA="/usr/local/jdk1.8/bin/java"
else
   JAVA=`which java`
fi

# manual parsing to find out, if process should be detached
if ! echo $* | grep -E '(^-d |-d$| -d |--daemonize$|--daemonize )' > /dev/null; then
  exec \
    "$JAVA" \
    $ES_JAVA_OPTS \
    -Des.path.home="$ES_HOME" \
    -Des.path.conf="$ES_PATH_CONF" \
    -Des.distribution.flavor="$ES_DISTRIBUTION_FLAVOR" \
    -Des.distribution.type="$ES_DISTRIBUTION_TYPE" \
    -Des.bundled_jdk="$ES_BUNDLED_JDK" \
    -cp "$ES_CLASSPATH" \
    org.elasticsearch.bootstrap.Elasticsearch \
    "$@"
else
  exec \
    "$JAVA" \
    $ES_JAVA_OPTS \
    -Des.path.home="$ES_HOME" \
    -Des.path.conf="$ES_PATH_CONF" \
    -Des.distribution.flavor="$ES_DISTRIBUTION_FLAVOR" \
    -Des.distribution.type="$ES_DISTRIBUTION_TYPE" \
    -Des.bundled_jdk="$ES_BUNDLED_JDK" \
    -cp "$ES_CLASSPATH" \
    org.elasticsearch.bootstrap.Elasticsearch \
    "$@" \
    <&- &
  retval=$?
  pid=$!
  [ $retval -eq 0 ] || exit $retval
  if [ ! -z "$ES_STARTUP_SLEEP_TIME" ]; then
    sleep $ES_STARTUP_SLEEP_TIME
  fi
  if ! ps -p $pid > /dev/null ; then
    exit 1
  fi
  exit 0
fi

exit $?

2)root账户不能启动

解决:

# 创建es账户
adduser es
# 修改密码
passwd es  
#输入的密码会提示不能少于8个字符,并且不能太过简单(eg:123qwe.lxw)
#给es用户elasticsearch目录的授权
chown -R es /usr/local/elasticsearch-7.4.2/

三、配置开机启动以及远程访问

1. 配置开机启动

  1. 创建开机启动文件
vim  /usr/lib/systemd/system/elasticsearch.service

内容如下:

[Unit]
Description=elasticsearch
[Service]
User=es    #此处为刚才设置的用户名
LimitNOFILE=100000
LimitNPROC=100000
ExecStart=/usr/local/elasticsearch/bin/elasticsearch
[Install]
WantedBy=multi-user.target
  1. 设置开机启动
systemctl daemon-reload   		#加载文件配置
systemctl enable elasticsearch  #设置开机启动
systemctl start|stop|status|restart elasticsearch   #启动|停止|状态|重启es
  1. 启动成功访问

2. 配置远程访问

  1. 修改elasticsearch.yml配置文件,允许外网访问。
vim  /usr/local/elasticsearch/config/elasticsearch.yml

添加相关配置(单机版)。

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.

可能出现:

  1. [1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]
    elasticsearch用户拥有的可创建文件描述的权限太低,至少需要65536;

    解决:
vim  /etc/security/limits.conf

追加以下内容

* soft nofile 65536
* hard nofile 65536


2. [2]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
elasticsearch用户拥有的内存权限太小,至少需要262144;
解决:

vim /etc/sysctl.conf

追加以下内容:

vm.max_map_count=655360

保存后,执行:

sysctl -p

重新启动

四、elasticsearch-head的安装和配置

1. elasticsearch-head下载

插件下载地址

2. 插件的安装和配置

  1. 将下载好的zip文件传输到centos中并进行解压:
cd /usr/local/   # 传输到该文件夹下,进入该文件夹
unzip elasticsearch-head-master.zip.zip 
  1. 下载并安装node.js
cd /usr/local/      # 这里下载到/usr/local目录下
wget https://nodejs.org/dist/v12.13.1/node-v12.13.1-linux-x64.tar.xz   # 下载最新压缩包
tar -xzf node-v12.13.1-linux-x64.tar.xz  #解压
# 链接
ln -s /usr/local/node/bin/node /usr/local/bin/node
ln -s /usr/local/node/bin/npm /usr/local/bin/npm
npm install -g cnpm --registry=https://registry.npm.taobao.org   #安装cnpm
ln -s /usr/local/node/bin/cnpm /usr/local/bin/cnpm


3. 配置elasticsearch
添加一下代码实现连接,否则会连接不成功

 vim /usr/local/elasticsearch/config/elasticsearch.yml   # 编写配置文件
#添加以下信息
http.cors.enabled: true
http.cors.allow-origin: "*"


4. 启动并查看。

cd /usr/local/elasticsearch-head-master/
npm install  # 安装

a. 安装过程中出现的问题

解决:使用cnpm进行安装

cnpm   install


启动:

npm run start

启动出现的问题:未安装grunt-contrib-jasmine

解决:
使用cnpm安装所需要的工具

cnpm install grunt-contrib-jasmine


再次启动:

浏览器查看是否成功:

其中:绿色表示健康,黄色表示集群不是很健康,但是可以使用,红色表示集群健康度很差,数据有丢失情况。

到此这篇关于“centos8安装elasticsearch”的文章就介绍到这了,更多文章或继续浏览下面的相关文章,希望大家以后多多支持JQ教程网!

您可能感兴趣的文章:
centos8安装elasticsearch
Windows-ElasticSearch安装和启动
ElasticSearch安装及使用入门教程
Centos7安装Elasticsearch和Kibana
PHP基于ElasticSearch做搜索
Mac下brew安装elasticsearch
安装Elasticsearch7.4.2、IK分词器以及Head插件步骤
php环境下使用elasticSearch ik分词器进行全文搜索
使用docker-compose安装elasticsearch6.8.1
Centos7 ElasticSearch7.6安装

[关闭]
~ ~