配置完成后,即可以启动Elasticsearch,但是在启动之前需要先创建一个用户,并将此用户的权限赋予Elasticsearch的目录。(主要是因为Elasticsearch不能用root用户来启动,必须用非root用户)
[root@localhost /]# useradd elkuser
#elasticsearch 只能用非 root 启动
[root@localhost /]# chown -R elkuser.elkuser elasticsearch-6.1.0
[root@localhost elasticsearch-6.1.0]# pwd
/usr/local/elasticsearch-6.1.0
[root@localhost elasticsearch-6.1.0]# cd bin
[root@localhost bin]# ls
elasticsearch elasticsearch-env.bat elasticsearch-plugin elasticsearch-service-mgr.exe elasticsearch-translog.bat
elasticsearch.bat elasticsearch-keystore elasticsearch-plugin.bat elasticsearch-service-x64.exe
elasticsearch-env elasticsearch-keystore.bat elasticsearch-service.bat elasticsearch-translog
[root@localhost bin]# ./elasticsearch
Elasticsearch文件打开数及堆大小检测
在ES启动过程中可能会报如下的错误:
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]
错误主要说明,linux中elasticsearch最大文件打开数太小,需要我们修改到对应的数值:
1.max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]
修改/etc/security/limits.conf文件,添加或修改如下行:
* hard nofile 65536
* soft nofile 65536
2.max virtual memory areas vm.max……
修改 /etc/sysctl.conf 文件,添加如下行:
vm.max_map_count=262144
修改好了以后,运行/sbin/sysctl -p
重启以后,再启动es即可,就可以通过主机ip访问。
如果是内存不足就需要调整内存大小了或者调整config/jvm.options的参数
在elasticsearch-6.1.0/config目录中有jvm.options文件,可以设置JVM大小
[root@localhost config]# pwd
/usr/local/elasticsearch-6.1.0/config
[root@localhost config]# ls
elasticsearch.yml jvm.options log4j2.properties
[root@localhost config]# vi jvm.options
-Xms2g
-Xmx2g
启动Elasticsearch
前序工作全部准备完成后,即可在elasticsearch-6.1.0目录中的bin目录下执行elasticsearch-6.1.0文件:
[root@localhost elasticsearch-6.1.0]# pwd
/usr/local/elasticsearch-6.1.0
[root@localhost elasticsearch-6.1.0]# cd bin
[root@localhost bin]# ls
elasticsearch elasticsearch-env.bat elasticsearch-plugin elasticsearch-service-mgr.exe elasticsearch-translog.bat
elasticsearch.bat elasticsearch-keystore elasticsearch-plugin.bat elasticsearch-service-x64.exe
elasticsearch-env elasticsearch-keystore.bat elasticsearch-service.bat elasticsearch-translog
[root@localhost bin]# ./elasticsearch
[root@localhost bin]# ./elasticsearch -d 可以使其在后台运行