更新时间:2025-01-20 GMT+08:00
perf_event_open被限制导致的No access to perf events报错问题
问题现象
CPU Profiler依赖perf_event_open的系统调用,但因为Linux kernel的Syscall安全策略(seccomp)控制,可能会禁止进程调用特定Syscall。
错误提示如下:
[ERROR] xxxx Failed to execute 'start,jfr=7,jstackdepth=100,threads=true,event=cpu,interval=50ms,alloc=512k,wall=50ms,file=xxxx.jfr' [ERROR] xxxx Failed to start Continuous Profile Collector [ERROR] xxxx No access to perf events. Try --fdtransfer or --all-user option or 'sysctl kernel.perf_event_paranoid=1'
解决方案
- Docker环境:执行以下命令运行容器。如需配置更精细化的系统调用控制,请参见官方文档。开启特权容器存在容器逃逸风险,请评估后使用。
docker run --security-opt seccomp=unconfined XXX
- Kubernetes环境:配置特权容器参数privileged: true,特权容器始终保持为Unconfined。如果无法配置特权容器参数privileged: true,可以通过修改k8s的yaml文件中的securityContext配置,使用默认的系统调用控制,请参见官方文档。开启特权容器存在容器逃逸风险,请评估后使用。
apiVersion: v1 kind: Pod metadata: name: default-pod labels: app: default-pod spec: containers: - name: test-container image: hashicorp/http-echo:1.0 args: - "-text=just made some more syscalls!" securityContext: seccompProfile: type: RuntimeDefault capabilities: add: [ "SYS_ADMIN" ] privileged: false
父主题: Profiler性能分析常见问题