MongoDB Linux 安装配置 后台运行
介绍安装的文档很多,可以参考这篇:
http://www.mkyong.com/mongodb/how-to-install-mongodb-on-mac-os-x/
安装完后你可能会碰到的2个问题。
1.让mongod在后台运行
启动mongo的命令mongod有一个参数--fork可以使mongo在后台运行,但同时必须设置--logpath参数指定启动日志文件的路径,因为此时日志无法写到控制台了。例子:
mongod --fork --logpath /var/log/mongod.log
The MongoDB daemon (mongod) has a command-line option to run the server in the background...
--fork
This command-line option requires that you also specify a file to log messages to (since it can not use the current console). An example of this command looks like:
mongod --fork --logpath /var/log/mongod.log
You could put this into an /etc/init.d/mongod bash script file. And then to have the service run at startup, create the standard symbolic links (S## & K##) inside of /etc/rc#.d/. Here is a tutorial that explains this process in more detail. Scroll down to the section titled "Init Script Activation". This also has the added benefit of being able to execute commands like...
service mongod status
service mongod start
service mongos stop
2.执行mongod —fork —logpath /var/log/mongod.log 出错
about to fork child process, waiting until server is ready for connections. forked process: 10293 child process started successfully, parent exiting
这是因为当前用户对日志目录/var/log的权限不足
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Brainfly: 用 C# 类型系统构建 Brainfuck 编译器
· 智能桌面机器人:用.NET IoT库控制舵机并多方法播放表情
· Linux glibc自带哈希表的用例及性能测试
· 深入理解 Mybatis 分库分表执行原理
· 如何打造一个高并发系统?
· DeepSeek 全面指南,95% 的人都不知道的9个技巧(建议收藏)
· 对比使用DeepSeek与文新一言,了解DeepSeek的关键技术论文
· Brainfly: 用 C# 类型系统构建 Brainfuck 编译器
· DeepSeekV3+Roo Code,智能编码好助手
· AI编程:如何编写提示词