Install and add instances of mongodb
Description:
MongoDB is a cross-platform, document-oriented database. High performance, high availability, and easy scalability. Is an open source database system based on distributed file storage, in the case of high load, add more nodes, can ensure server performance.
MongoDB is also a product between relational databases and non-relational databases, the most feature-rich and most relational of the non-relational databases. MongoDB no longer has the concept of "rows," and its operation mode is mainly based on two concepts: collections and documents.
.
.
Environment: Centos 7
.
.
The experimental procedure is as follows:
.
.
1 . Configure yum source repository
cd /etc/yum.repos.d/ #Enter this directory
vim mongodb-org.repo #Enter the following into the configuration file:
[mongodb-org] #Name
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/3.6/x86_64/ #yum Source
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-3.6.asc #Verify
.
.
2 . yum source saved after exit
yum list #Load it
yum install mongodb-org -y #Install mongodb
vim /etc/mongod.conf #After installation, enter the configuration file and change it as follows
....
port: 27017 #port
bindIp: 0.0.0.0 #Listening address
....
.
.
3 . This completes the installation.
systemctl stop firewalld.service
setenforce 0 #turn off firewall and features
systemctl start mongod.service #Open mongodb
mongo #Enter mongodb
.
.
4 . Add an example below
cd /etc/
cp -p mongod.conf mongod2.conf #Create a configuration file for the instance, where you can copy the mongodb configuration file
vim mongod2.conf #Enter the instance configuration file to configure, mainly changing three points
path: /data/mongodb/mongod2.log #Log file location
dbPath: /data/mongodb/mongo #Data file location
port: 27018 #port
.
.
5 . Create instance file
mkdir -p /data/mongodb #Create file directory
The requested URL/data/mongodb/was not found on this server.
mkdir mongo #Create a directory of data files
touch mongod2.log #Create log file directory
chmod 777 mongod2.log #Grant log file permissions
mongod -f /etc/mongod2.conf #Open Instance
mongo --port 27018 #Enter instance
.
.
.
mongodb installation and add instance operation completed, there are also simple instructions on the basic operation command
.
.
show dbs #View database
.
show tables #View Collections
.
db.info.find() #View data in a collection
.
use school #enters the database, if there is no database, it will be created
.
db.copyDatabase("school","school2") #Copy Database
.
db.version() #View Version
.
db.createCollection ('info ') #Create a collection info
.
db.info.insert ({"id":1,"name":"zhao"}) #Insert data into a collection
.
db.info.drop() #Delete collection
.
db.dropDatabase() #Advanced database, delete this database
.
mongoexport -d school -c info -o/opt/school.json #Export to specified file
.
mongoimport -d school -c test --file/opt/school.json #import
.
mongoexport -d school -c info -q '{"id":{"$eq":10}' -o/opt/top10.json #Export specified line, this example has 10 lines
.
mkdir /backup
mongodump -d school -o /backup/ #backup to file
.
mongostore-d school2 --dir-/backup/school #restore