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

Construction of mongodb and creation of user authentication

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

Share

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

Today, the company needs to deploy the mongodb environment to migrate the server, and then Baidu has a lot of blogs and documents online. Finally, the construction is completed, and the specific construction process is shared with you. I hope it will be helpful to you. MongoDB installation steps

Step 1: create a directory

Mkdir-p / data_master/tools/

Cd / data_master/tools/

Step 2: download the installation package and extract it

# download

Curl-O https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-3.0.6.tgz

# decompression

Tar-zxvf mongodb-linux-x86_64-3.0.6.tgz

Step 3: copy the extracted package to the specified directory

Mv mongodb-linux-x86_64-3.0.6 / / usr/local/mongodb

Step 4: add environment variables and restart them

Echo "export PATH=/usr/local/mongodb/bin:$PATH" > > / etc/profile

Source / etc/profile

Step 5: create a database directory

The data for # MongoDB is stored in the db directory of the data directory, but this directory is not automatically created during installation, so you need to manually create the data directory and create the db directory in the data directory.

In the following example, we create the data directory under the root directory (/).

# Note: / data/db is the default MongoDB startup database path (--dbpath).

Mkdir-p / data_master/db

Mkdir-p / data_master/mongdb/log

Step 6: run the mongodb service on the command line

Cd / usr/local/mongodb/bin

It is recommended to run in the background.

. / mongod-dbpath / data_master/db-logpath / data_master/mongdb/log/mongo.log-logappend-fork-port 27017

-dbpath specified path-logpath specified log path-fork background operation-port number specified by port

Step 7: see if it can be started

Cd / usr/local/mongodb/bin

. / mongo

Step 8: end the mongodb process and start the configuration file instead

Ps-ef | grep mongo

Kill-9 process number

Cd / usr/local/mongodb/bin/

Vim mongodb.conf

Idae-MongoDB config start-20180203 set the directory where the data files are stored

Dbpath = / data_master/db

Set the directory where the log files are stored and the name of the log file

Logpath = / data_master/mongdb/log/mongo.log

Set the port number (default port number is 27017)

Port = 27017

Set to run as a daemon, that is, in the background

Fork = true

Nohttpinterface = true

Nohttpinterface = true

# turn on authentication

Auth = on

Step 9: open the mongodb service

/ usr/local/mongodb/bin/mongod-- config / usr/local/mongodb/bin/mongodb.conf

Step 10: join Boot Auto Boot

Echo "/ usr/local/mongodb/bin/mongod-- config / usr/local/mongodb/bin/mongodb.conf" > > / etc/rc.local

Set authenticated users and passwords

Use admin

Switched to db admin

Db.createUser ({user:'dbAdmin', pwd:'aqvfgJk', roles: ["root"]})

Successfully added user: {"user": "dbAdmin", "roles": ["root"]}

Use jhpicdb

Switched to db jhpicdb

Db.createUser ({user:'db', pwd:'aqvfgJk', roles: ["readWrite"]})

Successfully added user: {"user": "admin", "roles": ["readWrite"]}

Then download the command line and log in to verify the user.

[root@vm-11a001mz log] # mongo

MongoDB shell version: 3.0.6

Connecting to: test

Use admin

Switched to db admin

Db.auth ("dbAdmin", "aqMkDuYbRAvfgJk")

one

Show dbs

Admin 0.078GB

Db 49.930GB

Local 0.078GB

These are the specific steps of my installation this time. Thank you for your support.

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