centos7下MongoDB3.4安装并解决告警
MongoDB官网下载安装包
3.6.8版本
wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel62-3.6.8.tgz
3.4.18版本
wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel62-3.4.18.tgz
解压
tar zxf mongodb-linux-x86_64-rhel62-3.4.18.tgz
mv mongodb-linux-x86_64-rhel62-3.4.18 /usr/local/mongodb
echo 'export PATH=$PATH:/usr/local/mongodb/bin'>> /etc/profile
source /etc/profile
groupadd mongo
useradd -g mongo mongo
mkdir -p /server/mongodb27017/data
mkdir -p /server/mongodb27017/log
chown -R mongo.mongo /server/mongodb27017/
chown -R mongo.mongo /usr/local/mongodb
vim /server/mongodb27017/mongodb27017.cnf
配置文件
#SERVER
fork = true
port = 27017
quiet = true
dbpath = /server/mongodb27017/data
logpath = /server/mongodb27017/log/mongod.log
logappend = true
journal = true
#auth = true #开启认证
# <=3.4
nohttpinterface = true
directoryperdb = true
#SLOW_LOG
profile = 1
slowms = 500
#RS
replSet = rs01
oplogSize = 4096
# add for 3.4
# shardsvr = true
#SCO
#cinfigsvr = true
#configdb = MSCHOST
#USER
#keyFile=/
#setParameter=enableLocalhostAuthBypass=1
storageEngine=wiredTiger
wiredTigerCacheSizeGB=1
wiredTigerCollectionBlockCompressor=snappy
#mongo_version=mongodb34
启动
sudo -u mongo mongod -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: You are running this process as the root user, which is not recommended.
解决:启动MongoDB的时候使用普通用户,而不用root用户执行
sudo -u mongo mongod -f /server/mongodb27017/mongodb27017.cnf
告警2
2018-11-15T17:21:03.335+0800 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2018-11-15T17:21:03.335+0800 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2018-11-15T17:21:03.335+0800 I CONTROL [initandlisten]
2018-11-15T17:21:03.335+0800 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2018-11-15T17:21:03.335+0800 I CONTROL [initandlisten] ** We suggest setting it to 'never'
解决
echo "never" >> /sys/kernel/mm/transparent_hugepage/enabled
echo "never" >> /sys/kernel/mm/transparent_hugepage/defrag
并添加到 /etc/rc.local
告警3
** WARNING: soft rlimits too low. rlimits set to 4096 processes, 65535 files. Number of processes should be at least 32767.5 : 0.5 times number of files.
解决
vim /etc/security/limits.conf
mongo soft nofile 65535
mongo hard nofile 65535
mongo soft nproc 65535
mongo hard nproc 65535
mongo soft stack 1024
mongo hards tack 1024
vim /etc/security/limits.d/90-nproc.conf
soft nproc 65535
告警4
WARNING: Access control is not enabled for the database.
2018-11-15T17:38:44.181+0800 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.
use admin
db.createUser(
{
user: "root", //用户名
pwd: "root", //密码
roles: [ { role: "userAdminAnyDatabase", db: "admin" } ] //权限
}
在配置文件中添加
auth = true
依次解决后进入shell命令行,真的干净!没有任何告警信息,简直是强迫症患者福音 O(∩_∩)O哈哈~
再见 各位~
免责声明:
① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。
② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341