One: Download
Download Address:
https://www.mongodb.org/
Two: Installation 2.1 Decompression
[root@ser6-51 download]# ls-ltr total 71552-rw-r--r--1 root 32979820 June 10:01 mysql-5.6.20.tar.gz drwxr-xr-x 4 Root root 4096 June 13:39 mysql-rw-r--r--1 root 40280527 June 11:54 mongodb-linux-x86_64-3.0.4.tgz [root@s er6-51 download]# tar-xvf mongodb-linux-x86_64-3.0.4.tgz mongodb-linux-x86_64-3.0.4/readme mongodb-linux-x86_
64-3.0.4/third-party-notices mongodb-linux-x86_64-3.0.4/gnu-agpl-3.0 Mongodb-linux-x86_64-3.0.4/bin/mongodump Mongodb-linux-x86_64-3.0.4/bin/mongorestore Mongodb-linux-x86_64-3.0.4/bin/mongoexport mongodb-linux-x86_
64-3.0.4/bin/mongoimport Mongodb-linux-x86_64-3.0.4/bin/mongostat Mongodb-linux-x86_64-3.0.4/bin/mongotop Mongodb-linux-x86_64-3.0.4/bin/bsondump Mongodb-linux-x86_64-3.0.4/bin/mongofiles Mongodb-linux-x86_64-3.0.4/bin /mongooplog Mongodb-linux-x86_64-3.0.4/bin/mongoperf Mongodb-linux-x86_64-3.0.4/bin/mongod mongodb-linux-x86_ 64-3.0.4/bin/mongos Mongodb-linux-x86_64-3.0.4/bin/mongo [root@ser6-51 download]# ls-ltr Total 71556-rw-r--r--1 root 32979820 June 10:01 mysql-5.6.20.tar.gz drwxr-xr-x 4 root root 4096 June 13:39 mysql-rw-r-- r--1 root 40280527 June 11:54 mongodb-linux-x86_64-3.0.4.tgz drwxr-xr-x 3 root root 4096 June 11:54 mongodb-
linux-x86_64-3.0.4
#为了方便管理, move the installation files to the/usr/local
[Root@ser6-51 download]# MV Mongodb-linux-x86_64-3.0.4/usr/local/mongodb
2.2 Creating a related directory
Create a location and log file for the MongoDB database
[Root@ser6-51 mongodb]# Cd/usr/local/mongodb
[Root@ser6-51 mongodb]# mkdir data
[Root@ser6-51 mongodb]# Touch logs
[Root@ser6-51 mongodb]# ls-ltr
Total 72
-rw-r--r--1 1046 1046 22660 June 23:51 Third-party-notices
-rw-r--r--1 1046 1046 1359 June 23:51 README
-rw-r--r--1 1046 1046 34520 June 23:51 gnu-agpl-3.0
Drwxr-xr-x 2 root root 4096 June 11:54 bin
Drwxr-xr-x 2 root root 4096 June 12:00 data
-rw-r--r--1 Root 0 June 12:00 logs 2.3 Create Linux users
[Root@ser6-51 init.d]# Groupadd MongoDB
[root@ser6-51 init.d]# useradd-g MongoDB MongoDB
[Root@ser6-51 init.d]# chown-r Mongodb:mongodb/usr/local/mongodb
2.4 Configuration Path
#mongodb用户:
Add the MongoDB installation file/bin path at the end of path:
[Root@ser6-51 init.d]# Su-mongodb
[Mongodb@ser6-51 ~]$ Vi. Bash_profile
Path= $PATH: $HOME/bin:/usr/local/mongodb/bin
[mongodb@ser6-51 ~]$ Source Bash_profile
So you can not go into the/usr/local/mongodb/bin path to use the MONGO command, directly enter the MONGO command.
#root用户省略Three: Start MongoDB
#验证是否安装成功
[mongodb@ser6-51 ~]$ mongod--dbpath=/usr/local/mongodb/data--fork--logpath=/usr/local/mongodb/logs about to fork
Child process, waiting until the server is ready for connections. Forked process:12135 child process started successfully, parent exiting [root@ser6-51 bin]# MONGO Shell version : 3.0.4 connecting To:test Server has startup warnings:2015-06-25t12:02:26.238+0800 I control [Initandlisten] * * Warni
Ng:you are running this process as the root user, which are not recommended. 2015-06-25t12:02:26.238+0800 I control [Initandlisten] 2015-06-25t12:02:26.247+0800 i control [Initandlisten] 2015-06-
25t12:02:26.247+0800 I control [Initandlisten] * * WARNING:/sys/kernel/mm/transparent_hugepage/enabled is ' always '. 2015-06-25t12:02:26.247+0800 I control [Initandlisten] * * We suggest setting it to ' Never ' 2015-06-25t12:02:26.247 +0800 I control [Initandlisten] 2015-06-25t12:02:26.247+0800 i control [initandlisten] * * WARNING:/sys/kernel/mm/trans Parent_hugepage/deFrag is ' always '. 2015-06-25t12:02:26.247+0800 I control [Initandlisten] * * We suggest setting it to ' Never ' 2015-06-25t12:02:26.247
+0800 I control [Initandlisten] > show DBS; Local 0.078GB
You can see that there is a local database indicating that the installation was successful.
Four: Build the configuration file
[Mongodb@ser6-51 ~]$ Cd/usr/local/mongodb
[Mongodb@ser6-51 mongodb]$ VI mongod.cnf
Add to:
Logpath=/usr/local/mongodb/logs
Logappend = True
#fork and run in background
fork = true
#port = 27017< C5/>dbpath=/usr/local/mongodb/data
#location of Pidfile
In addition to starting the database in Mongod--dbpath=/usr/local/mongodb/data--fork--logpath=/usr/local/mongodb/logs, you can also start the database through a configuration file:
Before opening the database, so first Guanqu:
You can use the Db.shutdownserver () command
> Use admin
switched to DB admin
> Db.shutdownserver ()
2015-06-25t15:15:57.839+0800 I Network Dbclientcursor::init call () failed
server should is down ...
2015-06-25t15:15:57.841+0800 I Network trying reconnect to 127.0.0.1:27017 (127.0.0.1) failed
2015-06-25t15 : 15:57.842+0800 W Network Failed to connect to 127.0.0.1:27017, reason:errno:104 Connection reset by peer
2015-06 -25t15:15:57.842+0800 I Network reconnect 127.0.0.1:27017 (127.0.0.1) failed failed ' t connect to server 127.0 .0.1:27017 (127.0.0.1), connection attempt failed
#通过配置文件连接数据库
[Mongodb@ser6-51 mongodb]$ Mongod--config/usr/local/mongodb/mongod.cnf
About to fork the child process, the waiting until server is ready for connections.
Forked process:2059
Child process started successfully, parent exiting
Five: Set boot up
[Mongodb@ser6-51 mongodb]$ Su-
Password:
[Root@ser6-51 ~]# vi/etc/rc.local
Add to:
/usr/local/mongodb/bin/mongod--config/usr/local/mongodb/mongod.cnf
#重启机器, detect whether it takes effect
[Root@ser6-51 ~]# reboot
--After a little while--
[Root@ser6-51 ~]# Ps-ef | grep Mongod
Root 1828 1 0 17:32? 00:00:00/usr/local/mongodb/bin/mongod--dbpath=/usr/local/mongodb/data--fork--logpath=/usr/local/mongodb/logs
Root 1900 1624 0 17:33 pts/1 00:00:00 grep mongod
See the database is up. VI: How to use service to start the database
The way you started the database earlier is a bit cumbersome, so you want to start the database with service MongoDB start.
Default service MongoDB status will complain (because the service is not joined to service):
[root@ser6-51 bin]# Service MongoDB Status
Mongodb:unrecognized Service
The following configuration is required:
[root@ser6-51 ~] #vi/etc/init.d/mongod
Add to:
#!/bin/sh config=/usr/local/mongodb/mongod.cnf program=/usr/local/mongodb/bin/mongod MONGOPID= ' Ps-ef | grep ' Mongod--config ' | Grep-v grep | awk ' {print $} ' Test-x $PROGRAM | | Exit 0 Case "$" in start echo "Starting MongoDB Server ..." $PROG
RAM--config $CONFIG & ; stop) echo "Stopping MongoDB Server ..." IF [! -Z "$MONGOPID"];
Then kill-15 $MONGOPID fi status) If [ -z "$MONGOPID"]; Then echo "MongoDB is not running!" else &NBS P echo "MongoDB is running!
("$MONGOPID") " fi ;; restart) echo "shutting down MongoDB Server ..." if [! -Z "$MONGOPID"]; Then &NBSP;KILL-15 $MONGOPID &NBSP;FI echo "starting MongoDB ..." $PROGRAM--config $CONFIG &A
mp
; *) log_success_msg "Usage:/etc/init.d/mongod {start|stop|status|restart}" exit 1 Esac exit 0 &N Bsp
#为该文件赋予执行权限
[Root@ser6-51 ~]# ls-l/etc/init.d/mongod
-rw-r--r--. 1 Root 529 June 17:33/etc/init.d/mongod
[Root@ser6-51 ~]# chmod 744/etc/init.d/mongod
[Root@ser6-51 ~]# ls-l/etc/init.d/mongod
-rwxr--r--. 1 Root 529 June 17:33/etc/init.d/mongod
Test effect:
[root@ser6-51 mongodb]# service Mongod stop
Stopping MongoDB Server
Terminated
Terminated
[root@ser6-51 mongodb]# Service Mongod start
Starting MongoDB Server
[root@ser6-51 mongodb]# about to fork the child process, waiting until server are ready for connections.
Forked process:3632
Child process started successfully, parent exiting
--Open user authentication, please refer to MongoDB user rights operation
--the corresponding Shell installation script, please refer to: MongoDB 3.0.4 Shell Installation script