CentOS에서 직접 설치해서 운영하던 MongoDB를 YUM으로 설치하여 운영하는 형태로 변경하던 중 다음과 같은 오류가 발생하면서 MongoDB 서비스가 올라오지 않는 문제를 겪었습니다.
$ systemctl start mongod # 여기서 리턴되지 않고 한참 행이 걸림 $ systemctl status mongod.service ● mongod.service - MongoDB Database Server Loaded: loaded (/usr/lib/systemd/system/mongod.service; enabled; vendor preset: disabled) Active: failed (Result: timeout) since Wed 2021-04-14 14:19:10 KST; 32s ago Docs: https://docs.mongodb.org/manual Process: 32523 ExecStart=/usr/bin/mongod $OPTIONS (code=exited, status=0/SUCCESS) Process: 32520 ExecStartPre=/usr/bin/chmod 0755 /var/run/mongodb (code=exited, status=0/SUCCESS) Process: 32517 ExecStartPre=/usr/bin/chown mongod:mongod /var/run/mongodb (code=exited, status=0/SUCCESS) Process: 32514 ExecStartPre=/usr/bin/mkdir -p /var/run/mongodb (code=exited, status=0/SUCCESS) Apr 14 14:17:39 your-hostname systemd[1]: Starting MongoDB Database Server... Apr 14 14:17:39 your-hostname mongod[32523]: about to fork child process, waiting until server is ready for connections. Apr 14 14:17:39 your-hostname mongod[32523]: forked process: 32526 Apr 14 14:17:41 your-hostname mongod[32523]: child process started successfully, parent exiting Apr 14 14:17:41 your-hostname systemd[1]: PID file /var/run/mongodb/mongod.pid not readable (yet?) after start. Apr 14 14:19:09 your-hostname systemd[1]: mongod.service start operation timed out. Terminating. Apr 14 14:19:10 your-hostname systemd[1]: Failed to start MongoDB Database Server. Apr 14 14:19:10 your-hostname systemd[1]: Unit mongod.service entered failed state. Apr 14 14:19:10 your-hostname systemd[1]: mongod.service failed.
오류를 확인해보면 mongod
실행 후 pid
이 확인되지 않아서 타임아웃이 발생했습니다.
PID file /var/run/mongodb/mongod.pid not readable (yet?) after start.
pid
파일의 경로를 확인해보니 설정한 pid
파일의 경로가 아니었습니다. 다음은 mongod.conf
파일의 processManagement
설정입니다.
processManagement: fork: true pidFilePath: /your-path/mongodb/mongod.pid
지정한 /your-path/mongodb/mongod.pid
경로가 아닌 /var/run/mongodb/mongod.pid
기본 설정에서 pid
파일을 확인하려고 대기하다가 타임아웃이 발생하는 문제였습니다. systemd
에서 커스텀하게 설정한 pid
파일 경로를 찾을 수 없기 때문에 발생하는 문제입니다.
MongoDB 공식 문서에 이와 관련된 내용이 정리되어 있습니다.
Linux On Linux, PID file management is generally the responsibility of your distro's init system: usually a service file in the /etc/init.d directory, or a systemd unit file registered with systemctl. Only use the processManagement.pidFilePath option if you are not using one of these init systems. For more information, please see the respective Installation Guide for your operating system.
systemd
를 사용 하는 경우 mongod.conf
설정에 processManagement.pidFilePath
설정을 사용하지 말라는 내용입니다. 왜 안되지 하고 잠시 삽질했는데요. 무지하면 몸이 고생한다능..
같은 문제로 삽질하시는 분들이 계시다면 도움이 되었으면 합니다.