您好,登錄后才能下訂單哦!
一、系統(tǒng)環(huán)境
CentOS 6.8_x64
官方參考文檔https://docs.mongodb.org/manual/reference/glossary/#term-init-script
二、添加官方y(tǒng)um庫
#cd /etc/yum.repo.d/
#vim mongodb.repo
[mongodb-org-3.0] name=MongoDB Repository baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/3.0/x86_64/ gpgcheck=0 enabled=1
三、安裝配置
1、安裝并創(chuàng)建數(shù)據(jù)目錄
#yum install -y mongodb-org #mkdir -p /Data/mongodb #chown mongod.mongod /Data/mongodb -R
2、配置mongod.conf
#vim /etc/mongod.conf
# mongod.conf # for documentation of all options, see: # http://docs.mongodb.org/manual/reference/configuration-options/ # where to write logging data. systemLog: destination: file logAppend: true path: /Data/mongodb/mongod.log #需要自定義 # Where and how to store data. storage: dbPath: /Data/mongodb/db #需要自定義 journal: enabled: true # engine: # mmapv1: # wiredTiger: # how the process runs processManagement: fork: true # fork and run in background pidFilePath: /var/run/mongodb/mongod.pid # location of pidfile # network interfaces net: port: 27017 bindIp: 10.1.0.7 # Listen to local interface only, comment to listen on all interfaces. 需要自定義 #security: #operationProfiling: #replication: #sharding: # Enterprise-Only Options #auditLog:
啟動mongod
#service mongod start
四、測試
登錄mongodb
#mongo --host 10.1.0.7
> db.version();
3.0.7
> show dbs
com_ylt_plat_passport 0.078GB
local 0.078GB
chown mongod.mongod /Data/mongodb -R
service mongod start
五、排錯
故障描述 :
service mongod stop 時發(fā)現(xiàn) 并沒有 關(guān)閉mongod服務(wù) 進(jìn)程依然在
通過排查發(fā)現(xiàn)問題出在/etc/mongod.conf中第24行
pidFilePath: /var/run/mongodb/mongod.pid # location of pidfile
把后面的# location of pidfile 刪除掉 即可,這個是一個小bug
六、mogond備份與還原腳本
#cat mongodb_bak.sh
#!/bin/sh DUMP=/usr/bin/mongodump OUT_DIR=/data1/backup/mongodb/mongod_bak_now BAK_DIR=/data1/backup/mongodb/mongod_bak_list DATE=`date +%F_%H%M%d` #DB_USER=username #DB_PASS= DAYS=7 TAR_BAK="mongodb_bak_$DATE.tar.gz" [ -d $OUT_DIR ] || mkdir -v $OUT_DIR [ -d $BAK_DIR ] || mkdir -v $BAK_DIR BAK_DB(){ cd $OUT_DIR rm -rf $OUT_DIR/* mkdir -p $DATE #$DUMP -u $DB_USER -p $DB_PASS -o $OUT_DIR/$DATE $DUMP -o $OUT_DIR/$DATE tar czvf $BAK_DIR/$TAR_BAK $OUT_DIR/$DATE find $BAK_DIR/ -mtime +$DAYS -delete } RESTORE_ALL(){ cd $OUT_DIR for d in `ls`; do echo $OUT_DIR/$d /usr/bin/mongorestore -d $OUT_DIR/$d done } RESTORE_Choose(){ while true do echo "when you choose 'quit|exit' exit to restore!" read -p "What's your choose?(Enter continue!)" choose if [[ $choose == 'quit' || $choose == 'exit' ]] then echo "You choose exit!" && exit 2 fi cd $OUT_DIR d=`ls` cd $OUT_DIR/$d ls read -p "What's db your choose?" whatdb if [ "$whatdb" != '' ]; then /usr/bin/mongorestore -d $whatdb else echo "choose is empty,exit~" && exit 0 fi done } case $1 in back) BAK_DB ;; resall) RESTORE_ALL ;; resone) RESTORE_Choose ;; *) echo "USGE:back|resall|resone" ;; esac
使用說明:
back 備份全部的mongod數(shù)據(jù)庫
resall 還原所有的數(shù)據(jù)庫
resone可以指定還原某一個數(shù)據(jù)庫
七、解決警告提示
1、問題描述
解決登錄mongo --host 10.1.0.7 --port 27017 類似如下提示
** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'. 和 ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
MongoDB shell version: 3.0.7
connecting to: 10.1.0.7:27017/test
Server has startup warnings:
2016-12-08T16:10:15.638+0800 I CONTROL [initandlisten]
2016-12-08T16:10:15.638+0800 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2016-12-08T16:10:15.638+0800 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2016-12-08T16:10:15.638+0800 I CONTROL [initandlisten]
2016-12-08T16:10:15.638+0800 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2016-12-08T16:10:15.638+0800 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2016-12-08T16:10:15.638+0800 I CONTROL [initandlisten]
由于環(huán)境為CentOS6.8 所以解決方法如下,其他平臺及版本請參考官方文檔:https://docs.mongodb.org/manual/tutorial/transparent-huge-pages/
2、解決方法:
添加如下腳本
#vim /etc/init.d/disable-transparent-hugepages
#!/bin/sh### BEGIN INIT INFO # Provides: disable-transparent-hugepages # Required-Start: $local_fs # Required-Stop: # X-Start-Before: mongod mongodb-mms-automation-agent # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: Disable Linux transparent huge pages # Description: Disable Linux transparent huge pages, to improve # database performance. ### END INIT INFO case $1 in start) if [ -d /sys/kernel/mm/transparent_hugepage ]; then thp_path=/sys/kernel/mm/transparent_hugepage elif [ -d /sys/kernel/mm/redhat_transparent_hugepage ]; then thp_path=/sys/kernel/mm/redhat_transparent_hugepage else return 0 fi echo 'never' > ${thp_path}/enabled echo 'never' > ${thp_path}/defrag unset thp_path ;; esac
添加到開機(jī)自啟服務(wù)
#chmod +x /etc/init.d/disable-transparent-hugepages #chkconfig --add disable-transparent-hugepages
3、修改系統(tǒng)參數(shù)
#mkdir -p /etc/tune-profiles/no-thp #cd /etc/tune-profiles/no-thp #echo "set_transparent_hugepages never" > ktune.sh #chmod +x ktune.sh #tuned-adm profile no-thp 如果提示找不到命令請執(zhí)行yum install tuned -y
reboot 系統(tǒng)
4、驗(yàn)證:
$mongo --host 10.1.0.7 --port 27017
MongoDB shell version: 3.0.7
connecting to: 10.1.0.7:27017/test
>
5、出現(xiàn)如下錯誤:
** WARNING: soft rlimits too low. rlimits set to 1024 processes, 64000 files. Number of processes should be at least 32000 : 0.5 times number of files.
#vim /etc/security/limits.conf
添加:
mongod soft nofile 64000
mongod hard nofile 64000
mongod soft nproc 32000
mongod hard nproc 32000
重啟mongod
到此mongod安裝完成~如有錯誤之處歡迎指正!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。