How to Configure Log Rotate Manually in MongoDB 4.0.11 Verison on CentOS 7.6
How to Configure Log rotate Manually in MongoDB 4.0.11 On CentOS 7.6
Form of logRotate command against the admin database is {logRotate : 1}
Configuration file of MongoDB : /etc/mongod.conf
Configuration process:
Check the version of mongoDB by executing the following command
[root@linuxhelp ~]# mongod --version
db version v4.0.11
git version: 417d1a712e9f040d54beca8e4943edce218e9a8c
OpenSSL version: OpenSSL 1.0.1e-fips 11 Feb 2013
allocator: tcmalloc
modules: none
build environment:
distmod: rhel70
distarch: x86_64
target_arch: x86_64
Navigate to the MongoDB Configuration File to check the log path of mongoDB
[root@linuxhelp ~]# vim /etc/mongod.conf
where to write logging data.
systemLog:
destination: file
logAppend: true
path: /var/log/mongodb/mongod.log
Navigate to Log path of MongoDB
[root@linuxhelp ~]# cd /var/log/mongodb/
List the directory to view the log file of mongodb
[root@linuxhelp mongodb]# ls
mongod.log
Log into the MongoDB shell using the following command
[root@linuxhelp mongodb]# mongo
MongoDB shell version v4.0.11
connecting to: mongodb://127.0.0.1:27017/?gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("09c8b617-24bf-42ba-8d90-a5dd35dc7497") }
MongoDB server version: 4.0.11
Server has startup warnings:
2019-08-06T15:33:04.607+0530 I CONTROL [initandlisten]
2019-08-06T15:33:04.607+0530 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.
2019-08-06T15:33:04.607+0530 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.
2019-08-06T15:33:04.607+0530 I CONTROL [initandlisten]
2019-08-06T15:33:04.607+0530 I CONTROL [initandlisten]
2019-08-06T15:33:04.607+0530 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2019-08-06T15:33:04.607+0530 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2019-08-06T15:33:04.607+0530 I CONTROL [initandlisten]
2019-08-06T15:33:04.607+0530 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2019-08-06T15:33:04.607+0530 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2019-08-06T15:33:04.607+0530 I CONTROL [initandlisten]
---
Enable MongoDB's free cloud-based monitoring service, which will then receive and display
metrics about your deployment (disk utilization, CPU, operation statistics, etc).
The monitoring data will be available on a MongoDB website with a unique URL accessible to you
and anyone you share the URL with. MongoDB may use this information to make product
improvements and to suggest MongoDB products and deployment options to you.
To enable free monitoring, run the following command: db.enableFreeMonitoring()
To permanently disable this reminder, run the following command: db.disableFreeMonitoring()
---
>
>
Check the version of MongoDB
> db.version();
4.0.11
List the default databases that exists in the MongoDB
> show dbs;
admin 0.000GB
config 0.000GB
local 0.000GB
Switch over to the admin database
> use admin;
switched to db admin
Configure the Log Rotate
> db.adminCommand( { logRotate : 1 } );
{ "ok" : 1 }
Exit from the MongoDB
> exit
Bye
List the directory to view the logfiles
[root@linuxhelp mongodb]# ls -la
total 12
drwxr-xr-x 2 mongod mongod 62 Aug 27 08:56 .
drwxr-xr-x. 21 root root 4096 Aug 27 08:03 ..
-rw------- 1 mongod mongod 1275 Aug 27 08:56 mongod.log
-rw------- 1 mongod mongod 2952 Aug 27 08:56 mongod.log.2019-08-27T03-26-50
With this,Manual Configuration of LogRotate In MongoDB 4.0.11 Version On CentOS 7.6
Q
How to list the log files in MongoDB?
A
ls /var/log/mongodb/ is the command to list the log files in MongoDB.
Q
Which database should log be rotated in MongoDB?
A
From the Admin database, log rotate should be applied in MongoDB
Q
How to rotate the log file in MongoDB?
A
db.adminCommand( { logRotate : 1 } ) is the way to rotate the log file In MongoDB
Q
Where would the log rotate files be logged In MongoDB?
A
The log Rotate files would be logged under /var/log/mongodb/ In MongoDB
Q
What is logrotate in MongoDB?
A
Logrotate is a tool which manages log files created by system processes.