﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava-术之塔-文章分类-开源项目</title><link>http://www.blogjava.net/chrisstrive/category/54386.html</link><description /><language>zh-cn</language><lastBuildDate>Thu, 05 Jun 2014 19:10:22 GMT</lastBuildDate><pubDate>Thu, 05 Jun 2014 19:10:22 GMT</pubDate><ttl>60</ttl><item><title>搭建logstash+kibana+elasticsearch+redis搭建集中式日志分析平台</title><link>http://www.blogjava.net/chrisstrive/articles/414164.html</link><dc:creator>克里斯</dc:creator><author>克里斯</author><pubDate>Tue, 27 May 2014 07:03:00 GMT</pubDate><guid>http://www.blogjava.net/chrisstrive/articles/414164.html</guid><wfw:comment>http://www.blogjava.net/chrisstrive/comments/414164.html</wfw:comment><comments>http://www.blogjava.net/chrisstrive/articles/414164.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/chrisstrive/comments/commentRss/414164.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/chrisstrive/services/trackbacks/414164.html</trackback:ping><description><![CDATA[LogStash架构专为收集、分析和存储日志所设计，正适合分布式系统，因此我根据官方文档和网上经验搭建了这个平台。<br /><div><ol><li>安装环境</li><ol><li>平台架构<br /><div>采用LogStash的官方推荐</div><div><div><img alt="安装logstash+kibana+elasticsearch+redis搭建日志分析平台 - 傲风 - 0与1构筑世界，程序员创造时代" style="margin:0 10px 0 0;" src="http://img0.ph.126.net/ycmJtSvQLMqqBIhCHxnRRg==/3303108851799736440.png" /></div></div></li><li>环境规划<br /><div><ul><li>10.2.169.64(CentOS5.5)：Broker</li><li>10.2.169.234(CentOS5.5)：Indexer,Storage&amp;Search,Web Interface</li><li>10.2.169.21/10.2.169.22....(CentOS5.5)：Shiper</li></ul></div></li><li>必要组件<br /><ul><li>JDK<br /></li></ul></li></ol><li>安装步骤<br /><div><ol><li>在10.2.169.64安装并启动Redis<br /><div><ul><li>下载解压<br /># cd /usr/local<br /><div># wget http://redis.googlecode.com/files/redis-2.6.14.tar.gz<br /><div># tar -xzvf redis-2.6.14.tar.gz</div></div></li><li>创建软链接（非必须）<br />这里是个人习惯，以后版本变迁的时候便于升级，可以跳过，但如果跳过的话下面相应的目录就要变更。<br /># ln -s redis-2.6.14 redis</li><li>编译<br /># cd redis<br /># make</li><li>建立Redis目录（非必须）<br />这步只是习惯将Redis相关的资源统一管理，可以跳过。<br /><div> <div><div style="color: #000000; font-family: Tahoma; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium;"># mkdir -p bin</div><div style="color: #000000; font-family: Tahoma; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium;"># mkdir -p etc</div><div style="color: #000000; font-family: Tahoma; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium;"># mkdir -p var</div><div style="color: #000000; font-family: Tahoma; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium;"># cp src/redis-server src/redis-cli src/redis-benchmark src/redis-sentinel src/redis-check-dump src/redis-check-aof&nbsp;bin/</div><div style="color: #000000; font-family: Tahoma; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium;"># cp redis.conf etc/</div></div></div></li><li><div><div><div style="color: #000000; font-family: Tahoma; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium;">配置参数<br /># vi etc/redis.conf<br />对redis.conf做如下变更<br /><hr /><div> <div><div style="color: #000000; font-family: Tahoma; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium;">daemonize yes</div><div style="color: #000000; font-family: Tahoma; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium;">pidfile /usr/local/redis/var/redis.pid</div><div style="color: #000000; font-family: Tahoma; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium;">port 6379</div><div style="color: #000000; font-family: Tahoma; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium;">timeout 300</div><div style="color: #000000; font-family: Tahoma; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium;">loglevel debug</div><div style="color: #000000; font-family: Tahoma; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium;">logfile /usr/local/redis/var/redis.log</div><div style="color: #000000; font-family: Tahoma; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium;">databases 16</div><div style="color: #000000; font-family: Tahoma; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium;">save 900 1</div><div style="color: #000000; font-family: Tahoma; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium;">save 300 10</div><div style="color: #000000; font-family: Tahoma; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium;">save 60 10000</div><div style="color: #000000; font-family: Tahoma; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium;">rdbcompression yes</div><div style="color: #000000; font-family: Tahoma; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium;">dbfilename dump.rdb</div><div style="color: #000000; font-family: Tahoma; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium;">dir /usr/local/redis/var/</div><div style="color: #000000; font-family: Tahoma; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium;">appendonly no</div><div style="color: #000000; font-family: Tahoma; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium;">appendfsync always<br /><hr /></div></div></div></div></div></div></li><li><div><div><div style="color: #000000; font-family: Tahoma; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium;">启动<br /># bin/redis-server etc/redis.conf</div></div></div></li></ul></div></li><li>在10.2.169.234安装并启动ElasticSearch<br /><ul><li>下载解压,可到官网直接下载，也可使用wget。<br /># cd /usr/local<br /><div># wget https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-1.1.1.tar.gz</div># tar -zxvf elasticsearch-1.1.1.tar.gz</li><li><div>创建软连接。<br />这里是个人习惯，以后版本变迁的时候便于升级，可以跳过，但如果跳过的话下面相应的目录就要变更。<br /># ln -s elasticsearch-1.1.1 elasticsearch</div></li><li>这里我们使用默认配置，直接启动。<br /># elasticsearch/bin/elasticsearch<br /></li></ul></li><li><div>在10.2.169.234安装并启动LogStash</div></li><ul><li>下载并解压Logstash。<br /><div># curl -O https://download.elasticsearch.org/logstash/logstash/logstash-1.4.1.tar.gz<br /># tar -xzvf logstash-1.4.1</div></li><li><div>创建软连接。<br />这里是个人习惯，以后版本变迁的时候便于升级，可以跳过，但如果跳过的话下面相应的目录就要变更。<br /># ln -s logstash-1.4.1 logstash</div></li><li>创建配置文件<br /># cd logstash<br /><div># mkdir conf<br /># vi conf/redis.conf</div>内容如下<br /><hr /><div> <div><span style="color: #000000; font-family: Tahoma; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; display: inline !important; float: none;">input&nbsp;{</span><br style="color: #000000; font-family: Tahoma; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium;" /><span style="color: #000000; font-family: Tahoma; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; display: inline !important; float: none;">&nbsp; redis&nbsp;{&nbsp;</span><br style="color: #000000; font-family: Tahoma; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium;" /><span style="color: #000000; font-family: Tahoma; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; display: inline !important; float: none;">&nbsp; &nbsp; host&nbsp;=&gt;&nbsp;'10.2.169.64'&nbsp;</span><br style="color: #000000; font-family: Tahoma; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium;" /><span style="color: #000000; font-family: Tahoma; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; display: inline !important; float: none;">&nbsp; &nbsp; data_type&nbsp;=&gt;&nbsp;'list'</span><br style="color: #000000; font-family: Tahoma; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium;" /><span style="color: #000000; font-family: Tahoma; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; display: inline !important; float: none;">&nbsp; &nbsp; port&nbsp;=&gt;&nbsp;"6379"&nbsp;</span><br style="color: #000000; font-family: Tahoma; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium;" /><span style="color: #000000; font-family: Tahoma; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; display: inline !important; float: none;">&nbsp; &nbsp; key&nbsp;=&gt;&nbsp;'logstash:redis'&nbsp;</span><br style="color: #000000; font-family: Tahoma; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium;" /><span style="color: #000000; font-family: Tahoma; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; display: inline !important; float: none;">&nbsp; &nbsp; type&nbsp;=&gt;&nbsp;'redis-input'&nbsp;</span><br style="color: #000000; font-family: Tahoma; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium;" /><span style="color: #000000; font-family: Tahoma; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; display: inline !important; float: none;">&nbsp; }</span><br style="color: #000000; font-family: Tahoma; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium;" /><span style="color: #000000; font-family: Tahoma; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; display: inline !important; float: none;">}</span><br style="color: #000000; font-family: Tahoma; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium;" /><span style="color: #000000; font-family: Tahoma; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; display: inline !important; float: none;">output&nbsp;{&nbsp;</span><br style="color: #000000; font-family: Tahoma; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium;" /><span style="color: #000000; font-family: Tahoma; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; display: inline !important; float: none;">&nbsp; elasticsearch&nbsp;{&nbsp;</span><br style="color: #000000; font-family: Tahoma; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium;" /><span style="color: #000000; font-family: Tahoma; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; display: inline !important; float: none;">&nbsp; &nbsp; host =&gt; "127.0.0.1"</span><br style="color: #000000; font-family: Tahoma; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium;" /><span style="color: #000000; font-family: Tahoma; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; display: inline !important; float: none;">&nbsp; }</span><br style="color: #000000; font-family: Tahoma; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium;" /><span style="color: #000000; font-family: Tahoma; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; display: inline !important; float: none;">}&nbsp;</span><hr /></div>  </div><div>解释一下 logstash的配置文件由 input filter output 等几个基本的部分组成，顾名思义 input 就是在哪收集数据，output就是输出到哪，filter代表一个过滤规则意思是什么内容<br />会被收集。<br />上面这段是让 logstash 去10.2.169.64 这个redis服务器上去收集日志 redis端口为6379，key是 logstash:redis 类型为 redis-input ，（注意:这几个值必须跟logstash agent的<br />output 所对应），收集完成后输出到 elasticsearch ,如果elasticsearch有更改端口，需要将这条改为<br />host =&gt; 'elasticsearch的ip' port =&gt; 端口&nbsp;</div></li><li>启动logstash index<br /><div># bin/logstash -f conf/redis.conf <br />-l /data/logs/logstash.log &amp;<br />其中-f是指以指定的配置文件启动，-l是设置logstash本身的日志位置。&amp;是以守护进程方式启动。</div></li><li>启动logstash web<br /># bin/logstash-web<br /></li></ul><li><div>在10.2.169.21/10.2.169.22....安装并启动LogStash agent 这里的机器就是我们应用部署的各台机器了。这里的步骤与logstash index的步骤差不多，差异除了不用启动logstash web外，主要有两个。<br /><div><ul><li>redis.conf的配置内容。<br /><hr /><div>input { <br />&nbsp;&nbsp;&nbsp; file { <br />&nbsp;&nbsp;&nbsp; type =&gt; "dev_integrate" <br />&nbsp;&nbsp;&nbsp; path =&gt; "/data/logs/integrate/integrate.log"<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp; &nbsp;file { <br />&nbsp;&nbsp;&nbsp; type =&gt; "dev_custom" <br />&nbsp;&nbsp;&nbsp; path =&gt; "/data/logs/custom/custom.log"<br />&nbsp;&nbsp;&nbsp; }&nbsp;&nbsp; &nbsp;<br />}<br />filter {<br />&nbsp; multiline {<br />&nbsp;&nbsp;&nbsp; pattern =&gt; "^[^2014]"<br />&nbsp;&nbsp;&nbsp; what =&gt; "previous"<br />&nbsp; }<br />&nbsp; } &nbsp;<br />output { <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; redis { <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; host =&gt; '10.2.169.64' <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; data_type =&gt; 'list' <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; key =&gt; 'logstash:redis' <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } <br /><hr />其中input指定了本机部署的两个应用的log文件。type是我自定义的一个类型，用来在后面的UI中区分各应用，path就是log文件路径了。如果有更多应用，照格式添加即可。<br />filter用来处理log中的error信息，因为我的应用java程序，部署在tomcat下，所以错误信息类似如下：<br /><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><span style="color: #000000; ">2014</span><span style="color: #000000; ">-</span><span style="color: #000000; ">05</span><span style="color: #000000; ">-</span><span style="color: #000000; ">27</span>&nbsp;<span style="color: #000000; ">02</span><span style="color: #000000; ">:</span><span style="color: #000000; ">17</span><span style="color: #000000; ">:</span><span style="color: #000000; ">16</span><span style="color: #000000; ">&nbsp;[emailJMSContainer</span><span style="color: #000000; ">-</span><span style="color: #000000; ">1</span><span style="color: #000000; ">]&nbsp;ERROR&nbsp;com.xxx.xxx.email.EmailSender.errorLog(</span><span style="color: #000000; ">79</span><span style="color: #000000; ">)):&nbsp;</span><span style="color: #000000; ">-</span><span style="color: #000000; ">&nbsp;exception&nbsp;occurred:<br />javax.mail.SendFailedException:&nbsp;Invalid&nbsp;Addresses;<br />&nbsp;&nbsp;nested&nbsp;exception&nbsp;is:<br />&nbsp;&nbsp;&nbsp;&nbsp;com.sun.mail.smtp.SMTPAddressFailedException:&nbsp;</span><span style="color: #000000; ">553</span>&nbsp;<span style="color: #000000; ">5.7</span><span style="color: #000000; ">.</span><span style="color: #000000; ">1</span>&nbsp;<span style="color: #000000; ">&lt;</span><span style="color: #000000; ">xxx</span><span style="color: #000000; ">-</span><span style="color: #000000; ">saas@xxx.com</span><span style="color: #000000; ">&gt;</span><span style="color: #000000; ">:&nbsp;Sender&nbsp;address&nbsp;rejected:&nbsp;not&nbsp;owned&nbsp;by&nbsp;user&nbsp;paymonitor@xxx.com<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;at&nbsp;com.sun.mail.smtp.SMTPTransport.rcptTo(SMTPTransport.java:</span><span style="color: #000000; ">1196</span><span style="color: #000000; ">)<br />&nbsp;&nbsp;&nbsp;&nbsp;at&nbsp;com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:</span><span style="color: #000000; ">584</span><span style="color: #000000; ">)<br />&nbsp;&nbsp;&nbsp;&nbsp;at&nbsp;javax.mail.Transport.send0(Transport.java:</span><span style="color: #000000; ">169</span><span style="color: #000000; ">)<br />&nbsp;&nbsp;&nbsp;&nbsp;at&nbsp;javax.mail.Transport.send(Transport.java:</span><span style="color: #000000; ">98</span><span style="color: #000000; ">)<br />&nbsp;&nbsp;&nbsp;&nbsp;at&nbsp;com.xxx.communication.email.EmailSender.sendEmail(EmailSender.java:</span><span style="color: #000000; ">97</span><span style="color: #000000; ">)<br />&nbsp;&nbsp;&nbsp;&nbsp;at&nbsp;com.xxx.notification.EmailNotificationConsumer.processTxtMsg(EmailNotificationConsumer.java:</span><span style="color: #000000; ">24</span><span style="color: #000000; ">)<br />&nbsp;&nbsp;&nbsp;&nbsp;at&nbsp;com.xxx.asyncmsg.consumer.AbstractConsumer.onMessage(AbstractConsumer.java:</span><span style="color: #000000; ">78</span><span style="color: #000000; ">)<br />&nbsp;&nbsp;&nbsp;&nbsp;at&nbsp;org.springframework.jms.listener.AbstractMessageListenerContainer.doInvokeListener(AbstractMessageListenerContainer.java:</span><span style="color: #000000; ">562</span><span style="color: #000000; ">)<br />&nbsp;&nbsp;&nbsp;&nbsp;at&nbsp;org.springframework.jms.listener.AbstractMessageListenerContainer.invokeListener(AbstractMessageListenerContainer.java:</span><span style="color: #000000; ">500</span><span style="color: #000000; ">)<br />&nbsp;&nbsp;&nbsp;&nbsp;at&nbsp;org.springframework.jms.listener.AbstractMessageListenerContainer.doExecuteListener(AbstractMessageListenerContainer.java:</span><span style="color: #000000; ">468</span><span style="color: #000000; ">)<br />&nbsp;&nbsp;&nbsp;&nbsp;at&nbsp;org.springframework.jms.listener.AbstractPollingMessageListenerContainer.doReceiveAndExecute(AbstractPollingMessageListenerContainer.java:</span><span style="color: #000000; ">326</span><span style="color: #000000; ">)<br />&nbsp;&nbsp;&nbsp;&nbsp;at&nbsp;org.springframework.jms.listener.AbstractPollingMessageListenerContainer.receiveAndExecute(AbstractPollingMessageListenerContainer.java:</span><span style="color: #000000; ">264</span><span style="color: #000000; ">)<br />&nbsp;&nbsp;&nbsp;&nbsp;at&nbsp;org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.invokeListener(DefaultMessageListenerContainer.java:</span><span style="color: #000000; ">1071</span><span style="color: #000000; ">)<br />&nbsp;&nbsp;&nbsp;&nbsp;at&nbsp;org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.executeOngoingLoop(DefaultMessageListenerContainer.java:</span><span style="color: #000000; ">1063</span><span style="color: #000000; ">)<br />&nbsp;&nbsp;&nbsp;&nbsp;at&nbsp;org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.run(DefaultMessageListenerContainer.java:</span><span style="color: #000000; ">960</span><span style="color: #000000; ">)<br />&nbsp;&nbsp;&nbsp;&nbsp;at&nbsp;java.lang.Thread.run(Thread.java:</span><span style="color: #000000; ">662</span><span style="color: #000000; ">)<br />Caused&nbsp;by:&nbsp;com.sun.mail.smtp.SMTPAddressFailedException:&nbsp;</span><span style="color: #000000; ">553</span>&nbsp;<span style="color: #000000; ">5.7</span><span style="color: #000000; ">.</span><span style="color: #000000; ">1</span>&nbsp;<span style="color: #000000; ">&lt;</span><span style="color: #000000; ">xxx</span><span style="color: #000000; ">-</span><span style="color: #000000; ">saas@xxx.com</span><span style="color: #000000; ">&gt;</span><span style="color: #000000; ">:&nbsp;Sender&nbsp;address&nbsp;rejected:&nbsp;not&nbsp;owned&nbsp;by&nbsp;user&nbsp;paymonitor@xxx.com<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;at&nbsp;com.sun.mail.smtp.SMTPTransport.rcptTo(SMTPTransport.java:</span><span style="color: #000000; ">1047</span><span style="color: #000000; ">)<br />&nbsp;&nbsp;&nbsp;&nbsp;<img src="http://www.blogjava.net/Images/dot.gif" alt="" />&nbsp;</span><span style="color: #000000; ">15</span><span style="color: #000000; ">&nbsp;more</span></div><hr />如果不加fitler，那采集来的message就是单独的一条。所以这里我配置了一个fitler，所有不是以2014开头（这里演示我偷了一下懒，应该用正则）的都并到上一条。<br />output就是输入到我们的redis服务器。</div></li><li>启动agent<br /><div># bin/logstash -f conf/redis.conf <br />-l /data/logs/logstash.log &amp;</div></li></ul></div></div></li></ol></div></li><li>查看和搜索日志<br />打开浏览器，输入以下地址：<br /><div>http://10.2.169.234:9292/index.html#/dashboard/file/logstash.json<br />即可看到如下界面。<br /><div><div><img alt="安装logstash+kibana+elasticsearch+redis搭建日志分析平台 - 傲风 - 0与1构筑世界，程序员创造时代" style="margin:0 10px 0 0;" src="http://img2.ph.126.net/ZZ_s9EHgJmLCrNoDeG7hxg==/6608407930561742180.png" /></div>这个界面可以设置各种检索条件，就不细说了。</div></div></li></ol>到此为止，整个平台就搭建完毕。当然，这三者的功能不仅仅只有这么一点，而是能够提供更有趣的日志分析，大家可以自己研究。</div><img src ="http://www.blogjava.net/chrisstrive/aggbug/414164.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/chrisstrive/" target="_blank">克里斯</a> 2014-05-27 15:03 <a href="http://www.blogjava.net/chrisstrive/articles/414164.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>