Deploy and install MongoDB on a Windows server

1. Installation

The download address of the official website:  https://www.mongodb.com/download-center

After downloading, double-click mongodb-win32-x86_64-2008plus-ssl-4.0.5-signed.msi to enter the installation

1. Installation process (not to do too many illustrations) : next ——> custom ——> default installation path (you can choose other installation paths by yourself) ——> Then with the progress bar, the installation is complete

2. Test whether the installation is successful:

(1) Open the cmd command line

(2) Enter the C:\Program Files\MongoDB\Server\4.0\bin directory

(3) Enter the following command to start the mongodb service: mongod

(4) Enter http://localhost:27017 (27017 is the port number of mongodb ) in the browser to view. If the display is as follows, it means the connection is successful. If it is unsuccessful, you can check whether the port is occupied.

2. Environment configuration:

1. First, we first create a file named "mongod.config" in the bin directory, and enter in it:

  ##database directory

  dbpath=d:\MongoDB\data

  ##log file

  logpath=d:\MongoDB\log

Then save the file, please continue to look down.

Configure MongoDB directly as a system service (the advantage of this is that it eliminates the need to enter the data path every time you start. For convenience, you can write the startup database as a window service.)

First, we first create two folders log and data in the directory under MongoDB, which are used to store logs and data respectively; start the cmd command line as an administrator, and switch the path to MongoDB/Server/4.0/bin Directory, and then we enter an important command: sc create mongodb binPath= "d:\MongoDB\Server\4.0\bin\mongod.exe --service --dbpath d:\MongoDB\data --logpath=d:\ MongoDB\log\mongodb.log --logappend --directoryperdb"

This command creates a service item, and we can view the service in the following way. "win+r" enter the "run" interface, enter "services.msc" to enter "services" -> as shown in the figure

Then enter the following interface, we can see that there is a service item named "MongoDB" in the name, and then click the right mouse button to "start" the service item.

Well, at this point, our service is successfully started. Another way to start the service is to start cmd as an administrator, enter net start MongoDB in cmd, and then the word "service started successfully" appears in MongoDB, indicating that we have started the service success!

2. In your installation directory, find mongodb.cfg, open it and edit it:

parameter description
--bind_ip

Bind the service IP, if you bind 127.0.0.1, you can only access it locally; the service IP here should be 0.0.0.0, allowing other machines to access.

--logpath Set the MongoDB log file, note that the specified file is not a directory
--logappend Use append to write log
--dbpath Specify the database path
--port Specify the service port number, the default port is 27017
--serviceName Specify the service name
--serviceDisplayName Specify the service name and execute it when there are multiple mongodb services.
--install Designate to install as a Windows service.

3. Configure environment variables:

Right-click and select "Computer" "Properties"

Select "Environment Variables" to enter the interface shown below. Click on the "Path" marked on the picture, select "New", we enter the path of the bin folder of MongoDB that we installed in the new, and then select "OK"!

The environment variable configuration is successful! After configuring the environment variables, we can enter mongo in cmd to start the MongoDB database for operation. Open cmd, enter mongo, and see the following picture:

Well, here, the complete installation and configuration of our MongoDB database under the current system is introduced.

In this process, it is mainly to pay attention to the configuration of environment variables and the configuration of the .cfg file.

4. Configure account information:

use admin

db.createUser({user:"admin",pwd:"admin123",roles:[{"role":"userAdminAnyDatabase","db":"admin"},{"role":"readWriteAnyDatabase","db":"admin"}]})

The code here means: the account is admin and the password is admin123.

 

1. Installation

The download address of the official website:  https://www.mongodb.com/download-center

After downloading, double-click mongodb-win32-x86_64-2008plus-ssl-4.0.5-signed.msi to enter the installation

1. Installation process (not to do too many illustrations) : next ——> custom ——> default installation path (you can choose other installation paths by yourself) ——> Then with the progress bar, the installation is complete

2. Test whether the installation is successful:

(1) Open the cmd command line

(2) Enter the C:\Program Files\MongoDB\Server\4.0\bin directory

(3) Enter the following command to start the mongodb service: mongod

(4) Enter http://localhost:27017 (27017 is the port number of mongodb ) in the browser to view. If the display is as follows, it means the connection is successful. If it is unsuccessful, you can check whether the port is occupied.

2. Environment configuration:

1. First, we first create a file named "mongod.config" in the bin directory, and enter in it:

  ##database directory

  dbpath=d:\MongoDB\data

  ##log file

  logpath=d:\MongoDB\log

Then save the file, please continue to look down.

Configure MongoDB directly as a system service (the advantage of this is that it eliminates the need to enter the data path every time you start. For convenience, you can write the startup database as a window service.)

First, we first create two folders log and data in the directory under MongoDB, which are used to store logs and data respectively; start the cmd command line as an administrator, and switch the path to MongoDB/Server/4.0/bin Directory, and then we enter an important command: sc create mongodb binPath= "d:\MongoDB\Server\4.0\bin\mongod.exe --service --dbpath d:\MongoDB\data --logpath=d:\ MongoDB\log\mongodb.log --logappend --directoryperdb"

This command creates a service item, and we can view the service in the following way. "win+r" enter the "run" interface, enter "services.msc" to enter "services" -> as shown in the figure

Then enter the following interface, we can see that there is a service item named "MongoDB" in the name, and then click the right mouse button to "start" the service item.

Well, at this point, our service is successfully started. Another way to start the service is to start cmd as an administrator, enter net start MongoDB in cmd, and then the word "service started successfully" appears in MongoDB, indicating that we have started the service success!

2. In your installation directory, find mongodb.cfg, open it and edit it:

parameter description
--bind_ip

Bind the service IP, if you bind 127.0.0.1, you can only access it locally; the service IP here should be 0.0.0.0, allowing other machines to access.

--logpath Set the MongoDB log file, note that the specified file is not a directory
--logappend Use append to write log
--dbpath Specify the database path
--port Specify the service port number, the default port is 27017
--serviceName Specify the service name
--serviceDisplayName Specify the service name and execute it when there are multiple mongodb services.
--install Designate to install as a Windows service.

3. Configure environment variables:

Right-click and select "Computer" "Properties"

Select "Environment Variables" to enter the interface shown below. Click on the "Path" marked on the picture, select "New", we enter the path of the bin folder of MongoDB that we installed in the new, and then select "OK"!

The environment variable configuration is successful! After configuring the environment variables, we can enter mongo in cmd to start the MongoDB database for operation. Open cmd, enter mongo, and see the following picture:

Well, here, the complete installation and configuration of our MongoDB database under the current system is introduced.

In this process, it is mainly to pay attention to the configuration of environment variables and the configuration of the .cfg file.

4. Configure account information:

use admin

db.createUser({user:"admin",pwd:"admin123",roles:[{"role":"userAdminAnyDatabase","db":"admin"},{"role":"readWriteAnyDatabase","db":"admin"}]})

The code here means: the account is admin and the password is admin123.

 

Guess you like

Origin blog.csdn.net/sunzheng176/article/details/110004453