总览
官网:https://www.elastic.co/cn
GitHub:https://github.com/elastic/el...
API教程:
- 官方文档:https://www.elastic.co/guide/...
- 官方中文教程:https://www.elastic.co/guide/...
- 入门教程(阮一峰): http://www.ruanyifeng.com/blo...
一、下载并解压
环境搭建官方文档:https://www.elastic.co/guide/...
安装之前必须先按装JDK:源码安装JDK
$ curl -O https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.6.9.tar.gz #下载5.6.9版本
$ sha1sum elasticsearch-5.6.9.zip #验证文件的正确性
$ tar -xzf elasticsearch-5.6.9.tar.gz #解压
$ cd elasticsearch-5.6.9/
二、启动ES
因为安全问题elasticsearch 不让用root用户直接运行,所以要创建新用户
$ sudo adduser es
$ sudo passwd es。
$ sudo chown -R es /opt/elasticsearch-5.6.9 # 把/opt/elasticsearch-5.6.9目录的拥有者改为es用户(将目录的读写和执行权限全部授予给es用户)
$ su es #切换用户为es
2.1 配置
ES默认启动需要2G的内存,可以根据本机环境调整
配置elasticsearch下的jvm.options,然后重启
$ vim ./config/jvm.options
## JVM configuration
################################################################
## IMPORTANT: JVM heap size
################################################################
##
## You should always set the min and max JVM heap
## size to the same value. For example, to set
## the heap to 4 GB, set:
##
## -Xms4g
## -Xmx4g
##
## See https://www.elastic.co/guide/en/elasticsearch/reference/current/heap-size.html
## for more information
##
################################################################
# Xms represents the initial size of total heap space
# Xmx represents the maximum size of total heap space
-Xms2g #根据主机内存修改这个参数
-Xmx2g #根据主机内存修改这个参数
2.2 运行ES
$ ./bin/elasticsearch
$ ./bin/elasticsearch -d #在后台启动
$ ps aux|grep elasticsearch #查看是否启动
或
$jps
2.3 报错处理
# 报错:[1]max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]
$ vim /etc/security/limits.conf
es hard nofile 65536
es soft nofile 65536
# 报错:[2]max number of threads [1024] for user [work] likely too low, increase to at least [2048]
$ vim /etc/security/limits.d/90-nproc.conf
soft nproc 2048 (修改1024为2048)
# 报错:[3]max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
$ vim /etc/sysctl.conf
vm.max_map_count=655360
$ sysctl -p #使参数生效
# 报错:[4]system call filters failed to install; check the logs and fix your configuration or disable system call filters at your own risk(这是阿里云服务器上会报的错误)
$ vim ./config/elasticsearch.yml
bootstrap.system_call_filter: false (添加)
# 报错:[5][WARN ][o.e.b.JNANatives] unable to install syscall filter:
java.lang.UnsupportedOperationException: seccomp unavailable: CONFIG_SECCOMP not compiled into kernel, CONFIG_SECCOMP and CONFIG_SECCOMP_FILTER are needed(这是阿里云服务器上会报的错误)
$ vim ./config/elasticsearch.yml
bootstrap.memory_lock: false (添加)
bootstrap.system_call_filter: false (添加)
三、访问 ES
在浏览器直接输入地址:http://127.0.0.1:9200,或者使用 curl 来访问
$ curl -X GET 'http://127.0.0.1:9200'
如果外网无法访问
$ service firewalld stop # 关闭防火墙
$ vim ./config/elasticsearch.yml
修改如下参数为"0.0.0.0"即可
network.host: "0.0.0.0"
四、卸载X-Pack
由于X-Pack目前收费,这里直接卸载它
$ ./bin/elasticsearch-plugin remove x-pack # 卸载X-Pack
五、关闭
$ jps #查看进程id
$ kill `es pid` #es pid为ES的进程id
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。