MongoDB安装手册 MongoDB Installation Guide

Installation on Linux

Linux Version

CentOS Linux release 7.6.1810 (Core)

Reference

https://docs.mongodb.com/manual/tutorial/install-mongodb-on-red-hat/

Install MongoDB Community Edition

Note that the MongoDB here is installed by default settings.
Make sure that the proxy for yum repository has been configured and the root permission has been accessed.

step1: Configure the package management system (yum). Create a /etc/yum.repos.d/mongodb-org-4.0.repo file so that you can install MongoDB directly using yum:

[mongodb-org-4.0]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/4.0/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-4.0.asc

step2: Install the MongoDB packages. To install the latest stable version of MongoDB, issue the following command:

yum install -y mongodb-org

Run MongoDB Community Edition

1. Start MongoDB

You can start the mongod process by issuing the following command:

service mongod start

2. Verify that MongoDB has started successfully

You can verify that the mongod process has started successfully by checking the contents of the log file at /var/log/mongodb/mongod.log for a line reading.

[initandlisten] waiting for connections on port <port>

You can optionally ensure that MongoDB will start following a system reboot by issuing the following command:where is the port configured in /etc/mongod.conf, 27017 by default.

chkconfig mongod on

3. Stop MongoDB

As needed, you can stop the mongod process by issuing the following command:

service mongod stop

4. Restart MongoDB.

You can restart the mongod process by issuing the following command:

service mongod restart

5. Begin using MongoDB.

Start a mongo shell on the same host machine as the mongod. You can run the mongo shell without any command-line options to connect to a mongod that is running on your localhost with default port 27017:

mongo

MongoDB GUI Client

Like Redis Desktop Manager, MongoDB client is used for connect to MongoDB service and visualize the mongo command lines.
在这里插入图片描述
Click ‘Connect to’ and enter the mongo server’s IP, then click ‘connect’:
在这里插入图片描述
However, the first-time connection usually fail because the mongo service refuses the remote access by default. The solution is to modify the bind_ip in mongod.conf file.

vim /etc/mongod.conf

replace the bindIP from 127.0.0.1 to 0.0.0.0:
在这里插入图片描述

remember to restart the mongodb service:

service mongod restart

Now the connection is successful:
在这里插入图片描述

发布了79 篇原创文章 · 获赞 322 · 访问量 9万+

猜你喜欢

转载自blog.csdn.net/qq_15329947/article/details/90906427