首页 > 为何运行mongo客户端始终提示我在用root权限运行?

为何运行mongo客户端始终提示我在用root权限运行?

我的mongodb版本是3.0.5,系统是Ubuntu14.04,在阿里云上运行。
mongod运行正常,使用我自己的配置,运行mongo ip:port之后连接上了,但是会有提示:

2015-07-28T15:49:12.859+0800 I CONTROL  [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.
2015-07-28T15:49:12.859+0800 I CONTROL  [initandlisten]

我确定没有用root用户运行,也没有sudo,用ps命令查看mongo进程的用户也不是root,但是我重启并运行多次仍然有这个警报。
我看了mongo的源码,发现了显示这个警报的代码,是这个文件,相关代码如下:

#if !defined(_WIN32)
    if (getuid() == 0) {
        log() << "** WARNING: You are running this process as the root user, "
              << "which is not recommended." << startupWarningsLog;
        warned = true;
    }
#endif

我自己写了段简单程序测了下getuid的返回值,不是0。
为什么会一直有这个警报呢?

【热门文章】
【热门文章】