Preamble
If you tried to control services manually on Linux servers then here is the solution for you. First of all you will need to install Monit on Linux.
We can set up Monit to check the Tomcat and MySQL processes. We have to configure for MySQL and Tomcat using Monit. We can also test the Monit and Java processes. We will see how to control MySQL.
It is very easy to configure Monit on Linux and you can find the log file in /var/log/monit. We discussed with you some examples of monitoring using ssh and MySQL services.
SSH configuration
We will create a file to monitor the ssh service using the Monit tool.
[root@andrex ~]# 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 restart the services on failure. It will try 5 times.
You can check the status if it works or is configured correctly using the 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 control the MySQL server as well as with this tool. Create a file to monitor MySQL.
- Note:
You can change the location of the configuration file according to your server.
[root@andrex ~]# 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 rebooting the monitoring service.
[root@andrex ~]# monit -t # check the configuration before rebooting the service
[root@andrex ~]#get reload # reboot the configuration to make changes
You can check the PID location and run the program, it may be different on your computer.
Check the status by using the monitoring 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 SSH and MySQL services to monitor and automatically restart on failure.
Test configuration
We will stop the MySQL service manually to check if it works or not.
As soon as it is done. You check the status by using the monitoring 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 that it will be in the process of initialization for a few seconds and then you will check the state of MySQL service.
The service will be restarted automatically.
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 have set up access with GUI for Monit monitoring panel. You can also check the status there.
About Enteros
Enteros helps associations of each size with making their cloud data stockrooms work for any usage case and our experts are skilled in the fluctuating nuances of the different data circulation focus courses of action.
The views expressed on this blog are those of the author and do not necessarily reflect the opinions of Enteros Inc. This blog may contain links to the content of third-party sites. By providing such links, Enteros Inc. does not adopt, guarantee, approve, or endorse the information, views, or products available on such sites.
Are you interested in writing for Enteros’ Blog? Please send us a pitch!
RELATED POSTS
Enhancing Identity and Access Management in Healthcare with Enteros
- 19 November 2024
- Database Performance Management
In the fast-evolving world of finance, where banking and insurance sectors rely on massive data streams for real-time decisions, efficient anomaly man…
Maximizing Efficiency with Enteros: Revolutionizing Cost Allocation Through a Cloud Center of Excellence
In the fast-evolving world of finance, where banking and insurance sectors rely on massive data streams for real-time decisions, efficient anomaly man…
Driving Efficiency in the Transportation Sector: Enteros’ Cloud FinOps and Database Optimization Solutions
- 18 November 2024
- Database Performance Management
In the fast-evolving world of finance, where banking and insurance sectors rely on massive data streams for real-time decisions, efficient anomaly man…
Empowering Nonprofits with Enteros: Optimizing Cloud Resources Through AIOps Platform
In the fast-evolving world of finance, where banking and insurance sectors rely on massive data streams for real-time decisions, efficient anomaly man…