首先從官網(wǎng)下載mongodb的安裝包http://www.mongodb.org/downloads我的系統(tǒng)是redhat5.8所有選擇相應(yīng)的版本包就ok現(xiàn)在最新版是3.0.3
創(chuàng)新互聯(lián)公司主要從事成都做網(wǎng)站、成都網(wǎng)站制作、網(wǎng)頁設(shè)計(jì)、企業(yè)做網(wǎng)站、公司建網(wǎng)站等業(yè)務(wù)。立足成都服務(wù)成華,10余年網(wǎng)站建設(shè)經(jīng)驗(yàn),價(jià)格優(yōu)惠、服務(wù)專業(yè),歡迎來電咨詢建站服務(wù):13518219792解壓mongodb-linux-x86_64-rhel55-3.0.3.tgz
3.創(chuàng)建mongodb用戶
[root@mongodb /]# useradd mongodb4.創(chuàng)建相應(yīng)文件目錄并修改權(quán)限
[root@mongodb /]# mkdir /data/db -p [root@mongodb /]# chown mongodb:mongodb /data/ -R [root@mongodb opt]# chown -R mongodb:mongodb /opt/*5.添加PATH環(huán)境變量在shell下正常訪問mongodb的應(yīng)用工具
[root@mongodb bin]# vim /etc/profile.d/mongodb.sh export PATH=$PATH:/opt/mongodb/bin [root@mongodb bin]# source /etc/profile.d/mongodb.sh [root@mongodb 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/bin6.創(chuàng)建mongodb的PID存放目錄
[root@mongodb run]# mkdir /var/run/mongodb [root@mongodb run]# chown mongodb:mongodb /var/run/mongodb/ -R [root@mongodb opt]# mongod --dbpath /data/db/ --logpath /var/log/mongodb.log --logappend --port 27017 --pidfilepath /var/run/mongodb/mongodb.pid --maxConns 250 --rest --httpinterface --fork about to fork child process, waiting until server is ready for connections. forked process: 4060 child process started successfully, parent exiting --maxConns 250 :表示大連接數(shù)是250個(gè) --rest --httpinterface : web接口,指定這項(xiàng)28017端口才能啟用 --fork :后臺(tái)運(yùn)行7.安裝過程中遇見的問題
裝好之后連接出現(xiàn)以下警告
(1).[root@mongodb ~]# mongo MongoDB shell version: 3.0.3 connecting to: test Server has startup warnings: 2015-06-15T20:27:49.892+0800 I CONTROL [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended. 2015-06-15T20:27:49.892+0800 I CONTROL [initandlisten]出現(xiàn)這個(gè)問題就查看關(guān)于mongodb的文件權(quán)限,主要是/opt /data/db/ /var/run/mongodb/ /var/log/mongodb.log的權(quán)限因?yàn)閱?dòng)初始化時(shí)以root用戶的權(quán)限在運(yùn)行,所以這些目錄下的權(quán)限可能會(huì)變成root root
(2).[mongodb@mongodb db]$ mongod --dbpath /data/db/ --logpath /var/log/mongodb.log --logappend --port 27017 --pidfilepath /var/run/mongodb/mongodb.pid --maxConns 250 --rest --httpinterface --fork 2015-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'修改兩個(gè)參數(shù)即可
echo "never" > /sys/kernel/mm/transparent_hugepage/enabled echo "never" > /sys/kernel/mm/transparent_hugepage/defrag8.安裝成功并登錄
[root@mongodb ~]# ss -tanlp | grep mongod 0 0 *:27017 *:* users:(("mongod",4095,6)) 0 0 *:28017 *:* users:(("mongod",4095,8)) [root@mongodb ~]# mongo MongoDB shell version: 3.0.3 connecting 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登錄web接口 28017端口
9.關(guān)閉服務(wù)器
(1).[root@mongodb ~]# mongod --shutdown killing process with pid: 3936 (2).[root@mongodb ~]# killall mongod10.給mongodb編寫配置文件/etc/mongodb.conf
[root@mongodb ~]# grep -v ^# /etc/mongodb.conf logpath=/var/log/mongodb.log logappend=true fork = true dbpath=/data/db pidfilepath = /var/run/mongodb/mongodb.pid rest = true httpinterface = true啟動(dòng)
[root@mongodb ~]# mongod -f /etc/mongodb.conf about to fork child process, waiting until server is ready for connections. forked process: 4169 child process started successfully, parent exiting [root@mongodb ~]# ss -tanlp | grep mongod 0 0 *:27017 *:* users:(("mongod",4169,6)) 0 0 *:28017 *:* users:(("mongod",4169,8))11.用service mongodb * 來啟動(dòng)mongodb
啟動(dòng)腳本:/etc/rc.d/init.d/mongod
測(cè)試啟動(dòng)
[root@mongodb ~]# service mongod start Starting mongod: about to fork child process, waiting until server is ready for connections. forked process: 4426 child process started successfully, parent exiting [ OK ] [root@mongodb init.d]# ss -tanlp | grep mongod 0 0 *:27017 *:* users:(("mongod",4426,6)) 0 0 *:28017 *:* users:(("mongod",4426,8)) [root@mongodb ~]# mongo MongoDB shell version: 3.0.3 connecting to: test > [root@mongodb ~]# service mongod start Starting mongod: about to fork child process, waiting until server is ready for connections. forked process: 4426 child process started successfully, parent exiting [ OK ] [root@mongodb ~]# service mongod stop Stopping mongod: [ OK ]另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)cdcxhl.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場(chǎng)景需求。