centos

Filebeat在CentOS上的部署步骤是什么

小樊
33
2025-06-04 04:26:28
栏目: 智能运维

在CentOS上部署Filebeat的步骤如下:

1. 获取安装包并校验完整性

2. 解压安装包

3. 配置Filebeat

4. 启动Filebeat

5. 设置Filebeat开机自启动

6. 验证部署

7. (可选)配置文件beat服务账户和权限(适用于Kubernetes环境)

如果你在Kubernetes集群中部署Filebeat,可以按照以下步骤配置服务账户和权限:

创建Filebeat服务账户和ClusterRole

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

创建Filebeat ConfigMap

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

部署Filebeat作为DaemonSet

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环境中,还需要额外配置服务账户和权限。

0
看了该问题的人还看了