【参考】java
官网:linux
https://www.elastic.co/downloadsnginx
参考:git
http://my.oschina.net/itblog/blog/547250web
http://baidu.blog.51cto.com/71938/1676798bootstrap
【ELK组成】vim
Elasticsearch:centos
Search and analyze data in real time.浏览器
Logstash:
Collect, enrich, and transport data.
Kibana:
Explore and visualize your data.
注意:三个组建缩写ELK
【安装系统环境和软件包】
系統信息:
[root@log_server src]# du -sh elasticsearch-2.2.1.tar.gz logstash-all-plugins-2.2.0.tar.gz kibana-4.4.2-linux-x64.tar.gz
29M elasticsearch-2.2.1.tar.gz
72M logstash-2.2.2.tar.gz
32M kibana-4.4.2-linux-x64.tar.gz
能够检查的校验码与官网对比是否包已经下载完整
[root@log_server src]# sha1sum kibana-4.4.2-linux-x64.tar.gz
6251dbab12722ea1a036d8113963183f077f9fa7 kibana-4.4.2-linux-x64.tar.gz
[root@log_server src]# cat /etc/redhat-release ; uname -m
CentOS release 6.4 (Final)
x86_64
关闭防火墙
[root@log_server src]# /etc/init.d/iptables status
iptables: Firewall is not running.
[root@log_server src]# getenforce
Disabled
最大文件描述符(默人用户级别的1024过小咯 要求是65536以上)
[root@master ~]# ulimit -n
102400
修改方式:
打开文件增长两行 /etc/security/limits.conf
* soft nofile 102400
* hard nofile 102400
查看 ulimit -n
[root@log_server src]# java -version
java version "1.7.0_99"
OpenJDK Runtime Environment (rhel-2.6.5.0.el6_7-x86_64 u99-b00)
OpenJDK 64-Bit Server VM (build 24.95-b01, mixed mode)
注意:jdk可自行网上搜索安装方法
注:因为Logstash的运行依赖于Java环境, 而Logstash 1.5以上版本不低于java 1.7,所以推荐使用最新版本的Java。由于咱们只须要Java的运行环境,因此能够只安装JRE,不过这里我依然使用JDK,请自行搜索安装。
(推荐yum安装yum install -y java-1.7.0-openjdk)
yum install -y java-1.8.0-openjdk.x86_64 (推荐用1.8 不然会有警告)
!!! Please upgrade your java version, the current version '1.7.0_09-icedtea-mockbuild_2013_01_16_18_52-b00' may cause problems. We recommend a minimum version of 1.7.0_51
这是版本建议(推荐1.8)
【下载来自官网源和软件安装介绍】
系统环境和版本信息:本文把ELK套件部署在一台CentOS单机上。
具体的版本要求以下:
wget https://download.elasticsearch.org/elasticsearch/release/org/elasticsearch/distribution/tar/elasticsearch/2.2.1/elasticsearch-2.2.1.tar.gz
wget https://download.elastic.co/logstash/logstash/logstash-2.2.2.tar.gz
wget https://download.elastic.co/kibana/kibana/kibana-4.4.2-linux-x64.tar.gz
【安装elasticsearch】
解压、软链接、cd到目录下
tar xvf elasticsearch-2.2.1.tar.gz -C /usr/local/ ln -s /usr/local/elasticsearch-2.2.1/ /usr/local/elasticsearch cd /usr/local/elasticsearc
安装这个重要的插件:
[root@master elasticsearc]# ./bin/plugin install mobz/elasticsearch-head
-> Installing mobz/elasticsearch-head...
Plugins directory [/usr/local/elasticsearc/plugins] does not exist. Creating...
Trying https://github.com/mobz/elasticsearch-head/archive/master.zip ...
Downloading .................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................DONE
Verifying https://github.com/mobz/elasticsearch-head/archive/master.zip checksums if available ...
NOTE: Unable to verify checksum for downloaded plugin (unable to find .sha1 or .md5 file to verify)
Installed head into /usr/local/elasticsearc/plugins/head
建立用户和目录(由于elasticsearch 2.0.0 以上版本不能用root用户运行)
[root@master elasticsearc]# groupadd -g 1000 elasticsearch [root@master elasticsearc]# useradd -g 1000 -u 1000 elasticsearch [root@master elasticsearc]# sudo -u elasticsearch mkdir /tmp/elasticsearch [root@master elasticsearc]# ls /tmp/elasticsearch [root@master elasticsearc]# sudo -u elasticsearch mkdir /tmp/elasticsearch/{data,logs}
mkdir /usr/local/elasticsearch/config/scripts
编辑配置文件vim config/elasticsearch.yml 加如如下四行(注意冒号后面有空格):
path.data: /tmp/elasticsearch/data
path.logs: /tmp/elasticsearch/logs
network.host: 192.168.100.10
network.port: 9200
启动配置默认,启动elasticsearch
sudo -u elastsearch /usr/local/elasticsearch/bin/elasticsearch
注意:若是正式应用须要在后台运行
sudo -u elastsearch /usr/local/elasticsearch/bin/elasticsearch -d
查看进程和端口
[root@master ~]# ps -ef | grep java
1000 9477 9338 2 21:02 pts/4 00:00:07 /usr/bin/java -Xms256m -Xmx1g -Djava.awt.headless=true -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly -XX:+HeapDumpOnOutOfMemoryError -XX:+DisableExplicitGC -Dfile.encoding=UTF-8 -Djna.nosys=true -Des.path.home=/usr/local/elasticsearch -cp /usr/local/elasticsearch/lib/elasticsearch-2.2.1.jar:/usr/local/elasticsearch/lib/* org.elasticsearch.bootstrap.Elasticsearch start
root 9620 9576 0 21:07 pts/0 00:00:00 grep --color=auto java
[root@master ~]# netstat -tulnp |grep java
tcp 0 0 ::ffff:192.168.100.10:9200 :::* LISTEN 9477/java
tcp 0 0 ::ffff:192.168.100.10:9300 :::* LISTEN 9477/java
注意:
能够看到,它跟其余的节点的传输端口为9300,接受HTTP请求的端口为9200。
# curl 192.168.100.10:9200
{
"name" : "Wilson Fisk",
"cluster_name" : "elasticsearch",
"version" : {
"number" : "2.2.1",
"build_hash" : "d045fc29d1932bce18b2e65ab8b297fbf6cd41a1",
"build_timestamp" : "2016-03-09T09:38:54Z",
"build_snapshot" : false,
"lucene_version" : "5.4.1"
},
"tagline" : "You Know, for Search"
}
返回展现了配置的cluster_name和name,以及安装的ES的版本等信息。
刚刚安装的head插件,它是一个用浏览器跟ES集×××互的插件,能够查看集群状态、集群的doc内容、执行搜索和普通的Rest请求等。如今也能够使用它打开http://192.168.100.10:9200/_plugin/head/页面来查看ES集群状态:
上面的功能仍是不错的!
【安装Logstash---数据日志存储和传输】
Logstash的功能以下:
其实它就是一个收集器而已,收集(input)和传输(output),咱们须要为它指定Input和Output(固然Input和Output能够为多个)。能够指定input的日志和output到elasticsearch中
解压、软链接
tar xvf logstash-2.2.2.tar.gz -C /usr/local/ ln -s /usr/local/logstash-2.2.2/ /usr/local/logstash
测试logstash
(1) 屏幕输入输出方式测试
/usr/local/logstash/bin/logstash -e 'input { stdin { } } output { stdout {} }'
咱们能够看到,咱们输入什么内容logstash按照某种格式输出,其中-e参数参数容许Logstash直接经过命令行接受设置。这点尤为快速的帮助咱们反复的测试配置是否正确而不用写配置文件。使用CTRL-C命令能够退出以前运行的Logstash。
使用-e参数在命令行中指定配置是很经常使用的方式
不过若是须要配置更多设置则须要很长的内容。这种状况,咱们首先建立一个简单的配置文件,而且指定logstash使用这个配置文件。例如:在logstash安装目录下建立
配置logstash
建立配置文件目录: mkdir -p /usr/local/logstash/etc vim /usr/local/logstash/etc/hello_search.conf 输入下面:
# cat /usr/local/logstash/etc/hello_search.conf
input {
stdin {
type => "human"
}
}
output {
stdout {
codec => rubydebug
}
elasticsearch {
hosts => "192.168.100.10:9200"
}
}
启动: /usr/local/logstash/bin/logstash -f /usr/local/logstash/etc/hello_search.conf
(以频幕上输入的方式输入,以rubydebug格式输出到屏幕,而且传递到elasticsearch)
测试logstash日志是否传输到了elasticsearch
经过如下接口:
curl 'http://192.168.100.10:9200/_search?pretty'
代表已经接收到了日志
至此,你已经成功利用Elasticsearch和Logstash来收集日志数据了。
【安装kibana---展现数据】
注:如今kibanna能够自带了web服务,bin/kibana就能够直接启动了,建议不用nginx进行配合启动了。
使用自带的web
5.1 安装Kibana
下载kibana后,解压到对应的目录就完成kibana的安装
解压、软链接
tar -xzvf kibana-4.4.2-linux-x64.tar.gz -C /usr/local/ ln -s /usr/local/kibana-4.4.2-linux-x64/ /usr/local/kibana
启动kibanna
/usr/local/kibana-4.4.2-linux-x64/bin/kibana
或者
/usr/local/kibana/bin/kibana
此时是没有链接上elasticsearch
配置kibanna
vim /usr/local/kibana/config/kibana.yml
修改
# elasticsearch.url: "http://localhost:9200"
elasticsearch.url: "http://192.168.100.10:9200"
重启
/usr/local/kibana/bin/kibana
web访问:
监听了5601做为web端口
使用http://kibanaServerIP:5601访问Kibana,登陆后,首先,配置一个索引,默认,Kibana的数据被指向Elasticsearch,使用默认的logstash-*的索引名称,而且是基于时间的,点击“Create”便可。
In order to use Kibana you must configure at least one index pattern. Index patterns are used to identify the Elasticsearch index to run search and analytics against. They are also used to configure fields.
为了后续使用Kibana,须要配置至少一个Index名字或者Pattern,它用于在分析时肯定ES中的Index
点击“Discover”,能够搜索和浏览Elasticsearch中的数据,默认搜索的是最近15分钟的数据。能够自定义选择时间。
到此,说明你的ELK平台安装部署完成。
补充:
[配置logstash做为Indexer]
将logstash配置为索引器,并将logstash的日志数据存储到Elasticsearch,本范例主要是索引本地系统日志
cat /usr/local/logstash/etc/logstash-indexer.conf
input {
file {
type =>"syslog"
path => ["/var/log/messages", "/var/log/secure" ]
}
syslog {
type =>"syslog"
port =>"5544"
}
}
output {
stdout { codec=> rubydebug }
elasticsearch {hosts => "192.168.100.10:9200" }
}
执行:
/usr/local/logstash/bin/logstash -f /usr/local/logstash/etc/logstash-indexer.conf
执行:
echo "谷歌alphago和李世石围棋大战" >> /var/log/messages
刷新kibana
每一个收集日志的启动,都是一个独立的进程