一、服务、端口查询
1.1、服务查询及启停
-
查询状态:
systemctl status mongod
-
重启服务:
systemctl restart mongod
-
停止服务:
systemctl stop mongod
-
启动服务:
systemctl start mongod
-
设置开机启动:
systemctl enable mongod
-
取消开机启动:
systemctl disable mongod
1.2、端口监听查询
- 端口监听查询:
ss -ntpl |grep 27017
二、版本、日志查询
2.1、版本查询
- 版本查询:
mongo --version
2.2、日志路径
- 日志路径:
/var/log/mongodb/mongod.log
三、访问数据库
3.1、查询数据库用户名密码
数据库密码存放于/opt/cloudbility/conf/common.properties
文件中:
cat /opt/cloudbility/conf/common.properties|grep mongo.credentials|cut -d'=' -f2
3.2、访问数据库
(1)如果数据库没有密码,输入以下命令访问:
mongo cloudguanjia;
(2)如果数据库有密码,输入以下命令访问(假设数据库密码是xxxxxxxx):
mongo localhost:27017/cloudguanjia -u admin -p xxxxxxxx
四、如何启用门户服务器Mongodb密码?
问题解答:
如果您的行云管家门户服务器没有并且需要启用Mongodb密码,请先和行云管家技术客服联系评估,否则可能会影响后续升级使用;
(1)登录门户服务器后,执行以下七行命令,设置Mongodb密码(假设将Mongodb的密码设置为 123-QWEasd )
MO_PWD="123-QWEasd" mongo 127.0.0.1:27017/admin --eval "db.createUser({'user':'root','pwd':\"${MO_PWD}\",'roles':['root']});" mongo 127.0.0.1:27017/cloudguanjia --eval "db.createUser({user: 'admin',pwd: \"${MO_PWD}\",roles: [{ role: 'dbOwner', db: 'cloudguanjia' }]})" sed -i "s/#security:/security:\n authorization: enabled/g" /etc/mongod.conf grep "mongo.credentials" /opt/cloudbility/conf/common.properties > /dev/null 2>&1 && sed -e "s/^mongo.credentials.*$/mongo.credentials=admin:${MO_PWD}@cloudguanjia/g" -i /opt/cloudbility/conf/common.properties || echo "mongo.credentials=admin:${MO_PWD}@cloudguanjia" >> /opt/cloudbility/conf/common.properties grep "mongo.credentials" /opt/cloudbility/conf/common.properties > /dev/null 2>&1 && sed -e "s/^mongo.credentials.*$/mongo.credentials=admin:${MO_PWD}@cloudguanjia/g" -i /opt/cloudbility/conf/cloudPortal.properties || echo "mongo.credentials=admin:${MO_PWD}@cloudguanjia" >> /opt/cloudbility/conf/cloudPortal.properties grep "mongo.credentials" /opt/cloudbility/conf/common.properties > /dev/null 2>&1 && sed -e "s/^mongo.credentials.*$/mongo.credentials=admin:${MO_PWD}@cloudguanjia/g" -i /opt/cloudbility/conf/cloudMonitor.properties || echo "mongo.credentials=admin:${MO_PWD}@cloudguanjia" >> /opt/cloudbility/conf/cloudMonitor.properties
- 注意:如果是HA部署,还需要在备机里也执行以下命令:
sed -i "s/#security:/security:\n authorization: enabled/g" /etc/mongod.conf
(2)重启Mongodb
systemctl restart mongod
(3)重启行云管家门户服务
/opt/cloudbility/bin/restart.sh
(4)完成以上设置后即可登录门户网址以及管理控制台检查是否能正常登录;
五、如何修改mongodb虚拟内存占用大小
我们会发现,门户服务器mongodb占用内存较多,有时会导致服务器内存不足,这是因为java堆大小设置最大4G,对于mongodb缓存占用默认为操作系统1/3,其实通常不需要这么大,这个可以通过修改mongodb配置文件来限制;
(1)修改门户服务器mongodb配置文件;
vi /etc/mongod.conf
(2)把mongodb cache总大小进行修改(请注意大小写),如图把wiredTiger前的#去掉,然后在这句下面新增engineConfig:以及cacheSizeGB: 2
(3)重启mongodb
systemctl restart mongod
(4)重启行云管家门户服务
/opt/cloudbility/bin/restart.sh