在CentOS上部署Filebeat的步骤如下:
filebeat-x.x.x-linux-amd64.tar.gz
)。md5sum filebeat-x.x.x-linux-amd64.tar.gz
确保输出与官方提供的校验码一致。tar -zxvf filebeat-x.x.x-linux-amd64.tar.gz
解压后,你将得到一个名为 filebeat-x.x.x
的目录。cd filebeat-x.x.x
filebeat.yml
到 /etc/filebeat/
目录:cp filebeat.yml /etc/filebeat/
/etc/filebeat/filebeat.yml
配置文件,例如设置输出到Elasticsearch的地址:output.elasticsearch.hosts: ["http://elasticsearch:9200"]
./bin/filebeat -e
这将以守护进程模式启动Filebeat,并将其配置文件设置为 /etc/filebeat/filebeat.yml
。systemctl enable filebeat
systemctl start filebeat
systemctl status filebeat
tail -f /var/log/filebeat/filebeat
如果你在Kubernetes集群中部署Filebeat,可以按照以下步骤配置服务账户和权限:
apiVersion: v1
kind: Namespace
metadata:
name: logging
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: filebeat
namespace: logging
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: filebeat
namespace: logging
rules:
- apiGroups: [""]
resources:
- namespaces
- pods
verbs:
- get
- watch
- list
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: filebeat
namespace: logging
subjects:
- kind: ServiceAccount
name: filebeat
namespace: kube-system
roleRef:
kind: ClusterRole
name: filebeat
apiGroup: rbac.authorization.k8s.io
apiVersion: v1
kind: Namespace
metadata:
name: logging
---
apiVersion: v1
kind: ConfigMap
metadata:
name: filebeat-conf
namespace: logging
labels:
k8s-app: filebeat
data:
filebeat.yml: |
filebeat.config:
inputs:
- type: log
paths:
- /var/log/*.log
reload.enabled: true
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: filebeat
namespace: logging
spec:
selector:
matchLabels:
k8s-app: filebeat
template:
metadata:
labels:
k8s-app: filebeat
spec:
serviceAccountName: filebeat
containers:
- name: filebeat
image: docker.elastic.co/beats/filebeat:x.x.x
args: ["-e", "-c", "/etc/filebeat/filebeat.yml"]
volumeMounts:
- name: config-volume
mountPath: /etc/filebeat
volumes:
- name: config-volume
configMap:
name: filebeat-conf
通过以上步骤,你可以在CentOS上成功部署Filebeat,并将其配置为守护进程运行。如果是在Kubernetes环境中,还需要额外配置服务账户和权限。