Elasticsearch 简称es.是一个开源的分布式 RESTful 搜索和分析引擎
实际应用场景:存储日志
官网地址:https://www.elastic.co/cn/
注:Elasticsearch启动不能通过root用户,只能通过普通用户。默认端口:9200
es安装步骤:
1.下载并解压
wget https://download.elastic.co/elasticsearch/elasticsearch/elasticsearch-6.3.2.tar.gz
tar -xzvf elasticsearch-6.3.2.tar.gz
cd 到./elasticsearch-6.3.2/config/ 目录下
2.编辑配置文件,将network.host: 0.0.0.0改为任意访问ip并保存
vi config/elasticsearch.yml
3.执行./bin/elasticsearch
4.执行常见错误解决方案:
问题一 .can not run elasticsearch as root:
解决方案: 不能用root用户登录来执行,切换为普通用户
问题二.max virtual memory areas vm.max_count [65530] likely too low,increase to at least [262144]
解决方案:虚拟内存小,加大虚拟内存 。
在root用户下,
修改配置 /etc/sysctl.conf
添加下面配置:
vm.max_map_count=655360
执行命令:sysctl -p
问题三:max file descriptors [4096] for elasticsearch process likely too low, increase to at least [65536]
解决方案:
vi /etc/security/limits.conf
添加如下内容:
* soft nofile 65536
* hard nofile 131072
* soft nproc 2048
* hard nproc 4096
问题四:报错elastic: Error 403 (Forbidden): blocked by: [FORBIDDEN/12/index read-only / allow delete (api)]; [type=cluster_block_exception]
解决方案:
curl -XPUT -H "Content-Type: application/json" http://127.0.0.1:9200/_all/_settings -d '{"index.blocks.read_only_allow_delete": null}'
返回结果如下即可
{"acknowledged":true}
5.没有错误的话切换到普通用户重新执行启动命令:./bin/elasticsearch
后台启动命令:./bin/elasticsearch & [推荐 ] bin/elasticsearch -d
验证是否启动成功:curl http://本机IP:9200 ,返回json就表示成功
es健康检查
curl -XGET 'http://127.0.0.1:9200/_cluster/health'
es安装可视化页面kibana
图形化界面使用教程:https://yq.aliyun.com/articles/205028
kibana API : https://www.elastic.co/guide/en/elasticsearch/reference/5.2/docs-index_.html
1.下载并解压
wget https://www.elastic.co/cn/downloads/kibana
https://artifacts.elastic.co/downloads/kibana/kibana-6.3.2-linux-x86_64.tar.gz
tar -xzf kibana-6.2.2-linux-x86_64.tar.gz
cd ./kibana/config/ 目录下
2. 编辑 vi config/kibana.yml
server.port: 5601 //默认端口
server.host: "0.0.0.0" // 任意端口可以访问
elasticsearch.url: "http://localhost:9200" // 已安装好的es的ip地址
3. 进入目录执行命令:./bin/kibana 后台启动命令./bin/kibana &
4. 获取所有ype
curl -XGET 'http://localhost:9200/_mapping?pretty=true'
5. 删除指定index
curl -XDELETE http://localhost:9200/xxx
6. 删除指定条件数据 https://blog.csdn.net/QYHuiiQ/article/details/90812570
新建脚本es-index-delete-by-query-30d.sh 。加入
LAST_DATA=`date -d "-30 days" "+%Y-%m-%dT00:00:00"`
echo ${LAST_DATA}
curl -XPOST 'http://127.0.0.1:9200/这里写要删除的index/_delete_by_query' -H 'Content-Type: application/json' -d '
{
"query": {
"bool": {
"must": [
{
"range": {
"value.timestamp": {
"lte":"'${LAST_DATA}'"
}
}
}
]
}
}
}
'
正在上传…重新上传取消正在上传…重新上传取消正在上传…重新上传取消正在上传…重新上传取消正在上传…重新上传取消转存失败重新上传取消正在上传…重新上传取消正在上传…重新上传取消正在上传…重新上传取消