1. 下载解压
# 建议搭梯子下载后上传
# 这个版本包含了jdk13
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.6.2-linux-x86_64.tar.gz
# 这里上传到 /usr/local/elk 目录下
tar -zxvf elasticsearch-7.6.2-linux-x86_64.tar.gz
2. 配置
2.1 配置jdk和新建用户
需要配置jdk,这里配置elasticsearch自带的jdk作为es用户的jdk
elasticsearch 不能以root用户运行,所以得创建用户
# 创建es组和用户
groupadd es
useradd es -g es
# 修改权限
chown -R es.es /usr/local/elk/elasticsearch-7.6.2
# 切换到es用户
su es
# 设置es用户的jdk环境
cd ~
vi .bashrc
在.bashrc文件后面追加:
export JAVA_HOME=/usr/local/elk/elasticsearch-7.6.2/jdk
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
# 使配置生效
source .bashrc
# 验证java
java -version
[es@vince ~]$ java -version
openjdk version "13.0.2" 2020-01-14
OpenJDK Runtime Environment AdoptOpenJDK (build 13.0.2+8)
OpenJDK 64-Bit Server VM AdoptOpenJDK (build 13.0.2+8, mixed mode, sharing)
2.1 修改内核参数
# 修改es用户文件打开数
vi /etc/security/limits.conf
往limits.conf里追加以下内容:
es soft nofile 65536
es hard nofile 65536
vi /etc/sysctl.conf
往sysctl.conf 里追加以下内容:
vm.max_map_count = 262144
# 使修改立即生效
sysctl -p
2.2 修改es配置文件
设置network.host 使es可以在其他服务器访问
network.host: 0.0.0.0
http.port: 9200
discovery.seed_hosts: ["127.0.0.1", "[::1]"]
添加跨域访问,方便开发
#允许跨域访问
http.cors.enabled: true
http.cors.allow-origin: "*"
3.启动
# 切换到es用户
su es
# 启动
cd /usr/local/elk/elasticsearch-7.6.2
./bin/elasticsearch
# 后台启动,默认log文件目录:/usr/local/elasticsearch-7.6.2/logs/my-es.log
./bin/elasticsearch -d
访问ip:9200, 返回以下内容代表成功
4. 启动错误
4.1启动时报内存不足错误
[es@vince elasticsearch-7.6.2]$ ./bin/elasticsearch -d
Exception in thread "main" java.lang.RuntimeException: starting java failed with [1]
output:
#
# There is insufficient memory for the Java Runtime Environment to continue.
# Native memory allocation (mmap) failed to map 986513408 bytes for committing reserved memory.
# An error report file with more information is saved as:
# logs/hs_err_pid17395.log
解决:调小启动内存
vi /usr/local/elasticsearch-7.6.2/config/jvm.options
# 修改为512m
#-Xms2g
#-Xmx2g
-Xms512m
-Xmx512m
4.2 failed to obtain node locks(绑定节点失败)
uncaught exception in thread [main]
java.lang.IllegalStateException: failed to obtain node locks, tried [[/usr/local/elk/elasticsearch-7.6.2/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])?
at org.elasticsearch.env.NodeEnvironment.<init>(NodeEnvironment.java:301)
at org.elasticsearch.node.Node.<init>(Node.java:277)
at org.elasticsearch.node.Node.<init>(Node.java:257)
at org.elasticsearch.bootstrap.Bootstrap$5.<init>(Bootstrap.java:221)
at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:221)
at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:349)
at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:170)
at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:161)
at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:86)
解决:由于上一次没有正常关闭es导致。
# 查看进程
ps aux | grep elastic
# 查询到以下进程
es 12705 0.0 0.0 112728 976 pts/2 R+ 23:53 0:00 grep --color=auto elastic
es 30116 12.1 41.2 2833332 776204 pts/2 Sl 23:48 0:36 /usr/local/elk/elasticsearch-7.6.2/jdk/bin/java -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 -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=COMPAT -Xms512m -Xmx512m -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly -Djava.io.tmpdir=/tmp/elasticsearch-14028617868054823808 -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=268435456 -Des.path.home=/usr/local/elk/elasticsearch-7.6.2 -Des.path.conf=/usr/local/elk/elasticsearch-7.6.2/config -Des.distribution.flavor=default -Des.distribution.type=tar -Des.bundled_jdk=true -cp /usr/local/elk/elasticsearch-7.6.2/lib/* org.elasticsearch.bootstrap.Elasticsearch -d
# 杀掉进程,重新启动就可以了
kill -9 30116