在MHN上安装ELK

来源:互联网 发布:合肥淘宝托管 编辑:程序博客网 时间:2024/06/16 14:51

下载MHN的源码后用里面的安装脚本安装MHN,接着再继续用里面的install_elk.sh安装脚本安装ELK(MHN和ELK均在ubuntu下用root用户安装)。以上均安装在ip为ipx的虚拟机里。
默认安装后不能访问http://ipx:9200(elasticsearch默认端口)和http://ipx:5601 (kibana默认端口),只能在虚拟机中访问http://127.0.0.1:9200(elasticsearch)和http://127.0.0.1:5601(kibana)。


1.用ipx的方式访问ELK

修改配置文件/etc/elasticsearch/elasticsearch.yml里的
network.host: localhost
为:
network.host: 0.0.0.0
(另外:默认transport.tcp.port: 9300,http.port: 9200)
重启elasticsearch让配置生效:
sudo /etc/init.d/elasticsearch restart
这样就可以用ipx的方式访问ELK了。

2.elasticsearch安装head插件

cd /usr/share/elasticsearch/bin/
sudo ./plugin -install mobz/elasticsearch-head/1.x
结果:
Installed mobz/elasticsearch-head/1.x into /usr/share/elasticsearch/plugins/head
访问:
http://ipx:9200/_plugin/head/
安装参考https://github.com/mobz/elasticsearch-head
中的“for Elasticsearch 1.x: sudo elasticsearch/bin/plugin -install mobz/elasticsearch-head/1.x”

3.logstash FATAL

logstash由supervisor管理

cat /etc/supervisor/conf.d/logstash.conf

查看错误日志如下:

tail /var/log/mhn/logstash.log

{:timestamp=>”2017-02-21T15:28:52.027000+0800”, :message=>”No SINCEDB_DIR or HOME environment variable set, I don’t know where to keep track of the files I’m watching. Either set HOME or SINCEDB_DIR in your environment, or set sincedb_path in in your Logstash config for the file input with path ‘[\”/var/log/mhn/mhn-json.log\”]’”, :level=>:error}
The error reported is:

用命令sudo find / -name ‘*.sincedb*’查找.sincedb文件,到目前为止,系统中没能找到.sincedb文件,猜测是因为到现在为止,/var/log/mhn/mhn-json.log文件内容还为空,但是当在mhn-json.log文件中加上点内容后再用supervisor去restart logstash后,系统中仍然没能出现.sincedb文件,故不是文件为空这个原因。

真正的原因是supervisor管理进程默认是将进程变成daemon进程(守护进程),而logstash进程(由supervisor管理)的运行又需要指定系统中的一个文件(/var/log/mhn/mhn-json.log),故需要在logstash配置文件中为该文件设置sincedb_path,指向.sincedb文件的路径,.sincedb文件首先是需要用户在控制终端中先运行logstash进程,这样就会为该用户在该用户主根目录下产生.sincedb文件,这样就满足了该logstash进程在后台运行的条件了。(用root用户在控制终端运行logstash进程就在root根目录下产生其.sincedb文件,用普通用户在控制终端运行logstash进程就在普通用户根目录下产生其.sincedb文件)
logstash进程在控制终端运行:(先用supervisor stop logstash)
root@jackgao-virtual-machine:/opt/logstash/bin# ./logstash -f ../mhn.conf
You are using a deprecated config setting “index_type” set in elasticsearch. Deprecated settings will continue to work, but are scheduled for removal from logstash in the future. Please use the ‘document_type’ setting instead. It has the same effect, but is more appropriately named. If you have any questions about this, please visit the #logstash channel on freenode irc. {:name=>”index_type”, :plugin= LogStash::Outputs::ElasticSearch host=>”127.0.0.1”, port=>9200, protocol=>”http”, index=>”mhn-%{+YYYYMMddHH00}”, index_type=>”event”, template_name=>”mhn_event”, template=>”/opt/logstash/mhn-template.json”, template_overwrite=>”true”, manage_template=>”true”>, :level=>:warn}
Logstash startup completed

中断logstash程序后在logstash配置文件(mhn中是/opt/logstash/mhn.conf)中添加.sincedb文件路径:
input {
file {
path => “/var/log/mhn/mhn-json.log”
sincedb_path => “/root/.sincedb_fdb10f9db860c3b76251abf2190d38ab”
start_position => “end”
}
}
保存后用supervisor start logstash即可。(这样logstash就一直是running成功运行起来的状态了,不再是之前的starting, backoff和fatal这些没运行起来的状态了。)


  1. Linux日志分析ELK环境搭建:
    http://www.cnblogs.com/lixuwu/p/6116513.html
  2. https://github.com/mobz/elasticsearch-head
  3. http://stackoverflow.com/questions/24039865/logstash-agent-doesnt-run-as-an-daemon-on-mac-os-x-10-9-1
0 0
原创粉丝点击