在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環境中,還需要額外配置服務賬戶和權限。