In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
Editor to share with you how mongodb quickly build their own database, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
Mongoddb installation
Install locally
Download the corresponding compressed package mongodb directly through the official website.
Install on CVM (centos system)
Wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-amazon-3.4.9.tgztar zxvf mongodb-linux-x86_64-3.2.6.tgzmv mongodb-linux-x86_64-3.2.6.tgz mongodbcd mongodb
Please download the corresponding version according to your system.
Environment configuration & start the server
Create a folder under the file directory to store the data. The general directory is / usr/local/mongodb/data/db/. Start mongodb by running the command.
. / bin/mongod-dbpath=/usr/local/mongodb/data/db/-rest
Here are a few parameters to highlight, mongod for your mongodb command line support can be started, if necessary, you can edit / etc/profile edit into the global environment, dbpath is the data path, corresponding to your established data directory. Rest is a graphic support.
The default path of mongodb is / / localhost:27017. If you access this address successfully, you will be prompted for success and add the parameter rest to access / / localhost:28017.
. / bin/mongo can open shell
Common commands:
# query all databases show dbs;# to delete the currently used database db.dropDatabase (); # Clone host data db.cloneDatabase ("127.0.0.1"); # repair the current database db.repairDatabase (); # View the current database db.getName (); # display the current db status db.stats (); # View the linked machine address of the current db ()
Deploy mongodb environment on CVM
Now the cloud is very popular, and many people choose to use the cloud server to deploy their own projects. Here is an introduction to the cloud mongodb configuration.
. / bin/mongod-fork-dbpath=/usr/local/mongodb/data/db/-logpath=/usr/local/mongodb/data/log/error.log-logappend-rest
When the database is deployed to the CVM, it needs to be run in the background. The forever plug-in of centos was used at the beginning, and it was found that the database could not be run in the background. After consulting the information, it is found that the official command-- fork starts the backend service-- logpath-- logappend parameter adds a log log to the backend service. The rest effect is the same as above.
Make the database more intuitive
Isn't the dense data ugly? It's hard? At this time, we need a plug-in to beautify the database.
There are many online such as mongovue, adminmongo can search the living Github to look it up.
The following is the database encryption. It was only after I was attacked that I updated the encryption process.
Add Super Admin
First, run your database and perform the shell operation after success.
> use admin > db.createUser ({user: "your name", pwd: "your pwd", roles: [{role: "root", db: "admin"}]}) Successfully added user: {"user": "admin", "roles": [{"role": "root", "db": "admin"}]}
Root stands for super permissions, so an account with super privileges is created. You can view the user with the following command.
[Uploading image_088895.png. . .]
Db.getUsers ()
MongoDB database role
Role refers to the role that manages the permissions to control the database. The first user, preferably root, can perform any operation.
Initialize the user who is best to create root permissions. When auth mode is enabled, permission is required to perform any operation. Do not start the background running mode directly with auth, otherwise you will not have the permission to shut down the database.
Read: allows the user to read the specified database
ReadWrite: allows users to read and write to a specified database
DbAdmin: allows users to perform administrative functions in a specified database, such as index creation, deletion, viewing statistics, or accessing system.profile
UserAdmin: allows users to write to the system.users collection. You can create, delete and manage users in a specified database.
ClusterAdmin: available only in the admin database, giving users administrative rights to all shard and replication set related functions.
ReadAnyDatabase: available only in admin databases, giving users read access to all databases
ReadWriteAnyDatabase: available only in admin databases, giving users read and write permissions to all databases
UserAdminAnyDatabase: available only in admin databases, giving users userAdmin permissions for all databases
DbAdminAnyDatabase: available only in admin databases, giving users dbAdmin permissions for all databases.
Root: available only in the admin database. Super account, super privilege
Start auth mode
Only after you have created the Super Admin can you really start the encrypted database, otherwise you don't have the right to operate the database yourself.
/ / the normal mode database needs to be closed in shell. Enter the following command > use admin > db.shutdownServer () / / the terminal starts the encrypted database-- auth$. / bin/mongod-- fork-- dbpath=/root/mongodb/db/-- logpath=/root/mongodb/log/error.log-logappend-- auth// runs the database through the command, and adds the suffix-- auth to your running command. This starts the encrypted database. Perform database operation > show dbs2017-09-23T14:09:58.922+0800 E QUERY [thread1] Error: listDatabases failed: {"ok": 0, "errmsg": "not authorized on admin to execute command {listDatabases: 1.0}", "code": 13 "codeName": "Unauthorized"}: _ getErrorWithCode@src/mongo/shell/utils.js:25:13Mongo.prototype.getDBs@src/mongo/shell/mongo.js:62:1shellHelper.show@src/mongo/shell/utils.js:769:19shellHelper@src/mongo/shell/utils.js:659:15@ (shellhelp2): 1Rank / error found Need authentication information > db.auth ('your name','your pwd') successfully return 1 failed return 0 input before the super account, OK, simple encryption is completed.
Encryption is successful. Authentication is required to operate the database.
Link encrypted database
After the database is encrypted, our server code should be changed accordingly.
Xxx.db ('mongodb://your name: your pwd@localhost:27017/db?authSource=admin')
Xxx means the plug-ins you use, such as mongoose, mongoskin and so on.
The above is how mongodb quickly set up all the contents of its own database, thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.