前言
正文
我是直接下载的7.8的tar进行安装的。
1.解压
[root@localhost opt]# ll
总用量 311636
-rw-r--r--. 1 root root 319112561 12月 21 20:50 elasticsearch-7.8.0-linux-x86_64.tar.gz
[root@localhost opt]# tar -zxvf elasticsearch-7.8.0-linux-x86_64.tar.gz
[root@localhost opt]# ll
总用量 311636
drwxr-xr-x. 9 root root 155 6月 14 2020 elasticsearch-7.8.0
-rw-r--r--. 1 root root 319112561 12月 21 20:50 elasticsearch-7.8.0-linux-x86_64.tar.gz
[root@localhost opt]# mkdir tool
[root@localhost opt]# mv ./elasticsearch-7.8.0-linux-x86_64.tar.gz ./tool/
[root@localhost opt]# ll
总用量 0
drwxr-xr-x. 9 root root 155 6月 14 2020 elasticsearch-7.8.0
drwxr-xr-x. 2 root root 53 12月 21 20:52 tool
2.创建data目录,创建esuser用户
ES不允许使用root操作,新建data目录后面修改配置使存储指向它。
[root@localhost opt]# mkdir data
[root@localhost opt]# useradd esuser
[root@localhost opt]# chown -R esuser:esuser /opt/elasticsearch-7.8.0/
[root@localhost opt]# chown -R data
[root@localhost opt]# ll
总用量 0
drwxr-xr-x. 2 esuser esuser 6 12月 21 20:53 data
drwxr-xr-x. 9 esuser esuser 155 6月 14 2020 elasticsearch-7.8.0
drwxr-xr-x. 2 root root 53 12月 21 20:52 tool
修改核心配置文件
进入es目录,先简单看下结构
[root@localhost opt]# cd elasticsearch-7.8.0/
[root@localhost elasticsearch-7.8.0]# ll
总用量 568
drwxr-xr-x. 2 esuser esuser 4096 6月 14 2020 bin
drwxr-xr-x. 3 esuser esuser 169 12月 21 20:52 config
drwxr-xr-x. 9 esuser esuser 107 6月 14 2020 jdk
drwxr-xr-x. 3 esuser esuser 4096 6月 14 2020 lib
-rw-r--r--. 1 esuser esuser 13675 6月 14 2020 LICENSE.txt
drwxr-xr-x. 2 esuser esuser 6 6月 14 2020 logs
drwxr-xr-x. 47 esuser esuser 4096 6月 14 2020 modules
-rw-r--r--. 1 esuser esuser 544318 6月 14 2020 NOTICE.txt
drwxr-xr-x. 2 esuser esuser 6 6月 14 2020 plugins
-rw-r--r--. 1 esuser esuser 8165 6月 14 2020 README.asciidoc
bin:可执行文件在里面,运行es的命令就在这个里面,包含了一些脚本文件等
config:配置文件目录
JDK:java环境
lib:依赖的jar,类库
logs:日志文件
modules:es相关的模块
plugins:插件
现在开始修改配置:
elasticearch.yml
[root@localhost elasticsearch-7.8.0]# vi config/elasticearch.yml
修改以下参数,单节点的话,集群名称和节点名称可以不改
# 集群名称和节点名称
cluster.name: my-application
node.name: node-1
# 存储位置修改为之前创建的data目录下
path.data: /opt/data/elastic-7.8.0/data
path.logs: /opt/data/elastic-7.8.0/logs
# 设置为true锁住内存,当服务混合部署了多个组件及服务时,应开启此操作,允许es占用足够多的内存。
bootstrap.memory_lock: true
# ip地址修改,如果想被其他直接访问的话,改0.0.0.0
network.host: 192.168.0.153
# http端口,默认,想改就改
#http.port: 9200
# 设定启动时要寻找的主节点IP地址和节点名称,全部找到后才会进行主节点推选
discovery.seed_hosts: ["192.168.0.153:9300"]
cluster.initial_master_nodes: ["node-1"]
集群的话增加下面修改
# 每个节点的集群名称要保持一致
cluster.name: my-application
node.name: node-2
# 集群的话,要把参与主节点选举的都放进来
discovery.seed_hosts: ["192.168.0.153:9300", "host2"]
cluster.initial_master_nodes: ["node-1", "node-2"]
# 支持跨域,跨域配置是为了kibana,head连接
http.cors.enabled: true
http.cors.allow-origin: "*"
修改jvm参数
打开 jvm.options 文件
[root@localhost elasticsearch-7.8.0]# vi config/jvm.options
# 修改这里的配置,官方建议是服务器内存的一半,最大不超过32g
-Xms1g
-Xmx1g
指定jar包
es7.8自带的有java11。
[root@localhost elasticsearch-7.8.0]# vi bin/elasticsearch
# 可以在开头添加下面语句指定jdk11
export JAVA_HOME=/opt/elasticsearch-7.8.0/jdk
export PATH=$JAVA_HOME/bin:$PATH
# 添加jdk判断
if [ -x "$JAVA_HOME/bin/java" ]; then
JAVA="/opt/elasticsearch-7.8.0/jdk/bin/java"
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`. Example
# values are "512m", and "10g".
#
# ES_JAVA_OPTS="-Xms8g -Xmx8g" ./bin/elasticsearch
# 指定jdk11
export JAVA_HOME=/opt/elasticsearch-7.8.0/jdk
export PATH=$JAVA_HOME/bin:$PATH
# 添加jdk判断
if [ -x "$JAVA_HOME/bin/java" ]; then
JAVA="/opt/elasticsearch-7.8.0/jdk/bin/java"
else
JAVA=`which java`
fi
source "`dirname "$0"`"/elasticsearch-env
其它环境设置修改
修改/etc/security/limits.conf 文件
[root@localhost elasticsearch-7.8.0]# vi /etc/security/limits.conf
增加下面内容
esuser soft nofile 65536
esuser hard nofile 131072
esuser soft nproc 4096
esuser hard nproc 4096
# allow user 'esuser' mlockall,配置开启内存锁定的话要加这个
esuser soft memlock unlimited
esuser hard memlock unlimited
也可以将esuser改为*,允许所有的用户。
修改 /etc/sysctl.conf 增加 vm.max_map_count=262145
[root@localhost elasticsearch-7.8.0]# vi /etc/sysctl.conf
# sysctl settings are defined through files in
# /usr/lib/sysctl.d/, /run/sysctl.d/, and /etc/sysctl.d/.
#
# Vendors settings live in /usr/lib/sysctl.d/.
# To override a whole file, create a new file with the same in
# /etc/sysctl.d/ and put new settings there. To override
# only specific settings, add a file with a lexically later
# name in /etc/sysctl.d/ and put new settings there.
#
# For more information, see sysctl.conf(5) and sysctl.d(5).
vm.max_map_count=262145
修改完后 sysctl -p
刷新一下
[root@localhost elasticsearch-7.8.0]# sysctl -p
vm.max_map_count = 262145
[root@localhost elasticsearch-7.8.0]#
启动es
切换到es用户
[root@localhost elasticsearch-7.8.0]# su esuser
[esuser@localhost elasticsearch-7.8.0]$ ./bin/elasticsearch
如果正常的话就可以后台启动了。
# 后台启动
[esuser@localhost elasticsearch-7.8.0]$ ./bin/elasticsearch -d
# 检查是否启动ok
[esuser@localhost elasticsearch-7.8.0]$ curl http://192.168.0.153:9200
# 会出现以下,注意防火墙放开端口
{
"name" : "node-1",
"cluster_name" : "my-application",
"cluster_uuid" : "GJJVYZe9RB-1vlQN4prcdg",
"version" : {
"number" : "7.8.0",
"build_flavor" : "default",
"build_type" : "tar",
"build_hash" : "757314695644ea9a1dc2fecd26d1a43856725e65",
"build_date" : "2020-06-14T19:35:50.234439Z",
"build_snapshot" : false,
"lucene_version" : "8.5.1",
"minimum_wire_compatibility_version" : "6.8.0",
"minimum_index_compatibility_version" : "6.0.0-beta1"
},
"tagline" : "You Know, for Search"
}
安装成功!接下来就是安装kibana以及其它工具,开始使用啦。
关闭es
查询进程pid,杀掉。
注意,如果是集群节点重启的话,需要留意节点平衡相关,这个在后面会详细的写到。
[esuser@localhost elasticsearch-7.8.0]$ ps -ef|grep elastic
esuser 7325 1 9 21:59 pts/0 00:00:31 /opt/elasticsearch-7.8.0/jdk/bin/java -Xshare:auto -Des.networkaddress.cache.ttl=60 -Des.networkaddress.cache.negative.ttl=10 -XX:+AlwaysPreTouch -Xss1m -Djava.awt.headless=true -Dfile.encoding=UTF-8 -Djna.nosys=true -XX:-OmitStackTraceInFastThrow -XX:+ShowCodeDetailsInExceptionMessages -Dio.netty.noUnsafe=true -Dio.netty.noKeySetOptimization=true -Dio.netty.recycler.maxCapacityPerThread=0 -Dio.netty.allocator.numDirectArenas=0 -Dlog4j.shutdownHookEnabled=false -Dlog4j2.disable.jmx=true -Djava.locale.providers=SPI,COMPAT -Xms1g -Xmx1g -XX:+UseG1GC -XX:G1ReservePercent=25 -XX:InitiatingHeapOccupancyPercent=30 -Djava.io.tmpdir=/tmp/elasticsearch-15007387074446335488 -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=data -XX:ErrorFile=logs/hs_err_pid%p.log -Xlog:gc*,gc+age=trace,safepoint:file=logs/gc.log:utctime,pid,tags:filecount=32,filesize=64m -XX:MaxDirectMemorySize=536870912 -Des.path.home=/opt/elasticsearch-7.8.0 -Des.path.conf=/opt/elasticsearch-7.8.0/config -Des.distribution.flavor=default -Des.distribution.type=tar -Des.bundled_jdk=true -cp /opt/elasticsearch-7.8.0/lib/* org.elasticsearch.bootstrap.Elasticsearch -d
esuser 7348 7325 0 21:59 pts/0 00:00:00 /opt/elasticsearch-7.8.0/modules/x-pack-ml/platform/linux-x86_64/bin/controller
esuser 7401 6623 0 22:04 pts/0 00:00:00 grep --color=auto elastic
[esuser@localhost elasticsearch-7.8.0]$ kill -9 7325