Service mysqld monit.d]# service mysqld stop Stopping mysqld: monit.d]# service mysqld stop Stopping mysqld: Service monit monit.d]# service monit restart Stopping monit: Dec 31 12:20:56 web1 monit: Shutting down monit HTTP server Dec 31 12:20:56 web1 monit: monit HTTP server stopped Dec 31 12:20:56 web1 monit: monit daemon with pid killed Dec 31 12:20:56 web1 monit: 'web1' Monit stopped Starting monit: Starting monit daemon with http interface at Dec 31 12:20:57 web1 monit: Starting monit daemon with http interface at monit.d]# Dec 31 12:20:57 web1 monit: Starting monit HTTP server at Dec 31 12:20:57 web1 monit: monit HTTP server started Dec 31 12:20:57 web1 monit: 'web1' Monit started Lets restart Monit and run some tests, for this I will run a tail on the log file while stopping services and killing processes: Note: these configurations should also work with Debian based distributions but check the location of the pid files, also the service names are slightly different (mysql and apache2 if memory serves correctly). The also monitor the respective tcp ports for the particular applications, 3306 for mysqld and 80 for apache. These two config files will check the pid files for activity outside monit, namely if the process stops without monit stopping it, and take action based on the status. Next we can create some config files in /etc/monit.d/ for our services (apache httpd and mysql in this case)Ĭheck process mysqld with pidfile /var/run/mysqld/mysqld.pid start program = "/sbin/service mysqld start" stop program = "/sbin/service mysqld stop" if failed host 127.0.0.1 port 3306 then restart if 5 restarts within 5 cycles then timeoutĬheck process httpd with pidfile /var/run/httpd/httpd.pid start program = "/sbin/service httpd start" stop program = "/sbin/service httpd stop" if failed host 127.0.0.1 port 80 then restart if 5 restarts within 5 cycles then timeout Which turns on logging, whether this is needed further down the line is to be decided but for now its great to have during configuration. The only directive I changed in the master config file was to uncomment the following line: If all is good then we can now tailor the configuration to our needs, monit uses the common approach for config files by having a master config at /etc/nf which also reads in files from /etc/monit.d/. Note: if using a systemd based distro such as Fedora or CentOS 7 then systemctl commands will need to be used instead of the above (systemctl enable monit and systemctl start monit) Lets enable the service to start on boot, and also start it to ensure it works OK before configuring: Once thats installed we can install the monit software It would be worth checking the website to ensure that rpm version is correct ( ) Scenario: small hosting server with low spec, occasionally gets hit with a large amount of traffic resulting in either apache or mysql dying.Ĭonfiguration: In this instance a CentOS 6 server with standard LAMP stack, but i’m sure this will work with other distributions such as Fedora or CentOS 7 just replacing the relevant commands for systemd based commands.įirst off lets install monit, this comes from the rpmforge ( ) repositories so if you haven’t already got them installed do so I was pleasantly surprised with the result, and how simple the whole process was. This was far more than I really needed, but the monitoring of services definitely caught my attention so I set about installing and configuring. Monit is an application I’ve been meaning to setup for a while, I was first made aware of it from a chap I had the pleasure of talking to at OggCamp this year, he seemed to use it to the n’th degree to monitor files and services within docker containers to ensure a development environment was as it should be.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |