CentOS6.8安裝mongodb3.0並添加到系統服務
一、系統環境
CentOS 6.8_x64
官方參考文檔https://docs.mongodb.org/manual/reference/glossary/#term-init-script
二、添加官方yum庫
#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、安裝並創建數據目錄
#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 時發現 並沒有 關閉mongod服務 進程依然在
通過排查發現問題出在/etc/mongod.conf中第24行
pidFilePath: /var/run/mongodb/mongod.pid # location of pidfile
六、解決警告提示
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]
由於環境為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
添加到開機自啟服務
#chmod +x /etc/init.d/disable-transparent-hugepages #chkconfig --add disable-transparent-hugepages
3、修改系統參數
#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 如果提示找不到命令請執行yum install tuned -y
reboot 系統
4、驗證:
$mongo --host 10.1.0.7 --port 27017
MongoDB shell version: 3.0.7
connecting to: 10.1.0.7:27017/test
>
5、出現如下錯誤:
** 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安裝完成~如有錯誤之處歡迎指正!
本文出自 “學地止境” 博客,請務必保留此出處http://dyc2005.blog.51cto.com/270872/1942438
CentOS6.8安裝mongodb3.0並添加到系統服務