0%

在kubernetes-1.12.x上搭建EFK日志分析平台

EFK 插件是kubernetes项目的一个日志解决方案,它包括三个组件:Elasticsearch, Fluentd, Kibana。

由于官方部署方案存在elasticsearch存储模式为emptyDir,国内下载镜像不能成功,部署Fluentd,还需要添加标签

1
2
kubectl label nodes node2 beta.kubernetes.io/fluentd-ds-ready=true

问题也有可能出现Fluentd镜像不可用等问题,部署起来操作比较繁琐。因此本次搭建EFK采用Elasticsearch、Kibana单独部署,独立于容器,Fluentd采用官方的daemonset部署方式。

部署java

java 版本需要1.8以上

添加java环境变量

1
2
3
export JAVA_HOME=/usr/local/jdk1.8.0_161/
export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH
export LASSPATH=.:$JAVA_HOME/lib:$JAVA_HOME/jre/lib:$CLASSPATH

部署Elasticsearch

添加仓库源

1
2
3
4
5
6
7
8
9
10
vim /etc/yum.repos.d/elasticsearch.repo

[elasticsearch-6.x]
name=Elasticsearch repository for 6.x packages
baseurl=https://artifacts.elastic.co/packages/6.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=1
autorefresh=1
type=rpm-md

安装Elasticsearch并启动

1
2
yum install elasticsearch
systemctl start elasticsearch

检查es健康状态:

1
2
[root@public03 efk]# curl http://172.16.0.17:9200/_cat/health
1542354774 07:52:54 my-cluster yellow 1 1 381 381 0 0 370 0 - 50.7%

部署Kibana

添加仓库源

1
2
3
4
5
6
7
8
9
10
vim /etc/yum.repos.d/kibana.repo

[kibana-6.x]
name=Kibana repository for 6.x packages
baseurl=https://artifacts.elastic.co/packages/6.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=1
autorefresh=1
type=rpm-md

安装kibana并启动

1
2
yum install kibana
systemctl start kibana

部署Fluentd

官方仓库地址:https://github.com/fluent/fluentd-kubernetes-daemonset

1
2
3
4
5
6
7
8
9
10
# 下载部署文件
wget https://raw.githubusercontent.com/fluent/fluentd-kubernetes-daemonset/master/fluentd-daemonset-cloudwatch-rbac.yaml

# 修改权限,在env添加如下配置
- name: FLUENT_UID
value: "0"

修改elasticsearch连接地址
- name: FLUENT_ELASTICSEARCH_HOST
value: "172.16.0.17"

如设置环境FLUENT_UID为0,启动会提示权限不足。

1
2
3
4
5
6
7
8
2018-11-16 06:48:42 +0000 [error]: unexpected error error_class=Errno::EACCES error=#<Errno::EACCES: Permission denied @ rb_sysopen - /var/log/fluentd-containers.log.pos>
2018-11-16 06:48:42 +0000 [error]: /fluentd/vendor/bundle/ruby/2.4.0/gems/fluentd-0.12.43/lib/fluent/plugin/
.
.
.
2018-11-16 06:48:42 +0000 [info]: shutting down output type="null" plugin_id="object:2acb0bd67e18"
2018-11-16 06:48:42 +0000 [info]: process finished code=0
2018-11-16 06:48:42 +0000 [warn]: process died within 1 second. exit.

部署成功后,打开kibana设置索引,搜索如图所示: