时间:2021-07-01 10:21:17 帮助过:4人阅读
一、系统环境
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
把后面的# location of pidfile 删除掉 即可,这个是一个小bug
六、解决警告提示
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并添加到系统服务
标签:脚本 mongodb