22

mongodb运行的二三事

 4 years ago
source link: http://mp.weixin.qq.com/s?__biz=MzAwOTU4NzM5Ng%3D%3D&%3Bmid=2455771636&%3Bidx=1&%3Bsn=0fb708abaf0f21bce3b8fffce4011319
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

1:包安装mongodb

配置mongodb源后,进行安装:

yum install -y mongodb-org

或者:

yum install -y mongodb-org-4.2.8 mongodb-org-server-4.2.8 mongodb-org-shell-4.2.8 mongodb-org-mongos-4.2.8 mongodb-org-tools-4.2.8

为避免yum更新的时候,mongodb也升级,可以配置/etc/yum.conf:

exclude=mongodb-org,mongodb-org-server,mongodb-org-shell,mongodb-org-mongos,mongodb-org-tools

2:mongodb如何运行

使用Linux发行版的Init System管理mongodb的进程管理,可以采用systemd或System V init,通过以下命令得知:

ps --no-headers -o comm 1

CentOS7采用systemd:

systemctl start mongod
systemctl status mongod

#确保重启启动的时候自运行mongodb
systemctl enable mongod

3:systemctl运行失败问题

遇到不能启动的问题,通过两种方式排查问题。

(1)查看systemctl日志

systemctl status mongod.service

如下错误:

ExecStart=/usr/bin/mongod $OPTIONS (code=exited, status=14)
ERROR: child process failed, exited with error number 14

(2)查看mongodb启动日志

CONTROL  [initandlisten] build environment:
CONTROL  [initandlisten]     distmod: rhel70
CONTROL  [initandlisten]     distarch: x86_64
[initandlisten] Failed to start up WiredTiger under any compatibility version
[initandlisten] Reason: 13: Permission denied

看的出来是权限问题,配置dbpath和logpath目录权限:

chown mongod:mongod  目录 -R

再次运行成功

4:systemctl 如何启动mongodb

查看 /usr/lib/systemd/system/mongod.service 文件,如果要修改,则必须:

systemctl daemon-reload
systemctl status mongod.service

5:如何轮转mongodb日志文件

(1)发送信号

kill -SIGUSR1  `ps -aux | grep -v grep |  grep mongodb | awk '{print $2}'`

(2)或使用mongodb管理命令

use admin
db.runCommand({logRotate:1})

6:环境

php7.2.8,mongodb server是4.2,php mongodb ext是1.7,php mongodb library是1.6。

参考:

  • https://docs.mongodb.com/manual/tutorial/install-mongodb-on-red-hat/

  • https://docs.mongodb.com/manual/reference/command/logRotate/index.html

bEJJJr.jpg!web


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK