Detailed steps for installing the monitoring tool monit on CentOS 7

Source: Internet
Author: User
Tags memory usage time 0 ssh centos

During server O & M, we usually use Zabbix for monitoring. Here we install and configure monit. When the process is detected to be stopped, the process can be automatically started.

We recommend that you use the rpmforge source to install monit, because the rpmforge monit version is newer.

Install monit

# Cd/tmp
# Rpm-ivh http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el7.rf.x86_64.rpm
# Yum install -- enablerepo = rpmforge monit
# Rpm-q monit
Monit-5.6-1.el7.x86_64
# Rpm-ql monit
/Etc/logrotate. d/monit
/Etc/monit. d
/Etc/monit. d/logging
/Etc/monitrc
/Usr/bin/monit
/Usr/lib/systemd/system/monit. service
/Usr/share/doc/monit-5.6
/Usr/share/doc/monit-5.6/CHANGES
/Usr/share/doc/monit-5.6/COPYING
/Usr/share/doc/monit-5.6/PLATFORMS
/Usr/share/doc/monit-5.6/README
/Usr/share/man/man1/monit.1.gz
/Var/log/monit. log
# Monit-V
This is Monit version 5.6
Copyright (C) 2001-2013 Tildeslash Ltd. All Rights Reserved.
The latest version of September 9, 2015 is 5.6.

Configure monit

View the content of the default configuration file

# Grep-v '^ #'/etc/monitrc
Set daemon 60 # check services at 1-minute intervals
Set httpd port 2812 and
Use address localhost # only accept connection from localhost
Allow localhost # allow localhost to connect to the server and
Allow admin: monit # require user 'admin' with password 'monit'
Allow @ monit # allow users of group 'monit' to connect (rw)
Allow @ users readonly # allow users of group 'users' to connect readonly

Include/etc/monit. d /*
# Cat/etc/logrotate. d/monit
/Var/log/monit. log {
Missingok
Notifempty
Size 100 k
Create 0644 root
Postrotate
/Bin/systemctl reload monit. service>/dev/null 2> & 1 |:
Endscript
}
# Cat/etc/monit. d/logging
# Log to monit. log
Set logfile/var/log/monit. log
The monitoring period is 60 seconds. Log output and log scrolling are configured.

Configure monit

Sshd

Check process sshd with pidfile/var/run/sshd. pid
Start program "/usr/bin/systemctl start sshd. service"
Stop program "/usr/bin/systemctl stop sshd. service"
If failed port 22 protocol ssh then restart
If 5 restart within 5 cycles then timeout
Apache

The configuration of monit Apache on CentOS6.5 is different from the start/stop command on CentOS 7.

Check process apache with pidfile/var/run/httpd. pid
Start program = "/etc/init. d/httpd start" with timeout 60 seconds
Stop program = "/etc/init. d/httpd stop"
If failed host www. zabbix. cc port 80 protocol http
And request "/readme.html"
Then restart
If 3 restarts within 5 cycles then timeout
Group apache
Nginx

Check process nginx with pidfile/var/run/nginx. pid
Start program = "/usr/bin/systemctl start nginx. service"
Stop program = "/usr/bin/systemctl stop nginx. service"
MySQL

MySQL for monit configuration on CentOS6.5 is different from the command for starting/stopping CentOS 7.

Check process mysqld with pidfile "/var/run/mysqld. pid"
Start = "/etc/init. d/mysqld start"
Stop = "/etc/init. d/mysqld stop"
If failed unixsocket/var/lib/mysql. sock with timeout 60 seconds then restart
If 5 restarts within 5 cycles then timeout
MariaDB

Check process mariadb with pidfile "/var/run/mariadb. pid"
Start = "/usr/bin/systemctl start mariadb. service"
Stop = "/usr/bin/systemctl stop mariadb. service"
If failed host 127.0.0.1 port 3306 protocol mysql then restart
If 5 restarts within 5 cycles then timeout

View monit status

# Monit status
The Monit daemon 5.6 uptime: 8 m

Process 'sshd'
Status Running
Monitoring status Monitored
Pid 884
Parent pid 1
Uptime 19d 11 h 57 m
Children 4
Apsaradb for memory kilobytes 3016
Memory kilobytes total 19420
Memory percent 0.0%
Memory percent total 0.5%
Cpu percent 0.0%
Cpu (percent total 0.0%)
Port response time 0.008 s to localhost: 22 [SSH via TCP]
Data collected Sun, 05 Apr 2015 21:41:18

Process 'nginx'
Status Running
Monitoring status Monitored
Pid 13963
Parent pid 1
Uptime 6 m
Children 3
Apsaradb for memory kilobytes 2428
Memory kilobytes total 67520
Memory percent 0.0%
Memory percent total 1.8%
Cpu percent 0.0%
Cpu (percent total 0.0%)
Data collected Sun, 05 Apr 2015 21:41:18

Process 'mariadb'
Status Running
Monitoring status Monitored
Pid 24790
Parent pid 24354
Uptime 10d 4 h 36 m
Children 0
Apsaradb for memory kilobytes 216168
Memory kilobytes total 216168
Memory percent 5.9%
Memory percent total 5.9%
Cpu percent 0.0%
Cpu (percent total 0.0%)
Port response time 0.000 s to 127.0.0.1: 3306 [MYSQL via TCP]
Data collected Sun, 05 Apr 2015 21:41:18

System 'zabbix. Cc'
Status Running
Monitoring status Monitored
Load average [0.00] [0.01] [0.05]
Cpu 0.8% us 0.1% sy 0.1% wa
Memory usage 1524496 kB [42.1%]
Swap usage 0 kB [0.0%]
Data collected Sun, 05 Apr 2015 21:41:18

Confirm that monit automatically starts the process

View the monit. log file after stopping the nginx process.

# Systemctl stop nginx. service
# Tailf/var/log/monit. log
[CST Apr 5 21:35:18] error: 'nginx' process is not running
[CST Apr 5 21:35:18] info: 'nginx' trying to restart
[CST Apr 5 21:35:18] info: 'nginx' start:/usr/bin/systemctl

Configure automatic OS startup

Configure automatic startup when the OS is started. Depending on the automatic startup commands of the system and version, we will introduce how to configure automatic startup on CentOS7.

# Systemctl list-unit-files | grep monit. service
Monit. service disabled
# Systemctl enable monit. service
Ln-s '/usr/lib/systemd/system/monit. Service'/etc/systemd/system/multi-user.target.wants/monit. Service'
# Systemctl list-unit-files | grep monit. service
Monit. service enabled
Zabbix monitoring monit

When the process is detected to be stopped, the environment that automatically starts the process can be set up, but the monit itself cannot be detected after it is stopped. Use Zabbix to monitor monit.

Monitor monit processes

Monitored object (Item)

Monitored object (Item)

Project Configuration
Name Process monit daemon running
Type Zabbix agent
Key Proc. num [monit]
Data type Numeric (integer)

Trigger)

Project Configuration
Name Process monit daemon down
Logical condition {Zabbix server: proc. num [monit]. last ()} = 0
Severity Warning (Warning)

Monitor monit log files
Monitored object (Item)

Project Configuration
Name Process monit daemon running
Type Zabbix agent
Key Log [/var/log/monit, error]
Data type Log)

Trigger)

Project Configuration
Name Process monit daemon error
Logical condition ({Zabbix server: log [/var/log/monit, error]. regexp (error)}) #0) & ({Zabbix server: log [/var/log/monit, error]. no data (300)} = 0)
Severity Warning (Warning)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.