mirror of
https://github.com/LCTT/TranslateProject.git
synced 2025-01-25 23:11:02 +08:00
20150326-1 选题
This commit is contained in:
parent
ca7e27cfce
commit
5f385fe573
110
sources/share/20150326 Mydumper--Mysql Database Backup tool.md
Normal file
110
sources/share/20150326 Mydumper--Mysql Database Backup tool.md
Normal file
@ -0,0 +1,110 @@
|
||||
Mydumper – Mysql Database Backup tool
|
||||
================================================================================
|
||||
Mydumper is a tool used for backing up MySQL database servers much faster than the mysqldump tool distributed with MySQL. It also has the capability to retrieve the binary logs from the remote server at the same time as the dump itself.
|
||||
|
||||
### Mydumper advantages ###
|
||||
|
||||
o Parallelism (hence, speed) and performance (avoids expensive character set conversion routines, efficient code overall)
|
||||
|
||||
o Easier to manage output (separate files for tables, dump metadata,etc, easy to view/parse data)
|
||||
|
||||
o Consistency -- maintains snapshot across all threads, provides accurate master and slave log positions, etc
|
||||
|
||||
o Manageability -- supports PCRE for specifying database and tables inclusions and exclusions
|
||||
|
||||
### Install mydumper on ubuntu ###
|
||||
|
||||
Open the terminal and run the following command
|
||||
|
||||
sudo apt-get install mydumper
|
||||
|
||||
### Using Mydumper ###
|
||||
|
||||
#### Syntax ####
|
||||
|
||||
mydumper [options]
|
||||
|
||||
Application Options:
|
||||
|
||||
- -B, --database Database to dump
|
||||
- -T, --tables-list Comma delimited table list to dump (does not exclude regex option)
|
||||
- -o, --outputdir Directory to output files to
|
||||
- -s, --statement-size Attempted size of INSERT statement in bytes, default 1000000
|
||||
- -r, --rows Try to split tables into chunks of this many rows
|
||||
- -c, --compress Compress output files
|
||||
- -e, --build-empty-files Build dump files even if no data available from table
|
||||
- -x, --regex Regular expression for ‘db.table' matching
|
||||
- -i, --ignore-engines Comma delimited list of storage engines to ignore
|
||||
- -m, --no-schemas Do not dump table schemas with the data
|
||||
- -k, --no-locks Do not execute the temporary shared read lock. WARNING: This will cause inconsistent backups
|
||||
- -l, --long-query-guard Set long query timer in seconds, default 60
|
||||
- --kill-long-queries Kill long running queries (instead of aborting)
|
||||
- -b, --binlogs Get a snapshot of the binary logs as well as dump data
|
||||
- -D, --daemon Enable daemon mode
|
||||
- -I, --snapshot-interval Interval between each dump snapshot (in minutes), requires --daemon, default 60
|
||||
- -L, --logfile Log file name to use, by default stdout is used
|
||||
- -h, --host The host to connect to
|
||||
- -u, --user Username with privileges to run the dump
|
||||
- -p, --password User password
|
||||
- -P, --port TCP/IP port to connect to
|
||||
- -S, --socket UNIX domain socket file to use for connection
|
||||
- -t, --threads Number of threads to use, default 4
|
||||
- -C, --compress-protocol Use compression on the MySQL connection
|
||||
- -V, --version Show the program version and exit
|
||||
- -v, --verbose Verbosity of output, 0 = silent, 1 = errors, 2 = warnings, 3 = info, default 2
|
||||
|
||||
#### Mydumper Example ####
|
||||
|
||||
mydumper \
|
||||
--database=$DB_NAME \
|
||||
--host=$DB_HOST \
|
||||
--user=$DB_USER \
|
||||
--password=$DB_PASS \
|
||||
--outputdir=$DB_DUMP \
|
||||
--rows=500000 \
|
||||
--compress \
|
||||
--build-empty-files \
|
||||
--threads=2 \
|
||||
--compress-protocol
|
||||
|
||||
Description of Mydumper's output data
|
||||
|
||||
Mydumper does not output to files, but rather to files in a directory. The --outputdir option specifies the name of the directory to use.
|
||||
|
||||
The output is two parts
|
||||
|
||||
Schema
|
||||
|
||||
For each table in the database, a file containing the CREATE TABLE statement will be created. It will be named:
|
||||
|
||||
dbname.tablename-schema.sql.gz
|
||||
|
||||
Data
|
||||
|
||||
For each table with number of rows above the --rows parameter, you will have a file called:
|
||||
|
||||
dbname.tablename.0000n.sql.gz
|
||||
|
||||
Where "n" starts with 0 up to the number of.
|
||||
|
||||
If you want to restore these backup you can use Myloader
|
||||
|
||||
myloader \
|
||||
--database=$DB_NAME \
|
||||
--directory=$DB_DUMP \
|
||||
--queries-per-transaction=50000 \
|
||||
--threads=10 \
|
||||
--compress-protocol \
|
||||
--verbose=3
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: http://www.ubuntugeek.com/mydumper-mysql-database-backup-tool.html
|
||||
|
||||
作者:[ruchi][a]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:http://www.ubuntugeek.com/author/ubuntufix
|
@ -0,0 +1,191 @@
|
||||
A Peep into Process Management Commands in Linux
|
||||
================================================================================
|
||||
A program in execution is called a process. While a program is an executable file present in storage and is passive, a process is a dynamic entity comprising of allocated system resources, memory, security attributes and has a state associated with it. There can be multiple processes associated with the same program and operating simultaneously without interfering with each other. The operating system efficiently manages and keeps track of all the processes running in the system.
|
||||
|
||||
In order to manage these processes, user should be able to
|
||||
|
||||
- See all the processes that are running
|
||||
- View the system resources consumed by the processes
|
||||
- Locate a particular process and take specific action on it
|
||||
- Change the priority levels associated with processes
|
||||
- Kill the required processes
|
||||
- Restrict the system resources available to processes etc.
|
||||
|
||||
Linux offers many commands to the user to effectively handle the above mentioned scenarios. Let's understand them one by one.
|
||||
|
||||
### 1. ps ###
|
||||
|
||||
'ps' is one of the basic commands in Linux to view the processes on the system. It lists the running processes in a system along with other details such as process id, command, cpu usage, memory usage etc. Some of the following options come handy to get more useful information
|
||||
|
||||
ps -a - List all the running / active processes
|
||||
|
||||
![Output of "ps -a" command](http://blog.linoxide.com/wp-content/uploads/2015/02/ps-a2.png)
|
||||
|
||||
ps -ef |grep - List only the required process
|
||||
|
||||
ps -aux - Displays processes including those with no terminals(x) Output is user oriented (u) with fields like USER, PID, %CPU, %MEM etc
|
||||
|
||||
### 2. pstree ###
|
||||
|
||||
In Linux, every process gets spawned by its parent process. This command helps visualize the processes by displaying a tree diagram of the processes showing the relationship between them. If a pid is mentioned, the root of the tree will be the pid. Else it will be rooted at init.
|
||||
|
||||
![pstree](http://blog.linoxide.com/wp-content/uploads/2015/02/pstree.png)
|
||||
|
||||
### 3. top ###
|
||||
|
||||
'top' is a very useful command to monitor the system as it shows the system resources used by different processes. It gives a snapshot of the situation that the system is currently in. Its output includes data like process identification number(PID), user of the process, nice value, %CPU and %memory currently consumed by the process etc. One can use this output to figure out which process is hogging the CPU or memory.
|
||||
|
||||
![top](http://blog.linoxide.com/wp-content/uploads/2015/02/top.png)
|
||||
|
||||
### 4. htop ###
|
||||
|
||||
htop is similar to top, but is an interactive text mode process viewer. It displays the per CPU usage and memory, swap usage using a text graph. One can use the Up/Down arrow key to select processes, F7 and F8 to change the priority and F9 to kill a process. It is not present by default in the system and need to be installed explicitly.
|
||||
|
||||
![htop output](http://blog.linoxide.com/wp-content/uploads/2015/03/htop1.png)
|
||||
|
||||
### 5. nice ###
|
||||
|
||||
With the help of nice command, users can set or change the priorities of processes in Linux. Higher the priority of a process, more is the CPU time allocated by the kernel for it. By default, a process gets launched with priority 0. Process priority can be viewed using the top command output under the NI (nice value) column.
|
||||
|
||||
Values of process priority range from -20 to 19. Lower the nice value, higher the priority.
|
||||
|
||||
nice <priority value> <process name> - starts the process by setting its priority to the given value
|
||||
|
||||
![nice command](http://blog.linoxide.com/wp-content/uploads/2015/02/nice-cmd.png)
|
||||
|
||||
![changed nice value of 'top'](http://blog.linoxide.com/wp-content/uploads/2015/02/top-nice.png)
|
||||
|
||||
In the above example, 'top' gets launched with a priority -3.
|
||||
|
||||
### 6. renice ###
|
||||
|
||||
It is similar to nice command. Use this command to change the priority of an already running process. Please note that users can change the priority of only the processes that they own.
|
||||
|
||||
renice -n -p - change the priority of the given process
|
||||
|
||||
![renice command](http://blog.linoxide.com/wp-content/uploads/2015/02/renice2.png)
|
||||
|
||||
Priority of process with id 3806 which had an initial priority of 0 is now changed to priority 4.
|
||||
|
||||
renice -u -g - change the priority of processes owned by the given user and group
|
||||
![output of renice for a user group](http://blog.linoxide.com/wp-content/uploads/2015/02/renice1.png)
|
||||
|
||||
In the above example, priority of all processes owned by user 'mint' get changed to '-3'
|
||||
|
||||
### 7. kill ###
|
||||
|
||||
This is a command used to terminate processes by sending signals. If a process is not responding to kill command, then it can be forcefully killed using the kill -9 command. But this needs to be used carefully as it does not give a chance for the process to clean up and might end up in corrupted files. If we are not aware of the PID of the process to be killed or want to mention the process name to be killed, then killall comes to rescue.
|
||||
|
||||
kill <pid>
|
||||
|
||||
kill -9 <pid>
|
||||
|
||||
killall -9 - kill all instances having the same process name
|
||||
|
||||
If you use kill, you need to know the process id of the process to be killed. pkill is a similar command but can be used to kill processes using a pattern, i.e. process name, process owner etc.
|
||||
|
||||
pkill <process name>
|
||||
|
||||
![kill initiated](http://blog.linoxide.com/wp-content/uploads/2015/02/kill-initiated.png)
|
||||
|
||||
![kill](http://blog.linoxide.com/wp-content/uploads/2015/02/kill.png)
|
||||
|
||||
### 8. ulimit ###
|
||||
|
||||
Command useful in controlling the system-wide resources available to the shells and processes. Mostly useful for system administrators to manage systems that are heavily used and have performance problems. Limiting the resources ensures that important processes continue to run while other processes do not consume more resources.
|
||||
|
||||
ulimit -a - Displays the current limits associated with the current user.
|
||||
|
||||
![ulimit -a](http://blog.linoxide.com/wp-content/uploads/2015/02/ulimit-a.png)
|
||||
|
||||
-f - maximum file size
|
||||
|
||||
-v - maximum virtual memory size (in KB)
|
||||
|
||||
-n - maximum file descriptor plus 1
|
||||
|
||||
-H : To change and report the hard limit
|
||||
|
||||
-S : To change and report the soft limit
|
||||
|
||||
Check out the ulimit man page for more options.
|
||||
|
||||
### 9. w ###
|
||||
|
||||
w gives us information about the users who have currently logged in and the processes that they are running. The header details displayed contain information like current time, how long the system has been running, total number of users logged in, load average of the system for the last 1, 5 and 15 minutes
|
||||
|
||||
Based on the user information, one can take care before terminating any processes that do not belong to them.
|
||||
|
||||
!['w' command](http://blog.linoxide.com/wp-content/uploads/2015/02/w.png)
|
||||
|
||||
**who** is a related command and gives a list of currently logged in users, time of last system boot, current run levels etc.
|
||||
|
||||
!['who' command](http://blog.linoxide.com/wp-content/uploads/2015/02/who.png)
|
||||
|
||||
**whoami** command prints the username of the current user ID
|
||||
|
||||
!['whoami' command](http://blog.linoxide.com/wp-content/uploads/2015/02/whoami.png)
|
||||
|
||||
### 10. pgrep ###
|
||||
|
||||
pgrep stands for "Process-ID Global Regular Expression Print". It scans the currently running processes and lists the process IDs that match the selection criteria mentioned on command line to stdout. Useful for retrieving the process id of a process by using its name.
|
||||
|
||||
pgrep -u mint sh
|
||||
|
||||
This command will display the process ID for the process named 'sh' and owned by user 'mint'
|
||||
|
||||
![output of pgrep](http://blog.linoxide.com/wp-content/uploads/2015/03/pgrep.png)
|
||||
|
||||
### 11. fg , bg ###
|
||||
|
||||
Sometimes, the commands that we execute take a long time to complete. In such situations, we can push the jobs to be executed in the background using 'bg' command and can be brought to the foreground with the 'fg' command.
|
||||
|
||||
We can start a program in background by using the '&' :
|
||||
|
||||
find . -name *iso > /tmp/res.txt &
|
||||
|
||||
A program that is already running can also be sent to the background using 'CTRL+Z' and 'bg' command:
|
||||
|
||||
find . -name *iso > /tmp/res.txt & - start the job in the background
|
||||
|
||||
ctrl+z - suspend the currently executing foreground job
|
||||
|
||||
bg - push the command execution to background
|
||||
|
||||
We can list all the background processes using 'jobs' command
|
||||
|
||||
jobs
|
||||
|
||||
We can bring back a background process to foreground using the 'fg' command.
|
||||
|
||||
fg %
|
||||
|
||||
![output of fg, bg and jobscommands](http://blog.linoxide.com/wp-content/uploads/2015/03/fg-bg-jobs.png)
|
||||
|
||||
### 12. ipcs ###
|
||||
|
||||
ipcs command is used for listing the inter-process communication facilities (shared memory, semaphores and message queues).
|
||||
|
||||
This command with -p option can be combined with options -m, -s or-q to display the process id which recently accessed the corresponding ipc facility.
|
||||
|
||||
ipcs -p -m
|
||||
|
||||
The screen shot below is listing the creator id and process id which accessed the shared memory recently.
|
||||
|
||||
![ipcs command](http://blog.linoxide.com/wp-content/uploads/2015/03/ipcs.png)
|
||||
|
||||
### Conclusion ###
|
||||
|
||||
Generally, it is considered the job of administrators to fix problems and tweak the system to improve the performance. But users also need to deal with processes in Linux quite often. Hence, it is essential to familiarise ourselves with the various commands available to manage them effectively.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: http://linoxide.com/linux-command/process-management-commands-linux/
|
||||
|
||||
作者:[B N Poornima][a]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:http://linoxide.com/author/bnpoornima/
|
@ -0,0 +1,252 @@
|
||||
How to set up server monitoring system with Monit
|
||||
================================================================================
|
||||
Many Linux admins rely on a centralized remote monitoring system (e.g., [Nagios][1] or [Cacti][2]) to check the health of their network infrastructure. While centralized monitoring makes an admin's life easy when dealing with many hosts and devices, a dedicated monitoring box obviously becomes a single point of failure; if the monitoring box goes down or becomes unreachable for whatever reason (e.g., bad hardware or network outage), you will lose visibility on your entire infrastructure.
|
||||
|
||||
One way to add redundancy to your monitoring system is to install standalone monitoring software (as a fallback) at least on any critical/core servers on your network. In case a centralized monitor is down, you will still be able to maintain visibility on your core servers from their backup monitor.
|
||||
|
||||
### What is Monit? ###
|
||||
|
||||
[Monit][3] is a cross-platform open-source tool for monitoring Unix/Linux systems (e.g., Linux, BSD, OSX, Solaris). Monit is extremely easy to install and reasonably lightweight (with only 500KB in size), and does not require any third-party programs, plugins or libraries. Yet, Monit lends itself to full-blown monitoring, capable of process status monitoring, filesystem change monitoring, email notification, customizable actions for core services, and so on. The combination of ease of setup, lightweight implementation and powerful features makes Monit an ideal candidate for a backup monitoring tool.
|
||||
|
||||
I have been using Monit for several years on multiple hosts, and I am very pleased how reliable it has been. Even as a full-blown monitoring system, Monit is very useful and powerful for any Linux admin. In this tutorial, let me demonstrate how to set up Monit on a local server (as a backup monitor) to monitor common services. With this setup, I will only scrach the surface of what Monit can do for us.
|
||||
|
||||
### Installation of Monit on Linux ###
|
||||
|
||||
Most Linux distributions already include Monit in their repositories.
|
||||
|
||||
Debian, Ubuntu or Linux Mint:
|
||||
|
||||
$ sudo aptitude install monit
|
||||
|
||||
Fedora or CentOS/RHEL:
|
||||
|
||||
On CentOS/RHEL, you must enable either [EPEL][4] or [Repoforge][5] repository first.
|
||||
|
||||
# yum install monit
|
||||
|
||||
Monit comes with a very well documented configuration file with a lots of examples. The main configuration file is located in /etc/monit.conf in Fedora/CentOS/RHEL, or /etc/monit/monitrc in Debian/Ubuntu/Mint. Monit configuration has two parts: "Global" and "Services" sections.
|
||||
|
||||
Gl### ###obal Configuration: Web Status Page
|
||||
|
||||
Monit can use several mail servers for notifications, and/or an HTTP/HTTPS status page. Let's start with the web status page with the following requirements.
|
||||
|
||||
- Monit listens on port 1966.
|
||||
- Access to the web status page is encrypted with SSL.
|
||||
- Login requires monituser/romania as user/password.
|
||||
- Login is permitted from localhost, myhost.mydomain.ro, and internal LAN (192.168.0.0/16) only.
|
||||
- Monit stores an SSL certificate in a pem format.
|
||||
|
||||
For subsequent steps, I will use a Red Hat based system. Similar steps will be applicable on a Debian based system.
|
||||
|
||||
First, generate and store a self-signed certificate (monit.pem) in /var/cert.
|
||||
|
||||
# mkdir /var/certs
|
||||
# cd /etc/pki/tls/certs
|
||||
# ./make-dummy-cert monit.pem
|
||||
# cp monit.pem /var/certs
|
||||
# chmod 0400 /var/certs/monit.pem
|
||||
|
||||
Now put the following snippet in the Monit's main configuration file. You can start with an empty configuration file or make a copy of the original file.
|
||||
|
||||
set httpd port 1966 and
|
||||
SSL ENABLE
|
||||
PEMFILE /var/certs/monit.pem
|
||||
allow monituser:romania
|
||||
allow localhost
|
||||
allow 192.168.0.0/16
|
||||
allow myhost.mydomain.ro
|
||||
|
||||
### Global Configuration: Email Notification ###
|
||||
|
||||
Next, let's set up email notification in Monit. We need at least one active [SMTP server][6] which can send mails from the Monit host. Something like the following will do (adjust it for your case):
|
||||
|
||||
- Mail server hostname: smtp.monit.ro
|
||||
- Sender email address used by monit (from): monit@monit.ro
|
||||
- Who will receive mail from monit daemon: guletz@monit.ro
|
||||
- SMTP port used by mail server: 587 (default is 25)
|
||||
|
||||
With the above information, email notification would be configured like this:
|
||||
|
||||
set mailserver smtp.monit.ro port 587
|
||||
set mail-format {
|
||||
from: monit@monit.ro
|
||||
subject: $SERVICE $EVENT at $DATE on $HOST
|
||||
message: Monit $ACTION $SERVICE $EVENT at $DATE on $HOST : $DESCRIPTION.
|
||||
|
||||
Yours sincerely,
|
||||
Monit
|
||||
|
||||
}
|
||||
|
||||
set alert guletz@monit.ro
|
||||
|
||||
As you can see, Monit offers several built-in variables ($DATE, $EVENT, $HOST, etc.), and you can customize your email message for your needs. If you want to send mails from the Monit host itself, you need a sendmail-compatible program (e.g., postfix or ssmtp) already installed.
|
||||
|
||||
### Global Configuration: Monit Daemon ###
|
||||
|
||||
The next part is setting up monit daemon. We will set it up as follows.
|
||||
|
||||
- Performs the first check after 120 seconds.
|
||||
- Checks services once every 3 minutes.
|
||||
- Use syslog for logging.
|
||||
|
||||
Place the following snippet to achieve the above setting.
|
||||
|
||||
set daemon 120
|
||||
with start delay 240
|
||||
set logfile syslog facility log_daemon
|
||||
|
||||
We must also define "idfile", a unique ID used by monit demon, and "eventqueue", a path where mails sent by monit but undelivered due to SMTP/network errors. Verifiy that path (/var/monit) already exists. The following configuration will do.
|
||||
|
||||
set idfile /var/monit/id
|
||||
set eventqueue
|
||||
basedir /var/monit
|
||||
|
||||
### Test Global Configuration ###
|
||||
|
||||
Now the "Global" section is finished. The Monit configuration file will look like this:
|
||||
|
||||
# Global Section
|
||||
|
||||
# status webpage and acl's
|
||||
set httpd port 1966 and
|
||||
SSL ENABLE
|
||||
PEMFILE /var/certs/monit.pem
|
||||
allow monituser:romania
|
||||
allow localhost
|
||||
allow 192.168.0.0/16
|
||||
allow myhost.mydomain.ro
|
||||
|
||||
# mail-server
|
||||
set mailserver smtp.monit.ro port 587
|
||||
# email-format
|
||||
set mail-format {
|
||||
from: monit@monit.ro
|
||||
subject: $SERVICE $EVENT at $DATE on $HOST
|
||||
message: Monit $ACTION $SERVICE $EVENT at $DATE on $HOST : $DESCRIPTION.
|
||||
|
||||
Yours sincerely,
|
||||
Monit
|
||||
|
||||
}
|
||||
|
||||
set alert guletz@monit.ro
|
||||
|
||||
# delay checks
|
||||
set daemon 120
|
||||
with start delay 240
|
||||
set logfile syslog facility log_daemon
|
||||
|
||||
# idfile and mail queue path
|
||||
set idfile /var/monit/id
|
||||
set eventqueue
|
||||
basedir /var/monit
|
||||
|
||||
Now it is time to check what we have done. You can test an existing configuration file (/etc/monit.conf) by running:
|
||||
|
||||
# monit -t
|
||||
|
||||
----------
|
||||
|
||||
Control file syntax OK
|
||||
|
||||
If Monit complains about any error, please review the configuration file again. Fortunately, error/warnings messages are informative. For example:
|
||||
|
||||
monit: Cannot stat the SSL server PEM file '/var/certs/monit.pem' -- No such file or directory
|
||||
/etc/monit/monitrc:10: Warning: hostname did not resolve 'smtp.monit.ro'
|
||||
|
||||
Once you verify the syntax of configuration, start monit daemon, and wait 2 to 3 minutes:
|
||||
|
||||
# service monit start
|
||||
|
||||
If you are using systemd, run:
|
||||
|
||||
# systemctl start monit
|
||||
|
||||
Now open a browser window, and go to https://<monit_host>:1966. Replace &<monit_host> with your Monit hostname or IP address.
|
||||
|
||||
Note that if you have a self-signed SSL certificate, you will see a warning message in your browser.
|
||||
|
||||
![](https://farm8.staticflickr.com/7596/16737206479_96b9f7dfdb_c.jpg)
|
||||
|
||||
After you have completed login, you must see the following page.
|
||||
|
||||
![](https://farm8.staticflickr.com/7594/16303369973_6019482dea_c.jpg)
|
||||
|
||||
In the rest of the tutorial, let me show how we can monitor a local server and common services. You will see a lot of useful examples on the [official wiki page][7]. Most of them are copy-and-pastable!
|
||||
|
||||
### Service Configuration: CPU/Memory Monitoring ###
|
||||
|
||||
Let start with monitoring a local server's CPU/memory usage. Copy the following snippet in the configuration file.
|
||||
|
||||
check system localhost
|
||||
if loadavg (1min) > 10 then alert
|
||||
if loadavg (5min) > 6 then alert
|
||||
if memory usage > 75% then alert
|
||||
if cpu usage (user) > 70% then alert
|
||||
if cpu usage (system) > 60% then alert
|
||||
if cpu usage (wait) > 75% then alert
|
||||
|
||||
You can easily interpret the above configuration. The above checks are performed on local host for every monitoring cycle (which is set to 120 seconds in the Global section). If any condition is met, monit daemon will send an alert with an email.
|
||||
|
||||
If certain properties do not need to be monitored for every cycle, you can use the following format. For example, this will monitor average load every other cycle (i.e., every 240 seconds).
|
||||
|
||||
if loadavg (1min) > 10 for 2 cycles then alert
|
||||
|
||||
### Service Configuration: SSH Service Monitoring ###
|
||||
|
||||
Let's check if we have sshd binary installed in /usr/sbin/sshd:
|
||||
|
||||
check file sshd_bin with path /usr/sbin/sshd
|
||||
|
||||
We also want to check if the init script for sshd exist:
|
||||
|
||||
check file sshd_init with path /etc/init.d/sshd
|
||||
|
||||
Finally, we want to check if sshd daemon is up an running, and listens on port 22:
|
||||
|
||||
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
|
||||
|
||||
More specifically, we can interpret the above configuration as follows. We check if a process named sshd and a pidfile (/var/run/sshd.pid) exist. If either one does not exist, we restart sshd demon using init script. We check if a process listening on port 22 can speak SSH protocol. If not, we restart sshd daemon. If there are at least 5 restarts within the last 5 monitoring cycles (i.e., 5x120 seconds), sshd daemon is declared non-functional, and we do not try to check again.
|
||||
|
||||
![](https://farm9.staticflickr.com/8685/16735725998_62c26a24bc_c.jpg)
|
||||
|
||||
### Service Configuration: SMTP Service Monitoring ###
|
||||
|
||||
Now let's set up a check on a remote SMTP mail server (e.g., 192.168.111.102). Let's assume that the SMTP server is running SMTP, IMAP and SSH on its LAN interface.
|
||||
|
||||
check host MAIL with address 192.168.111.102
|
||||
if failed icmp type echo within 10 cycles then alert
|
||||
if failed port 25 protocol smtp then alert
|
||||
else if recovered then exec "/scripts/mail-script"
|
||||
if failed port 22 protocol ssh then alert
|
||||
if failed port 143 protocol imap then alert
|
||||
|
||||
We check if the remote host responds to ICMP. If we haven't received ICMP response within 10 cycles, we send out an alert. If testing for SMTP protocol on port 25 fails, we send out an alert. If testing succeeds again after a failed test, we run a script (/scripts/mail-script). If testing for SSH and IMAP protocols fail on port 22 and 143, respectively, we send out an alert.
|
||||
|
||||
### Conclusion ###
|
||||
|
||||
In this tutorial, I demonstrate how to set up Monit on a local server. What I showed here is just the tip of the iceberg, as far as Monit's capabilities are concerned. Take your time and read the man page about Monit (a very good one). Monit can do a lot for any Linux admin with a very nice and easy to understand syntax. If you put together a centralized remote monitor and Monit to work for you, you will have a more reliable monitoring system. What is your thought on Monit?
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: http://xmodulo.com/server-monitoring-system-monit.html
|
||||
|
||||
作者:[Iulian Murgulet][a]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:http://xmodulo.com/author/iulian
|
||||
[1]:http://xmodulo.com/monitor-common-services-nagios.html
|
||||
[2]:http://xmodulo.com/monitor-linux-servers-snmp-cacti.html
|
||||
[3]:http://mmonit.com/monit/
|
||||
[4]:http://xmodulo.com/how-to-set-up-epel-repository-on-centos.html
|
||||
[5]:http://xmodulo.com/how-to-set-up-rpmforge-repoforge-repository-on-centos.html
|
||||
[6]:http://xmodulo.com/mail-server-ubuntu-debian.html
|
||||
[7]:http://mmonit.com/wiki/Monit/ConfigurationExamples
|
Loading…
Reference in New Issue
Block a user