ELK平台的搭建
参考:https://my.oschina.net/u/3030681/blog/785565
https://my.oschina.net/itblog/blog/547250
并结合自己实际搭建的步骤综述如下。
一、环境
系统:centos 7
JDK:1.8
Elasticsearch-6.2.3
Logstash-6.2.3
kibana-6.2.3
二、配置
(1)安装JDK
本环境下载的是64位tar.gz包,将安装包拷贝至安装服务器/usr/local目录,或者使用xshell中xftp插件,上传到服务器,xshell和xftp皆可从网上下载安装即可。
安装步骤:
1.[root@localhost ~]# cd /usr/local/
2.[root@localhost local]# tar -zxvf jdk-8u161-linux-x64.tar.gz
配置环境变量
[root@localhost local]# vim /etc/profile
将下面的内容添加至文件末尾(假如服务器需要多个JDK版本,为了ELK不影响其它系统,也可以将环境变量的内容稍后添加到ELK的启动脚本中)
JAVA_HOME=/usr/local/jdk1.8.0_161
JRE_HOME=/usr/local/jdk1.8.0_161/jre
CLASSPATH=.:$JAVA_HOME/lib:/dt.jar:$JAVA_HOME/lib/tools.jar
PATH=$PATH:$JAVA_HOME/bin
export JAVA_HOME
export JRE_HOME
ulimit -u 4096
[root@localhost local]# source /etc/profile
配置limit相关参数
[root@localhost local]# vim /etc/security/limits.conf
添加以下内容
* soft nproc 2048
* hard nproc 4096
* soft nofile 65536
* hard nofile 131072
创建运行ELK的用户
[[email protected] local]# groupadd elk
[[email protected] local]# useradd -g elk elk
[[email protected] local]# passwd elk
创建ELK运行目录
[[email protected] local]# mkdir /elk
[[email protected] local]# chown -R elk:elk /elk
关闭防火墙:
[[email protected] ~]# iptables -F
以上全部是root用户完成
(2)安装ELK
必须先登录elk用户操作
下载ELK安装包:https://www.elastic.co/downloads,并上传到服务器且解压,解压命令:tar -xzvf 包名
配置Elasticsearch
修改内容如下:
保存退出 esc :wq 回车
启动Elasticsearch
报错分析:
借鉴文章:https://blog.****.net/yulio1234/article/details/74054996 第一步即可
第二类错误:
修改:
可参考:https://www.cnblogs.com/woxpp/p/6061073.html
用浏览器访问 192.168.0.11:9200
Elasticsearch安装完毕
(3)安装logstash
logstash是ELK中负责收集和过滤日志的
解压并进入到一下文件夹:(自己新建即可,名字和位置可以随意,这里我放在config目录下,取名为logstash.conf)
创建文件
touch logstash.conf
粘贴到logstash.conf下
# Set: https://www.elastic.co/guide/en/logstash/current/configuration-file-structure.html
input {
# For detail config for log4j as input,
# See: https://www.elastic.co/guide/en/logstash/current/plugins-inputs-log4j.html
log4j {
mode => "server"
host => "192.168.0.11"
port => 4567
}
}
filter {
#Only matched data are send to output.
}
output {
# For detail config for elasticsearch as output,
# See: https://www.elastic.co/guide/en/logstash/current/plugins-outputs-elasticsearch.html
elasticsearch {
action => "index" #The operation on ES
hosts => "192.168.0.11:9200" #ElasticSearch host, can be array.
index => "applog" #The index to write data to.
}
}
退出保存
启动(使用-f指定配置文件):
启动成功:
到这里,我们已经可以使用Logstash来收集日志并保存到ES中了
(3)安装kibana
如下设置,端口可以不动,打开注释就可以了
启动