一、環境準備:html
1 mkdir /home/mongodb #建立MongoDB程序存放目錄2 mkdir /data/mongodata -p #建立數據存放目錄3 mkdir /data/log/mongolog -p #建立日誌存放目錄
二、下載:linux
1 curl -O https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-3.2.1.tgz
三、安裝:mongodb
1 tar xf mongodb-linux-x86_64-3.2.1.tgz2 cd mongodb-linux-x86_64-3.2.13 cp -r * /home/mongodb
爲了便於命令啓動,須要編輯全局變量PATHshell
1 vim /etc/profile.d/mongo.sh2 export PATH=$PATH:/home/mongodb/bin
source /etc/profile.d/mongo.sh
四、啓動服務vim
首先查看mongod的幫助信息app
1 [root@test ~]# mongod --help 啓動服務示例:
1 mongod --dbpath=/data/mongodata --logpath=/data/log/mongolog/mongodb.log --logappend --fork
查看是否啓動:curl
1 netstat -tnlp | grep mongod2 tcp 0 0 0.0.0.0:27017 0.0.0.0:* LISTEN 17909/mongod
以上可看出端口27017已經運行tcp
五、測試ide
啓動mongodb的shell:測試
1 [root@test ~]# mongo 2 MongoDB shell version: 3.2.1 3 connecting to: test 4 Server has startup warnings: 5 2016-01-25T16:12:52.960+0800 I CONTROL [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended. 6 2016-01-25T16:12:52.960+0800 I CONTROL [initandlisten] 7 2016-01-25T16:12:52.960+0800 I CONTROL [initandlisten] 8 2016-01-25T16:12:52.960+0800 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'. 9 2016-01-25T16:12:52.960+0800 I CONTROL [initandlisten] ** We suggest setting it to 'never'10 2016-01-25T16:12:52.960+0800 I CONTROL [initandlisten] 11 2016-01-25T16:12:52.960+0800 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.12 2016-01-25T16:12:52.960+0800 I CONTROL [initandlisten] ** We suggest setting it to 'never'13 2016-01-25T16:12:52.960+0800 I CONTROL [initandlisten] 14 > help15 db.help() help on db methods16 db.mycoll.help() help on collection methods17 sh.help() sharding helpers18 rs.help() replica set helpers19 help admin administrative help20 help connect connecting to a db help21 help keys key shortcuts22 help misc misc things to know23 help mr mapreduce24 25 show dbs show database names26 show collections show collections in current database27 show users show users in current database28 show profile show most recent system.profile entries with time >= 1ms29 show logs show the accessible logger names30 show log [name] prints out the last segment of log in memory, 'global' is default31 use <db_name> set current database32 db.foo.find() list objects in collection foo33 db.foo.find( { a : 1 } ) list objects in foo where a == 134 it result of the last line evaluated; use to further iterate35 DBQuery.shellBatchSize = x set default number of items to display on shell36 exit quit the mongo shell37 > show dbs38 local 0.000GB39 >
至此,MongoDB3.2.1安裝完畢。
http://www.bubuko.com/infodetail-1340781.html