Mongodb installation and configuration steps
This article mainly explains "mongodb installation and configuration steps". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn the steps of mongodb installation and configuration.
1. Download mongodb
Https://www.mongodb.org/dl/linux/x86_64-rhel62?_ga=2.188218154.323484055.1507690032-19904153.1501119957
2. Install mongodb
Tar-zxvf mongodb-linux-x86_64-rhel62-3.4.9.gz
Mv mongodb-linux-x86_64-rhel62-3.4.9 mongodb-3.4.9
Mkdir. / mongodb-3.4.9/logs
Mkdir. / mongodb-3.4.9/data
Mkdir. / mongodb-3.4.9/conf
3. Create a configuration file mongodb.conf in the directory. / mongodb-3.4.9/conf
Dbpath = / usr/local/jenkins/mongodb/mongodb-3.4.9/data
Logpath = / usr/local/jenkins/mongodb/mongodb-3.4.9/logs/mongodb.log
Port = 27017
Fork = true
Auth = true
Logappend = true
4. Create the startup script startup.sh and close the script shutdowm.sh in the directory. / mongodb-3.4.9
Startup.sh:
/ usr/local/jenkins/mongodb/mongodb-3.4.9/bin/mongod-- config / usr/local/jenkins/mongodb/mongodb-3.4.9/conf/mongodb.conf
Shutdown.sh:
/ usr/local/jenkins/mongodb/mongodb-3.4.9/bin/mongod-shutdown-config / usr/local/jenkins/mongodb/mongodb-3.4.9/conf/mongodb.conf
5. Connect mongodb
. / bin/mongo-u username-p password 192.168.1.135:27017/database (database corresponding to user name)
6. Configuration steps of mongodb authentication method
Mongodb authorization authentication under linux (example of configuration steps)
(1) first login does not start authorization (mongo does not start by default)
. / mongod-dbpath=/home/db/data-logpath=/home/db/logs/mongodb.log
(2) then use the. / mongo command to connect to the database
. / mongo
Switch to admin database use admin
Use the create user command:
Use admin
Db.createUser (
{
User: "root"
Pwd: "root"
Roles: [{role: "root", db: "admin"}]
}
)
A user named root is added to the admin database (Note: mongo provides a set of user rights for each database)
(3) then close the database (Note: when authorization authentication is started, only the root role has permission to shut down the database)
Db.shutdownServer ()
(4) enable authorization authentication for the second login:
. / mongod-- auth-- dbpath=/home/db/data-- logpath=/home/db/logs/mongodb.log
(5) then switch to the admin database and use the View user command
Use admin
Show users
Will be prompted for unauthorized authorization
Authorization authentication is needed at this time.
Db.auth ("root", "root")
If you call the command just now, you can view the user information.
(6) then we need to add relevant users to our database. Here we use logbackdb as an example.
Use logbackdb
Db.createUser (
{
User: "root"
Pwd: "root"
Roles: [
{role: "readWrite", db: "logbackdb"}
]
}
)
Roles with read and write permissions have been added to the logbackdb database
At this point, I believe you have a deeper understanding of the "mongodb installation and configuration steps". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!