安装时一定要切换到普通用户(非root账号),减少错误发生。
下载地址
选择对应版本即可 https://www.elastic.co/downloads/elasticsearch
,这边官网下载太慢了,大家可以选择华为云 https://mirrors.huaweicloud.com/elasticsearch/7.6.0/
,我这边是 ubuntu
就直接下载 linux
版本了。
elasticsearch
是要依赖 java
的,如果大家没有安装,下载高版本后自带。
目录结构说明
目录 | 配置文件 | 描述 |
---|---|---|
bin | 脚步文件,包括启动elasticsearch,安装插件,运行统计数据等 | |
config | elasticsearch.yml | 集群配置文件,user,role based 相关配置 |
JDK | Java运行环境 | |
data | path.data | 数据文件 |
lib | Java类库 | |
logs | path.log | 日志文件 |
modules | 包含所有ES模块 | |
plugins | 包含所有已安装插件 |
- 修改JVM配置
vi config/jvm.options
# 默认配置是1GB
# 生产环境配置建议
# 1. Xms和Xms设置成一样
# 2. Xmx不要超过机器内存的50%
# 3. 最好不要超过30GB 官网有说明
- 启动elasticsearch
./bin/elasticsearch
安装Elasticsearch插件
- 安装analysis-icu插件
./bin/elasticsearch-plugin install analysis-icu
- 查看已安装插件
./bin/elasticsearch-plugin list
- api查看 访问 host:9200/_cat/plugins
可以利用插件做备份、安全等,还是挺不错的。
安装错误处理
启动后访问不了9200端口?
- 如果采用云服务器,请先设置服务器的出入端口 确保9200已经允许出入
- 修改config/elasticsearch.yml中的
network.host: 0.0.0.0
允许所有访问即可
报错elasticsearch启动报错Exception in thread "main" java.nio.file.AccessDeniedException
代码语言:javascript复制Exception in thread "main" java.nio.file.AccessDeniedException: /root/home/searchengine/elasticsearch/config/jvm.options
at sun.nio.fs.UnixException.translateToIOException(UnixException.java:84)
at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:102)
at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:107)
at sun.nio.fs.UnixFileSystemProvider.newByteChannel(UnixFileSystemProvider.java:214)
at java.nio.file.Files.newByteChannel(Files.java:361)
at java.nio.file.Files.newByteChannel(Files.java:407)
at java.nio.file.spi.FileSystemProvider.newInputStream(FileSystemProvider.java:384)
at java.nio.file.Files.newInputStream(Files.java:152)
at org.elasticsearch.tools.launchers.JvmOptionsParser.main(JvmOptionsParser.java:58
错误原因:使用非 root
用户启动ES
,而该用户的文件权限不足而被拒绝执行。
解决方法: chown -R 用户名:用户名 文件(目录)名
can not run elasticsearch as root
代码语言:javascript复制OpenJDK 64-Bit Server VM warning: Option UseConcMarkSweepGC was deprecated in version 9.0 and will likely be removed in a future release.
[2019-01-09T10:43:22,092][WARN ][o.e.b.ElasticsearchUncaughtExceptionHandler] [unknown] 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:140) ~[elasticsearch-6.5.4.jar:6.5.4]
at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:127) ~[elasticsearch-6.5.4.jar:6.5.4]
at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:86) ~[elasticsearch-6.5.4.jar:6.5.4]
at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:124) ~[elasticsearch-cli-6.5.4.jar:6.5.4]
at org.elasticsearch.cli.Command.main(Command.java:90) ~[elasticsearch-cli-6.5.4.jar:6.5.4]
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:93) ~[elasticsearch-6.5.4.jar:6.5.4]
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:86) ~[elasticsearch-6.5.4.jar:6.5.4]
Caused by: java.lang.RuntimeException: can not run elasticsearch as root
at
报错很明显“can not run elasticsearch as root”,所以切换到普通用户重新来吧。
ERROR: [5] bootstrap checks failed
[1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65535]
代码语言:javascript复制ERROR: [5] bootstrap checks failed
[1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65535]
[2]: max number of threads [1024] for user [es] is too low, increase to at least [4096]
[3]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
[4]: failed to install; check the logs and fix your configuration or disable system call filters at your own risk
[5]: 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
[2019-04-09T09:51:29,228][INFO ][o.e.n.Node ] [localhost.localdomain] stopping ...
[2019-04-09T09:51:29,264][INFO ][o.e.n.Node ] [localhost.localdomain] stopped
[2019-04-09T09:51:29,265][INFO ][o.e.n.Node ] [localhost.localdomain] closing ...
[2019-04-09T09:51:29,320][INFO ][o.e.n.Node ] [localhost.localdomain] closed
[2019-04-09T09:51:29,323][INFO ][o.e.x.m.p.NativeController] [localhost.localdomain] Native controller process has stopped - no new native processes can be started
切换root
用户 vi /etc/security/limits.conf
,在倒数第二行,修改如下
* soft nofile 65536
* hard nofile 65536
vi /etc/sysctl.conf
添加 vm.max_map_count=655360
, 保存后执行 sysctl -p
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
代码语言:javascript复制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
修改 elasticsearch.yml
取消注释保留一个节点 cluster.initial_master_nodes:["node-1"]
这个的话,这里的 node-1
是上面一个默认的记得打开就可以了
ERROR: [3] bootstrap checks failed
[1]: max number of threads [1024] for user [es] is too low, increase to at least [4096]
代码语言:javascript复制ERROR: [3] bootstrap checks failed
[1]: max number of threads [1024] for user [es] is too low, increase to at least [4096]
[2]: system call filters failed to install; check the logs and fix your configuration or disable system call filters at your own risk
[3]: 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
vi /etc/security/limits.d/90-nproc.conf
修改为
* soft nproc 1024
* soft nproc 4096