<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>服务器安全维护工作室 &#187; 开源分布式搜索平台ELK(Elasticsearch+Logstash+Kibana)+Redis+Syslog-ng实现日志实时搜索</title>
	<atom:link href="https://www.fuwuqiok.com/tag/%e5%bc%80%e6%ba%90%e5%88%86%e5%b8%83%e5%bc%8f%e6%90%9c%e7%b4%a2%e5%b9%b3%e5%8f%b0elkelasticsearchlogstashkibanaredissyslog-ng%e5%ae%9e%e7%8e%b0%e6%97%a5%e5%bf%97%e5%ae%9e%e6%97%b6%e6%90%9c/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.fuwuqiok.com</link>
	<description></description>
	<lastBuildDate>Sun, 01 Mar 2020 07:28:40 +0000</lastBuildDate>
	<language>zh-CN</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.2.26</generator>
	<item>
		<title>开源分布式搜索平台ELK(Elasticsearch+Logstash+Kibana)+Redis+Syslog-ng实现日志实时搜索</title>
		<link>https://www.fuwuqiok.com/%e5%bc%80%e6%ba%90%e5%88%86%e5%b8%83%e5%bc%8f%e6%90%9c%e7%b4%a2%e5%b9%b3%e5%8f%b0elkelasticsearchlogstashkibanaredissyslog-ng%e5%ae%9e%e7%8e%b0%e6%97%a5%e5%bf%97%e5%ae%9e%e6%97%b6%e6%90%9c/</link>
		<comments>https://www.fuwuqiok.com/%e5%bc%80%e6%ba%90%e5%88%86%e5%b8%83%e5%bc%8f%e6%90%9c%e7%b4%a2%e5%b9%b3%e5%8f%b0elkelasticsearchlogstashkibanaredissyslog-ng%e5%ae%9e%e7%8e%b0%e6%97%a5%e5%bf%97%e5%ae%9e%e6%97%b6%e6%90%9c/#comments</comments>
		<pubDate>Sun, 10 Jan 2016 13:33:01 +0000</pubDate>
		<dc:creator><![CDATA[admin]]></dc:creator>
				<category><![CDATA[服务器迁移]]></category>
		<category><![CDATA[网站代维]]></category>
		<category><![CDATA[网站防挂马]]></category>
		<category><![CDATA[开源分布式搜索平台ELK(Elasticsearch+Logstash+Kibana)+Redis+Syslog-ng实现日志实时搜索]]></category>
		<category><![CDATA[服务器基础环境搭建]]></category>
		<category><![CDATA[阿里云代维]]></category>

		<guid isPermaLink="false">https://www.fuwuqiok.com/?p=2876</guid>
		<description><![CDATA[<p>logstash + elasticsearch + Kibana+Redis+Syslog-ng Elast [&#8230;]</p>
<p><a rel="nofollow" href="https://www.fuwuqiok.com/%e5%bc%80%e6%ba%90%e5%88%86%e5%b8%83%e5%bc%8f%e6%90%9c%e7%b4%a2%e5%b9%b3%e5%8f%b0elkelasticsearchlogstashkibanaredissyslog-ng%e5%ae%9e%e7%8e%b0%e6%97%a5%e5%bf%97%e5%ae%9e%e6%97%b6%e6%90%9c/">开源分布式搜索平台ELK(Elasticsearch+Logstash+Kibana)+Redis+Syslog-ng实现日志实时搜索</a>，首发于<a rel="nofollow" href="https://www.fuwuqiok.com">服务器安全维护工作室</a>。</p>
]]></description>
				<content:encoded><![CDATA[<p>logstash + elasticsearch + Kibana+Redis+Syslog-ng</p>
<p>ElasticSearch是一个基于Lucene构建的开源，分布式，RESTful搜索引擎。设计用于云计算中，能够达到实时搜索，稳定，可靠，快速，安装使用方便。支持通过HTTP使用JSON进行数据索引。</p>
<p>logstash是一个应用程序日志、事件的传输、处理、管理和搜索的平台。你可以用它来统一对应用程序日志进行收集管理，提供 Web 接口用于查询和统计。其实logstash是可以被别的替换，比如常见的fluented</p>
<p>Kibana是一个为 Logstash 和 ElasticSearch 提供的日志分析的 Web 接口。可使用它对日志进行高效的搜索、可视化、分析等各种操作。</p>
<p>Redis是一个高性能的内存key-value数据库,非必需安装,可以防止数据丢失.<br />
<a href="https://www.fuwuqiok.com/wp-content/uploads/2016/01/kibana.jpg"><img class="attachment-medium" src="https://www.fuwuqiok.com/wp-content/uploads/2016/01/kibana.jpg" alt="kibana" width="536" height="177" /></a><br />
参考:<br />
http://www.logstash.net/<br />
http://chenlinux.com/2012/10/21/elasticearch-simple-usage/<br />
http://www.elasticsearch.cn<br />
http://download.oracle.com/otn-pub/java/jdk/7u67-b01/jdk-7u67-linux-x64.tar.gz?AuthParam=1408083909_3bf5b46169faab84d36cf74407132bba<br />
http://curran.blog.51cto.com/2788306/1263416<br />
http://storysky.blog.51cto.com/628458/1158707/<br />
http://zhumeng8337797.blog.163.com/blog/static/10076891420142712316899/<br />
http://enable.blog.51cto.com/747951/1049411<br />
http://chenlinux.com/2014/06/11/nginx-access-log-to-elasticsearch/<br />
http://www.w3c.com.cn/%E5%BC%80%E6%BA%90%E5%88%86%E5%B8%83%E5%BC%8F%E6%90%9C%E7%B4%A2%E5%B9%B3%E5%8F%B0elkelasticsearchlogstashkibana%E5%85%A5%E9%97%A8%E5%AD%A6%E4%B9%A0%E8%B5%84%E6%BA%90%E7%B4%A2%E5%BC%95<br />
http://woodygsd.blogspot.com/2014/06/an-adventure-with-elk-or-how-to-replace.html<br />
http://www.ricardomartins.com.br/enviando-dados-externos-para-a-stack-elk/<br />
http://tinytub.github.io/logstash-install.html</p>
<p>http://jamesmcfadden.co.uk/securing-elasticsearch-with-nginx/<br />
https://github.com/elasticsearch/logstash/blob/master/patterns/grok-patterns<br />
http://zhaoyanblog.com/archives/319.html<br />
http://www.vpsee.com/2014/05/install-and-play-with-elasticsearch/</p>
<p>ip说明<br />
118.x.x.x/16 为客户端ip<br />
192.168.0.39和61.x.x.x为ELK的内网和外网ip</p>
<h1>安装JDK</h1>
<p>http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html</p>
<div class="hl-surround">
<ol class="hl-main ln-show" title="Double click to hide line number.">
<li class="hl-firstline">tar zxvf jdk-7u67-linux-x64.tar.gz\?AuthParam\=1408083909_3bf5b46169faab84d36cf74407132b</li>
<li>mv jdk1.7.0_67 /usr/local/</li>
<li>cd /usr/local/</li>
<li>ln -s jdk1.7.0_67 jdk</li>
<li>chown -R root:root jdk/</li>
</ol>
</div>
<p><strong>配置环境变量</strong><br />
vi /etc/profile</p>
<div class="hl-surround">
<ol class="hl-main ln-show" title="Double click to hide line number.">
<li class="hl-firstline">export JAVA_HOME=/usr/local/jdk</li>
<li>export JRE_HOME=$JAVA_HOME/jre</li>
<li>export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib:$CLASSPATH</li>
<li>export PATH=$JAVA_HOME/bin:$PATH</li>
<li>export REDIS_HOME=/usr/local/redis</li>
<li>export ES_HOME=/usr/local/elasticsearch</li>
<li>export ES_CLASSPATH=$ES_HOME/config</li>
</ol>
</div>
<p><strong>变量生效</strong><br />
source /etc/profile</p>
<p><strong>验证版本</strong><br />
java -version</p>
<div class="hl-surround">
<ol class="hl-main ln-show" title="Double click to hide line number.">
<li class="hl-firstline">java version &#8220;1.7.0_67&#8243;</li>
<li>Java(TM) SE Runtime Environment (build 1.7.0_67-b01)</li>
<li>Java HotSpot(TM) 64-Bit Server VM (build 24.65-b04, mixed mode)</li>
</ol>
</div>
<p>如果之前安装过java,可以先卸载<br />
rpm -qa |grep java<br />
java-1.6.0-openjdk-1.6.0.0-1.24.1.10.4.el5<br />
java-1.6.0-openjdk-devel-1.6.0.0-1.24.1.10.4.el5</p>
<p>rpm -e java-1.6.0-openjdk-1.6.0.0-1.24.1.10.4.el5 java-1.6.0-openjdk-devel-1.6.0.0-1.24.1.10.4.el5</p>
<h1>安装redis</h1>
<p>http://redis.io/</p>
<div class="hl-surround">
<ol class="hl-main ln-show" title="Double click to hide line number.">
<li class="hl-firstline">wget http://download.redis.io/releases/redis-2.6.17.tar.gz</li>
<li>tar zxvf redis-2.6.17.tar.gz</li>
<li>mv redis-2.6.17 /usr/local/</li>
<li>cd /usr/local</li>
<li>ln -s redis-2.6.17 redis</li>
<li>cd /usr/local/redis</li>
<li>make</li>
<li>make install</li>
</ol>
</div>
<p>cd utils<br />
./install_server.sh</p>
<div class="hl-surround">
<ol class="hl-main ln-show" title="Double click to hide line number.">
<li class="hl-firstline">Please select the redis port for this instance: [6379]</li>
<li>Selecting default: 6379</li>
<li>Please select the redis config file name [/etc/redis/6379.conf]</li>
<li>Selected default &#8211; /etc/redis/6379.conf</li>
<li>Please select the redis log file name [/var/log/redis_6379.log]</li>
<li>Selected default &#8211; /var/log/redis_6379.log</li>
<li>Please select the data directory for this instance [/var/lib/redis/6379]</li>
<li>Selected default &#8211; /var/lib/redis/6379</li>
<li>Please select the redis executable path [/usr/local/bin/redis-server]</li>
</ol>
</div>
<p><strong>编辑配置文件</strong><br />
vi /etc/redis/6379.conf</p>
<div class="hl-surround">
<ol class="hl-main ln-show" title="Double click to hide line number.">
<li class="hl-firstline">daemonize yes</li>
<li>port 6379</li>
<li>timeout 300</li>
<li>tcp-keepalive 60</li>
</ol>
</div>
<p><strong>启动</strong><br />
/etc/init.d/redis_6379 start</p>
<p>exists, process is already running or crashed<br />
如报这个错,需要编辑下/etc/init.d/redis_6379,去除头上的\n</p>
<p><strong>加入自动启动</strong><br />
chkconfig –add redis_6379</p>
<h1>安装Elasticsearch</h1>
<p>http://www.elasticsearch.org/<br />
http://www.elasticsearch.cn<br />
集群安装只要节点在同一网段下，设置一致的cluster.name，启动的Elasticsearch即可相互检测到对方，组成集群</p>
<div class="hl-surround">
<ol class="hl-main ln-show" title="Double click to hide line number.">
<li class="hl-firstline">wget https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-1.3.2.tar.gz</li>
<li>tar zxvf elasticsearch-1.3.2.tar.gz</li>
<li>mv elasticsearch-1.3.2 /usr/local/</li>
<li>cd /usr/local/</li>
<li>ln -s elasticsearch-1.3.2 elasticsearch</li>
<li>elasticsearch/bin/elasticsearch -f</li>
</ol>
</div>
<div class="hl-surround">
<ol class="hl-main ln-show" title="Double click to hide line number.">
<li class="hl-firstline">[2014-08-20 13:19:05,710][INFO ][node                     ] [Jackpot] version[1.3.2], pid[19320], build[dee175d/2014-08-13T14:29:30Z]</li>
<li>[2014-08-20 13:19:05,727][INFO ][node                     ] [Jackpot] initializing &#8230;</li>
<li>[2014-08-20 13:19:05,735][INFO ][plugins                  ] [Jackpot] loaded [], sites []</li>
<li>[2014-08-20 13:19:10,722][INFO ][node                     ] [Jackpot] initialized</li>
<li>[2014-08-20 13:19:10,723][INFO ][node                     ] [Jackpot] starting &#8230;</li>
<li>[2014-08-20 13:19:10,934][INFO ][transport                ] [Jackpot] bound_address {inet[/0.0.0.0:9301]}, publish_address {inet[/61.x.x.x:9301]}</li>
<li>[2014-08-20 13:19:10,958][INFO ][discovery                ] [Jackpot] elasticsearch/5hUOX-2ES82s_0zvI9BUdg</li>
<li>[2014-08-20 13:19:14,011][INFO ][cluster.service          ] [Jackpot] new_master [Jackpot][5hUOX-2ES82s_0zvI9BUdg][Impala][inet[/61.x.x.x:9301]], reason: zen-disco-join (elected_as_master)</li>
<li>[2014-08-20 13:19:14,060][INFO ][http                     ] [Jackpot] bound_address {inet[/0.0.0.0:9201]}, publish_address {inet[/61.x.x.x:9201]}</li>
<li>[2014-08-20 13:19:14,061][INFO ][node                     ] [Jackpot] started</li>
<li>[2014-08-20 13:19:14,106][INFO ][gateway                  ] [Jackpot] recovered [0] indices into cluster_state</li>
<li></li>
<li></li>
<li>[2014-08-20 13:20:58,273][INFO ][node                     ] [Jackpot] stopping &#8230;</li>
<li>[2014-08-20 13:20:58,323][INFO ][node                     ] [Jackpot] stopped</li>
<li>[2014-08-20 13:20:58,323][INFO ][node                     ] [Jackpot] closing &#8230;</li>
<li>[2014-08-20 13:20:58,332][INFO ][node                     ] [Jackpot] closed</li>
</ol>
</div>
<p>ctrl+c退出</p>
<p><strong>以后台方式运行</strong><br />
elasticsearch/bin/elasticsearch -d</p>
<p><strong>访问默认的9200端口</strong><br />
curl -X GET http://localhost:9200</p>
<div class="hl-surround">
<ol class="hl-main ln-show" title="Double click to hide line number.">
<li class="hl-firstline">{</li>
<li>  &#8220;status&#8221; : 200,</li>
<li>  &#8220;name&#8221; : &#8220;Steve Rogers&#8221;,</li>
<li>  &#8220;version&#8221; : {</li>
<li>    &#8220;number&#8221; : &#8220;1.3.2&#8221;,</li>
<li>    &#8220;build_hash&#8221; : &#8220;dee175dbe2f254f3f26992f5d7591939aaefd12f&#8221;,</li>
<li>    &#8220;build_timestamp&#8221; : &#8220;2014-08-13T14:29:30Z&#8221;,</li>
<li>    &#8220;build_snapshot&#8221; : false,</li>
<li>    &#8220;lucene_version&#8221; : &#8220;4.9&#8221;</li>
<li>  },</li>
<li>  &#8220;tagline&#8221; : &#8220;You Know, for Search&#8221;</li>
<li>}</li>
</ol>
</div>
<h1>安装logstash</h1>
<p>http://logstash.net/</p>
<div class="hl-surround">
<ol class="hl-main ln-show" title="Double click to hide line number.">
<li class="hl-firstline">wget https://download.elasticsearch.org/logstash/logstash/logstash-1.4.2.tar.gz</li>
<li>tar zxvf logstash-1.4.2.tar.gz</li>
<li>mv logstash-1.4.2 /usr/local</li>
<li>cd /usr/local</li>
<li>ln -s logstash-1.4.2 logstash</li>
<li>mkdir logstash/conf</li>
<li>chown -R root:root logstash</li>
</ol>
</div>
<p><a href="https://www.fuwuqiok.com/wp-content/uploads/2016/01/logstash.png"><img class="attachment-medium" src="https://www.fuwuqiok.com/wp-content/uploads/2016/01/logstash.png" alt="logstash" width="304" height="486" /></a></p>
<p>因为java的默认heap size,回收机制等原因,logstash从1.4.0开始不再使用jar运行方式.<br />
以前方式:<br />
java -jar logstash-1.3.3-flatjar.jar agent -f logstash.conf<br />
现在方式:<br />
bin/logstash agent -f logstash.conf</p>
<p>logstash下载即可使用，命令行参数可以参考logstash flags，主要有<br />
http://logstash.net/docs/1.2.1/flags</p>
<h1>安装kibana</h1>
<p>logstash的最新版已经内置kibana，你也可以单独部署kibana。kibana3是纯粹JavaScript+html的客户端，所以可以部署到任意http服务器上。<br />
http://www.elasticsearch.org/overview/elkdownloads/</p>
<div class="hl-surround">
<ol class="hl-main ln-show" title="Double click to hide line number.">
<li class="hl-firstline">wget https://download.elasticsearch.org/kibana/kibana/kibana-3.1.0.tar.gz</li>
<li>tar zxvf kibana-3.1.0.tar.gz</li>
<li>mv kibana-3.1.0 /opt/htdocs/www/kibana</li>
<li>vi /opt/htdocs/www/kibana/config.js</li>
</ol>
</div>
<p>配置elasticsearch源<br />
elasticsearch: “http://”+window.location.hostname+”:9200″,</p>
<p><strong>加入iptables</strong><br />
6379为redis端口,9200为elasticsearch端口,118.x.x.x/16为当前测试时的客户端ip</p>
<div class="hl-surround">
<ol class="hl-main ln-show" title="Double click to hide line number.">
<li class="hl-firstline">iptables -A INPUT -p tcp -m tcp -s 118.x.x.x/16 &#8211;dport 9200 &#8211;j ACCEPT</li>
</ol>
</div>
<p><strong>测试运行前端输出</strong><br />
bin/logstash -e ‘input { stdin { } } output { stdout {} }’</p>
<p><strong>输入hello测试 </strong><br />
2014-08-20T05:17:02.876+0000 Impala hello</p>
<p><strong>测试运行输出到后端</strong><br />
bin/logstash -e ‘input { stdin { } } output { elasticsearch { host =&gt; localhost } }’</p>
<p><strong>访问kibana</strong><br />
http://adminimpala.campusapply.com/kibana/index.html#/dashboard/file/default.json<br />
Yes- Great! We have a prebuilt dashboard: (<a href="http://adminimpala.campusapply.com/kibana/index.html#/dashboard/file/logstash.json">Logstash Dashboard</a>). See the note to the right about making it your global default</p>
<p>No results There were no results because no indices were found that match your selected time span</p>
<p><strong>设置kibana读取源</strong><br />
在kibana的右上角有个 configure dashboard,再进入Index Settings<br />
[logstash-]YYYY.MM.DD<br />
这个需和logstash的输出保持一致</p>
<p><strong>elasticsearch 跟 MySQL 中定义资料格式的角色关系对照表如下</strong></p>
<p>MySQL elasticsearch<br />
database index<br />
table type</p>
<p>table schema mapping<br />
row document<br />
field field</p>
<h1>ELK整合</h1>
<p><strong>syslog-ng.conf</strong></p>
<div class="hl-surround">
<ol class="hl-main ln-show" title="Double click to hide line number.">
<li class="hl-firstline">#省略其它内容</li>
<li></li>
<li># Remote logging syslog</li>
<li>source s_remote {</li>
<li>        udp(ip(192.168.0.39) port(514));</li>
<li>};</li>
<li></li>
<li>#nginx log</li>
<li>source s_remotetcp {</li>
<li>        tcp(ip(192.168.0.39) port(514) log_fetch_limit(100) log_iw_size(50000) max-connections(50) );</li>
<li>};</li>
<li></li>
<li>filter f_filter12     { program(&#8216;c1gstudio\.com&#8217;); };</li>
<li></li>
<li>#logstash syslog</li>
<li>destination d_logstash_syslog { udp(&#8220;localhost&#8221; port(10999) localport(10998)  ); };</li>
<li></li>
<li>#logstash web</li>
<li>destination d_logstash_web { tcp(&#8220;localhost&#8221; port(10997) localport(10996) ); };</li>
<li></li>
<li>log { source(s_remote); destination(d_logstash_syslog); };</li>
<li></li>
<li>log { source(s_remotetcp); filter(f_filter12); destination(d_logstash_web); };</li>
</ol>
</div>
<p><strong>logstash_syslog.conf</strong></p>
<div class="hl-surround">
<ol class="hl-main ln-show" title="Double click to hide line number.">
<li class="hl-firstline">input {</li>
<li>  udp {</li>
<li>    port =&gt; 10999</li>
<li>    type =&gt; syslog</li>
<li>  }</li>
<li>}</li>
<li>filter {</li>
<li>  if [type] == &#8220;syslog&#8221; {</li>
<li>    grok {</li>
<li>      match =&gt; { &#8220;message&#8221; =&gt; &#8220;%{SYSLOGTIMESTAMP:syslog_timestamp} %{SYSLOGHOST:syslog_hostname} %{DATA:syslog_program}(?:\[%{POSINT:syslog_pid}\])?: %{GREEDYDATA:syslog_message}&#8221; }</li>
<li>      add_field =&gt; [ &#8220;received_at&#8221;, &#8220;%{@timestamp}&#8221; ]</li>
<li>      add_field =&gt; [ &#8220;received_from&#8221;, &#8220;%{host}&#8221; ]</li>
<li>    }</li>
<li>    syslog_pri { }</li>
<li>    date {</li>
<li>      match =&gt; [ &#8220;syslog_timestamp&#8221;, &#8220;MMM  d HH:mm:ss&#8221;, &#8220;MMM dd HH:mm:ss&#8221; ]</li>
<li>    }</li>
<li>  }</li>
<li>}</li>
<li></li>
<li>output {</li>
<li>  elasticsearch {</li>
<li>  host =&gt; localhost</li>
<li>  index =&gt; &#8220;syslog-%{+YYYY}&#8221;</li>
<li>}</li>
<li>}</li>
</ol>
</div>
<p><strong>logstash_redis.conf</strong></p>
<div class="hl-surround">
<ol class="hl-main ln-show" title="Double click to hide line number.">
<li class="hl-firstline">input {</li>
<li>  tcp {</li>
<li>    port =&gt; 10997</li>
<li>    type =&gt; web</li>
<li>  }</li>
<li>}</li>
<li>filter {</li>
<li>  grok {</li>
<li>    match =&gt; [ &#8220;message&#8221;, &#8220;%{SYSLOGTIMESTAMP:syslog_timestamp} (?:%{SYSLOGFACILITY:syslog_facility} )?%{SYSLOGHOST:syslog_source} %{PROG:syslog_program}(?:\[%{POSINT:syslog_pid}\])?: %{IPORHOST:clientip} &#8211; (?:%{USER:remote_user}|-) \[%{HTTPDATE:timestamp}\] \&#8221;%{WORD:method} %{URIPATHPARAM:request} HTTP/%{NUMBER:httpversion}\&#8221; %{NUMBER:status} (?:%{NUMBER:body_bytes_sent}|-) \&#8221;(?:%{URI:http_referer}|-)\&#8221; %{QS:agent} (?:%{IPV4:http_x_forwarded_for}|-)&#8221;]</li>
<li>    remove_field =&gt; [ &#8216;@version&#8217;,&#8217;host&#8217;,&#8217;syslog_timestamp&#8217;,&#8217;syslog_facility&#8217;,&#8217;syslog_pid&#8217;]</li>
<li>  }</li>
<li>  date {</li>
<li>    match =&gt; [ &#8220;timestamp&#8221; , &#8220;dd/MMM/yyyy:HH:mm:ss Z&#8221; ]</li>
<li>  }</li>
<li>   useragent {</li>
<li>        source =&gt; &#8220;agent&#8221;</li>
<li>        prefix =&gt; &#8220;useragent_&#8221;</li>
<li>        remove_field =&gt; [ &#8220;useragent_device&#8221;, &#8220;useragent_major&#8221;, &#8220;useragent_minor&#8221; ,&#8221;useragent_patch&#8221;,&#8221;useragent_os&#8221;,&#8221;useragent_os_major&#8221;,&#8221;useragent_os_minor&#8221;]</li>
<li>    }</li>
<li>   geoip {</li>
<li>        source =&gt; &#8220;clientip&#8221;</li>
<li>        fields =&gt; [&#8220;country_name&#8221;, &#8220;region_name&#8221;, &#8220;city_name&#8221;, &#8220;real_region_name&#8221;, &#8220;latitude&#8221;, &#8220;longitude&#8221;]</li>
<li>        remove_field =&gt; [ &#8220;[geoip][longitude]&#8221;, &#8220;[geoip][latitude]&#8221;,&#8221;location&#8221;,&#8221;region_name&#8221; ]</li>
<li>    }</li>
<li>}</li>
<li></li>
<li>output {</li>
<li>  #stdout { codec =&gt; rubydebug }</li>
<li> redis {</li>
<li> batch =&gt; true</li>
<li> batch_events =&gt; 500</li>
<li> batch_timeout =&gt; 5</li>
<li> host =&gt; &#8220;127.0.0.1&#8221;</li>
<li> data_type =&gt; &#8220;list&#8221;</li>
<li> key =&gt; &#8220;logstash:web&#8221;</li>
<li> workers =&gt; 2</li>
<li> }</li>
<li>}</li>
</ol>
</div>
<p><strong>logstash_web.conf</strong></p>
<div class="hl-surround">
<ol class="hl-main ln-show" title="Double click to hide line number.">
<li class="hl-firstline">input {</li>
<li>  redis {</li>
<li>    host =&gt; &#8220;127.0.0.1&#8221;</li>
<li>    port =&gt; &#8220;6379&#8221;</li>
<li>    key =&gt; &#8220;logstash:web&#8221;</li>
<li>    data_type =&gt; &#8220;list&#8221;</li>
<li>    codec  =&gt; &#8220;json&#8221;</li>
<li>    type =&gt; &#8220;web&#8221;</li>
<li>  }</li>
<li>}</li>
<li></li>
<li>output {</li>
<li>  elasticsearch {</li>
<li>  flush_size =&gt; 5000</li>
<li>  host =&gt; localhost</li>
<li>  idle_flush_time =&gt; 10</li>
<li>  index =&gt; &#8220;web-%{+YYYY.MM.dd}&#8221;</li>
<li>  }</li>
<li>  #stdout { codec =&gt; rubydebug }</li>
<li>}</li>
</ol>
</div>
<p><strong>启动elasticsearch和logstash</strong><br />
/usr/local/elasticsearch/bin/elasticsearch -d</p>
<p>/usr/local/logstash/bin/logstash agent -f /usr/local/logstash/conf/logstash_syslog.conf &amp;<br />
/usr/local/logstash/bin/logstash agent -f /usr/local/logstash/conf/logstash_redis.conf &amp;<br />
/usr/local/logstash/bin/logstash agent -f /usr/local/logstash/conf/logstash_web.conf &amp;</p>
<p><strong>关闭</strong><br />
ps aux|egrep ‘search|logstash’<br />
kill pid</p>
<p><strong>安装控制器elasticsearch-servicewrapper</strong><br />
如果是在服务器上就可以使用elasticsearch-servicewrapper这个es插件，它支持通过参数，指定是在后台或前台运行es，并且 支持启动，停止，重启es服务（默认es脚本只能通过ctrl+c关闭es）。使用方法是到https://github.com /elasticsearch/elasticsearch-servicewrapper下载service文件夹，放到es的bin目录下。下面是命 令集合：<br />
bin/service/elasticsearch +<br />
console 在前台运行es<br />
start 在后台运行es<br />
stop 停止es<br />
install 使es作为服务在服务器启动时自动启动<br />
remove 取消启动时自动启动</p>
<p>vi /usr/local/elasticsearch/service/elasticsearch.conf<br />
set.default.ES_HOME=/usr/local/elasticsearch</p>
<h1>命令示例</h1>
<p><strong>查看状态</strong><br />
http://61.x.x.x:9200/_status?pretty=true</p>
<p><strong>集群健康查看</strong><br />
http://61.x.x.x:9200/_cat/health?v<br />
epoch timestamp cluster status node.total node.data shards pri relo init unassign<br />
1409021531 10:52:11 elasticsearch yellow 2 1 20 20 0 0 20</p>
<p><strong>列出集群索引</strong><br />
http://61.x.x.x:9200/_cat/indices?v<br />
health index pri rep docs.count docs.deleted store.size pri.store.size<br />
yellow web-2014.08.25 5 1 5990946 0 3.6gb 3.6gb<br />
yellow kibana-int 5 1 2 0 20.7kb 20.7kb<br />
yellow syslog-2014 5 1 709 0 585.6kb 585.6kb<br />
yellow web-2014.08.26 5 1 1060326 0 712mb 712mb</p>
<p><strong>删除索引</strong><br />
curl -XDELETE ‘http://localhost:9200/kibana-int/’<br />
curl -XDELETE ‘http://localhost:9200/logstash-2014.08.*’</p>
<p><strong>优化索引</strong><br />
$ curl -XPOST ‘http://localhost:9200/old-index-name/_optimize’</p>
<p><strong>查看日志</strong><br />
tail /usr/local/elasticsearch/logs/elasticsearch.log</p>
<div class="hl-surround">
<ol class="hl-main ln-show" title="Double click to hide line number.">
<li class="hl-firstline">2.4mb]-&gt;[2.4mb]/[273mb]}{[survivor] [3.6mb]-&gt;[34.1mb]/[34.1mb]}{[old] [79.7mb]-&gt;[80mb]/[682.6mb]}</li>
<li>[2014-08-26 10:37:14,953][WARN ][monitor.jvm              ] [Red Shift] [gc][young][71044][54078] duration [43s], collections [1]/[46.1s], total [43s]/[26.5m], memory [384.7mb]-&gt;[123mb]/[989.8mb], all_pools {[young] [270.5mb]-&gt;[1.3mb]/[273mb]}{[survivor] [34.1mb]-&gt;[22.3mb]/[34.1mb]}{[old] [80mb]-&gt;[99.4mb]/[682.6mb]}</li>
<li>[2014-08-26 10:38:03,619][WARN ][monitor.jvm              ] [Red Shift] [gc][young][71082][54080] duration [6.6s], collections [1]/[9.1s], total [6.6s]/[26.6m], memory [345.4mb]-&gt;[142.1mb]/[989.8mb], all_pools {[young] [224.2mb]-&gt;[2.8mb]/[273mb]}{[survivor] [21.8mb]-&gt;[34.1mb]/[34.1mb]}{[old] [99.4mb]-&gt;[105.1mb]/[682.6mb]}</li>
<li>[2014-08-26 10:38:10,109][INFO ][cluster.service          ] [Red Shift] removed {[logstash-Impala-26670-2010][av8JOuEoR_iK7ZO0UaltqQ][Impala][inet[/61.x.x.x:9302]]{client=true, data=false},}, reason: zen-disco-node_failed([logstash-Impala-26670-2010][av8JOuEoR_iK7ZO0UaltqQ][Impala][inet[/61.x.x.x:9302]]{client=true, data=false}), reason transport disconnected (with verified connect)</li>
<li>[2014-08-26 10:39:37,899][WARN ][monitor.jvm              ] [Red Shift] [gc][young][71171][54081] duration [3.4s], collections [1]/[4s], total [3.4s]/[26.6m], memory [411.7mb]-&gt;[139.5mb]/[989.8mb], all_pools {[young] [272.4mb]-&gt;[1.5mb]/[273mb]}{[survivor] [34.1mb]-&gt;[29.1mb]/[34.1mb]}{[old] [105.1mb]-&gt;[109mb]/[682.6mb]}</li>
</ol>
</div>
<p><strong>安装bigdesk</strong><br />
要想知道整个插件的列表，请访问http://www.elasticsearch.org/guide/reference/modules /plugins/ 插件还是很多的，个人认为比较值得关注的有以下几个，其他的看你需求，比如你要导入数据当然就得关注river了。</p>
<p>该插件可以查看集群的jvm信息，磁盘IO，索引创建删除信息等，适合查找系统瓶颈，监控集群状态等，可以执行如下命令进行安装，或者访问项目地址:https://github.com/lukas-vlcek/bigdesk</p>
<p>bin/plugin -install lukas-vlcek/bigdesk</p>
<div class="hl-surround">
<ol class="hl-main ln-show" title="Double click to hide line number.">
<li class="hl-firstline">Downloading &#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;DONE</li>
<li>Installed lukas-vlcek/bigdesk into /usr/local/elasticsearch/plugins/bigdesk</li>
<li>Identified as a _site plugin, moving to _site structure &#8230;</li>
</ol>
</div>
<p>cp -ar plugins/bigdesk/_site/ /opt/htdocs/www/bigdesk<br />
<strong>访问</strong><br />
http://localhost/bigdesk</p>
<p><a href="https://www.fuwuqiok.com/wp-content/uploads/2016/01/bigdesk-2.0.0-SNAPSHOT.jpg"><img class="attachment-medium" src="https://www.fuwuqiok.com/wp-content/uploads/2016/01/bigdesk-2.0.0-SNAPSHOT.jpg" alt="bigdesk-2.0.0-SNAPSHOT" width="980" height="763" /></a></p>
<h1>安全优化</h1>
<p>1.安全漏洞,影响ElasticSearch 1.2及以下版本 http://bouk.co/blog/elasticsearch-rce/<br />
/usr/local/elasticsearch/config/elasticsearch.yml<br />
script.disable_dynamic: true</p>
<p>2.如果有多台机器，可以以每台设置n个shards的方式，根据业务情况，可以考虑取消replias<br />
这里设置默认的5个shards, 复制为0，shards定义后不能修改,replicas可以动态修改<br />
/usr/local/elasticsearch/config/elasticsearch.yml<br />
index.number_of_shards: 5<br />
index.number_of_replicas: 0</p>
<p>#定义数据目录(可选)<br />
path.data: /opt/elasticsearch</p>
<p>3.内存适当调大，初始是-Xms256M, 最大-Xmx1G,-Xss256k，<br />
调大后，最小和最大一样，避免GC, 并根据机器情况，设置内存大小，<br />
vi /usr/local/elasticsearch/bin/elasticsearch.in.sh<br />
if [ “x$ES_MIN_MEM” = “x” ]; then<br />
#ES_MIN_MEM=256m<br />
ES_MIN_MEM=2g<br />
fi<br />
if [ “x$ES_MAX_MEM” = “x” ]; then<br />
#ES_MAX_MEM=1g<br />
ES_MAX_MEM=2g<br />
fi</p>
<p>4.减少shard刷新间隔<br />
curl -XPUT ‘http://61.x.x.x:9200/dw-search/_settings’ -d ‘{<br />
“index” : {<br />
“refresh_interval” : “-1”<br />
}<br />
}’</p>
<p>完成bulk插入后再修改为初始值<br />
curl -XPUT ‘http://61.x.x.x:9200/dw-search/_settings’ -d ‘{<br />
“index” : {<br />
“refresh_interval” : “1s”<br />
}<br />
}’</p>
<p>/etc/elasticsearch/elasticsearch.yml<br />
tranlog数据达到多少条进行平衡，默认为5000,刷新频率，默认为120s<br />
index.translog.flush_threshold_ops: “100000”<br />
index.refresh_interval: 60s</p>
<p>5.关闭文件的更新时间</p>
<p>/etc/fstab</p>
<p>在文件中添加 noatime,nodiratime<br />
/dev/sdc1 /data1 ext4 noatime,nodiratime 0 0</p>
<p>自启动<br />
chkconfig add redis_6379<br />
vi /etc/rc.local<br />
/usr/local/elasticsearch/bin/elasticsearch -d<br />
/usr/local/logstash/bin/logstash agent -f /usr/local/logstash/conf/logstash_syslog.conf &amp;<br />
/usr/local/logstash/bin/logstash agent -f /usr/local/logstash/conf/logstash_redis.conf &amp;<br />
/usr/local/logstash/bin/logstash agent -f /usr/local/logstash/conf/logstash_web.conf &amp;<br />
/opt/lemp startnginx</p>
<h1>安装问题</h1>
<p>==========================================<br />
LoadError: Could not load FFI Provider: (NotImplementedError) FFI not available: null<br />
See http://jira.codehaus.org/browse/JRUBY-4583</p>
<p>一开始我以为是没有FFI,把jruby,ruby gem都装了一遍.<br />
实际是由于我的/tmp没有运行权限造成的,建个tmp目录就可以了,附上ruby安装步骤.</p>
<p>mkdir /usr/local/jdk/tmp</p>
<p>vi /usr/local/logstash/bin/logstash.lib.sh<br />
JAVA_OPTS=”$JAVA_OPTS -Djava.io.tmpdir=/usr/local/jdk/tmp”</p>
<p>===============================<br />
jruby 安装</p>
<div class="hl-surround">
<ol class="hl-main ln-show" title="Double click to hide line number.">
<li class="hl-firstline">wget http://jruby.org.s3.amazonaws.com/downloads/1.7.13/jruby-bin-1.7.13.tar.gz</li>
<li>mv jruby-1.7.13 /usr/local/</li>
<li>cd /usr/local/</li>
<li>ln -s jruby-1.7.13 jruby</li>
</ol>
</div>
<p>Ruby Gem 安装<br />
Ruby 1.9.2版本默认已安装Ruby Gem<br />
安装gem 需要ruby的版本在 1.8.7 以上，默认的centos5 上都是1.8.5 版本，所以首先你的升级你的ruby ，</p>
<p>ruby -v<br />
ruby 1.8.5 (2006-08-25) [x86_64-linux]
<div class="hl-surround">
<ol class="hl-main ln-show" title="Double click to hide line number.">
<li class="hl-firstline">wget http://cache.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p547.tar.gz</li>
<li>tar zxvf ruby-1.9.3-p547.tar.gz</li>
<li>cd ruby-1.9.3-p547</li>
<li>./configure &#8211;prefix=/usr/local/ruby-1.9.3-p547</li>
<li>make &amp;&amp; make install</li>
<li>cd /usr/local</li>
<li>ln -s ruby-1.9.3-p547 ruby</li>
</ol>
</div>
<p>vi /etc/profile<br />
export PATH=$JAVA_HOME/bin:/usr/local/ruby/bin:$PATH<br />
source /etc/profile</p>
<p>gem install bundler<br />
gem install i18n<br />
gem install ffi</p>
<p>=======================</p>
<p>elasticsearch 端口安全<br />
绑定内网ip</p>
<p>iptables 只开放内网</p>
<p>前端机反向代理<br />
server<br />
{<br />
listen 9201;<br />
server_name big.c1gstudio.com;<br />
index index.html index.htm index.php;<br />
root /opt/htdocs/www;<br />
include manageip.conf;<br />
deny all;</p>
<p>location / {<br />
proxy_pass http://192.168.0.39:9200;<br />
proxy_set_header Host $host;<br />
proxy_set_header X-Real-IP $remote_addr;<br />
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;<br />
#proxy_set_header X-Forwarded-For $remote_addr;<br />
add_header X-Cache Cache-156;<br />
proxy_redirect off;<br />
}</p>
<p>access_log /opt/nginx/logs/access.log access;<br />
}</p>
<p>kibana的config.js<br />
elasticsearch: “http://”+window.location.hostname+”:9201″,</p>
<p><a rel="nofollow" href="https://www.fuwuqiok.com/%e5%bc%80%e6%ba%90%e5%88%86%e5%b8%83%e5%bc%8f%e6%90%9c%e7%b4%a2%e5%b9%b3%e5%8f%b0elkelasticsearchlogstashkibanaredissyslog-ng%e5%ae%9e%e7%8e%b0%e6%97%a5%e5%bf%97%e5%ae%9e%e6%97%b6%e6%90%9c/">开源分布式搜索平台ELK(Elasticsearch+Logstash+Kibana)+Redis+Syslog-ng实现日志实时搜索</a>，首发于<a rel="nofollow" href="https://www.fuwuqiok.com">服务器安全维护工作室</a>。</p>
]]></content:encoded>
			<wfw:commentRss>https://www.fuwuqiok.com/%e5%bc%80%e6%ba%90%e5%88%86%e5%b8%83%e5%bc%8f%e6%90%9c%e7%b4%a2%e5%b9%b3%e5%8f%b0elkelasticsearchlogstashkibanaredissyslog-ng%e5%ae%9e%e7%8e%b0%e6%97%a5%e5%bf%97%e5%ae%9e%e6%97%b6%e6%90%9c/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
