ELK日志分析单机系统详解

日志分析ELK平台,由ElasticSearch、Logstash和Kiabana三个开源工具组成。

官方网站: https://www.elastic.co/products

Elasticsearch是个开源分布式搜索引擎,它的特点有:分布式,零配置,自动发现,索引自动分片,索引副本机制,restful风格接口,多数据源,自动搜索负载等。

Logstash是一个完全开源的工具,他可以对你的日志进行收集、过滤,并将其存储供以后使用(如,搜索)。

Kibana 也是一个开源和免费的工具,它Kibana可以为 Logstash 和 ElasticSearch 提供的日志分析友好的 Web 界面,可以帮助您汇总、分析和搜索重要数据日志。

ELK原理图:

如图:Logstash收集AppServer产生的Log,并存放到ElasticSearch集群中,而Kibana则从ES集群中查询数据生成图表,再返回给Browser。

ELK官网下载: https://www.elastic.co/downloads/

JAVA环境配置

下载最新版本1.8.0_131

cd /tmp/

tar zxf jdk-8u131-linux-x64.tar.gz -C /usr/local/
vim /etc/profile
添加如下内容
JAVA_HOME=/usr/local/jdk1.8.0_131

PATH=$JAVA_HOME/bin:$PATH

CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar

export JAVA_HOME PATH CLASSPATH

source /etc/profile

ElasticSearch配置
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.3.1.tar.gz
  useradd elktest           

tar -zxvf elasticsearch-5.3.1.tar.gz
cd elasticsearch-5.3.1
vi config/elasticsearch.yml

修改以下配置项:
(路径需要先自行创建,并且elktest用户可读写)
cluster.name: elk_cluster
node.name: node0
path.data: /tmp/elasticsearch/data
path.logs: /tmp/elasticsearch/logs
network.host: 192.168.1.5
http.port: 9200

其他的选项保持默认,然后启动ES:
  su elktest            #ES不允许root启动服务 必须是普通用户
./bin/elasticsearch &

配置Logstash
wget https://artifacts.elastic.co/downloads/logstash/logstash-5.3.1.tar.gz
tar -zxvf logstash-5.3.1.tar.gz
cd logstash-5.3.1

vi config/test_es.conf

input {
        file {
        path => "/tmp/test.log"          #测试文件
    }
}
filter {

}
output {
        stdout { codec => rubydebug }
        elasticsearch {
                index => "test_%{+YYYY.MM.dd}"        #索引信息
                hosts => [ "192.168.1.5:9200" ]
        }
}


    ./bin/logstash -f config/test_es.conf  &            #启动服务

配置Kibana:
wget https://artifacts.elastic.co/downloads/kibana/kibana-5.3.1-linux-x86_64.tar.gz
tar -zxvf kibana-5.3.1-linux-x86.tar.gz
cd kibana-5.3.1-linux-x86
vi config/kibana.yml

server.port: 5601
server.host: "192.168.1.5"
elasticsearch.url: http://192.168.1.5:9200
kibana.index: ".kibana.yml"

./bin/kibana

部署中的常见错误及解决方法

1、启动 elasticsearch 如出现异常  can not run elasticsearch as root 
解决方法:创建ES 账户,修改文件夹 文件 所属用户 组

2、启动异常:ERROR: bootstrap checks failed
system call filters failed to install; check the logs and fix your configuration or disable system call filters at your own risk

解决方法:在elasticsearch.yml中配置bootstrap.system_call_filter为false,注意要在Memory下面:
bootstrap.memory_lock: false
bootstrap.system_call_filter: false

3、启动后,如果只有本地可以访问,尝试修改配置文件 elasticsearch.yml
中network.host(注意配置文件格式不是以 # 开头的要空一格, : 后要空一格)
为 network.host: 0.0.0.0

默认端口是 9200
注意:关闭防火墙 或者开放9200端口

4、ERROR: bootstrap checks failed
max file descriptors [4096] for elasticsearch process likely too low, increase to at least [65536]
max number of threads [1024] for user [lishang] likely too low, increase to at least [2048]

解决方法:切换到root用户,编辑limits.conf 添加类似如下内容
vi /etc/security/limits.conf
添加如下内容:
* soft nofile 65536
* hard nofile 131072
* soft nproc 2048
* hard nproc 4096

5、max number of threads [1024] for user [lish] likely too low, increase to at least [2048]

解决方法:切换到root用户,进入limits.d目录下修改配置文件。
vi /etc/security/limits.d/90-nproc.conf
修改如下内容:
* soft nproc 1024
#修改为
* soft nproc 2048

6、max virtual memory areas vm.max_map_count [65530] likely too low, increase to at least [262144]

解决方法:切换到root用户修改配置sysctl.conf
vi /etc/sysctl.conf
添加下面配置:
vm.max_map_count=655360
并执行命令:
sysctl -p
然后,重新启动elasticsearch,即可启动成功。

ElasticSearch 的详细介绍请点这里
ElasticSearch 的下载地址请点这里 

猜你喜欢

转载自www.linuxidc.com/Linux/2017-05/143625.htm