文章目录
ElasticSearch7.8环境搭建
一、前言
- ES是一个开源的高扩展的分布式全文搜索引擎,是整个Elastic Stack技术栈的核心。它可以近乎实时的存储、检索数据;本身扩展性很好,可以扩展到上百台服务器,处理PB级别的数据。
- 由于博主业务上的需要,为了简单的学一点技能,伪装成我很大佬的样子哈哈哈,至此就先从部署环境开始简单的记录一二吧。
- 由于一些懒得描述的原因,本次是以单节点过程实现环境搭建奥。
二、配置说明
博主使用的相关环境如下所示:
- windows10
- Linux centos-7.novalocal 3.10.0-862.2.3.el7.x86_64 #1 SMP Wed May 9 18:05:47 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
- elasticsearch-7.8.0
- elasticsearch-analysis-ik-7.8.0
- kibana-7.8.0-windows-x86_64
安装ES之前确保系统已安装JDK,其中需要JDK1.8及以上版本。具体是否需求哪个版本的JDK,可参考此链接。
三、环境安装
3.1 windows环境部署
3.1.1 部署步骤
- 将下载的elasticsearch-7.8.0-windows-x86_64.zip进行解压,如下图所示。
- 运行安装目录下—>bin文件夹—>双击执行:elasticsearch.bat
- 执行结果如下图所示:
看到started说明启动成功,至于看到Security is disabled的字样大概意思是安全控制关闭了,先无需理会哇,哈哈哈。我们打开浏览器测试一下,如下图:
3.1.2 ElasticSearch安装为Windows服务
说明:如果在服务中能发现ES服务,即此步骤跳过。但往往一般通过解压缩来事先安装的都不存在这种情况奥。
- 第一步:在elasticsearch-service.bat当前目录,在上面地址栏输入cmd:
- 第二步:在cmd中输入:elasticsearch-service.bat install
- 第三步:打开服务
- 第四步:选择【自动】
3.1.3 Kibana安装
Kibana是一个开源的分析和可视化平台,设计用于和Elasticsearch一起工作。你用Kibana来搜索,查看,并和存储在Elasticsearch索引中的数据进行交互。你可以轻松地执行高级数据分析,并且以各种图标、表格和地图的形式可视化数据。Kibana使得理解大量数据变得很容易。它简单的、基于浏览器的界面使你能够快速创建和共享动态仪表板,实时显示Elasticsearch查询的变化。
-
第一步:下载完毕后进行解压,然后进入bin目录,直接运行kibana.bat
-
第二步:浏览器中:localhost:5601
3.1.4 elasticsearch-analysis-ik安装
- 第一步:下载后解压结果如下图所示:
- 第二步:在ES的安装目录plugin下,创建文件夹analysis-ik(可以随意命名),将解压得到所有内容,复制到analysis-ik下。
- 第三步:重启ES即可。
3.1.5 ElasticSearch-head插件安装(待完善)
第一步:通过网址下载Windows版msi的node,下载完直接安装,一路点确定即可。
第二步:安装grunt
grunt是一个很方便的构建工具,可以进行打包压缩、测试、执行等等的工作,5.x里之后的head插件就是通过grunt启动的。因此需要安装grunt。
安装命令:npm install -g grunt-cli
版本查看命令:grunt -version
第三步:下载head插件及其配置
将下载好的head进行解压,然后进入head文件夹下,执行命令:npm install (此处是为安装进行安装pathomjs)
3.2 centos环境部署
3.2.1 部署步骤
- 第一步:将文件下载到自己指定的位置
- 第二步:解压到指定文件路径下
通过命令tar -zxvf elasticsearch-7.8.0-linux-x86_64.tar.gz
解压
- 第三步:创建用户
说明: 在es5.0版本后不支持与logstash和kibana2.x版本的混用,且安全级别的提升,使得es在后续的版本中不允许使用root用户启动,因此我们需要创建另外独立账户专供es使用。并且需要在root权限下将该特定环境准备好。
- 在启动elasticsearch之前,我们先来创建一个用户,因为ES在启动的时候是不允许使用root账户的,所以我们要新建一个elasticsearch用户:
useradd es
- 然后把
elasticsearch-7.8.0
这个目录和目录下所有的文件的拥有者都改成es:chown es:es -Rr elasticsearch-7.8.0
以上还可以通过如下实现:
groupadd es 创建es组
useradd -g es es 创建es用户,并且加入es组
passwd es 为es用户设定登录密码
为了让es用户拥有对elasticsearch执行权限,在root用户权限下解压后,需要将软件包更改属主属组。
chown -R es.es /home/elasticsearch-7.8.0/
ls -l /es/elasticsearch-7.8.0/
-
然后我们切换到
es
用户下:
通过安装的ES路径,我们定位到:./bin/elasticsearch
,实现启动。
-
验证是否成功
通过命令:curl 127.0.0.1:9200
查看,如果如下所示,则说明成功奥。
如果我们通过外网访问,则是无法访问的,例如:
因此,我们要修改一下配置文件。
3.2.2 修改配置文件
修改ES安装根目录下: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: /home/elasticsearch-7.8.0/data
#/path/to/data
#
# Path to log files:
#
#path.logs: /path/to/logs
path.logs: /home/elasticsearch-7.8.0/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: ["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
当我们修改完配置文件就可以实现启动:
3.2.3 启动ES
以创建的es用户身份,进入到ES安装目录下的bin目录下:
执行命令:
./elasticsearch
或者执行命令,实现后台启动:
./elasticsearch -d
结果访问:
出现上述截图结果,说明我们的ES环境成功部署。
3.2.4 启动报错解决
3.2.4.1 报错1
future versions of Elasticsearch will require Java 11; your Java version from [/Library/Java/JavaVirtualMachines/jdk1.8.0_152.jdk/Contents/Home/jre] does not meet this requirement
... 省略
[2019-08-16T16:29:53,069][INFO ][o.e.n.Node ] [BYSocketdeMacBook-Pro-2.local] started
[2019-08-16T16:29:53,478][INFO ][o.e.l.LicenseService ] [BYSocketdeMacBook-Pro-2.local] license [ef60f54d-4964-4cb6-98ac-aafdc0f2a4c0] mode [basic] - valid
[2019-08-16T16:29:53,491][INFO ][o.e.g.GatewayService ] [BYSocketdeMacBook-Pro-2.local] recovered [0] indices into cluster_state
[2019-08-16T16:30:23,057][INFO ][o.e.c.r.a.DiskThresholdMonitor] [BYSocketdeMacBook-Pro-2.local] low disk watermark [85%] exceeded on [DRs4DZO0SzCaYz3n3vA3Fg][BYSocketdeMacBook-Pro-2.local][/javaee/es/elasticsearch-7.2.1/data/nodes/0] free: 49.2gb[10.6%], replicas will not be assigned to this node
出现这个问题,是由于你本机的JDK是1.8版本的,而此时版本的ES需要JDK11支持。同时,我们大部分使用的是JDK1.8又不想换掉,这时该如何是好那,别慌,此时版本的ES自己都会带有相应的JDK,我们只需要修改一下环境即可:
解决方法:
在安装ES的根目录下,定位到:bin目录下,修改elasticsearch文件。
#!/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`. Example
# values are "512m", and "10g".
#
# ES_JAVA_OPTS="-Xms8g -Xmx8g" ./bin/elasticsearch
#配置自己的jdk11
export JAVA_HOME=/home/elasticsearch-7.8.0/jdk
export PATH=$JAVA_HOME/bin:$PATH
#添加jdk判断
if [ -x "$JAVA_HOME/bin/java" ]; then
JAVA="/home/elasticsearch-7.8.0/jdk/bin/java"
else
JAVA=`which java`
fi
source "`dirname "$0"`"/elasticsearch-env
CHECK_KEYSTORE=true
DAEMONIZE=false
for option in "$@"; do
case "$option" in
-h|--help|-V|--version)
CHECK_KEYSTORE=false
;;
-d|--daemonize)
DAEMONIZE=true
;;
esac
done
if [ -z "$ES_TMPDIR" ]; then
ES_TMPDIR=`"$JAVA" "$XSHARE" -cp "$ES_CLASSPATH" org.elasticsearch.tools.launchers.TempDirectory`
fi
# get keystore password before setting java options to avoid
# conflicting GC configurations for the keystore tools
unset KEYSTORE_PASSWORD
KEYSTORE_PASSWORD=
if [[ $CHECK_KEYSTORE = true ]] \
&& bin/elasticsearch-keystore has-passwd --silent
then
if ! read -s -r -p "Elasticsearch keystore password: " KEYSTORE_PASSWORD ; then
echo "Failed to read keystore password on console" 1>&2
exit 1
fi
fi
# The JVM options parser produces the final JVM options to start Elasticsearch.
# It does this by incorporating JVM options in the following way:
# - first, system JVM options are applied (these are hardcoded options in the
# parser)
# - second, JVM options are read from jvm.options and jvm.options.d/*.options
# - third, JVM options from ES_JAVA_OPTS are applied
# - fourth, ergonomic JVM options are applied
ES_JAVA_OPTS=`export ES_TMPDIR; "$JAVA" "$XSHARE" -cp "$ES_CLASSPATH" org.elasticsearch.tools.launchers.JvmOptionsParser "$ES_PATH_CONF"`
# manual parsing to find out, if process should be detached
if [[ $DAEMONIZE = false ]]; then
exec \
"$JAVA" \
"$XSHARE" \
$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 \
"$@" <<<"$KEYSTORE_PASSWORD"
else
exec \
"$JAVA" \
"$XSHARE" \
$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 \
"$@" \
<<<"$KEYSTORE_PASSWORD" &
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 $?
3.2.4.2 报错2
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
修改3.2.2的配置文件,具体如下所示:
cluster.initial_master_nodes: ["node-1"] #这里的node-1为node-name配置的值
3.2.4.2 报错3
具体报错内容如下所示:
[2018-05-18T17:44:59,658][INFO ][o.e.b.BootstrapChecks ] [gFOuNlS] bound or publishing to a non-loopback address, enforcing bootstrap checks
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]
解决方案一:在root用户下,编辑 /etc/security/limits.conf
,追加以下内容:
es soft nofile 65536
es hard nofile 65536
网上针对这个软硬件的大小给的具体数值说法不一,博主这里给到65536,反正是没有报错,哈哈。
解决方案二:编辑 /etc/sysctl.conf
,追加以下内容
vm.max_map_count=655360
保存后,执行:sysctl -p
说明:方案一、方案二同时修改奥。
3.3 Kibana安装
我们的kibana版本要和ES的版本对应起来,因此博主使用的Kibana版本同样也是7.8.0版本。
通过命令tar -zxvf kibana-7.8.0-linux-x86_64.tar.gz
实现解压。
kibana和Elasticsearch一样不能使用root账户启动, 因此我们需要设置成前面创建的es用户下。
# 在root下为 为kibana赋权
chown -R elsearch:elsearch /home/es/kibana-7.6.1-linux-x86_64/
# 切换回用户组 elsearch
su elsearch
在kibana中的config文件夹下面有一个文件kibana.yml:修改并去掉前面的“#”号
server.port: 5601
server.host: "自己的虚拟机IP"
elasticsearch.hosts: ["http://es的ip:9200"]
i18n.locale: "zh-CN" #汉化
在es用户下进行启动kibana:在kibana的安装目录的bin目录下
nohup ./kibana & #后台运行 kibana
或者:
./kibana
四、参考文献
- https://blog.csdn.net/u013521220/article/details/104070293/
- https://blog.csdn.net/weixin_39370907/article/details/99974710
- https://blog.csdn.net/qq_43655835/article/details/104637625
- https://blog.csdn.net/feng12345zi/article/details/80367907
- https://blog.csdn.net/zerokissingthefire/article/details/100104607
- centos7部署kibana,es,es可视化插件遇到的bug