MongoDB官网下载安装包3.6.8版本wgethttps://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel62-3.6.8.tgz3.4.18版本wgethttps://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel62-3.4.18.tgz解压tarzxfmongodb-linux-x86_64-rhel62-3.4.18.tgzmvmongodb-linux-x86_64-rhel62-3.4.18/usr/local/mongodbecho'exportPATH=$PATH:/usr/local/mongodb/bin'>>/etc/profilesource/etc/profilegroupaddmongouseradd-gmongomongomkdir-p/server/mongodb27017/datamkdir-p/server/mongodb27017/logchown-Rmongo.mongo/server/mongodb27017/chown-Rmongo.mongo/usr/local/mongodbvim/server/mongodb27017/mongodb27017.cnf

配置文件

#SERVERfork=trueport=27017quiet=truedbpath=/server/mongodb27017/datalogpath=/server/mongodb27017/log/mongod.loglogappend=truejournal=true#auth=true#开启认证#<=3.4nohttpinterface=truedirectoryperdb=true#SLOW_LOGprofile=1slowms=500#RSreplSet=rs01oplogSize=4096#addfor3.4#shardsvr=true#SCO#cinfigsvr=true#configdb=MSCHOST#USER#keyFile=/#setParameter=enableLocalhostAuthBypass=1storageEngine=wiredTigerwiredTigerCacheSizeGB=1wiredTigerCollectionBlockCompressor=snappy#mongo_version=mongodb34

启动

sudo-umongomongod-f/server/mongodb27017/mongodb27017.cnf

进入命令行

mongo 127.0.0.1:27017

敲命令报错

"errmsg" : "not master and slaveOk=false",

初始化

rs.initiate({_id:'rs01',version:1,members:[{_id:0,host:'10.238.162.33:27017'}]});

完成

安装完成后进入MongoDB的shell命令行后出现了很多报警如下,虽然都是一些warning,不影响使用,但是感觉就像是一个人处于亚健康状态,当数据库压力过大的时候这些warning有可能导致数据库出现error。所以下面挨着每个解决一下。

告警1

**WARNING:Youarerunningthisprocessastherootuser,whichisnotrecommended.

解决:启动MongoDB的时候使用普通用户,而不用root用户执行

sudo -u mongo mongod -f /server/mongodb27017/mongodb27017.cnf


告警2


2018-11-15T17:21:03.335+0800ICONTROL[initandlisten]**WARNING:/sys/kernel/mm/transparent_hugepage/enabledis'always'.2018-11-15T17:21:03.335+0800ICONTROL[initandlisten]**Wesuggestsettingitto'never'2018-11-15T17:21:03.335+0800ICONTROL[initandlisten]2018-11-15T17:21:03.335+0800ICONTROL[initandlisten]**WARNING:/sys/kernel/mm/transparent_hugepage/defragis'always'.2018-11-15T17:21:03.335+0800ICONTROL[initandlisten]**Wesuggestsettingitto'never'

解决

echo "never" >> /sys/kernel/mm/transparent_hugepage/enabled

echo "never" >> /sys/kernel/mm/transparent_hugepage/defrag

并添加到 /etc/rc.local


告警3

**WARNING:softrlimitstoolow.rlimitssetto4096processes,65535files.Numberofprocessesshouldbeatleast32767.5:0.5timesnumberoffiles.解决vim/etc/security/limits.confmongosoftnofile65535mongohardnofile65535mongosoftnproc65535mongohardnproc65535mongosoftstack1024mongohardstack1024vim/etc/security/limits.d/90-nproc.confsoftnproc65535


告警4

WARNING:Accesscontrolisnotenabledforthedatabase.2018-11-15T17:38:44.181+0800ICONTROL[initandlisten]**Readandwriteaccesstodataandconfigurationisunrestricted.useadmindb.createUser({user:"root",//用户名pwd:"root",//密码roles:[{role:"userAdminAnyDatabase",db:"admin"}]//权限}在配置文件中添加auth=true


依次解决后进入shell命令行,真的干净!没有任何告警信息,简直是强迫症患者福音 O(∩_∩)O哈哈~


再见 各位~