目录
elasticsearch索引管理
1、查看索引
[root@localhost ~]# curl '192.168.194.130:9200/_cat/indices?v'
health status index uuid pri rep docs.count docs.deleted store.size pri.store.size
yellow open msg_log-2020.10.21 ss2Y0mXqROqP2UsD9_Co3Q 5 1 7643 0 2.8mb 2.8mb
green open .kibana_1 iYHTbTyjQQC43PHlW91hNw 1 0 3 0 15.7kb 15.7kb
[root@localhost ~]# curl -X GET http://192.168.194.130:9200/_cat/indices?v
health status index uuid pri rep docs.count docs.deleted store.size pri.store.size
yellow open msg_log-2020.10.21 ss2Y0mXqROqP2UsD9_Co3Q 5 1 7643 0 2.8mb 2.8mb
green open .kibana_1 iYHTbTyjQQC43PHlW91hNw 1 0 3 0 15.7kb 15.7kb
2、删除指定索引
[root@localhost ~]# curl -XDELETE -u elastic:changeme http://192.168.194.130:9200/acc-apply-2018.08.09 -----索引名字(msg_log-2020.10.21)
3、删除指定多个索引。多个索引之间用,隔开
[root@localhost ~]# curl -XDELETE -u elastic:changeme http://localhost:9200/acc-apply-2018.08.09,acc-apply-2018.08.10
4、模糊匹配删除
[root@localhost ~]# curl -XDELETE -u elastic:changeme http://192.168.194.130:9200/acc-apply-*
5、使用通配符,删除所有的索引
[root@localhost ~]# curl -XDELETE http://localhost:9200/_all
或
[root@localhost ~]# curl -XDELETE http://localhost:9200/*
_all ,* 通配所有的索引
- 通常不建议使用通配符,误删了后果就很严重了,所有的index都被删除了
- 禁止通配符为了安全起见,可以在elasticsearch.yml配置文件中设置禁用_all和*通配符
action.destructive_requires_name = true
这样就不能使用_all和*了
6、定时删除索引
可以通过脚本的形式。删除3天前的索引。
#!/bin/bash
time=$(date -d '-3days' +'%Y.%m.%d')
curl -XDELETE -u elastic:changeme http://localhost:9200/acc-apply-${time}
也可以通过写入定时任务。删除3天前的索引。
30 2 * * * /usr/bin/curl -XDELETE -u elastic:changeme http://localhost:9200/*-$(date -d '-3days' +'%Y.%m.%d') >/dev/null 2>&1
elasticsearch配置等优化
JVM java虚拟机
JRE java 运行环境
JDK java工具包
JVM————JRE————JDK
vm虚拟机——linux系统——命令
1. 加大内存分配
一开始索引什么的都不多,量不大,所以都很轻松,后来量越来越大,默认的配置就有点吃不消了,打开一个页面,查询压力就会非常大。
- 横向扩展es集群
- 通过加大es的jvm内存来优化。
默认情况下,Elasticsearch告诉JVM(java 虚拟机)使用最小和最大大小为1 GB的堆。迁移到生产环境时,配置堆大小以确保Elasticsearch有足够的堆可用是很重要的。
Elasticsearch将通过(最小堆大小)和(最大堆大小)设置分配jvm.options中指定的整个堆 。Xms,Xmx可设置的值取决于服务器上可用的RAM量。一些好的建议是:
将最小堆大小(Xms)和最大堆大小(Xmx)设置为彼此相等。
Elasticsearch可用的堆越多,它可用于缓存的内存就越多。但请注意,过多的堆可能会使您陷入长时间的垃圾收集暂停。
设置Xmx为不超过物理RAM的50%,以确保有足够的物理RAM留给内核文件系统缓存。
最大内存不要超过32G,跨32G时,有一个现象,使用更多的内存,比如 40G,效果还不如31G!
[root@localhost ~]# vim /etc/elasticsearch/jvm.options
-Xms2g
-Xmx2g #一半内存(4G内存,改为2G)
比如我的主机是16核32G的主机,那么这时更改一下配置:
-Xms16g
-Xmx16g
-Xss128m
最小xms 最大xmx
ulimit -n 65535 //临时生效
然后重启es,会发现快很多了。
关于这一点,可以参考官方文档:https://www.elastic.co/guide/en/elasticsearch/reference/current/heap-size.html
2. 修改系统允许的最大文件打开数。
#并发连接数
[root@localhost ~]# echo "root soft nofile 65535" >> /etc/security/limits.conf
[root@localhost ~]# echo "root hard nofile 65535" >> /etc/security/limits.conf
[root@localhost ~]# echo "* soft nofile 65535" >> /etc/security/limits.conf
[root@localhost ~]# echo "* hard nofile 65535" >> /etc/security/limits.conf
[root@localhost ~]# echo -e "root soft nofile 65535\nroot hard nofile 65535\n* soft nofile 65535\n* hard nofile 65535\n" >> /etc/security/limits.conf
[root@localhost ~]# sed -i 's#4096#65535#g' /etc/security/limits.d/20-nproc.conf
一个是修改最大文件打开数,一个是最大进程数,其中root表示管理员,*表示普通用户。
更改之后重启主机即可。