美文网首页
ElasticSearch 安装

ElasticSearch 安装

作者: 墨小斗 | 来源:发表于2020-11-04 19:16 被阅读0次

ElasticSearch 安装

环境:centos-release-6-10.el6.centos.12.3.x86_64
es: elasticsearch-7.9.3-linux-x86_64.tar.gz
(查看环境的命令:rpm -q centos-release, 版本要下对, 本地已安装java8, 但是当前es7.9.3的版本需要java11, 我们还需要安装一个jdk11)

1. 下载elasticsearch-7.9.3-linux-x86_64.tar.gz

地址: https://www.elastic.co/cn/downloads/elasticsearch
选择->LINUX X86_64
上传到linux服务器 /home/servers(自定义的路径) 路径下

2.下载java11

官方账号登录了半天登录不上....找了一个镜像站,地址如下:
地址: https://mirrors.tuna.tsinghua.edu.cn/AdoptOpenJDK/11/jdk/x64/linux/

3. 解压es

#使用root账号操作
[root@bogon servers]# tar -zxvf elasticsearch-7.9.3-linux-x86_64.tar.gz

#es只能使用普通用户启动, 所以需要创建一个es用户, 用户名我们设为elastic, 密码也设为elastic
[root@bogon servers]# useradd -m elastic
[root@bogon servers]# passwd elastic
输入密码即可

4. 安装jdk11

解压压缩包即可, 可以不配置环境变量, 因为我们的项目都是用的jdk8, 可以修改es的启动脚本, 配置它使用jdk11,

5. 启动es, 接下来会报很多的错误,导致启动失败, 从网上找到了解决办法如下:

(1) future versions of Elasticsearch will require Java 11; your Java version from [/usr/local/jdk1.8.0_261/jre] does not meet this requirement
说明需要一个java11环境, 我们修改启动脚本, 在es目录下的bin下
#    vim elasticsearch 
参考了网上打算的博客, 修改完的启动脚本如下:
  1 #!/bin/bash
  2 # CONTROLLING STARTUP:
  3 
  4 # 你好,此版本需要使用jdk11  haosw
  5 
  6 # This script relies on a few environment variables to determine startup
  7 # behavior, those variables are:
  8 #
  9 #   ES_PATH_CONF -- Path to config directory
 10 #   ES_JAVA_OPTS -- External Java Opts on top of the defaults set
 11 #
 12 # Optionally, exact memory values can be set using the `ES_JAVA_OPTS`. Example
 13 # values are "512m", and "10g".
 14 #
 15 #   ES_JAVA_OPTS="-Xms8g -Xmx8g" ./bin/elasticsearch
 16 
 17 # 我添加的start
 18 export JAVA_HOME=/usr/local/jdk-11.0.9/
 19 export PATH=$JAVA_HOME/bin:$PATH
 20 # 我添加的 end
 21 
 22 source "`dirname "$0"`"/elasticsearch-env
 23 
 24 CHECK_KEYSTORE=true
 25 DAEMONIZE=false
 26 for option in "$@"; do
 27   case "$option" in
 28     -h|--help|-V|--version)
 29       CHECK_KEYSTORE=false
 30       ;;
 31     -d|--daemonize)
 32       DAEMONIZE=true
 33       ;;
 34   esac
 35 done
 36 
 37 if [ -z "$ES_TMPDIR" ]; then
 38   ES_TMPDIR=`"$JAVA" "$XSHARE" -cp "$ES_CLASSPATH" org.elasticsearch.tools.launchers.TempDirectory`
 39 fi
 40 
 41 # get keystore password before setting java options to avoid
 42 # conflicting GC configurations for the keystore tools
 43 unset KEYSTORE_PASSWORD
 44 KEYSTORE_PASSWORD=
 45 if [[ $CHECK_KEYSTORE = true ]] \
 46     && bin/elasticsearch-keystore has-passwd --silent
 47 then
 48   if ! read -s -r -p "Elasticsearch keystore password: " KEYSTORE_PASSWORD ; then
 49     echo "Failed to read keystore password on console" 1>&2
 50     exit 1
 51   fi
 52 fi
 53 
 54 # The JVM options parser produces the final JVM options to start Elasticsearch.
 55 # It does this by incorporating JVM options in the following way:
 56 #   - first, system JVM options are applied (these are hardcoded options in the
 57 #     parser)
 58 #   - second, JVM options are read from jvm.options and jvm.options.d/*.options
 59 #   - third, JVM options from ES_JAVA_OPTS are applied
 60 #   - fourth, ergonomic JVM options are applied
 61 # 我添加的 start
 62 if [ -x "$JAVA_HOME/bin/java" ]; then
 63         JAVA="/usr/local/jdk-11.0.9/bin/java"
 64 else
 65         JAVA=`which java`
 66 fi
 67 # 我添加的 end
 68 
 69 ES_JAVA_OPTS=`export ES_TMPDIR; "$JAVA" "$XSHARE" -cp "$ES_CLASSPATH" org.elasticsearch.tools.launchers.JvmOptionsParser "$ES_PATH_CONF"`
 70 
 71 # manual parsing to find out, if process should be detached
 72 if [[ $DAEMONIZE = false ]]; then
 73   exec \
 74     "$JAVA" \
 75     "$XSHARE" \
 76     $ES_JAVA_OPTS \
 77     -Des.path.home="$ES_HOME" \
 78     -Des.path.conf="$ES_PATH_CONF" \
 79     -Des.distribution.flavor="$ES_DISTRIBUTION_FLAVOR" \
 80     -Des.distribution.type="$ES_DISTRIBUTION_TYPE" \
 81     -Des.bundled_jdk="$ES_BUNDLED_JDK" \
 82     -cp "$ES_CLASSPATH" \
 83     org.elasticsearch.bootstrap.Elasticsearch \
 84     "$@" <<<"$KEYSTORE_PASSWORD"
 85 else
 86   exec \
 87     "$JAVA" \
 88     "$XSHARE" \
 89     $ES_JAVA_OPTS \
 90     -Des.path.home="$ES_HOME" \
 91     -Des.path.conf="$ES_PATH_CONF" \
 92     -Des.distribution.flavor="$ES_DISTRIBUTION_FLAVOR" \
 93     -Des.distribution.type="$ES_DISTRIBUTION_TYPE" \
 94     -Des.bundled_jdk="$ES_BUNDLED_JDK" \
 95     -cp "$ES_CLASSPATH" \
 96     org.elasticsearch.bootstrap.Elasticsearch \
 97     "$@" \
 98     <<<"$KEYSTORE_PASSWORD" &
 99   retval=$?
100   pid=$!
101   [ $retval -eq 0 ] || exit $retval
102   if [ ! -z "$ES_STARTUP_SLEEP_TIME" ]; then
103     sleep $ES_STARTUP_SLEEP_TIME
104   fi
105   if ! ps -p $pid > /dev/null ; then
106     exit 1
107   fi
108   exit 0
109 fi
110 
111 exit $?     
(2) [WARN ][o.e.b.JNANatives         ] unable to install syscall filter: java.lang.UnsupportedOperationException: seccomp unavailable: CONFIG_SECCOMP not compiled into kernel, CONFIG_SECCOMP and CONFIG_SECCOMP_FILTER are needed

    at org.elasticsearch.bootstrap.SystemCallFilter.linuxImpl(SystemCallFilter.java:363) 
解决办法:
修改elasticsearch.yml 添加以下内容:
bootstrap.memory_lock: false
bootstrap.system_call_filter: false
(3)ERROR: bootstrap checks failed
max file descriptors [4096] for elasticsearch process likely too low, increase to at least [65536]
max number of threads [1024] for user [lishang] likely too low, increase to at least [2048]
vi /etc/security/limits.conf 
添加如下内容:
* soft nofile 65536
* hard nofile 131072
* soft nproc 2048
* hard nproc 4096
(4) max number of threads [1024] for user [lish] likely too low, increase to at least [2048]
解决:切换到root用户,进入limits.d目录下修改配置文件。
vi /etc/security/limits.d/90-nproc.conf 
修改如下内容:
* soft nproc 1024
#修改为
* soft nproc 2048
(5)max virtual memory areas vm.max_map_count [65530] likely too low, increase to at least [262144]
解决:切换到root用户修改配置sysctl.conf

vi /etc/sysctl.conf 
添加下面配置:
vm.max_map_count=655360
并执行命令:
sysctl -p
(6)ax file descriptors [4096] for elasticsearch process likely too low, increase to at least [65536]
解决:修改切换到root用户修改配置limits.conf 添加下面两行

命令:vi /etc/security/limits.conf

* hard  nofile  65536
* soft  nofile  65536
(7)ERROR: [1] bootstrap checks failed
[1]: the default discovery settings are unsuitable for production use; at least one of [discovery.seed_hosts, discovery.seed_providers, cluster.initial_master_nodes] must be configured
解决办法;
vim elasticsearch.yml
放开注释:node.name: node-1
放开注释,删除多余节点,保留一个节点:
cluster.initial_master_nodes: ["node-1"]

此时再次切换成es用户: su elastic

启动es, 进入es目录下的bin/, 输入 ./elasticsearch

启动成功

6. 远程访问

修改es安装目录下的 config/elasticsearch.yml 去掉 network.host  ,将值改为0.0.0.0 ,去掉 http.port 的注释, 使用端口9200, 重启es 可以远程访问

7. 后台启动

nohup ./elasticsearch&

8. 访问查看结果

http://192.168.1.128:9200 返回结果:

{
    "name": "node-1",
    "cluster_name": "elasticsearch",
    "cluster_uuid": "JA5U86VwToiwx7ggaOfm9w",
    "version": {
        "number": "7.9.3",
        "build_flavor": "default",
        "build_type": "tar",
        "build_hash": "c4138e51121ef06a6404866cddc601906fe5c868",
        "build_date": "2020-10-16T10:36:16.141335Z",
        "build_snapshot": false,
        "lucene_version": "8.6.2",
        "minimum_wire_compatibility_version": "6.8.0",
        "minimum_index_compatibility_version": "6.0.0-beta1"
    },
    "tagline": "You Know, for Search"
}

相关文章

网友评论

      本文标题:ElasticSearch 安装

      本文链接:https://www.haomeiwen.com/subject/gztnvktx.html