开源分布式搜索引擎,它的特点有:分布式,零配置,自动发现,索引自动分片,
索引副本机制,restful 风格接口,多数据源,自动搜索负载等
官方的安装参考文档:https://www.elastic.co/guide/en/elasticsearch/reference/6.6/setup-configuration-memory.html
软件包下载地址:https://mirrors.tuna.tsinghua.edu.cn/elasticstack/6.x/yum/6.6.0/
elasticsearch-6.6.0.rpm
filebeat-6.6.0-x86_64.rpm
kibana-6.6.0-x86_64.rpm
logstash-6.6.0.rpm
搭建环境
准备elastic1:192.168.43.10
elastic2:192.168.43.100
每台服务器最少4g内存大小
1.安装elasticsearch:
前提需要jdk-1.8.0(java)
[root@elastic1 src]# rpm -ivh elasticsearch-6.6.0.rpm 警告:elasticsearch-6.6.0.rpm: 头V4 RSA/SHA512 Signature, 密钥 ID d88e42b4: NOKEY准备中... ################################# [100%]正在升级/安装... 1:elasticsearch-0:6.6.0-1 ( 1################################# [100%]### NOT starting on installation, please execute the following statements to configure elasticsearch service to start automatically using systemd sudo systemctl daemon-reload sudo systemctl enable elasticsearch.service ### You can start elasticsearch service by executing sudo systemctl start elasticsearch.service Created elasticsearch keystore in /etc/elasticsearch[root@elastic1 src]#
2.修改配置文件
vim /etc/elasticsearch/elasticsearch.yml
去除前面的#
node.name: node-1 #群集中本机节点名 path.data: /data/elasticsearch #数据目录 path.logs: /var/log/elasticsearch #数据目录 bootstrap.memory_lock: true #锁定内存 network.host: 192.168.43.10,127.0.0.1 #监听的IP地址 http.port: 9200 #端口号
3.创建数据目录,并修改权限(注意与主配置文件中的数据目录对应)
[root@elastic1 src]# mkdir -p /data/elasticsearch[root@elastic1 src]# chown -R elasticsearch.elasticsearch /data/elasticsearch/
4.分配锁定内存
vim /etc/elasticsearch/jvm.options
-Xms2g #分配最小内存-Xmx2g #分配最大内存,官方推荐为物理内存的一半,但最大为
5.修改锁定后,无法重启,解决方法如下(如果没有开启内存锁定可以不用修改)
systemctl edit elasticsearch
添加 添加完后按f2保存退出
[Service]LimitMEMLOCK=infinity
6.启动服务
[root@elastic1 src]# systemctl daemon-reload [root@elastic1 src]# systemctl restart elasticsearch.service
7.查看端口(可能服务启动比较慢)
[root@elastic1 src]# netstat -anput |grep java tcp6 0 0 192.168.43.10:9200 :::* LISTEN 4035/java tcp6 0 0 127.0.0.1:9200 :::* LISTEN 4035/java tcp6 0 0 192.168.43.10:9300 :::* LISTEN 4035/java tcp6 0 0 127.0.0.1:9300 :::* LISTEN 4035/java
8.查看单主机
http://192.168.43.10:9200/
查看群集健康状态
http://192.168.43.10:9200/_cluster/health?pretty
查看整个群集状态信息
http://192.168.43.10:9200/_cluster/state?pretty
9.创建索引(创建两个):vipinfo,类型:users,序号:1,数据部分:…
[root@elastic1 src]# curl -XPUT '192.168.43.10:9200/vipinfo/users/1?pretty&pretty' -H 'Content-Type:application/json' -d '{"name":"guofucheng","age":"45","job":"mingxing"}'{ "_index" : "vipinfo", "_type" : "users", "_id" : "1", "_version" : 1, "result" : "created", "_shards" : { "total" : 2, "successful" : 1, "failed" : 0 }, "_seq_no" : 0, "_primary_term" : 1}[root@elastic1 src]# curl -XPUT '192.168.43.10:9200/vipinfo/users/2?pretty&pretty' -H 'Content-Type:application/json' -d '{"name":"goudongxi","age":"250","job":"danshen"}'{ "_index" : "vipinfo", "_type" : "users", "_id" : "2", "_version" : 1, "result" : "created", "_shards" : { "total" : 2, "successful" : 1, "failed" : 0 }, "_seq_no" : 0, "_primary_term" : 1}
10.下载es-head插件
https://github.com/mobz/elasticsearch-head
下载后,解压,复制crx目录下es-head.crx到桌面
改名es-head.crx为es-head.crx.zip
解压es-head.crx.zip到es-head.crx目录,把目录es-head.crx,上传到谷歌浏览器开发工具–扩展程序里
11.到web网页上查看
elasticsearch群集:
状态颜色:
灰色:未连接
绿色:数据完整态
黄色:副本不完整
红色:数据分片不完整
紫色:数据分片复制过程
群集主机角色:
主节点master:负责管理调度
工作节点: 负责处理数据
默认情况,所有节点都是工作节点,即主节点也处理数据
12.到第二台elastic2
安装es,步骤参考第一台,注意配置文件需要修改
vim /etc/elasticsearch/elasticsearch.yml
node.name: node-2path.data: /data/elasticsearch path.logs: /var/log/elasticsearch bootstrap.memory_lock: true network.host: 192.168.43.100,127.0.0.1 http.port: 9200 discovery.zen.ping.unicast.hosts: ["192.168.43.10", "192.168.43.100"]discovery.zen.minimum_master_nodes: 2 #添加的值=节点数/2 + 1
13.创建数据目录,修改权限
[root@elastic2 /]# mkdir -p /data/elasticsearch[root@elastic2 /]# chown -R elasticsearch.elasticsearch /data/elasticsearch/
14.修改锁定内存,这里第二台没有锁定内存,所以不用田间,想添加可以参开第一台
重启服务
[root@elastic2 /]# systemctl daemon-reload[root@elastic2 /]# systemctl restart elasticsearch.service
15.可在web网页中查看
16.查看群集所有节点详细信息
注意:企业环境使用脚本监控群集健康状态是否为green 或 节点数不匹配 就邮件报警
[root@elastic2 src]# curl -XGET '192.168.43.10:9200/_nodes/_all/info/jvm.process?human&pretty'
17.创建索引index1时,修改分片为3和副本数为2
[root@elastic1 src]# curl -X PUT 192.168.43.10:9200/index1 -H 'Content-Type: application/json' -d '{> "settings" : {> "index" : {> "number_of_shards" : 3, > "number_of_replicas" : 2 > }> }> }'{"acknowledged":true,"shards_acknowledged":true,"index":"index1"}[root@elastic1 src]#
在查看web网页点击刷新
18.将副本数由2改为1
[root@elastic1 src]# curl -X PUT '192.168.43.10:9200/index1/_settings?pretty' -H 'Content-Type: application/json' -d '{ "settings": { "number_of_replicas": "1" } }'{ "acknowledged" : true}