为什么用到ELK
一般我们需要进行日志分析场景:直接在日志文件中 grep、awk 就可以获得自己想要的信息。但在规模较大的场景中,此方法效率低下,面临问题包括日志量太大如何归档、文本搜索太慢怎么办、如何多维度查询。需要集中化的日志管理,所有服务器上的日志收集汇总。常见解决思路是建立集中式日志收集系统,将所有节点上的日志统一收集,管理,访问。
ELK是三个开源软件的缩写,分别表示:Elasticsearch , Logstash, Kibana , 它们都是开源软件。
名称 | 作用 |
---|---|
Elasticsearch | Elasticsearch是个开源分布式搜索引擎,提供搜集、分析、存储数据三大功能。 |
Logstash | Logstash 主要是用来日志的搜集、分析、过滤日志的工具,支持大量的数据获取方式。 |
Kibana | Kibana可以为 Logstash 和 ElasticSearch 提供的日志分析友好的 Web 界面,可以帮助汇总、分析和搜索重要数据日志。 |
ES环境搭建
版本:elasticsearch-6.2.4
官方网站下载这3个软件:https://www.elastic.co/cn/products
上传到linux:/home
目录下。
- 首先确定自己的jdk版本:
java -version
必须jdk1.8以上。有尝试过jdk环境下搭建,需要改启动脚本指定启动使用1.8,百度无果。(我不会写脚本啊!!)
- 解压
tar -zxvf elasticsearch-6.2.4.tar.gz
- 修改参数conf/elasticsearch.yml
# ---------------------------------- Cluster -----------------------------------
# Use a descriptive name for your cluster:
#集群名称
cluster.name: my-elk
# ------------------------------------ Node ------------------------------------
# Use a descriptive name for the node:
#节点名字
node.name: node-1
# Add custom attributes to the node:
#node.attr.rack: r1
# ----------------------------------- Paths ------------------------------------
#
# Path to directory where to store the data (separate multiple locations by comma):
#数据文件存放路径,默认不设置
#path.data: /path/to/data
# Path to log files:
#日志文件存放路径,默认不设置
#path.logs: /path/to/logs
# ----------------------------------- Memory -----------------------------------
# Lock the memory on startup:
#内存锁,防止使用startup的内存
#bootstrap.memory_lock: true
# Make sure that the heap size is set to about half the memory available
# on the system and that the owner of the process is allowed to use this
# limit.
# Elasticsearch performs poorly when the system is swapping the memory.
# ---------------------------------- Network -----------------------------------
# Set the bind address to a specific IP (IPv4 or IPv6):
#设置绑定的ip,给外网使用设置为0.0.0.0
network.host: 0.0.0.0
#
# Set a custom port for HTTP:
#端口9200
http.port: 9200
- 启动
bin目录下
./elasticsearch
在没有什么意外的情况下,你肯定失败。详情看下面坑点。
坑点集合
- 不能使用root用户登录
- 内存不够
- 调节并发连接数
- max virtual memory areas vm.max_map_count [65530] is too low, increase to at
坑1.can not run elasticsearch as root
解决方案:
创建用户:useradd lin
添加目录用户权限:chown -R lin.lin /usr/local/elasticsearch
切换到lin用户:su lin
lin
是你创建的用户名,可随便修改
坑2.内存不够
报错提示内存不足:Java HotSpot(TM) 64-Bit Server VM warning: INFO: os::commit_memory(0x00000000c5330000, 986513408, 0) failed; error=’Cannot allocate memory’ (errno=12)
解决方案:修改config/jvm.options 修改为
-Xms512M
-Xmx512M
坑3.调节并发连接数
max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
解决方案:
vim /etc/security/limits.conf
在后面增加或者修改
# End of file
* soft nofile 655360
* hard nofile 655360
root soft nofile 100001
root hard nofile 100002
坑4:报错max virtual memory areas vm.max_map_count [65530] is too low, increase to at
修改:vim /etc/sysctl.conf
增加配置:vm.max_map_count=655360
配置生效:sysctl -p
配置查看:sysctl -a
以上都解决了
切换用户再启动
su lin
./bin/elasticsearch
成功图片
访问本机ip:9200
我的是http://192.168.0.111:9200/
安装成功