Dear readers of our blog, we'd like to recommend you to visit the main page of our website, where you can learn about our product SQLS*Plus and its advantages.
 
SQLS*Plus - best SQL Server command line reporting and automation tool! SQLS*Plus is several orders of magnitude better than SQL Server sqlcmd and osql command line tools.
 

REQUEST COMPLIMENTARY SQLS*PLUS LICENCE

Enteros UpBeat offers a patented database performance management SaaS platform. It proactively identifies root causes of complex revenue-impacting database performance issues across a growing number of RDBMS, NoSQL, and deep/machine learning database platforms. We support Oracle, SQL Server, IBM DB2, MongoDB, Casandra, MySQL, Amazon Aurora, and other database systems.

How to control MySQL and SSH service with Monit on Linux

26 August 2020

How to control MySQL and SSH service with Monit on Linux

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.

How to control MySQL and SSH service with Monit on Linux

 

MORE NEWS

 

Preamble​​NoSql is not a replacement for SQL databases but is a valid alternative for many situations where standard SQL is not the best approach for...

Preamble​​MongoDB Conditional operators specify a condition to which the value of the document field shall correspond.Comparison Query Operators $eq...

5 Database management trends impacting database administrationIn the realm of database management systems, moreover half (52%) of your competitors feel...

The data type is defined as the type of data that any column or variable can store in MS SQL Server. What is the data type? When you create any table or...

Preamble​​MS SQL Server is a client-server architecture. MS SQL Server process starts with the client application sending a query.SQL Server accepts,...

First the basics: what is the master/slave?One database server (“master”) responds and can do anything. A lot of other database servers store copies of all...

Preamble​​Atom Hopper (based on Apache Abdera) for those who may not know is an open-source project sponsored by Rackspace. Today we will figure out how to...

Preamble​​MongoDB recently introduced its new aggregation structure. This structure provides a simpler solution for calculating aggregated values rather...

FlexibilityOne of the most advertised features of MongoDB is its flexibility.  Flexibility, however, is a double-edged sword. More flexibility means more...

Preamble​​SQLShell is a cross-platform command-line tool for SQL, similar to psql for PostgreSQL or MySQL command-line tool for MySQL.Why use it?If you...

Preamble​​Writing an application on top of the framework on top of the driver on top of the database is a bit like a game on the phone: you say “insert...

Preamble​​Oracle Coherence is a distributed cache that is functionally comparable with Memcached. In addition to the basic function of the API cache, it...

Preamble​​IBM pureXML, a proprietary XML database built on a relational mechanism (designed for puns) that offers both relational ( SQL / XML ) and...

  What is PostgreSQL array? In PostgreSQL we can define a column as an array of valid data types. The data type can be built-in, custom or enumerated....

Preamble​​If you are a Linux sysadmin or developer, there comes a time when you need to manage an Oracle database that can work in your environment.In this...

Preamble​​Starting with Microsoft SQL Server 2008, by default, the group of local administrators is no longer added to SQL Server administrators during the...