# centos7 设置MongoDB开机自启动

1在/usr/lib/systemd/system/目录下新建mongodb.service文件，内容如下：

```
[Unit] 
   
Description=mongodb  
After=network.target remote-fs.target nss-lookup.target 
   
[Service] 
Type=forking 
ExecStart=/root/mongodb/bin/mongod --config  /root/mongodb/bin/mongodb.conf
ExecReload=/bin/kill -s HUP $MAINPID 
ExecStop=/root/mongodb/bin/mongod --shutdown --config  /root/mongodb/bin/mongodb.conf
PrivateTmp=true 
     
[Install] 
WantedBy=multi-user.target
```

2.启动服务

```
systemctl daemon-reload
systemctl start mongodb
systemctl status mongodb
#开机启动    
systemctl enable mongodb.service
```

3.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://qiangrens-organization.gitbook.io/qkd90/fu-wu-qi-yun-wei-he-ce-shi/linux-fu-wu-qi/centos7-she-zhi-mongodb-kai-ji-zi-qi-dong.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
