Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Detailed explanation of MongoDB installation and configuration under Linux

2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

MongoDB official website: http://www.mongodb.org/

MongoDB Learning website: http://www.runoob.com/mongodb

Create the resource directory and installation path of MongoDB

Mkdir-p / usr/local/source mongoDB

Second, the uploaded file is located in the resource directory on the Linux operating system. First download the corresponding version of the installation package on the MongoDB official website (shown below)

Https://www.mongodb.com/download-center/community

two。 Upload the installation package to the Linux operating system through the Xshell tool

Third, extract the file-to the specified directory 1. Extract the installation package

Tar-zxf mongodb-linux-x86_64-3.2.21.tgz-C / usr/local/mongoDB/

You can also use the following command to decompress and display the decompression process:

Tar-zxvf mongodb-linux-x86_64-3.2.21.tgz-C / usr/local/mongoDB/

two。 Rename folder

Mv / usr/local/mongoDB/mongodb-linux-x86_64-3.2.21 / usr/local/mongoDB/mongodbserver

Create a folder and configuration file 1. Before creating a configuration file, create a directory of files that will be used in the configuration file

For example: database folder, log folder, and configuration file folder.

Mkdir-p data logs etc

two。 Under the create configuration folder directory, create the configuration file mongodb.conf

Cd / usr/local/mongoDB/mongodbserver/etc/

Vim mongodb.conf

Dbpath=/usr/local/mongoDB/mongodbserver/data

Logpath=/usr/local/mongoDB/mongodbserver/logs/mongodb.log

Port=27017

Fork=true

Auth=true

5. Start MongoDB1. Start the mongod process according to the configuration file

. / mongod-- config / usr/local/mongoDB/mongodbserver/etc/mongodb.conf

Note:

MongoDB does not need a password to enter for the first time after installation, and it does not contain any users. It can be accessed directly through the shell command.

In the bin directory under the MongoDB installation path, execute the command on it.

two。 Specify the port number (to distinguish multiple instances on a single machine) and use the mongo command to link to the MongoDB server

. / mongo-- port 27017

3. Add administrative user

Use admin

Db.createUser ({user: "pfnieadmin", pwd: "123456", roles: [{role: "userAdminAnyDatabase", db: "admin"}]})

Note:

(1) mongoDB does not have root users, but only users userAdminAnyDatabase who can manage users.

(2) after adding users, you can use the following command to view existing users:

Show users

Db.system.users.find ()

4. After adding administrative users for the first time, close MongoDB

A. kill process number

You need to manually clear the mongo.lock file under the database directory data/

b. Command to shut down the database:

Db.shutdownServer ()

5. Start MongoDB again with permission to verify the administrative user

If you use the admin database and verify it, nothing can be done without verification (# authentication, return 1 indicates success).

Add the mongod path to the system path to facilitate the execution of mongod commands anywhere. Write the path of the Mongo database command set to the / etc/profile file

Export PATH=$PATH:/usr/local/mongoDB/mongodbserver/bin

two。 Refresh the system environment variable to take effect immediately

Source / etc/profile

3. Test whether mongo commands can be executed anywhere

Reference blog: http://www.cnblogs.com/hanyinglong/p/5690611.html

Since 2019.01.04

I began to record the traces of learning database-related knowledge here. I intended to move forward with vigilance and should not be slack off.

But if you can give others a little help at the entry level, it is also a great honor.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report