问题现象
将操作系统为 Ubuntu 22.04 LTS 的主机添加到 OCP 主机列表(添加主机时使用的凭据类型为:普通用户 test + 该用户的 sudo 免密登陆),添加主机时没有遇到任何报错,但是使用该主机来创建 OceanBase 数据库集群时,在【路径设置】的窗口遇到了报错:检测失败,请检查 OCP Agent 服务是否正常。相关路径的 owner:group 都已经修改为 admin:admin 了。

问题原因
通过分析 /home/admin/ocp_agent/log/ 路径下的 OCP Agent 相关日志后发现,在 mgragent.log 中,报错时间点附近存在如下日志信息。
2025-06-16T19:57:53.07956+08:00 INFO [94685,8d767562acd9c76a] caller=common/middleware.go:152:func1: API response OK: [POST /api/v1/file/checkDirectoryPermission, client=172.20.xx.xxx, ocpServerIp=172.20.xx.xxx, traceId=8d767562acd9c76a, duration=6.70846ms, status=200, data=CHECK_FAILED]
2025-06-16T19:57:53.10604+08:00 INFO [94685,1281859c7071e0ef] caller=common/middleware.go:60:func1: API request: [POST /api/v1/file/checkDirectoryPermission, client=172.20.xx.xxx, ocpServerIp=172.20.xx.xxx, traceId=1281859c7071e0ef, body={"directory":"/home/admin","user":"admin","permission":"ACCESS_EXECUTE","onlyExistingAncestor":true}]
2025-06-16T19:57:53.10619+08:00 INFO [94685,1281859c7071e0ef] caller=shell/exec.go:124:execute: execute shell command start, command=Command{user=admin, program=sh, outputType=std, cmd=if [ -"x" "/home/admin" ]; then echo 0; else echo 1; fi, timeout=10s} fields:, duration="20.899µs"
2025-06-16T19:57:53.10622+08:00 INFO [94685,] caller=shell/exec.go:128:execute: c.user=admin, currentUser=root
2025-06-16T19:57:53.11308+08:00 INFO [94685,1281859c7071e0ef] caller=shell/exec.go:163:execute: execute shell command failed, command=Command{user=admin, program=sh, outputType=std, cmd=if [ -"x" "/home/admin" ]; then echo 0; else echo 1; fi, timeout=10s}, exitCode=1, error=root is not in the sudoers file. This incident will be reported.
: exit status 1 fields:, duration=6.910099ms
2025-06-16T19:57:53.11314+08:00 INFO [94685,1281859c7071e0ef] caller=file/file.go:255:CheckDirectoryPermission: check directory permission failed, cannot check directory permission fields: directory=/home/admin, user=admin, permissionType=ACCESS_EXECUTE, error="failed to execute command: Command{user=admin, program=sh, outputType=std, cmd=if [ -\"x\" \"/home/admin\" ]; then echo 0; else echo 1; fi, timeout=10s}, exitCode: 1, output: , error: root is not in the sudoers file. This incident will be reported.\n: exit status 1"
2025-06-16T19:57:53.11319+08:00 INFO [94685,1281859c7071e0ef] caller=common/middleware.go:152:func1: API response OK: [POST /api/v1/file/checkDirectoryPermission, client=172.20.xx.xxx, ocpServerIp=172.20.xx.xxx, traceId=1281859c7071e0ef, duration=7.057125ms, status=200, data=CHECK_FAILED]
其中关键报错信息为:root is not in the sudoers file. This incident will be reported.
目前 OCP Agent 相关的进程在 OBServer 主机上都是以 <root> 用户的身份运行的。
root@observer:/home/admin/ocp_agent/log# ps -ef | grep agent | grep -v grep
root 36824 1 0 21:25 ? 00:00:01 /home/admin/ocp_agent/bin/ocp_agentd -c /home/admin/ocp_agent/conf/agentd.yaml
root 36844 36824 3 21:25 ? 00:02:32 /home/admin/ocp_agent/bin/ocp_mgragent
root 36845 36824 8 21:25 ? 00:06:07 /home/admin/ocp_agent/bin/ocp_monagent
root@observer:/home/admin/ocp_agent/log#
在该主机上用 <root> 用户的身份 + sudo 执行命令。
root@observer:/home/admin/ocp_agent/log# sudo -s whoami
输出内容如下:
root is not in the sudoers file. This incident will be reported.
问题的风险及影响
无法通过 OCP Web 界面创建 OceanBase 数据库集群。
适用版本
OCP 所有版本。
Ubuntu 或其它类 Debian 操作系统。
解决方法
通过比对正常环境上的 /etc/sudoers 配置文件,找到该问题的解决方法是将 root 用户添加到 /etc/sudoers 系统配置文件中去。
## Allow root to run any commands anywhere
root ALL=(ALL) ALL
备注:这边强烈推荐使用 sudo visudo 命令去修改 /etc/sudoers 配置文件(不要直接使用 vim 命令去编辑 /etc/sudoers),因为该命令会自动检查人为修改的语法是否包含非法的格式。
规避方式
无。