tomcat configuration monit

How To Monitor MySQL and SSH Service Using Monit On Linux

If you’re tried of monitoring the services manually on Linux servers, So here’s the solution for you. First of all, you will have to install Monit on Linux. We can configure Monit to check the tomcat and MySQL process. We have to do the configuration for MySQL and tomcat using Monit. we can also check monit and java process. Let’s see, how to monitor MySQL.

This is very easy to configure Monit in Linux and you can find the monit logfile located at /var/log/monit. We have discussed with you a few monit examples using ssh and MySQL services.

SSH Configuration:

We will create a file for ssh service monitoring using the Monit tool.

[[email protected] ~]# vim /etc/monit.d/ssh.conf
check process sshd with pidfile /var/run/sshd.pid
start program "/usr/sbin/sshd start"
stop program "/usr/sbin/sshd stop"
if failed host 127.0.0.1 port 22 protocol ssh then restart
if 5 restarts within 5 cycles then timeout

The above code will monitor the ssh services and it will restart the service when it’s failed. It will attempt 5 times.

Check Out: Useful Git Command For Admin and Developers On Linux

You can check the status whether it’s running or configured properly by using monit status command.

Process                                                        'sshd'
status                                                             OK
monitoring status                                      Monitored
monitoring mode                                       active
on reboot                                                     start
pid                                                                 7101
parent pid                                                    1
uid                                                                 0
effective uid                                                 0
gid                                                                 0
uptime                                                          1h 54m
threads                                                         1
children                                                       3
cpu                                                                0.0%
cpu total                                                      0.0%
memory                                                       0.0% [468 kB]
memory total                                             0.3% [2.8 MB]
security attribute system_u:system_r:sshd_t:s0-s0:c0.c1023
disk read                                                     0 B/s [116.6 MB total]
port response time 34.733 ms to 127.0.0.1:22 type TCP/IP protocol SSH
data collected Tue, 05 May 2020 14:22:32

MySQL Configuration:

We can also monitor the MySQL server as well as using this tool. Create a file for MySQL monitoring.

Note: you can change the location in the configuration file according to your server.

[[email protected] ~]# vim /etc/monit.d/mysql.conf
check process mysqld with pidfile /var/run/mysqld/mysqld.pid
group database
start program = "/etc/init.d/mysqld start"
stop program = "/etc/init.d/mysqld stop"
if failed host 127.0.0.1 port 3306 then restart
if 5 restarts within 5 cycles then timeout

We can also check the configuration before reloading the monit service.

[[email protected] ~]# monit -t                                        # check the config before reload service
[[email protected] ~]# monit reload                              # reload config to make changes

you may check the location of PID and start the program it may be different on your machine.

Check the status using monit status

Process                                                                                             'mysqld'
status                                                                                                 OK
monitoring status                                                                           Monitored
monitoring mode                                                                            active
on reboot                                                                                           start
pid                                                                                                      60708
parent pid                                                                                         60504
uid                                                                                                      27
effective uid                                                                                      27
gid                                                                                                      27
uptime                                                                                               0m
threads                                                                                              22
children                                                                                             0
cpu                                                                                                      0.1%
cpu total                                                                                             0.1%
memory                                                                                              45.3% [440.2 MB]
memory total                                                                                    45.3% [440.2 MB]
security attribute                                                                           system_u:system_r:mysqld_t:s0
disk read                                                                                         0 B/s [13.7 MB total]
disk write                                                                                       0 B/s [64 kB total]
port response time 0.924 ms to 127.0.0.1:3306 type TCP/IP protocol DEFAULT
data collected Tue, 05 May 2020 14:22:32

Now we have configured both SSH and MySQL services to monitor and automatically restart when failed.

Check Out: How To Rollback or Downgrade Installed Packages On Linux

Test the configuration:

I will stop the MySQL service manually to check whether it’s working or not.

Once it’s done. You check the status using monit status

Process                                                                                            'mysqld'
status                                                                                                Initializing
monitoring status                                                                          Initializing
monitoring mode                                                                              active
on reboot                                                                                             start
data collected Tue, 05 May 2020 14:39:08

You will see it will be in the initializing process for a few seconds then you check the status of MySQL service.

The service will be restarted automatically.

Check Out: How To Install Drupal CMS 8.8 Version on CentOS 8

Process                                                                                                  'mysqld'
status                                                                                                       OK
monitoring status                                                                                Monitored
monitoring mode                                                                                 active
on reboot                                                                                               start
pid                                                                                                           61687
parent pid                                                                                              61482
uid                                                                                                           27
effective uid                                                                                           27
gid                                                                                                            27
uptime                                                                                                     0m
threads                                                                                                     22
children                                                                                                     0
cpu                                                                                                              0.1%
cpu total                                                                                                  0.1%
memory                                                                                                 45.3% [440.2 MB]
memory total                                                                                       45.3% [440.2 MB]
security attribute                                                                 system_u:system_r:mysqld_t:s0
disk write                                                                                      0 B/s [60 kB total]
port response time 0.566 ms to 127.0.0.1:3306 type TCP/IP protocol DEFAULT
data collected Tue, 05 May 2020 14:40:11

if you configured the GUI access for the Monit dashboard. You can also check the status there.

How To Monitor MySQL

You’re done tomcat configuration monit mysql

LEAVE A REPLY

Please enter your comment!
Please enter your name here