1. Connect to the Linux system first.
2. Download the appropriate MongoDB install compression package to the MongoDB website.
Download page:.
Here i download the Linux 64-bit legacy
: https://www.qixoo.qixoo.com.fastdl.mongodb.org/linux/mongodb-linux-x86_64-3.0.7.tgz
# wget
Note: If the file cannot be downloaded properly, it can be downloaded to the local computer and then uploaded to the Linux server.
Enter the RZ command to select the native download file to upload to the current directory of the server to do the following.
Reference website:
Unzip the downloaded package: Tar xzvf mongodb-linux-x86_64-3.0.7.tgz
To migrate files in the extracted files directory to the MongoDB installation directory:
# MV Mongodb-linux-x86_64-3.0.7/data/mongodb
Creating MongoDB database directories and log files
# Mkdir/data/mongodb/data
# Mkdir/data/mongodb/log
# Touch/data/mongodb/log/logfile
Create a standby data storage directory
# Mkdir/data/mongodb/data_slave
# Mkdir/data/mongodb/log_slave
# Touch/data/mongodb/log_slave/logfile
After the MongoDB installation directory and log files have been created, the service is ready to start.
To start the main service command:
#/data/mongodb/bin/mongod–master--dbpath=/data/mongodb/data--logpath=/data/mongodb/log/logfile--logappend-- port=27017--fork
To start the Standby service command:
#/data/mongodb/bin/mongod--slave--source 10.12.72.253:27017--dbpath=/data/mongodb/data_slave--logpath=/data/ Mongodb/log_slave/logfile--logappend--port=27018–fork
Under normal circumstances, MongoDB will start up here.
If you start an exception, you can view the log information.
To view the log commands:
# Vi/data/mongodb/log/logfile
1 installation environment If the data directory disk space is not large enough, the boot will be alerted, the disk space is not large enough, the Mongod service will exit unexpectedly, and in the data directory generated mongod.lock files. Other exception causes can also cause mongod.lock files to be generated. If the development environment can delete or rename the file. Formal environments need to be analyzed for reasons.
Test environment If disk space is low, add--smallfiles--nojournal parameter to start successfully
#/data/mongodb/bin/mongod--port=27017--dbpath=/data/mongodb/data--logpath=/data/mongodb/log/logs--logappend-- Fork--smallfiles--nojournal
Connect to the server to try and connect the MongoDB service using the MONGO tool.
#/data/mongodb/bin/mongo 10.12.72.253:27017
The connection successfully returns to the service version and the default connection to the test database:
MongoDB Shell version:3.0.7
Connecting To:10.12.72.253:27017/test
Common Command explanations:
>show DBS---View the list of databases on the server
>use dbname---Switch to the specified database, which is created automatically when the collection is added, if the database does not exist.
Switched to DB Abctest
> Db.baseinfo.insert ({"Name": "Test", "Age": 22})--Add data rows in the collection (Baseinfo, not created automatically)
Writeresult ({"ninserted": 1})
> Db.baseinfo.find ()--Displays all data rows under the collection
{"_id": ObjectId ("56371c261959923f8f5d877c"), "name": "Test", "Age": 22}
> Show Collections--Displays the list of collections in the current database
Abcttt
Baseinfo
System.indexes
>db.abcttt.drop ()--Delete the collection and use it sparingly.
>exit--Close and exit the connection to the server
Connect the standby server to see if the standby server is up and running:
>mongo 10.12.72.253:27018
>show DBS---Execute the statement times wrong.
Error:listcollections failed: {"note": "From ExecCommand", "OK": 0, "errmsg": "Not Master"}
>rs.slaveok ()---Execution of the command is possible.
> Db.baseinfo.find ()---Find the document that was added on the primary server just as it appears on the primary server. configured correctly.
Close the MongoDB service, such as the following command:
>use Admin
>db.shutdownserver ()
For more server operation commands, refer to:
https://docs.mongodb.org/manual/tutorial/manage-mongodb-processes/
More functions View official documents:
Linux Command reference for installation:
RZ-Select local files to upload to Linux
Tar xzvf Compressed file name---Extract compressed files
MV Original directory target directory---Rename files or directories, or move files
If you move the logs file to the current log directory: mv/usr/local/mongodb/logs/usr/local/mongodb/log/
Df-h Viewing disk space information
(-H is the same as the-h parameter above, but the capacity is converted by 1000 instead of 1024 at the time of the initialization)
RM deletes files in the specified directory
mkdir Creating a Directory
Touch Create File
Cd.. /Return to Superior
CD Specifies the directory address to jump to the specified directory
LS View directory and file information under current directory
LL (Ls-l)
VI text Editing simple use reference:
Ctrl+u: Flip up half screen
Ctrl+f: Turn up one screen
Ctrl+d: Flip Down half screen
CTRL+B: Flip one screen down
: w--Save current file
: wq--Save (same as command: x function)
: q--Direct exit, if modified will prompt to save
: q! --Do not save direct exit
Installing MongoDB Guide under Linux system