Setting up Monit with tomcat
Sunday, April 16, 2017
Setting up Monit with tomcat :-
Monit is used for monitoring and restarting services when services are down, it can alert you or just restart after 3 or 5 failed connects/attempts. It handles everything from load, disk space, memory, services, and other things. we can easily configure it.
Step 1. To install
On Debian/Ubuntu based:-apt-get install monit
On Centos :-
1. Our system's hostname is site1.example.com, and we have a web site www.example.com on it with the document root /var/www/www.example.com/web.
2. Need To Enable The RPMforge Repository :-
On i386 hosts
wget http://packages.sw.be/rpmforge-release/rpmforge-release-0.3.6-1.el5.rf.i386.rpm
rpm -Uvh rpmforge-release-0.3.6-1.el5.rf.i386.rpm
rm -f rpmforge-release-0.3.6-1.el5.rf.i386.rpm
On x86_64 hosts
wget http://packages.sw.be/rpmforge-release/rpmforge-release-0.3.6-1.el5.rf.x86_64.rpm
rpm -Uvh rpmforge-release-0.3.6-1.el5.rf.x86_64.rpm
rm -f rpmforge-release-0.3.6-1.el5.rf.x86_64.rpm
3. Need to Install And Configure munin :-
yum install munin munin-node
Then we create the system startup links for munin and start it:
chkconfig --levels 235 munin-node on
/etc/init.d/munin-node start
Next, we must edit the munin configuration file /etc/munin/munin.conf. We want munin to put its output into the directory /var/www/www.example.com/web/monitoring, therefore we change the value of htmldir, and we want it to use the name site1.example.com instead of localhost.localdomain in the HTML output, therefore we replace localhost.localdomain with site1.example.com. Without the comments, the changed file looks like this:
vi /etc/munin/munin.conf
[...]
dbdir /var/lib/munin
htmldir /var/www/www.example.com/web/monitoring
logdir /var/log/munin
rundir /var/run/munin
# Where to look for the HTML templates
tmpldir /etc/munin/templates
[...]
# a simple host tree
[site1.example.com]
address 127.0.0.1
use_node_name yes
[...]
mkdir -p /var/www/www.example.com/web/monitoring
chown munin:munin /var/www/www.example.com/web/monitoring
/etc/init.d/munin-node restart
4. Password-Protect The munin Output Directory (Optional)
we can create an .htaccess file in /var/www/www.example.com/web/monitoring:
vi /var/www/www.example.com/web/monitoring/.htaccess
AuthType Basic
AuthName "Members Only"
AuthUserFile /var/www/www.example.com/.htpasswd
require valid-user
Then we must create the password file /var/www/www.example.com/.htpasswd. We want to log in with the username admin, so we do this:
htpasswd -c /var/www/www.example.com/.htpasswd admin
Enter a password for admin
Step 2:- Tomcat Monitoring Method A.
echo "check host tomcat with address localhost
stop program = "/etc/init.d/tomcat stop"
start program = "/etc/init.d/tomcat restart"
if failed port 8080 and protocol http
then start
" > /etc/monit.d/tomcat
/etc/init.d/monit restart
Step 3:- Tomcat Monitoring Method B.
check process tomcat with pidfile "/var/run/tomcat/tomcat.pid"
start program = "/usr/local/tomcat/bin/startup.sh"
as uid tomcat gid tomcat
stop program = "/usr/local/tomcat/bin/shutdown.sh"
as uid tomcat gid tomcat
if failed port 8080 then alert
if failed port 8080 for 5 cycles then restart
Then edit your catalina.sh and set
CATALINA_PID to be /var/run/tomcat/tomcat.pid
JAVA_HOME=/usr/java/jdk
Then of course create the pid directory
mkdir /var/run/tomcat/
chown tomcat.tomcat /var/run/tomcat/
Step 4:- MySQL Monitoring
Add this to your my.cnf under [mysqld]
pid-file=/var/run/mysqld/mysqld.pid
and this to your monit config
check process mysql with pidfile /var/run/mysqld/mysqld.pid
group database
start program = "/etc/init.d/mysql start"
stop program = "/etc/init.d/mysql stop"
if failed host 127.0.0.1 port 3306 protocol mysql then restart
if 5 restarts within 5 cycles then timeout
depends on mysql_rc
check file mysql_rc with path /etc/init.d/mysql
group database
if failed checksum then unmonitor
if failed permission 755 then unmonitor
if failed uid root then unmonitor
if failed gid root then unmonitor
Step 5:- Disk Space Monitoring
Add this to your monit config
check filesystem with path /dev/xvda1
if space usage > 95% then alert
if inode usage > 95% then alert
Step 6:- SSH Monitoring
Add this to your monit config
check process sshd with pidfile /var/run/sshd.pid
start program "/etc/init.d/sshd start"
stop program "/etc/init.d/sshd stop"
if failed port 22 protocol ssh then restart
if 5 restarts within 5 cycles then timeout
reloaded your monit config
0 comments:
Post a Comment