In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
Reference: http://www.runoob.com/mongodb/mongodb-linux-install.html
Introduction:
A MongoDB is an open source database system based on distributed file storage written by C++ language. Its purpose is to provide scalable high-performance data storage solutions for WEB applications.
B MongoDB is a product between relational database and non-relational database, which is the most functional and most like relational database among non-relational databases. It supports a very loose data structure, data will be stored as a document, data structure by key-value pairs (key= > value), is similar to the json bson format, field values can contain other documents, arrays and document arrays, so you can store more complex data types.
The most important feature of c MongoDB is that the query language it supports is very powerful, and its syntax is somewhat similar to the object-oriented query language. It can almost achieve most of the functions of single table query in relational database, and it also supports the establishment of data indexing.
The main features of d MongoDB (from the Internet, mainly for our preliminary understanding)
D.1 MongoDB provides a non-relational database that is simple and easy to operate for document storage.
D.2 you can set the index of any property in the MongoDB record to achieve faster sorting.
D.3 you can create data mirrors either locally or on the network, which makes MongoDB more extensible.
D.4 if the load increases (more storage space and stronger processing power are required), it can be distributed among other nodes in the computer network, which is called fragmentation.
D.5 MongoDB supports rich query expressions, and query instructions use tags in the form of JSON to easily query objects and arrays embedded in documents. D.6 MongoDB uses the update () command to replace the completed document (data) or some specified data fields. Map/Reduce in d.7 MongoDB is mainly used for batch processing and aggregation of data. The Map function calls emit (key,value) to traverse all the records in the collection, and passes the key in value to the Reduce function for processing. In addition, the Map and Reduce functions are written in JavaScript, so you can perform MapReduce operations through the db.runCommand and mapreduce commands. D.8 GridFS is a built-in feature in MongoDB that can be used to store a large number of small files.
D.9 MongoDB allows scripts to be executed on the server. You can write a function in JavaScript and execute it directly on the server, or store the definition of the function on the server and call it directly next time.
D.10 MongoDB supports a variety of programming languages: RUBY, PYTHON, JAVA, C++, PHP, C # and other languages, and MongoDB is very easy to install
F MongoDB official website: http://www.mongodb.org/
G MongoDB Learning website: http://www.runoob.com/mongodb
1. Installation of MongoDB
Download the community version
Https://www.mongodb.com/download-center#community
Tar-zxvf mongodb-linux-x86_64-3.2.8.tgz
Create two directories:
/ u01/mongnodb/
/ u01/mongodb/data/db
/ u01/mongodb/logs
Modify alias
Vim / etc/hosts
127.0.0.1 bogon
Start
. / bin/mongod-- dbpath / u01/mongodb/data/db
Enter the command lsof-I: 27017, and the monitoring port is already in use, so startup is complete.
II. MongoDB configuration
The startup parameters of MongoDB can be specified on the command line or through the configuration file
. / mongod-dbpath=/usr/local/mongodb/data-logpath=/usr/local/mongodb/log/mongod.log-fork-auth
Or
. / mongo-- config=/u01/mongnodb/mongno.conf
Cat / u01/mongnodb/mongno.conf
# Data file Path
# dbpath=/u01/mongodb/mongodb-linux-x86_64-rhel70-3.4.9/bin/mongod-- dbpat
Dbpath = / u01/mongodb/data/db
# Log file path
Logpath = / u01/mongodb/mongodb-linux-x86_64-rhel70-3.4.9/logs/mongodb.log
LogAppend=true
# bind IP
# bind_ip=127.0.0.1
# port
Port = 27017
# start in daemon mode
Fork = true
# Log output method, using appended method to write logs
Logappend = true
# PID File
Pidfilepath=/u01/mongodb/mongodb-linux-x86_64-rhel70-3.4.9/mongodb.pid
# disable the http interface and disable access to port 27018 by default
# nohttpinterface = true
# declare that this is a cluster shard
# shardsvr = true
# set that each database will be saved in a separate directory
# directoryperdb=true
# enable authentication
# auth = true
# set to open a simple rest API, and then open the 28017 web port
# rest = true
# # sharding configuration
Sharding:
# # specify config server
ConfigDB: 10.96.29.2:29017,10.96.29.2:29018,10.96.29.2:29019
III. Authorization and management of MongoDB users
1. Mongodb does not need a password to enter for the first time after installation, and there are no users. You can enter directly through the shell command, cd to the bin folder under the mongodb directory, and execute the command. / mongo
#. / bin/mongo
1) display the database
> show dbs
Admin 0.000GB
Local 0.000GB
2) use / create a library of admin. Rights management requires the use of admin database
> use admin
Switched to db admin
3) the first time I logged in, I only had a system.version table, and I didn't even have system.users. It doesn't matter if I can create a user.
System.user table, which is used to store the Super Admin
> show collections
System.users
System.version
4) query whether the system.user table contains data
> db.system.users.find ()
{"_ id": "admin.admin", "user": "admin", "db": "admin", "credentials": {"SCRAM-SHA-1": {"iterationCount": 10000, "salt": "Fyaf2IGrGbC+kDyTZpe/tg==", "storedKey": "Um7slisABOWPosz8h0XsxV18b68=", "serverKey": "AwpUC8YlyvpGnncuxUaYzHKEkuw="}}, "roles": [{"role": "userAdminAnyDatabase" "db": "admin"}]}
{"_ id": "svideo.vdb", "user": "vdb", "db": "svideo", "credentials": {"SCRAM-SHA-1": {"iterationCount": 10000, "salt": "C8xTDX0YZqOxybThand 2lkvgwigwk =", "storedKey": "9Vty4qpDso2F5793zIOoscobefk =", "serverKey": "q8dduration EwCuQcCLeTGIAHC3djnKmw ="}}, "roles": [{"role": "dbOwner" "db": "svideo"}]}
2. Add administrative users (mongoDB does not have invincible user root, but only user userAdminAnyDatabase that can manage users)
Db.createUser ({
User:'admin'
Pwd:'123456'
Roles: [
{role:'userAdminAnyDatabase',db:'admin'}
{role:'dbAdminAnyDatabase',db:'admin'}
{role:'clusterMonitor',db:'admin'}
]
})
Use mydb
Db.createUser ({
User:'vdb'
Pwd:'123456'
Roles: [{role:'dbOwner',db:'svideo'}]
})
Roles:
UserAdminAnyDatabase
DbOwner
ReadWrite
3. After adding administrative users, close MongoDB and use permission to turn on MongoDB again. Here, be careful not to use kill to kill the mongodb process directly. (if you do, go to the data/db directory to delete the mongo.lock file. You can use db.shutdownServer () to close it.
> db.shutdownServer ()
2017-09-15T21:23:01.223+0800 I NETWORK [thread1] trying reconnect to 127.0.0.1 trying reconnect to 27017 (127.0.0.1) failed
2017-09-15T21:23:01.223+0800 W NETWORK [thread1] Failed to connect to 127.0.0.1 Failed to connect to 27017, in (checking socket for error after poll), reason: Connection refused
2017-09-15T21:23:01.223+0800 I NETWORK [thread1] reconnect 127.0.0.1 reconnect 27017 (127.0.0.1) failed failed
Server should be down...
4. After adding users, you can start MongoDB with permissions.
. / mongod-dbpath=/usr/local/mongodb/data-logpath=/usr/local/mongodb/log/mongod.log-fork-auth
Or
. / mongo-- config=/u01/mongnodb/mongno.conf
Specify the parameter auth = true in mongno.conf
5. Enter mongo shell, use admin database and verify it. If you don't verify it, you can't do anything.
> use admin
> db.auth ("admin", "123456") # Authentication. A return of 1 indicates success.
6. After verification, the operation still cannot be done, because admin only has user management rights. Create users below, and users will follow the library.
> use mydb
> db.createUser ({user: "app", pwd: "123456", roles: [{role: "readWrite", db: "mydb"}]})
7. Use the created user root login to operate the database:
Mongo 127.0.0.1/mydb-uapp-p
Mongo 127.0.0.1/mydb-uvdb-p
Or use:
. / mongo-u username-p password-- port port-- authenticationDatabase databaseName
. / mongo databaseName-u username-p password-- port port
Then you can add, delete, modify and check all kinds of data operations.
Shutdown of Mongodb:
Foreground run: (do not start as daemon)
If you do not use-- fork, you can directly exit the foreground and close the terminal. In this way, Mongodb will do its own cleanup exit, write the unwritten data, and eventually close the data file. It is important to note that this process continues until all operations are completed.
Run in the background: (start fork in daemon mode = true)
If you use-- fork to run the mongdb service in the background, shut it down by sending a shutdownServer () message to the server.
1. General commands:
$. / mongod
> use admin
> db.shutdownServer ()
Mongodb Startup help
Mongod-help
If you specify a port number at startup, which is not the default of 27017, you must also specify a port when connecting
Mongo 127.0.0.1:27019
Reference:
Http://www.runoob.com/mongodb/mongodb-linux-install.html
MongoDB Authentication slow my TPS?
Http://www.mongoing.com/archives/4623
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.