Install MongoDB on Linux
Install MongoDB on Linux.
1. Download the installation package and decompress tgz (the installation on 64-bit Linux is demonstrated below ).
Curl-O https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-3.0.6.tgz # download tar-zxvf mongodb-linux-x86_64-3.0.6.tgz # unzip mv mongodb-linux-x86_64-3.0.6 // usr/local/mongodb # copy the package to the specified directory
2. the executable file of MongoDB is located in the bin directory, so you can add it to the PATH:
export PATH=<mongodb-install-directory>/bin:$PATH
<Mongodb-install-directory> is the MongoDB installation path. For example,/usr/local/mongodb in this article.
3. Create a database directory
MongoDB data is stored in the db directory of the data directory, but this directory is not automatically created during the installation process. Therefore, you need to manually create the data DIRECTORY and create a db directory in the data directory. In the following example, we create the data directory under the root directory (/).
Note:/data/db is the default database path (-- dbpath) started by MongoDB ).
mkdir -p /data/db
4. Run the MongoDB service in the command line
① You can run the following command in the/usr/local/mongodb/bin/directory:
./mongod
② Add the conf directory under/usr/local/mongodb/and add the mongodb. conf configuration file.
./Mongod-f/usr/local/mongodb/conf/mongodb. conf or
./Mongod -- config/usr/local/mongodb/conf/mongodb. conf
Mongodb. confThe configuration file is as follows:
Dbpath =/data/db
Bind_ip = 127.0.0.1
Port = 27017
Fork = true
Master = true
Verbose = true
Vvvv = true
MaxConns = 100
Objcheck = true
Logappend = true
Shardsvr = true
Directoryperdb = true
Logpath =/usr/local/mongodb/log/mongodb. log
5. Set mongo to start upon startup
Method 1. ① Add the mongod script in the/etc/init. d/directory,
② Add the script execution permission chmod + x/etc/init. d/mongod
③ Set chkconfig startup on
MongoThe script content is as follows:
#! /Bin/bash
# Chkconfig: 2345 80 90
# Description: mongodb
Start (){
/Usr/local/mongodb/bin/mongod-f/usr/local/mongodb/conf/mongodb. conf
}
Stop (){
/Usr/local/mongodb/bin/mongod-f/usr/local/mongodb/conf/mongodb. conf -- shutdown
}
Case "$1" in
Start)
Start
;;
Stop)
Stop
;;
Restart)
Stop
Start
;;
*)
Echo $ "Usage: $0 {start | stop | restart }"
Exit 1
Esac
Method 2:/Usr/local/mongodb/bin/mongod
-- Dbpath/data/db
-- Fork
-- Port 27017
-- Logpath =/usr/local/mongodb/log/mongodb. log
-- Logappend
Add/Etc/rc. localMedium.
For more MongoDB tutorials, see the following:
CentOS compilation and installation of php extensions for MongoDB and mongoDB
CentOS 6 install MongoDB and server configuration using yum
Install MongoDB2.4.3 in Ubuntu 13.04
MongoDB beginners must read (both concepts and practices)
MongoDB Installation Guide for Ubunu 14.04
MongoDB authoritative Guide (The Definitive Guide) in English [PDF]
Nagios monitoring MongoDB sharded cluster service practice
Build MongoDB Service Based on CentOS 6.5 Operating System
MongoDB details: click here
MongoDB: click here
This article permanently updates the link address: