Touge Big Data - Getting to Know MongoDB Answers

Level 1: Start MongoDB

programming requirements

According to the prompt, operate on the right command line (Linux environment):

  • Create a folder mydb under the /data path to store the data of the MongoDB service;

  • Create a folder mymongo under the /logs path to store the log file mongod.log;

  • Create a new configuration file mongod.conf under the /etc/mymongod path, use the configuration file to start MongoDB, and set the connection port number to 27020;

  • Use the command to start the service through the configuration file.

 Answer

cd /data
mkdir mydb
cd ..

mkdir /logs
cd /logs
mkdir mymongo
cd ..
cd /etc/mymongod
vim mongod.conf

#在文件内输入:
port=27020
dbpath=/data/mydb
logpath=/logs/mymongo/mongod.log
logappend=true
fork=true
#键入Esc键 输入:wq保存并退出

mongod -f /etc/mymongod/mongod.conf
mongo --port 27020

Level 2: Start MongoDB multi-instance

programming requirements

According to the prompt, operate on the right command line (Linux environment):

  • Create folders mydb1 and mydb2 under the /data path to store the data of two sets of MongoDB services;

  • Create folders mymongo1 and mymongo2 under the /logs path to store log files;

  • Create new configuration files mongod1.conf and mongod2.conf under the /etc/mymongod path, use the configuration files to start MongoDB, and set the connection port numbers to 27021 and 27022 respectively;

  • Use the command to start two sets of services through the configuration file.

Test instruction

After clicking the evaluation button, the platform will try to connect to the clients with ports 27021 and 27022, the connection is successful, and the output: 27021 port service started successfully! 27022 port service started successfully!

Connection failed, output: 27021 port service failed to start~ 27022 port service failed to start~

 Answer

cd /data
mkdir mydb1
mkdir mydb2

mkdir /logs #若有该文件夹则不需要创建
cd /logs
mkdir mymongo1
mkdir mymongo2

mkdir /etc/mymongod #若有该文件夹则不需要创建
cd /etc/mymongod

vim mongod1.conf
#在文件内输入
port=27021
dbpath=/data/mydb1
logpath=/logs/mymongo1/mongod.log
logappend=true
fork=true

vim mongod2.conf
#在文件内输入
port=27022
dbpath=/data/mydb2
logpath=/logs/mymongo2/mongod.log
logappend=true
fork=true

mongod -f /etc/mymongod/mongod1.conf
mongod -f /etc/mymongod/mongod2.conf

Level 3: Exit the client and close the MongoDB service

programming requirements

According to the prompt, operate on the right command line (Linux environment):

  • Close the MongoDB service with port 27017 (default port).

Test instruction

After clicking Evaluation, the platform will try to connect to the default client with port 27017, for example:

The service is closed successfully, and the output is: exception: connect failed 27017 The port service is closed successfully!

Failed to close the service, output: 27017 port service is not closed~

Answer

ps -ef | grep mongo
kill 32 #如图所示,若输入上行代码显示进程号不为32 则将本行代码的32替换为你的终端所显示的进程号即可
mongo

 

Guess you like

Origin blog.csdn.net/kercii/article/details/130419434