当前位置:网站首页>ELK日志收集系统部署
ELK日志收集系统部署
2022-06-23 15:54:00 【用户7353950】
日志在计算机系统中是一个非常广泛的概念,任何程序都有可能输出日志:操作系统内核、各种应用服务器等等。日志的内容、规模和用途也各不相同,很难一概而论。
Web日志中包含了大量人们——主要是产品分析人员会感兴趣的信息,最简单的,我们可以从中获取网站每类页面的PV值(PageView,页面访问量)、独立IP数(即去重之后的IP数量)等;稍微复杂一些的,可以计算得出用户所检索的关键词排行榜、用户停留时间最高的页面等;更复杂的,构建广告点击模型、分析用户行为特征等等。
今天给大家介绍一款日志分析工具:ELK
ELK由Elasticsearch、Logstash和Kibana三部分组件组成;
Elasticsearch 是基于 JSON 的分布式搜索和分析引擎,专为实现水平扩展、高可用和管理便捷性而设计
Logstash 是开源的服务器端数据处理管道,能够同时 从多个来源采集数据、转换数据,然后将数据发送到您最喜欢的 “存储库” 中。(我们的存储库当然是 Elasticsearch。)
Kibana 能够以图表的形式呈现数据,并且具有可扩展的用户界面,供您全方位配置和管理 Elastic Stack。
今天的试验是:通过ELK分析线上所有Nginx的访问日志。
一、试验拓扑图
二、软件包获得
Nginx下载http://nginx.org/en/download.html
Redis下载 https://redis.io/
Elasticsearch logstash kibana下载 https://www.elastic.co/downloads
三,开始部署
3.1)业务机部署A
业务机:192.168.1.242/24
OS:rhel6.5
涉及软件:nginx+logstash+redis+jdk
软件包准备:根据上述的提示下载软件包
[[email protected] opt]# ls
jdk-8u144-linux-x64.rpm logstash-5.5.1.tar.gz nginx-1.13.4.tar.gz redis-4.0.1.tar.gz
3.1.1)安装JDK
[[email protected] opt]# rpm -ivh jdk-8u144-linux-x64.rpm
Preparing... ####################################### [100%]
1:jdk1.8.0_144 ######################################## [100%]
Unpacking JAR files...
tools.jar...
plugin.jar...
javaws.jar...
deploy.jar...
rt.jar...
jsse.jar...
charsets.jar...
localedata.jar...
设置java环境变量
[[email protected] opt]# vim /root/.bash_profile 末尾追加一下内容
JAVA_HOME=/usr/java/jdk1.8.0_144
PATH=JAVA_HOME/bin:PATH:
CLASSPATH=.:JAVA_HOME/lib/tools.jar:JAVA_HOME/lib/dt.jar
export PATH JAVA_HOME CLASSPATH CATALINA_HOME
生效配置并验证
[[email protected] opt]# source /root/.bash_profile
[[email protected] opt]# java -version
java version "1.8.0_144"
Java(TM) SE Runtime Environment (build 1.8.0_144-b01)
Java HotSpot(TM) 64-Bit Server VM (build 25.144-b01, mixed mode)
3.1.2)安装redis
[[email protected] opt]# tar xf redis-4.0.1.tar.gz
[[email protected] opt]# cd redis-4.0.1
[[email protected] redis-4.0.1]# make
[[email protected] redis-4.0.1]# make install
配置redis
[[email protected] redis-4.0.1]# sed -i -r '/^(bind)/s/127.0.0.1/0.0.0.0/' redis.conf
[[email protected] redis-4.0.1]# sed -i -r '/^(daemonize)/s/no/yes/' redis.conf
启动redis
[[email protected] redis-4.0.1]# redis-server redis.conf
5789:C 30 Aug 11:09:58.584 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
5789:C 30 Aug 11:09:58.584 # Redis version=4.0.1, bits=64, commit=00000000, modified=0, pid=5789, just started
5789:C 30 Aug 11:09:58.584 # Configuration loaded
验证启动
[[email protected] redis-4.0.1]# lsof -i :6379
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
redis-ser 5790 root 6u IPv4 18672 0t0 TCP *:6379 (LISTEN)
3.1.3)安装nginx
[[email protected] opt]# tar xf nginx-1.13.4.tar.gz
[[email protected] opt]# cd nginx-1.13.4
[[email protected] nginx-1.13.4]# yum -y install pcre-devel zlib-devel
[[email protected] nginx-1.13.4]# ./configure --prefix=/usr/local/nginx
[[email protected] nginx-1.13.4]# make
[[email protected] nginx-1.13.4]# make install
修改nginx配置文件,重新定义log_format 以json格式输出日志到access.log
[[email protected] nginx-1.13.4]# cd /usr/local/nginx/conf/
[[email protected] conf]# vim nginx.conf
启动nginx并验证
[[email protected] conf]# /usr/local/nginx/sbin/nginx
[[email protected] conf]# lsof -i :80
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
nginx 10765 root 6u IPv4 24510 0t0 TCP *:http (LISTEN)
nginx 10766 nobody 6u IPv4 24510 0t0 TCP *:http (LISTEN)
访问一次nginx 验证日志格式是否正确
3.1.4)安装logstash
[[email protected] opt]# tar xf logstash-5.5.1.tar.gz -C /usr/local/
[[email protected] opt]# cd /usr/local/logstash-5.5.1/
[[email protected] logstash-5.5.1]# mkdir conf.d
[[email protected] logstash-5.5.1]# vim conf.d/nginx_to_redis
input {
file {
path => ["/usr/local/nginx/logs/access.log"]
type => "nginx_log"
codec => json
}
}
output {
redis{
host => "192.168.1.242"
key => 'logstash:redis'
data_type => 'channel'
port => '6379'
}
stdout {
codec => rubydebug
}
}
启动logstash 并测试是否成功收集nginx日志到redis
[[email protected] ~]# /usr/local/logstash-5.5.1/bin/logstash -f /usr/local/logstash-5.5.1/conf.d/nginx_to_redis
查看启动日志
[[email protected] logstash-5.5.1]# tailf /usr/local/logstash-5.5.1/logs/logstash-plain.log
测试日志收集
Logstash收集日志输出
开启redis 监控
3.2)业务机部署B
业务机:192.168.1.241/24
OS:rhel6.5
涉及软件:elasticsearch+logstash+kibana
[[email protected] opt]# ls
elasticsearch-5.5.1.rpm
kibana-5.5.1-x86_64.rpm
jdk-8u144-linux-x64.rpm
logstash-5.5.1.tar.gz
3.2.1)安装jdk
参考242设置
3.2.2)安装elasticsearch
[[email protected] opt]# rpm -ivh elasticsearch-5.5.1.rpm
warning: elasticsearch-5.5.1.rpm: Header V4 RSA/SHA512 Signature, key ID d88e42b4: NOKEY
Preparing... ######################################## [100%]
Creating elasticsearch group... OK
Creating elasticsearch user... OK
1:elasticsearch ######################################## [100%]
### NOT starting on installation, please execute the following statements to configure elasticsearch service to start automatically using chkconfig
sudo chkconfig --add elasticsearch
### You can start elasticsearch service by executing
sudo service elasticsearch start
配置elasticsearch
[[email protected] opt]# sed -i -r '/^(#network.host:)/cnetwork.host: 0.0.0.0' /etc/elasticsearch/elasticsearch.yml
[[email protected] opt]# sed -i -r '/^(#http.port:)/chttp.port: 9200' /etc/elasticsearch/elasticsearch.yml
[[email protected] opt]# sed -i -r '/^(#bootstrap.memory_lock:)/cbootstrap.memory_lock: falsenbootstrap.system_call_filter: false' /etc/elasticsearch/elasticsearch.yml
优化系统
[[email protected] opt]# vim /etc/security/limits.conf 末尾追加
elasticsearch soft nproc 10240
elasticsearch hard nproc 10240
* soft nofile 65540
* hard nofile 65540
重启计算机生效
启动elasticsearch
[[email protected] opt]# /etc/init.d/elasticsearch start
Starting elasticsearch: [ OK ]
验证
3.2.3)安装logstash
[[email protected] opt]# tar xf logstash-5.5.1.tar.gz -C /usr/local/
[[email protected] opt]# cd /usr/local/logstash-5.5.1/
[[email protected] logstash-5.5.1]# mkdir conf.d
[[email protected] logstash-5.5.1]# vim conf.d/redis_to_elk
input {
redis {
port => "6379"
host => "192.168.1.242"
data_type => "channel"
key => "logstash:redis"
type => "redis-input"
}
}
output {
elasticsearch {
hosts => "192.168.1.241"
index => "logstash-%{+YYYY.MM.dd}"
action => "index"
}
stdout {
codec => rubydebug
}
}
启动logstash
[[email protected] logstash-5.5.1]#./bin/logstash -f conf.d/redis_to_elk
访问一次测试数据是否有redis写入到elk
3.2.4)安装kibana
[[email protected] opt]# rpm -ivh kibana-5.5.1-x86_64.rpm
warning: kibana-5.5.1-x86_64.rpm: Header V4 RSA/SHA512 Signature, key ID d88e42b4: NOKEY
Preparing... ####################################### [100%]
1:kibana ####################################### [100%]
修改配置文件中的
[[email protected] opt]# sed -i -r '/^(#server.host:)/cserver.host: "0.0.0.0"' /etc/kibana/kibana.yml
[[email protected] opt]# /etc/init.d/kibana start
kibana started
验证启动
[[email protected] opt]# netstat -ntpl |grep 5601
tcp 0 0 0.0.0.0:5601 0.0.0.0:* LISTEN 1993/node
测试通过浏览器
边栏推荐
- TensorRT Paser加载onnx 推理使用
- Image reading: image open(ImgPath)
- 六石编程学:运用之妙,存乎一心
- Pytorch: saving and exporting models
- JS常见的报错及异常捕获
- R语言plotly可视化:plotly可视化在对比条形图中添加误差条(Bar Chart with Error Bars with plotly in R)
- How is it cheaper to open a stock account? Is it safe to open an account online now?
- 机器人方向与高考选专业的一些误区
- OutputDebugString使用说明以及异常处理
- Six stone programming: the subtlety of application
猜你喜欢
随机推荐
Server deployment and instructions
R language uses colorblinr package to simulate color blind vision, and uses edit to visualize the image of ggplot2_ The colors function is used to edit and convert color blindness into visual results
ADB 按键名、按键代码数字、按键说明对照表
leetcode:30. 串联所有单词的子串【Counter匹配 + 剪枝】
Golang writes to JSON files
谈谈redis缓存击穿透和缓存击穿的区别,以及它们所引起的雪崩效应
Does the enterprise want to use the MES system? These conditions have to be met
Array's own method
《ThreadLocal》
leetcode:30. Concatenate substrings of all words [counter matching + pruning]
The connection between supply and demand will no longer depend on the platform and center of the Internet Era
stylegan1: a style-based henerator architecture for gemerative adversarial networks
Readimg: read picture to variable variable variable
如何选择券商?手机开户安全么?
How to configure PostgreSQL data source on SSRs page
Golang对JSON文件的读写操作
Reading and writing JSON files by golang
Leetcode 450. Delete node in binary search tree
Thinking analysis of binary search method
Generating binary search balanced tree [using tree recursion]









