版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
Elasticsearch 作为最受欢迎的开源搜索框架之一,能够满足数据存储,数据搜索和数据分析的功能,在最近的几个月里我会慢慢地深入了解和学习elasticsearch。
安装
下载并安装ES的yum公钥
rpm --import https://packages.elastic.co/GPG-KEY-elasticsearch
配置ES的yum源
vim /etc/yum.repos.d/elasticsearch.repo
输入以下内容
[elasticsearch-2.x]
name=Elasticsearch repository for 2.x packages
baseurl=http://packages.elastic.co/elasticsearch/2.x/centos
gpgcheck=1
gpgkey=http://packages.elastic.co/GPG-KEY-elasticsearch
enabled=1
yum安装ES
更新yum的缓存
yum makecache
安装ES
yum install elasticsearch
配置和启动ES服务器进程
/sbin/chkconfig --add elasticsearch
systemctl start elasticsearch
查看ES状态
systemctl status elasticsearch
访问ES
curl -X GET localhost:9200
{
"name" : "Fight-Man",
"cluster_name" : "elasticsearch_test",
"cluster_uuid" : "MEz2NLgcRRGCcs02xGPhKw",
"version" : {
"number" : "2.4.6",
"build_hash" : "5376dca9f70f3abef96a77f4bb22720ace8240fd",
"build_timestamp" : "2017-07-18T12:17:44Z",
"build_snapshot" : false,
"lucene_version" : "5.5.4"
},
"tagline" : "You Know, for Search"
}
修改配置
目录:/etc/elasticsearch/elasticsearch.yml
可以配置cluster.name, host, port, node.name等信息
#vim /etc/elasticsearch/elasticsearch.yml
cluster.name: demo //设置集群名称
node.name: elk-1 //节点名称,一个集群之内节点的名称不能重复
path.data: /data/es-data //修改data存放的路径
path.logs: /var/log/elasticsearch/ //修改logs日志的路径
#bootstrap.memory_lock: true //锁住es内存,保证内存不分配至交换分区,这里暂时不配置。注释掉
network.host: 0.0.0.0 //监听的网络地址,可修改为本机ip
http.port: 9200 //开启监听的端口
http.cors.enabled: true //增加新的参数,这样head插件可以访问es
http.cors.allow-origin: "*"
bootstrap.system_call_filter: false
discovery.zen.ping.unicast.hosts: ["192.168.1.31","192.168.1.32"] //单播(配置一台即可,生产可以使用组播方式),如果有多个elasticsearch节点可配置
可通过curl工具和ES进行交互,包括POST,GET,PUT等
查看集群健康情况,
curl http://localhost:9200/_cluster/health?pretty=true
{
"cluster_name" : "elasticsearch_test",
"status" : "yellow",
"timed_out" : false,
"number_of_nodes" : 1,
"number_of_data_nodes" : 1,
"active_primary_shards" : 2,
"active_shards" : 2,
"relocating_shards" : 0,
"initializing_shards" : 0,
"unassigned_shards" : 2,
"delayed_unassigned_shards" : 0,
"number_of_pending_tasks" : 0,
"number_of_in_flight_fetch" : 0,
"task_max_waiting_in_queue_millis" : 0,
"active_shards_percent_as_number" : 50.0
}
status
字段指示着当前集群在总体上是否工作正常。它的三种颜色含义如下:
green
所有的主分片和副本分片都正常运行。
yellow
所有的主分片都正常运行,但不是所有的副本分片都正常运行。
red
有主分片没能正常运行。
Kibana 是为Elasticsearch设计的开源分析和可视化平台,你可以使用 Kibana 来搜索,查看存储在 Elasticsearch 索引中的数据并与之交互。你可以很容易实现高级的数据分析和可视化,以图表的形式展现出来。
下载安装
wget https://artifacts.elastic.co/downloads/kibana/kibana-6.0.0-x86_64.rpm
yum install -y kibana-6.0.0-x86_64.rpm
修改配置文件
vim /etc/kibana/kibana.yml
server.port: 5601 //监听端口
server.host: "192.168.1.31" //监听IP地址,建议内网ip
elasticsearch.url: "http://192.168.1.31:9200" //elasticsearch连接kibana的URL,也可以填写192.168.1.32,因为它们是一个集群
启动服务
systemctl enable kibana
systemctl start kibana
测试访问外网ip地址:5601
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有