elastic search监控

自定义副本分片和索引
1、注意事项

索引一旦建立完成,分片数就不可以修改了
但是副本数可以随时修改

2、创建索引的时候就自定义副本和分片

PUT /yayayaay/
{
  "settings": {
    "number_of_shards": 3, 
    "number_of_replicas": 0
  }
}

3、修改单个索引的副本数

PUT /oldzhang/_settings/
{
  "settings": {
    "number_of_replicas": 0
  }
}

4、修改所有的索引的副本数

PUT /_all/_settings/
{
  "settings": {
    "number_of_replicas": 0
  }
}

5、工作生成如何设置

2个节点: 默认就可以 
3个节点: 重要的数据,2副本 不重要的默认 
日志收集: 1副本3分片 

ES监控
1、监控注意

0.不能只监控集群状态
1.监控节点数
2.监控集群状态
3.两者任意一个发生改变了都报警

2、监控命令

GET _cat/nodes
GET _cat/health

命令行监控:
查看集群健康状态

curl -s 127.0.0.1:9200/_cat/health |grep "green"|wc -l

查看节点个数

curl   -s 127.0.0.1:9200/_cat/nodes|wc -l

集群健康状态不为green 或者 节点个数不为3
满足两个其中的一个条件 就报警

使用zabbix监控和kibana结合使用

使用kibana的monitoring进行监控

在这里插入图片描述
测试:
在这里插入图片描述

在这里插入图片描述

elastic search 的优化

官方参考
在这里插入图片描述
总结:
1、禁用交换分区
关闭swap分区
配置问文件打开内存锁定参数
2、虚拟内存的设置

1.内存 
    不要超过32G  超过32G的话  性能不升反降(官方建议)
1、系统建议预留一半
2、每个ES节点不要超过32G内存
官方的意思:如果性能不够了 就加节点 加机器

48内存 
系统留一半: 24G 
自己留一半: 24G
8G 12G 16G 24G 30G 

2.SSD硬盘
0	10 或者不做raid都可以  因为有副本在保证

3.代码优化

4.升级大版本

中文分词器
1、安装条件

所有的ES节点都需要安装
所有的ES都需要重启才能生效

2、安装中文分词器
在线安装

cd /usr/share/elasticsearch
./bin/elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v6.6.0/elasticsearch-analysis-ik-6.6.0.zip

离线本地安装
链接:https://pan.baidu.com/s/1D_bA7Qhl4LY-yEljOL2W7w
提取码:dfjf

/usr/share/elasticsearch/bin/elasticsearch-plugin install file:///XXX/elasticsearch-analysis-ik-6.6.0.zip

2、创建索引

PUT /news2

3、创建模板

POST /news2/text/_mapping
{
        "properties": {
            "content": {
                "type": "text",
                "analyzer": "ik_max_word",
                "search_analyzer": "ik_smart"
            }
        }

}

4、插入测试数据

POST /news2/text/1
{"content":"美国留给伊拉克的是个烂摊子吗"}

POST /news2/text/2
{"content":"公安部:各地校车将享最高路权"}

POST /news2/text/3
{"content":"中韩渔警冲突调查:韩警平均每天扣1艘中国渔船"}

POST /news2/text/4
{"content":"中国驻洛杉矶领事馆遭亚裔男子枪击 嫌犯已自首"}

5、再次查询数据发现已经能识别中文了

POST /news2/_search
{
    "query" : { "match" : { "content" : "中国" }},
    "highlight" : {
        "pre_tags" : ["<tag1>", "<tag2>"],
        "post_tags" : ["</tag1>", "</tag2>"],
        "fields" : {
            "content" : {}
        }
    }
}

6、再插入测试语句 查询

POST /news/txt/1
{"content":"美国留给伊拉克的是个烂摊子吗"}

POST /news/txt/2
{"content":"公安部:各地校车将享最高路权"}

POST /news/txt/3
{"content":"中韩渔警冲突调查:韩警平均每天扣1艘中国渔船"}

POST /news/txt/4
{"content":"中国驻洛杉矶领事馆遭亚裔男子枪击 嫌犯已自首"}


POST /news/_search
{
    "query" : { "match" : { "content" : "中国" }},
    "highlight" : {
        "pre_tags" : ["<tag1>", "<tag2>"],
        "post_tags" : ["</tag1>", "</tag2>"],
        "fields" : {
            "content" : {}
        }
    }
}

在这里插入图片描述

热更新中文分词库
1、安装nginx

cat >> /etc/yum.repos.d/nginx.repo<<EOF
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/\$releasever/\$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true

[nginx-mainline]
name=nginx mainline repo
baseurl=http://nginx.org/packages/mainline/centos/\$releasever/$basearch/
gpgcheck=1
enabled=0
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
EOF

yum makecache fast
yum install nginx -y

2、编写字典文件

cat >>/usr/share/nginx/html/my_dic.txt<<EOF
上海
班长
学委
张亚
胖虎
EOF

3、重启nginx

nginx -t
systemctl restart nginx 

4、配置es的中文分词器插件

vim /etc/elasticsearch/analysis-ik/IKAnalyzer.cfg.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
<properties>
	<comment>IK Analyzer 扩展配置</comment>
	<!--用户可以在这里配置自己的扩展字典 -->
	<entry key="ext_dict"></entry>
	 <!--用户可以在这里配置自己的扩展停止词字典-->
	<entry key="ext_stopwords"></entry>
	<!--用户可以在这里配置远程扩展字典 -->
	<entry key="remote_ext_dict">http://10.0.0.51/my_dic.txt</entry>
	<!--用户可以在这里配置远程扩展停止词字典-->
	<!-- <entry key="remote_ext_stopwords">words_location</entry> -->
</properties>

5、将修改好的LK配置文件复制到其他所有ES节点

cd /etc/elasticsearch/analysis-ik/
scp IKAnalyzer.cfg.xml 10.0.0.52:/etc/elasticsearch/analysis-ik/

6、重启所有ES节点

systemctl restart elasticsearch.service 

7、查看日志里字典的词有没有加载出来

[2020-02-12T14:56:38,610][INFO ][o.w.a.d.Monitor          ] [node-1] 重新加载词典...
[2020-02-12T14:56:38,611][INFO ][o.w.a.d.Monitor          ] [node-1] try load config from /etc/elasticsearch/analysis-ik/IKAnalyzer.cfg.xml
[2020-02-12T14:56:38,614][INFO ][o.w.a.d.Monitor          ] [node-1] [Dict Loading] http://10.0.0.51/my_dic.txt
[2020-02-12T14:56:38,628][INFO ][o.w.a.d.Monitor          ] [node-1] 上海
[2020-02-12T14:56:38,629][INFO ][o.w.a.d.Monitor          ] [node-1] 班长
[2020-02-12T14:56:38,629][INFO ][o.w.a.d.Monitor          ] [node-1] 学委
[2020-02-12T14:56:38,629][INFO ][o.w.a.d.Monitor          ] [node-1] 张亚
[2020-02-12T14:56:38,629][INFO ][o.w.a.d.Monitor          ] [node-1] 胖虎
[2020-02-12T14:56:38,629][INFO ][o.w.a.d.Monitor          ] [node-1] 重新加载词典完毕...

8、打开ES日志,然后更新字典内容,查看日志中会不会自动加载

echo "武汉" >> /usr/share/nginx/html/my_dic.txt

9、搜索测试验证结果

POST /news2/text/7
{"content":"武汉加油!"}


POST /news2/_search
{
    "query" : { "match" : { "content" : "武汉" }},
    "highlight" : {
        "pre_tags" : ["<tag1>", "<tag2>"],
        "post_tags" : ["</tag1>", "</tag2>"],
        "fields" : {
            "content" : {}
        }
    }
}

10、电商上架新产品流程

先把新上架的商品的关键词更新到词典里
查看ES日志,确认新词被动态更新了
自己编写一个测试索引,插入测试数据,然后查看搜索结果
确认没有问题之后,在让开发插入新商品的数据
测试

备份与恢复

1、官方解决方案:做快照
2、第三方解决方案

链接:https://pan.baidu.com/s/1j9XDmZKMyr7xWMYCPV0Z2Q
提取码:vjzb
复制这段内容后打开百度网盘手机App,操作更方便哦

1、前提条件
需要node环境

npm -v
node -v

2、nodejs安装

https://nodejs.org/dist/v10.16.3/node-v10.16.3-linux-x64.tar.xz
tar xf  node-v10.16.3-linux-x64.tar.xz -C /opt/node
echo "export PATH=/opt/node/bin:\$PATH" >> /etc/profile
source /etc/profile
npm -v
node -v

3、指定使用国内淘宝npm源

npm install -g cnpm --registry=https://registry.npm.taobao.org

4、安装es-dump

cnpm install elasticdump -g

5、备份
备份成可读点的json格式

elasticdump \
  --input=http://10.0.0.51:9200/news2 \
  --output=/data/news2.json \
  --type=data

备份成压缩格式

elasticdump \
  --input=http://10.0.0.51:9200/news2 \
  --output=$|gzip > /data/news2.json.gz  

备份分词器/mapping/数据一条龙服务

elasticdump \
  --input=http://10.0.0.51:9200/news2 \
  --output=/data/news2_analyzer.json \
  --type=analyzer
elasticdump \
  --input=http://10.0.0.51:9200/news2 \
  --output=/data/news2_mapping.json \
  --type=mapping
elasticdump \
  --input=http://10.0.0.51:9200/news2 \
  --output=/data/news2.json \
  --type=data

恢复
只恢复数据

elasticdump \
  --input=/data/news2.json \
  --output=http://10.0.0.51:9200/news2

恢复所有数据包含分词器/mapping一条龙

elasticdump \
  --input=/data/news2_analyzer.json \
  --output=http://10.0.0.51:9200/news2 \
  --type=analyzer
elasticdump \
  --input=/data/news2_mapping.json \
  --output=http://10.0.0.51:9200/news2 \
  --type=mapping
elasticdump \
  --input=/data/news2.json \
  --output=http://10.0.0.51:9200/news2
  --type=data

批量处理备份

[root@localhost data]#  curl -s 10.0.0.52:9200/_cat/indices|awk '{print $3}' |grep -v "^\."
oldzhang
news3
news4
website
news
news2

注意事项:

1、如果恢复的时候 数据冲突了,会被覆盖掉
2、如果已经存在备份文件里面没有的数据,会保留下来

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章