1. Installation steps of MongoDB in Linux environment
1.1 MongoDB online installation
Online installation command : yum –y install mongodb-server mongodb
After a successful installation, complete will appear as shown below:
1.2 MongoDB manual installation
1. Download the mongodb package,
The method of choice is to download online : wget
https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-3.0.6.tgz
2. General preparations
I created the directory in /usr/local/cache/mongodb
Step 1: Create mongo 's home directory: mkdir /usr/local/cache/mongodb
Step 2: Unzip mongo to the main directory: tar –xvf mongodb-linux-x86_64-3.0.6.tgz -C ./mongodb/ ( I executed it in the current directory )
Step 3: Create a data file storage directory and log storage directory ( try to put it on a disk with a large space )
Step 4: Start the service:
# cd /usr/local/mongodb/mongodb-linux-x86_64-3.0.6/bin/
#./mongod --dbpath=/usr/local/cache/mongodb/data/
--fork --logpath=/usr/local/cache/mongodb/log/mongo.log
dbpath : is the specified database path
fork : Add this parameter to let mongo run in the background , otherwise it will stop when the session is closed.
logpath : The log path.
Of course , we can also create a configuration file to write all the startup items into the configuration. This way, you only need to associate the configuration file when you start it.
General configuration file: mongod.conf, configuration file startup command: ./mongod –f mongod.conf
1.3 Start the MongoDB service ( this setting is mainly for online installation of mongodb)
Start command: service mongod start
Note :
1. If the service cannot be started in this way, it may be because the default database data storage path has not been created. Please refer to the dbpath item configured in the configuration file configuration . ( The default path of the configuration file is : /etc/mongod.conf)
2. The startup command for MongoDB with a configuration file is : ./mongod – config /etc/mongod.conf
( The default path for the MongoDB service is: /usr/bin/mongod)
3. The third way to start mongod – f /etc/mongod.conf
1.4 Stop the MongoDB service
MongoDB stop command : service mongod stop
1.5 View the service process of MongoDB
View the MongoDB service process command : pstree –p | grep 'mongod'
2. Possible problems
2.1 No package mongodb-server available.
Unable to find the service source for MongoDB :
The solution found , update yum to use the yum source provided by Alibaba Cloud :
1. Download update_source.sh
Download address: http://oss.aliyuncs.com/aliyunecs/update_source.tgz
2. Unzip update_source.tgz
Decompression command : tar –zxvf update_source.tgz
3. Execute the script
Execution method: Execute the command as root : bash update_source.sh