MongoDB设置系统服务启动教程

1、编辑mongodb.service文件

将MongoDB设置成系统服务,就可以通过systemctl进行启动停止重启,在目录/etc/systemd/system下编写mongodb.service文件:

|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Unit] Description=MongoDB Database Server Documentation=https://www.mongodb.com/docs/ After=network.target [Service] ExecStart=/usr/local/mongodb/bin/mongod --config /usr/local/mongodb/mongod.conf ExecReload=/bin/kill -s HUP $MAINPID ExecStop=/usr/local/mongodb/bin/mongod --shutdown --config /usr/local/mongodb/mongod.conf Restart=always LimitNOFILE=64000 LimitNPROC=64000 [Install] WantedBy=multi-user.target |

2、重新加载systemd服务配置

|------------------------------|
| sudo systemctl daemon-reload |

3、设置开机自启动

|-------------------------------|
| sudo systemctl enable mongodb |

4、MongoDB常用命令

|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| 启动MongoDB服务:sudo systemctl start mongodb 停止MongoDB服务:sudo systemctl stop mongodb 重启MongoDB服务:sudo systemctl restart mongodb 查看MongoDB服务状态:sudo systemctl status mongodb |

相关推荐
不想画图几秒前
负载均衡——LVS+Keepalived群集部署
运维·负载均衡·lvs
a***5606几秒前
MySQL数据库误删恢复_mysql 数据 误删
数据库·mysql·adb
love530love4 分钟前
【笔记】解决 Stable Diffusion WebUI 启动 “找不到llama_cpp模块”
运维·windows·笔记·python·stable diffusion·github·llama
豆浆whisky4 分钟前
构建可观测的Go应用:指标、日志与追踪的统一之道|Go语言进阶(21)
linux·运维·后端·golang
a***13145 分钟前
Django视图与URLs路由详解
数据库·django·sqlite
TeleostNaCl6 分钟前
Docker | 如何限制容器的 CPU/内存/磁盘IO 的资源利用以降低性能消耗
运维·经验分享·嵌入式硬件·docker·容器·智能路由器
i***17187 分钟前
使用 Qt 插件和 SQLCipher 实现 SQLite 数据库加密与解密
数据库·qt·sqlite
野生技术架构师7 分钟前
MySQL同步ES的 5 种方案
数据库·mysql·elasticsearch
v***91308 分钟前
在Django中安装、配置、使用CKEditor5,并将CKEditor5录入的文章展现出来,实现一个简单博客网站的功能
数据库·django·sqlite
Gavin在路上9 分钟前
架构设计之COLA架构
java·数据库·架构