Elasticsearch+Fluentd+Kibana的日志收集分析系统
0.首先安装Linux虚拟机
1. 安装Centos 6.5
安装步骤略过。
关闭防火墙:
/etc/init.d/iptables stop
/etc/init.d/iptables stop
chkconfig iptables off
chkconfig --list|grep ipt
2. 安装java使用的JDK
2.1切换到root用户
su –root
2.2查看虚拟机是否安装jdk
命令:rpm –qa | grep java
2.3卸载虚拟机自带的jdk
Rpm –e –nodeps jdk名称(名称是上面显示的名称)
2.4安装jdk
2.4.1进入usr目录
cd /usr
2.4.2在usr目录下创建java目录
mkdir java
2.4.3将本地的jdk上传
使用yum的rz,或者其他工具
2.4.4解压jdk安装包
tar –zxvf jdk压缩包名称
2.4.5创建快捷方式
ln –s /usr/java/解压的包名 /usr/jdk
2.4.6配置环境变量
vi /etc/profile
在最下面添加
export JAVA_HOME=/usr/jdk export PATH=$PATH:$JAVA_HOME/bin export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar export JAVA_HOME PATH CLASSPATH |
2.4.7重新编译环境变量
source /etc/profile
3. 安装Fluentd
3.1 在线安装
curl -L https://toolbelt.treasuredata.com/sh/install-redhat-td-agent2.sh| sh
3.2 启动fluentd
/etc/init.d/td-agent status
上面都显示ok时,表示安装完成
4.安装Elasticsearch
4.1 在线安装(这里使用1.7.1为例)
curl -O https://download.elastic.co/elasticsearch/elasticsearch/elasticsearch-1.7.1.tar.gz
4.2 解压压缩包
tar zxvf elasticsearch-1.7.1.tar.gz
4.3 启动服务
cd elasticsearch-1.7.1/
./bin/elasticsearch
4.5 出现问题:
启动出现Name or servicenot known异常
解决方案:修改vi/etc/sysconfig/network中的
添加服务路径
在启动步报错
4.6 安装插件
4.6.1 kopf插件 集群资源查询&数据查询
4.6.1.1 在线安装
./elasticsearch-1.7.1/bin/plugin installlmenezes/elasticsearch-kopf/1.0
4.7 访问服务
4.7.1启动服务
./elasticsearch-1.7.1/bin/elasticsearch
4.7.2 访问效果
访问路径:http://192.168.56.154:9200/
出现效果:
在访问插件效果:http://192.168.56.154:9200/_plugin/head/
4.8 elasticsearch常用设置
./elasticsearch console ------前台运行
./elasticsearch start ------后台运行
./elasticsearch install -------添加到系统自动启动
./elasticsearch remove -----取消随系统自动启动
5. 安装kibana
5.1 在线安装
curl -Ohttps://download.elastic.co/kibana/kibana/kibana-4.1.4-linux-x64.tar.gz
5.2 解压压缩包
tar zxvf kibana-4.1.4-linux-x64.tar.gz
5.3 启动服务
cd kibana-4.1.4-linux-x64/
./bin/kibana
注意:kibana只是一个前端展示平台需要es作为数据源,所以在启动ka的之前请确认es的连接地址是否正确!
5.4 修改kibana.yml文件
5.4.1 文件所在路径
./kibana-4.1.4-linux-x64/config/kibana.yml
5.4.2 常用修改
# The host to bind the server to.
host: "0.0.0.0"
# The Elasticsearch instance to use for allyour queries.
elasticsearch_url:"http://localhost:9200"
6.到这里三大软件以安装完成
后面还是进行三大软件的联系配置
7.安装Fluentd必要插件
7.1 安装fluent-plugin-elasticsearch
/usr/sbin/td-agent-gem installfluent-plugin-elasticsearch
7.2 安装fluentd type 插件
/usr/sbin/td-agent-gem installfluent-plugin-typecast
7.3 安装secure-forward 插件(非必须但常用)
/usr/sbin/td-agent-gem installfluent-plugin-secure-forward
例子:采集nginx access日志
1.设备:
虚机101centos6.5:nginx所在服务器,es,fd,ka 所在服务器 client agent
虚机102centos6.5 :fd及插件所在服务器server agent,负责文件存储nginx日志,并转发101es存储
2. nginx日志采集
2.1 修改虚机101 fluentd 配置
/etc/td-agent/td-agent.conf
2.2 添加tail源
<source> type tail path /var/log/nginx/access.log format /^(?<remote>[^ ]*) - - \[(?<time>[^\]]*)\] "(?<method>\S+)(?: +(?<path>[^\"]*) +\S*)?" (?<status>[^ ]*) (?<body_bytes_sent>[^ ]*) "(?<http_referer>[^\"]*)" ClientVersion "(?<clientVersion>[^ ]*)" "(?<userAgent>[^\"]*)" "(?<remoteHost>[^ ]*)" "(?<http_x_forwarded_for>[^\"]*)" upstream_response_time "(?<upstream_response_time>[^ ]*)" request_time "(?<request_time>[^ ]*)"\s$/ time_format %d/%b/%Y:%H:%M:%S %z types remote:ip,time:time,method:string,path:string,status:integer:body_bytes_sent:integer,http_referer:string,userAgent:string,remoteHost:string,http_x_forwarded_for:string,upstream_response_time:string,request_time:float tag 101nginx.access.log pos_file /var/log/td-agent/pos/nginx.access.log.pos </source> |
2.3 添加tag match 把采集的日志转发到虚机102
<match
<server> host 10.22.205.102 port 24224 </server> </match> |
2.4 修改虚机102 fluentd 配置
/etc/td-agent/td-agent.conf
2.4.1 102只做转发存储,顾只配置match
<store> type elasticsearch host 10.22.205.101 port 9200 include_tag_key true tag_key @log_name logstash_format true flush_interval 10s </store |
3. 安装成功
这里102对匹配到的日志做了2个操作:(1). 以时间文件夹路径本地存储nginx日志 (2). 转发获得的日志到101的es上。
重启101,102 fluentd 大功告成
/etc/init
.d/td-agent restart
访问路径
修改借鉴于:
http://blog.csdn.net/ebw123/article/details/46707559
http://blog.csdn.net/shiwenqing/article/details/50475330