find /usr/* -name kibana -print
ps -ax

nohup bin/elasticsearch -Des.insecure.allow.root=true &
nohup /usr/local/logstash/bin/logstash -f /usr/local/logstash/etc/logstash_agent.conf &
nohup /usr/bin/filebeat -e -c /etc/filebeat/filebeat.yml &
nohup /usr/local/nginx/html/kibana/bin/kibana &

概述
环境准备
1 软件要求
2 防火墙配置
安装JDK
安装ElasticSearch
安装Logstash
安装Kibana
配置Logstash
参考资料
1 概述
ELK套件(ELK stack)是指ElasticSearch、Logstash和Kibana三件套。这三个软件可以组成一套日志分析和监控工具。

由于三个软件各自的版本号太多,建议采用ElasticSearch官网推荐的搭配组合:http://www.elasticsearch.org/overview/elkdownloads/

2 环境准备
2.1 软件要求
本文把ELK套件部署在一台CentOS单机上。

具体的版本要求如下:

操作系统版本:CentOS 6.5;
JDK版本:1.7.0;
Logstash版本:2.3.3;
https://download.elastic.co/logstash/logstash/packages/centos/logstash-all-plugins-2.3.3-1.noarch.rpm
https://download.elastic.co/logstash/logstash/logstash-all-plugins-2.3.3.tar.gz
ElasticSearch版本:2.3.4;
https://download.elastic.co/elasticsearch/release/org/elasticsearch/distribution/rpm/elasticsearch/2.3.4/elasticsearch-2.3.4.rpm
https://download.elastic.co/elasticsearch/release/org/elasticsearch/distribution/tar/elasticsearch/2.3.4/elasticsearch-2.3.4.tar.gz
Kibana版本:4.5.2;
https://download.elastic.co/kibana/kibana/kibana-4.5.2-linux-x64.tar.gz
2.2 防火墙配置
为了正常使用HTTP服务等,需要关闭防火墙:

service iptables stop

3 安装JDK
ElasticSearch和Logstash依赖于JDK,所以需要安装JDK:

yum -y install java-1.7.0-openjdk*

java -version

4 安装ElasticSearch
ElasticSearch默认的对外服务的HTTP端口是9200,节点间交互的TCP端口是9300。
下载ElasticSearch:

mkdir -p /opt/software && cd /opt/software

sudo wget https://download.elastic.co/elasticsearch/release/org/elasticsearch/distribution/rpm/elasticsearch/2.3.4/elasticsearch-2.3.4.rpm

yum install elasticsearch-2.3.4.rpm —nogpgcheck

error: rpmts_HdrFromFdno: Header V4 RSA/SHA1 signature: BAD, key ID d88e42b4
引用
rpm —import /etc/pki/rpm-gpg/RPM*

安装elasticsearch插件

cd /usr/share/elasticsearch/ && ./bin/plugin -install mobz/elasticsearch-head && ./bin/plugin -install lukas-vlcek/bigdesk/2.5.0

vim /usr/local/elasticsearch/config/elasticsearch.yml

启动服务
$ cd elasticsearch-1.4.0
$ bin/elasticsearch

bin/elasticsearch -Des.insecure.allow.root=true

4.ElasticSearch_Head配置

a.Elasticsearch Head是集群管理、数据可视化、增删改查、查询语句可视化工具,它的安装方式有两种,一种是使用命令安装,一种是下载包安装。

b.命令安装

b.1 cd /usr/local/kencery/elasticsearch/elasticsearch

b.2 ./bin/plugin -install mobz/elasticsearch-head(*)

提示错误,错误信息是:ERROR: unknown command [-install]. Use [-h] option to list available commands,这是因为Elasticsearch在2.0以上的版本将-install变成了install。

b.3 故而执行命令 ./bin/plugin install mobz/elasticsearch-head即可。

b.4 详细信息请看:https://github.com/mobz/elasticsearch-head下面的README.md文件。

c.下载包安装

c.1 在准备下载包的时候我们已经将包下载到电脑本地了,所以讲下载下来的包(elasticsearch-head-master)解压elasticsearch-head-master文件夹。

c.2 在Elasticsearch的安装的plugin下创建目录head

cd /usr/local/kencery/elasticsearch/elasticsearch/plugins/

mkdir head

c.3 跳转到head文件夹下,将刚才解压的elasticsearch-head-master文件夹下的所有文件拷贝到head目录下,如图所示:

c.4 重新启动ElasticSearch,使用http://192.168.37.137:9200/_plugin/head/访问浏览器,如图所示,则说明安装成功。

d.安全问题

如图就可以看出,该插件可以对数据进行任何增删改查,所以不建议在正式环境中使用它,如果使用,也必须限制规定的IP能够使用。

5 安装logstash环境
Logstash默认的对外服务的端口是9292。
下载Logstash:
wget https://download.elastic.co/logstash/logstash/packages/centos/logstash-all-plugins-2.3.3-1.noarch.rpm && yum install logstash-all-plugins-2.3.3-1.noarch.rpm -y

6 安装kibana环境

wget https://download.elastic.co/kibana/kibana/kibana-4.5.2-linux-x64.tar.gz
&& unzip kibana-3.1.2.zip && mv kibana-3.1.2 kibana && mv kibana /var/www/html/

/var/www/html/kibana

配置
/usr/local/nginx/conf/
安装kibana(前端web)

  1. 下载 kibana

wget https://download.elastic.co/kibana/kibana/kibana-4.5.1-linux-x64.tar.gz

tar zxvf kibana-4.5.1-linux-x64.tar.gz

mv kibana-4.5.1-linux-x64 /opt/local/kibana

mkdir /opt/local/kibana/logs

cd /opt/local/kibana

  1. 修改配置

cp /opt/local/kibana/config/kibana.yml /opt/local/kibana/config/kibana.yml.bak

修改 elasticsearch_url: 为 elasticsearch_url: “http://172.16.32.31:9200

修改 server.host: 为 server.host: “172.16.1.100”

修改 kibana.index: 为 kibana.index: “.kibana”

  1. 启动 kibana 服务

cd /opt/local/kibana/logs && nohup /opt/local/kibana/bin/kibana &

http://http😕/172.16.1.100:5601/

kibana Index Patterns 必须要有数据才能创建索引。

FQA:

kibana 出现如下错误:

Courier Fetch Error: unhandled courier request error: Authorization Exception

这个错误是因为 elasticsearch 配置文件 elasticsearch.yml 里面使用了 http.cors.enabled

Kibana 4 的版本中,这个选项已经废弃了,请删除掉这个选项。

7 配置Logstash
再次创建Logstash配置文件,这里将HTTP日志和文件系统日志作为输入,输出直接传给ElasticSearch,不再打印在界面上:

log_format main ‘[$time_local] $remote_addr $status $request $request_time ‘
‘$body_bytes_sent “$http_referer” $upstream_addr ‘
‘$http_x_real_ip $http_x_forwarded_for $http_user_agent $request_filename ‘;

log_format main ‘$remote_addr - $remote_user [$time_local] ‘
‘“$request” $status $body_bytes_sent ‘
‘“$http_referer” “$http_user_agent” ‘;

[plain] view plain copy

vim /usr/local/logstash/etc/logstash_agent.conf

input {
file {
type => “http.access”
path => [“/var/log/httpd/access_log”]
}

file {
type => “http.error”
path => [“/var/log/httpd/error_log”]
}

file {
type => “messages”
path => [“/var/log/messages”]
}
}

output {
elasticsearch {
host => “10.111.121.22”
port => 9300
}
}
[root@vm software]# ls /data/other/nginx_logs/
nginx_error.log vm7.boyaa.com_80_access.log vm.by.com_80_access.log

nohup /usr/local/logstash/bin/logstash -f /usr/local/logstash/etc/logstash_agent.conf &

现在,一个简单的日志分析和监控平台就搭建好了,可以使用Kibana进行查看。

8 参考资料

  1. 《安装logstash,elasticsearch,kibana三件套》,http://www.cnblogs.com/yjf512/p/4194012.html

9、filebeat
/usr/bin/filebeat -e -c /etc/filebeat/filebeat.yml

/usr/local/nginx/html/kibana/optimize/bundles/kibana.bundle.js

home/wwwlogs/a
/usr/local/nginx/logs/

bin/elasticsearch -Des.insecure.allow.root=true &
./bin/kibana &
./filebeat -e -c ./filebeat.yml