In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-12 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
MongoDB installation and configuration
The first step is to download the mongoDB database from mongoDB's official website.
Download the version according to your operating system.
MongoDB such as: mongodb-linux-x86_64-3.2.10.tgz
Step 2, install the virtual machine
Skip installation of virtual machine
Step 3: install the linux system
Linux installation skipped
Step 4: install the SSH connection linx tool
Skip
Step 5, after the linx system is installed, log in to linx according to your user password
Use the SSH tool to connect to the linx
You can find the above on your own Baidu.
Step six, here comes the practical information.
Install mongoDB under linux
Decompress mongoDB
Change the folder name: mongodb
The file structure is as follows:
Mongodb
-> bin
-> GNU-AGPL-3.0
-> MPL-2
-> README
-> THIRD-PARTY-NOTICES
Create two folders in this folder to store data files and log files (of course, you can also choose your favorite location)
The folder name is: db
Log
Enter command: cd / usr/local/
Copy and paste the previous mongodb into this directory
Enter command: cd / usr/local/mongodb/bin
/ * * start the service * /
/ mongod-- dbpath=/usr/local/mongodb/db/-- logpath=/usr/local/mongodb/log/mongo.log-- logappend-- auth-- port=27017-- fork
/ * * success message * * /
About to fork child process, waiting until server is ready for connections.
Forked process: 12999
Child process started successfully, parent exiting
Finally, it started successfully.
. / mongod
Use admin
/ * * create a Super Admin. Versions later than mongoDB 3.0 are suitable for create creation, not add * * /
Db.createUser ({user: "super", pwd: "super", roles: [{role: "root", db: "admin"}]})
Db.auth ("super", "super")
/ * * create database * * /
Use mydb
Add data
Db.usr.insert ({'name':'tompig'})
/ * * above is only the account in which the admin database is created, and the newly created database cannot be accessed yet * /
Log in to create using your super account
. / mongo
Use admin
Db.auth ("super", "super")
Use mydb
Db.createUser ({user: "testx", pwd: "testx", roles: [{role: "dbAdmin", db: "mydb"}]})
After the creation is successful, access the data using the testx user connection.
/ * * disable the service * * /
1. General commands:
$. / mongo
> use admin
> db.shutdownServer ()
Note: the firewall must be turned off, otherwise you will not be able to access
/ * * turn off the firewall * /
Service iptables stop
/ * * permanently turn off the firewall * /
Chkconfig-level 35 iptables off
Encounter the following
Error report:
Permission denied.
Enter command: chmod-R 777 / usr/local/mongodb (the path here is the path of mongodb) reason = first see if it is root permission, and it is copied and pasted by ssh, and there is no permission.
Error report:
. / mongod: / usr/lib64/libcrypto.so.10: no version information available (required by. / mongod)
. / mongod: / usr/lib64/libssl.so.10: no version information available (required by. / mongod)
. / mongod: relocation error:. / mongod: symbol TLSv1_2_client_method, version libssl.so.10 not defined in file libssl.so.10 with link time reference
Input command: yum install-y openssl-devel openssl solution, installation of openssl dependent operation is required
Error report:
About to fork child process, waiting until server is ready for connections.
Forked process: 12981
ERROR: child process failed, exited with error number 1
Enter the command:. / mongod-- repair-- dbpath / usr/local/mongodb/db/-- repairpath / tmp/mongodb
How troublesome it is to set up the above settings. Configure the shortcut startup method below.
Create a new notepad, change the name to mongo.conf, and copy and paste the following
Dbpath=/usr/local/mongodb/db
Logpath=/usr/local/mongodb/log/mongo.log
Port=27017
Fork=true
Auth=true
Bind_ip=0.0.0.0
I believe you can understand the configuration above.
The database storage path of dbpath=mongodb
Log file storage path of logpath=mongodb
Port= port number
Fork=true this is run as a daemon
Does auth=true require authentication and login?
Bind_ip= binding port number. 0.0.0.0 means that any ip can access it. Otherwise, you need to specify an ip such as 192.168.1.102.
Once configured, put this file in the / usr/mongodb/bin directory
Enter the command: cd / usr/local/mongodb/bin enter the directory
Enter the command:. / mongod-f mongo.conf to start
Over, here is the help of db
Help from db
Db.createUser (username,password) add user
Db.auth (usrename,password) sets up database connection verification
Db.cloneDataBase (fromhost) Clones a database from the target server
Db.commandHelp (name) returns the help for the command
Db.copyDatabase (fromdb,todb,fromhost) replication database fromdb--- source database name, todb--- target database name, fromhost--- source database server address
Db.createCollection (name, {size:3333,capped:333,max:88888}) creates a dataset, which is equivalent to a table
Db.currentOp () cancels the current operation of the current library
Db.dropDataBase () deletes the current database
Db.eval (func,args) run code server-side
Db.getCollection (cname) gets a collection of data. Synonym: db ['cname'] or
Db.getCollenctionNames () gets a list of the names of all data sets
Db.getLastError () returns the last error message
Db.getLastErrorObj () returns the last wrong object
Db.getMongo () gets the connection object get the server of the current server
Db.getMondo (). SetSlaveOk () allow this connection to read from then nonmaster membr of a replica pair
Db.getName () returns the name of the database to be operated on
Db.getPrevError () returns the last error object
Db.getProfilingLevel () gets profile level
Db.getReplicationInfo () gets duplicate data
Db.getSisterDB (name) get the db at the same server as this onew
Db.killOp () stops (kills) the current operation in the current library
Db.printCollectionStats () returns the dataset status of the current library
Db.printReplicationInfo () prints the replication status information of the master database
Db.printSlaveReplicationInfo () prints replication status information from the database
Db.printShardingStatus () returns whether the current database is a shared database
Db.removeUser (username) Delete user
Db.repairDatabase () repairs the current database
Db.resetError ()
Db.runCommand (cmdObj) run a database command. If cmdObj is a string, turns it into {cmdObj:1}
Db.setProfilingLevel (level) sets profile level 0 to offline 1 to record 2 to all
Db.shutdownServer () closes the current service program
Db.version () returns the version information of the current program
Read: allows the user to read the specified database readWrite: allows the user to read and write the specified database dbAdmin: allows the user to perform management functions in the specified database, such as index creation, deletion, viewing statistics or accessing system.profileuserAdmin: allows the user to write to the system.users collection, and can find the specified database to create, delete and manage the user clusterAdmin: available only in the admin database, giving the user administrative rights to all shard and replication set related functions. ReadAnyDatabase: available only in admin databases, giving users read permissions 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 to all databases dbAdminAnyDatabase: available only in admin databases, giving users dbAdmin permissions to all databases. Root: available only in the admin database. Super account, super privilege
Table help, format, db. Table name .help ()
Db.test.find ({id:10}) returns the dataset of the test dataset ID=10
Db.test.find ({id:10}) .count () returns the total number of data from the test dataset ID=10
Db.test.find ({id:10}) .limit (2) returns the dataset of the test dataset ID=10 the dataset starting from Article 2
Db.test.find ({id:10}) .skip (8) returns the dataset of the test dataset ID=10 from 0 to 8
Db.test.find ({id:10}) .limit (2) .skip (8) returns data from articles 2 to 8 of the dataset of the test dataset ID=1=
Db.test.find ({id:10}) .sort () returns the sorted dataset of the test dataset ID=10
Db.test.findOne ([query]) returns a piece of data that meets the criteria
Db.test.getDB () returns the name of the database to which this dataset belongs
Db.test.getIndexes () returns the index information of some datasets
Db.test.group ({key:...,initial:...,reduce:... [, cond:...]}) returns grouping information
Db.test.mapReduce (mayFunction,reduceFunction,) this is a bit like a stored procedure.
Db.test.remove (query) deletes a piece of data in the dataset
Db.test.renameCollection (newName) renames some dataset names
Db.test.save (obj) inserts a piece of data into the dataset
Db.test.stats () returns the status of this dataset
Db.test.storageSize () returns the storage size of this dataset
Db.test.totalIndexSize () returns the index file size for this dataset
Db.test.totalSize () returns the total size of some datasets
Db.test.update (query,object [, upsert_bool]) updates a piece of data in this dataset
Db.test.validate () validates this dataset
Db.test.getShardVersion () returns the dataset shared version number
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.