elasticsearch安装使用步骤
1 拷贝elasticsearch-5.2.2文件夹
es5必须安装jdk1.8
2 修改/config/elasticsearch.yml中的
node.name
network.host
discovery.zen.ping.unicast.hosts
path.data
还可设置node的性质
#master节点
node.master: true
#存储数据节点
node.data: false
#搜索、协调节点
node.ingest: true
3 增加(如已增加,此步骤忽略)在/config/elasticsearch.yml中:
bootstrap.memory_lock: false
bootstrap.system_call_filter: false
4 使用head插件时需设置:
http.cors.enabled: true
http.cors.allow-origin: "*"
5 去除ES_HEAP_SIZE环境变量(如果以前没设置则忽略此步)
系统环境变量配置文件: /etc/profile
用户环境变量配置文件: /home/用户名/.bashrc
6 修改/etc/security/limits.conf,配置形如:
* soft nofile 655360
* hard nofile 655360
* soft nproc 2048
* hard nproc 4096
* soft memlock unlimited
* hard memlock unlimited
7.修改 /etc/security/limits.d/90-nproc.conf
修改如下内容
* soft nproc 1024改为
* soft nproc 2048
8 修改 /etc/sysctl.conf,增加
vm.max_map_count=655360
并执行命令:sysctl -p
9 以非root用户启动es,启动命令:
./bin/elasticsearch-5.2.2
FAQ:
1 Q: 启动时报:
unable to install syscall filter:
java.lang.UnsupportedOperationException: seccomp unavailable: requires kernel 3.5+
with CONFIG_SECCOMP and CONFIG_SECCOMP_FILTER compiled in
答:此为警告,操作系统内核版本太低,可升级操作系统;若不升级也可使用,部分功能会受影响。
2 Q: 启动时报ERROR: bootstrap checks failed
max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
system call filters failed to install; check the logs and fix your configuration or disable
system call filters at your own risk
答: 步骤8未正确执行所致,或者文件修改后未生效。
elasticsearch-head-master插件以及安装方式
1.修改es的设置
vi /es根目录/config/elasticsearch.yml
增加:(冒号之后有空格)
http.cors.enabled: true
http.cors.allow-origin: "*"
重启es
2.修改es-headmaster设置
elasticsearch-head-master\_site\app.js
4329行
this.base_uri = this.config.base_uri || this.prefs.get("app-base_uri") || "localhost:9200";
localhost地址改为es的地址
3.压缩文件夹elasticsearch-head-master
在cmd下命令:
jar -cvf head.war elasticsearch-head-master
将生成的head.war放到tomcat目录下的webapps,重启tomcat
4.浏览器输入
tomcat所在机器ip:8080//head/elasticsearch-head-master/ 即可。
elasticsearch常用命令【5.2.2版本】
一 检查es是否正常启动
http://es节点IP:9200/
输出以下信息表示启动正常
{
"name" : "node-157",
"cluster_name" : "datastore",
"cluster_uuid" : "sT4c_CSVTd65sGm3JldvJA",
"version" : {
"number" : "5.2.2",
"build_hash" : "f9d9b74",
"build_date" : "2017-02-24T17:26:45.835Z",
"build_snapshot" : false,
"lucene_version" : "6.4.1"
},
"tagline" : "You Know, for Search"
}
查看状态
curl -XGET "http://es节点IP:9200/_nodes/stats?pretty"
http://es节点IP:9200/_cluster/settings?pretty
查看节点状态
http://es节点IP:9200/_nodes/?pretty
http://es节点IP:9200/_nodes/jvm/?pretty
二 查看索引数据
//查看索引状态
http://es节点IP:9200/testsearchstore/_stats/?pretty
//查看索引数据
http://es节点IP:9200/testsearchstore/_search?pretty&size=30
//查看索引中数据的条数
http://es节点IP:9200/testsearchstore/_search?size=0&pretty
//查看索引的内容
http://es节点IP:9200/testsearchstore/_search?pretty
三 查看索引配置
//查看节点状态(索引信息)
http://es节点IP:9200/_nodes/?pretty
//查看节点jvm状态
http://es节点IP:9200/_nodes/jvm/?pretty
//查看线程设置
http://es节点IP:9200/_nodes/thread_pool?pretty
四 刷新
//刷新操作
http://es节点IP:9200/testsearchstore/_refresh
//冲洗
http://es节点IP:9200/testsearchstore/_flush
五 删除
删除索引
curl -XDELETE http://es节点IP:9200/searchstore?pretty
六 查看分词
http://es节点IP:9200/testsearchstore/_analyze?analyzer=ik_max_word&pretty&text=五环路
http://es节点IP:9200/testsearchstore/_analyze?analyzer=ik_smart&pretty&text=京华腾东光科技发展有限公司
http://es节点IP:9200/testsearchstore/_analyze?analyzer=ik_max_word&pretty&text=北京华腾东光科技发展有限公司
七 查看线程设置
http://es节点IP:9200/_nodes/thread_pool?pretty
八 修改线程设置
curl -XPUT "http://es节点IP:9200/_cluster/settings?pretty" -d'{
"transient":{
"threadpool.bulk.type":"fixed",
"threadpool.bulk.size":"24",
"threadpool.bulk.queue_size":"500"
}
}'
九 其他
curl -XPUT "http://es节点IP:9200/testsearchstore/_settings" -d '{"index":{"max_result_window":100000}}'
问题记录
ES head插件里可以看到Size和docs有两个值
size: 169Mi (169Mi)
docs: 89,139 (125,118)
表示是否包含副本。