First download MongoDB installation package Http://www.mongodb.org/downloads My system is redhat5.8 all select the corresponding version package is OK now the latest version is 3.0.3
Decompression mongodb-linux-x86_64-rhel55-3.0.3.tgz
[[email protected] ~]# tar zxvf mongodb-linux-x86_64-rhel55-3.0.3.tgz -c / opt/mongodb-linux-x86_64-rhel55-3.0.3/readmemongodb-linux-x86_64-rhel55-3.0.3/ third-party-noticesmongodb-linux-x86_64-rhel55-3.0.3/gnu-agpl-3.0mongodb-linux-x86_64-rhel55-3.0.3/bin/ mongodumpmongodb-linux-x86_64-rhel55-3.0.3/bin/mongorestoremongodb-linux-x86_64-rhel55-3.0.3/bin/ mongoexportmongodb-linux-x86_64-rhel55-3.0.3/bin/mongoimportmongodb-linux-x86_64-rhel55-3.0.3/bin/ mongostatmongodb-linux-x86_64-rhel55-3.0.3/bin/mongotopmongodb-linux-x86_64-rhel55-3.0.3/bin/ bsondumpmongodb-linux-x86_64-rhel55-3.0.3/bin/mongofilesmongodb-linux-x86_64-rhel55-3.0.3/bin/ mongooplogmongodb-linux-x86_64-rhel55-3.0.3/bin/mongoperfmongodb-linux-x86_64-rhel55-3.0.3/bin/ mongodmongodb-linux-x86_64-rhel55-3.0.3/bin/mongosmongodb-linux-x86_64-rhel55-3.0.3/bin/mongo[[email protected] opt]# ln -sv mongodb-linux-x86_64-rhel55-3.0.3/ mongodbcreate symbolic link ' MongoDB ' to ' mongodb-linux-x86_64-rhel55-3.0.3/'
3. Create a MongoDB user
[Email protected]/]# Useradd MongoDB
4. Create the appropriate file directory and modify permissions
[[email protected]/]# mkdir/data/db-p[[email protected]/]# chown mongodb:mongodb/data/-r[[email protected] opt]# cho Wn-r mongodb:mongodb/opt/*
5. Add the PATH environment variable under shell Normal access to MongoDB's utility
[Email protected] bin]# vim/etc/profile.d/mongodb.shexport path= $PATH:/opt/mongodb/bin[[email protected] bin]# SOURC e/etc/profile.d/mongodb.sh [[email protected] bin]# echo $PATH/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin :/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/opt/mongodb/bin
6. Creating a PID storage directory for MongoDB
[Email protected] run]# mkdir/var/run/mongodb[[email protected] run]# chown mongodb:mongodb/var/run/mongodb/-r[[ Email protected] opt]# mongod--dbpath/data/db/--logpath/var/log/mongodb.log--logappend--port 27017--pidfilepath/va R/run/mongodb/mongodb.pid--maxconns--rest--httpinterface--forkabout to fork child process, waiting until server is Ready for connections.forked Process:4060child process started successfully, parent Exiting--maxconns 250: Indicates that the maximum number of connections is 250- -rest--httpinterface:web Interface, specify this 28017 port to enable--fork: running in the background
7. Problems encountered during installation
After the connection is installed, the following warning appears.
(1). [[email protected] ~]# Mongomongodb shell version:3.0.3connecting To:testserver has startup Warnings:2015-06-15t20:27:4 9.892+0800 I CONTROL [initandlisten] * * Warning:you is running this process as the root user, which was not recommended. 2015-06-15t20:27:49.892+0800 I CONTROL [Initandlisten]
This problem occurs when viewing the file permissions on MongoDB, mainly/opt/data/db//var/run/mongodb//var/log/ The permissions of the Mongodb.log are run as root when the initialization is initiated, so the permissions under these directories may become root root
(2). [[email protected] db]$ mongod --dbpath /data/db/ --logpath /var/log/ mongodb.log --logappend --port 27017 --pidfilepath /var/run/mongodb/mongodb.pid --maxconns 250 --rest --httpinterface --fork2015-06-15t17:41:25.721+0800 i Control [initandlisten] ** warning: /sys/kernel/mm/transparent_hugepage/enabled is ' always '. 2015-06-15t17:41:25.721+0800 i control [initandlisten] ** We suggest setting it to ' Never ' 2015-06-15t17:41:25.721+0800 i control [initandlisten] 2015-06-15t17:41:25.721+0800 i control [initandlisten] ** warning: /sys/kernel/mm/transparent_hugepage /defrag is ' always '. 2015-06-15t17:41:25.721+0800 i control [initandlisten] ** we suggest setting it to ' Never '
Two parameters can be modified
echo "Never" >/sys/kernel/mm/transparent_hugepage/enabled echo "Never" >/sys/kernel/mm/transparent_hugepage/ Defrag
8. Successful Installation and Login
[[email protected] ~]# ss -tanlp | grep mongod0 0 *:27017 *:* users: (("Mongod", 4095,6)) 0 0 *:28017 *:* users: (("Mongod", 4095,8)) [[ email protected] ~]# mongomongodb shell version: 3.0.3connecting to: test> help db.help () help on db methods Db.mycoll.help () help on collection methods sh.help () sharding helpers rs.help () replica set helpers help admin Administrative help help connect connecting to a db help help keys key shortcuts help misc misc things to know help mr mapreduce show dbs show database names show collections show collections in current database show users show users in current database show profile show most recent system.profile entries with time >= 1ms show logs show the accessible logger names show log [name] prints out the last segment of log in memory, ' Global ' is default use <db_name> set current database db.foo.find () list objects in Collection foo db.foo.find ( { a : 1 } ) list objects in foo where a == 1 it result of the last line evaluated; use to further iterate dbquery.shellbatchsize = x set default number of items to display on Shell exit quit the mongo shell
Log on to the Web interface 28017 port
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/6E/7C/wKioL1V-Z8OwoPTiAAdSMuA5uvk007.jpg "title=" Mongodb.png "alt=" Wkiol1v-z8owoptiaadsmua5uvk007.jpg "/>
9. Shutting down the server
(1). [Email protected] ~]# Mongod--shutdown killing process with pid:3936 (2). [Email protected] ~]# Killall Mongod
10. Write a configuration file for MongoDB/etc/mongodb.conf
[Email protected] ~]# grep-v ^#/etc/mongodb.conf logpath=/var/log/mongodb.loglogappend=truefork = truedbpath=/data/ Dbpidfilepath =/var/run/mongodb/mongodb.pidrest = Truehttpinterface = True
start
[[email protected] ~]# mongod -f /etc/mongodb.conf about to fork Child process, waiting until server is ready for connections.forked process: 4169child process started successfully, parent exiting[[email protected] ~]# ss -tanlp | grep mongod0 0 *:27017 *:* users: (("Mongod", 4169,6)) 0 0 *:28017 *:* users: (("Mongod", 4169,8))
11. Start MongoDB
Startup script with service MongoDB *:/etc/rc.d/init.d/mongod
#!/bin/bash# mongod - startup script for mongod# chkconfig: 35 85 15# description: mongo is a scalable, document-oriented database.# processname: mongod# config: /etc/mongod.conf# pidfile: /var/run/mongo/ mongod.pid. /etc/rc.d/init.d/functions# things from mongod.conf get there By mongod reading itconfigfile= "/etc/mongodb.conf" options= " -f $CONFIGFILE" sysconfig= "/etc/sysconfig/mongod" dbpath= ' awk -f= '/^dbpath=/{print $2} ' "$CONFIGFILE" ' pidfile= ' awk -F= '/^dbpath\s=\s/{print $2} ' "$CONFIGFILE" ' Mongod=${mongod-/opt/mongodb/bin/mongod} mongo_user=mongodbmongo_group=mongodbif [ -f "$SYSCONFIG" ]; then . "$SYSCONFIG" fi# handle numa access to cpus (SERVER-3574) # this verifies the existence of numactl as well as testing that the command worksnumactl_args= "--interleave=all" if which numactl >/dev/null 2>/dev/null && numactl $NUMACTL _args ls / >/dev/null 2>/dev/nullthen numactl= "numactl $NUMACTL _args" else numactl= "" Fistart () { echo -n $ "starting mongod: " daemon --user "$MONGO _user" $ numactl $mongod $OPTIONS RETVAL=$? echo [ $RETVAL -eq 0 ] && touch /var/lock/subsys/mongod}stop () { echo -n $ " stopping mongod: " killproc -p " $PIDFILE " -d 300 /opt/mongodb/ bin/mongod retval=$? echo [ $RETVAL -eq 0 ] & & rm -f /var/lock/subsys/mongod}restart () { stop start}ulimit -n 12000RETVAL=0case "$" in start) start ;; stop) stop ;; restart|reload|force-reload) restart ;; condrestart) [ -f /var/lock/subsys/mongod ] && restart | | : ;; status) status $mongod RETVAL=$? ;; *) echo "usage: $0 {start|stop|status|restart|reload| Force-reload|condrestart} " RETVAL=1esacexit $RETVAL
test start
[[Email protected] ~]# service mongod startstarting mongod: about to fork child process, waiting until server is ready for connections.forked process: 4426child process started successfully, parent exiting [ ok ][[email protected] init.d]# ss -tanlp | grep mongod0 0 *:27017 *:* users :(("Mongod", 4426,6)) 0 0 *:28017 *:* users: (("Mongod", 4426,8)) [[email p rotected] ~]# mongomongodb shell version: 3.0.3connecting to: test> [[email protected] ~]# service mongod startstarting mongod: about to fork child process, waiting until server is ready for connections.forked process: 4426child process started successfully, parent exiting [ OK ][[email protected] ~]# service mongod stopstopping mongod: &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;[&NBSP;&NBSP;OK&NBSP;&NBSP;]
This article is from the "lovefish" blog, make sure to keep this source http://mictiger.blog.51cto.com/4854014/1661997
MongoDB Installation Configuration Practices