简介
网上有各种ES版本的安装步骤和问题解决方案,但是在安装过程中还是遇到了许多问题,那么今天来整理一份详细的安装过程以及碰到的问题和心得;有什么不对的和问题希望大家留言一起讨论。
- jdk至少需要在1.8.0_73以上版本。
- linux的内核版本需要在2.6以上(我用的是centos7.x)
一、下载elasticsearch
cd /usr/local
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.6.7.tar.gz
下载成功日志输出
--2018-10-31 10:36:28-- https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.6.7.tar.gz
Resolving artifacts.elastic.co... 54.235.82.130, 184.72.242.47, 54.235.171.120, ...
Connecting to artifacts.elastic.co|54.235.82.130|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 33789994 (32M) [binary/octet-stream]
Saving to: “elasticsearch-5.6.7.tar.gz”
100%[==========================================================>] 33,789,994 7.51M/s in 4.7s
2018-10-31 10:36:35 (6.83 MB/s) - “elasticsearch-5.6.7.tar.gz” saved [33789994/33789994]
二、解压安装
解压命令
tar -zxvf elasticsearch-5.6.7.tar.gz
解压成功日志输出
[root@iZuf6fj49j7lt0ckj85qurZ ~]# tar -zxvf elasticsearch-5.6.7.tar.gz
elasticsearch-5.6.7/
elasticsearch-5.6.7/lib/
elasticsearch-5.6.7/lib/elasticsearch-5.6.7.jar
elasticsearch-5.6.7/lib/lucene-core-6.6.1.jar
elasticsearch-5.6.7/lib/lucene-analyzers-common-6.6.1.jar
elasticsearch-5.6.7/lib/lucene-backward-codecs-6.6.1.jar
省略..................
elasticsearch-5.6.7/modules/percolator/plugin-descriptor.properties
elasticsearch-5.6.7/modules/percolator/percolator-5.6.7.jar
elasticsearch-5.6.7/modules/aggs-matrix-stats/
elasticsearch-5.6.7/modules/aggs-matrix-stats/plugin-descriptor.properties
elasticsearch-5.6.7/modules/aggs-matrix-stats/aggs-matrix-stats-5.6.7.jar
elasticsearch-5.6.7/plugins/
修改文件夹(方便寻找)
mv elasticsearch-5.6.7 elasticsearch
三、配置文件
1、配置文件说明
jvm.options 虚拟机参数配置文件
配置heap内存一样
elasticsearch.yml 主配置文件
cluster.name 集群名称,同一个网段自动加入
node.name 节点名称
http.port http端口
默认情况下,Elastic 只允许本机访问,如果需要远程访问,可以修改 Elastic 安装目录的config/elasticsearch.yml文件,去掉network.host的注释,将它的值改成0.0.0.0,然后重新启动 Elastic。
2、进入配置文件目录
在memory下添加如下
bootstrap.memory_lock: false
bootstrap.system_call_filter: false
退出保存后执行如下命令:
sysctl -p
3、修改如下文件
vi /etc/security/limits.conf
在文件末尾添加如下代码
# testes为登录服务器的用户名
testes soft nofile 65536
testes hard nofile 65536
testes soft nproc 4096
testes hard nproc 4096
4、创建testes 用户(root用户不能启动elasticsearch)
useradd testes
passwd 你的密码
按提示输入两次密码:你的密码
5、授权
cd /root
sudo chown -R python elasticsearch
sudo chgrp -R python elasticsearch
6、切换用户
su - python
四、启动elasticsearch
1:控制台启动(ctrl+c 后停止):
./bin/elasticsearch
1:控制台启动(ctrl+c 后停止):
./bin/elasticsearch -d
五、访问elasticsearch
http://101.132.243.207:9200/
结果
elasticsearch访问结果.png
六、踩坑
1、root 权限下启动elasticsearch 错误
错误信息
[root@iZuf6fj49j7lt0ckj85qurZ elasticsearch]# ./bin/elasticsearch
[2018-10-31T16:06:43,042][WARN ][o.e.b.ElasticsearchUncaughtExceptionHandler] [] uncaught exception in thread [main]
org.elasticsearch.bootstrap.StartupException: java.lang.RuntimeException: can not run elasticsearch as root
at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:136) ~[elasticsearch-5.6.7.jar:5.6.7]
at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:123) ~[elasticsearch-5.6.7.jar:5.6.7]
at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:70) ~[elasticsearch-5.6.7.jar:5.6.7]
at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:134) ~[elasticsearch-5.6.7.jar:5.6.7]
at org.elasticsearch.cli.Command.main(Command.java:90) ~[elasticsearch-5.6.7.jar:5.6.7]
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:91) ~[elasticsearch-5.6.7.jar:5.6.7]
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:84) ~[elasticsearch-5.6.7.jar:5.6.7]
Caused by: java.lang.RuntimeException: can not run elasticsearch as root
at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:106) ~[elasticsearch-5.6.7.jar:5.6.7]
at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:195) ~[elasticsearch-5.6.7.jar:5.6.7]
at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:342) ~[elasticsearch-5.6.7.jar:5.6.7]
at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:132) ~[elasticsearch-5.6.7.jar:5.6.7]
... 6 more
由于ElasticSearch可以接收用户的脚本并执行,处于安全性考虑,建议创建一个单独的用户来运行ElasticSearch。当然,可以通过配置来实现root用户启动。
修改bin目录elasticsearch.in.sh文件中追加(不过不建议):
JAVA_OPTS="$JAVA_OPTS -Des.insecure.allow.root=true"
2、max virutal memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
max_map_count-error.png原因:主要是因为ES使用的虚拟内存大小跟linux默认的大小不一样,默认的太小,需要配置更大一点
解决办法:
1、切换到root用户修改配置sysctl.conf
vi /etc/sysctl.conf
添加下面配置:
vm.max_map_count=655360
并执行命令:
sysctl -p
然后,重新启动elasticsearch,即可启动成功。
3、外网访问失败
修改配置elasticsearch.yml
network.host: 0.0.0.0
# Set the bind address to a specific IP (IPv4 or IPv6):
#
#network.host: 192.168.0.1
network.host: 0.0.0.0
#
# Set a custom port for HTTP:
#
#http.port: 9200
4、unknown setting [vm.max_map_count] please check that any required plugins a
报错信息
java.lang.IllegalArgumentException: unknown setting [vm.max_map_count] please check that any required plugins are installed, or check the breaking changes documentation for removed settings
at org.elasticsearch.common.settings.AbstractScopedSettings.validate(AbstractScopedSettings.java:293) ~[elasticsearch-5.6.7.jar:5.6.7]
at org.elasticsearch.common.settings.AbstractScopedSettings.validate(AbstractScopedSettings.java:256) ~[elasticsearch-5.6.7.jar:5.6.7]
at org.elasticsearch.common.settings.SettingsModule.<init>(SettingsModule.java:139) ~[elasticsearch-5.6.7.jar:5.6.7]
at org.elasticsearch.node.Node.<init>(Node.java:344) ~[elasticsearch-5.6.7.jar:5.6.7]
at org.elasticsearch.node.Node.<init>(Node.java:245) ~[elasticsearch-5.6.7.jar:5.6.7]
at org.elasticsearch.bootstrap.Bootstrap$5.<init>(Bootstrap.java:233) ~[elasticsearch-5.6.7.jar:5.6.7]
at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:233) ~[elasticsearch-5.6.7.jar:5.6.7]
at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:342) [elasticsearch-5.6.7.jar:5.6.7]
at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:132) [elasticsearch-5.6.7.jar:5.6.7]
at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:123) [elasticsearch-5.6.7.jar:5.6.7]
at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:70) [elasticsearch-5.6.7.jar:5.6.7]
at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:134) [elasticsearch-5.6.7.jar:5.6.7]
at org.elasticsearch.cli.Command.main(Command.java:90) [elasticsearch-5.6.7.jar:5.6.7]
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:91) [elasticsearch-5.6.7.jar:5.6.7]
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:84) [elasticsearch-5.6.7.jar:5.6.7]
[2018-10-31T15:23:15,809][WARN ][o.e.b.ElasticsearchUncaughtExceptionHandler] [] uncaught exception in thread [main]
org.elasticsearch.bootstrap.StartupException: java.lang.IllegalArgumentException: unknown setting [vm.max_map_count] please check that any required plugins are installed, or check the breaking changes documentation for removed settings
at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:136) ~[elasticsearch-5.6.7.jar:
省略。。。。。
原因:在elasticsearch.yml 文件配置了 vm.max_map_count=262144
网友评论