{"id":95945,"date":"2020-04-07T00:29:25","date_gmt":"2020-04-06T16:29:25","guid":{"rendered":"http:\/\/4563.org\/?p=95945"},"modified":"2020-04-07T00:29:25","modified_gmt":"2020-04-06T16:29:25","slug":"%e4%bd%bf%e7%94%a8-monit-%e6%9b%bf%e4%bb%a3-supervisor-%e8%87%aa%e5%8a%a8%e5%8c%96%e7%ae%a1%e7%90%86%e5%92%8c%e7%9b%91%e6%8e%a7%e6%9c%8d%e5%8a%a1%e5%b0%8f%e7%bb%93","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=95945","title":{"rendered":"\u4f7f\u7528 Monit \u66ff\u4ee3 Supervisor \u81ea\u52a8\u5316\u7ba1\u7406\u548c\u76d1\u63a7\u670d\u52a1\u5c0f\u7ed3"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  \u4f7f\u7528 Monit \u66ff\u4ee3 Supervisor \u81ea\u52a8\u5316\u7ba1\u7406\u548c\u76d1\u63a7\u670d\u52a1\u5c0f\u7ed3               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : wsgzao <\/span>  <span><i><\/i> 73<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<h2>\u524d\u8a00<\/h2>\n<p>\u5bf9\u4e8e\u8fdb\u7a0b\u7684\u76d1\u63a7\u6700\u5e38\u89c1\u7684\u9700\u6c42\u5c31\u662f\u8fdb\u7a0b\u6302\u4e86\u5982\u4f55\u88ab\u81ea\u52a8\u62c9\u8d77\u6765\uff0c\u73b0\u5728\u53ef\u4ee5\u7531 Kubernetes \u7b49\u5148\u8fdb\u7684\u5bb9\u5668\u5316\u6280\u672f\u6765\u81ea\u52a8\u5316\u7ba1\u7406\uff0c\u90a3\u539f\u6765\u518d\u7269\u7406\u670d\u52a1\u5668\u6216\u8005\u865a\u62df\u673a\u4e2d\u7684\u8fdb\u7a0b\u6709\u4ec0\u4e48\u597d\u7684\u529e\u6cd5\u5462\uff1f\u7b54\u6848\u5c31\u662f Monit\/Supervisor \u7b49\u7b2c\u4e09\u65b9\u5e94\u7528\u6765\u89e3\u51b3\uff0c\u56e0\u4e3a\u7ebf\u4e0a\u73af\u5883\u5206\u522b\u4f7f\u7528 Monit \u6765\u76d1\u63a7 Core Logical Service\uff0cSupervisor \u7528\u5728 Codis Dashboard\/FE\/Proxy \u4e0a\uff0c\u4f7f\u7528\u4e0b\u6765\u7684\u611f\u53d7\u548c\u7f51\u4e0a\u7684\u5bf9\u6bd4\u5206\u6790\u62a5\u544a\u7c7b\u4f3c\uff0c\u5177\u4f53\u5185\u5bb9\u4f1a\u5728\u6587\u7ae0\u5185\u5f15\u7528\uff0c\u63a8\u8350\u5927\u5bb6\u4f7f\u7528 Monit \u66ff\u4ee3 Supervisor \u81ea\u52a8\u5316\u7ba1\u7406\u548c\u76d1\u63a7\u670d\u52a1\u3002<\/p>\n<blockquote>\n<p>\u4f7f\u7528 Monit \u66ff\u4ee3 Supervisor \u81ea\u52a8\u5316\u7ba1\u7406\u548c\u76d1\u63a7\u670d\u52a1\u5c0f\u7ed3<\/p>\n<\/blockquote>\n<h2>\u66f4\u65b0\u5386\u53f2<\/h2>\n<p>2020 \u5e74 01 \u6708 15 \u65e5 &#8211; \u521d\u7a3f<\/p>\n<p>\u9605\u8bfb\u539f\u6587 &#8211; https:\/\/wsgzao.github.io\/post\/monit\/<\/p>\n<p><strong>\u6269\u5c55\u9605\u8bfb<\/strong><\/p>\n<p>Monit Supervisor<\/p>\n<h2>Monit \u4ecb\u7ecd<\/h2>\n<blockquote>\n<p>NAME<\/p>\n<\/blockquote>\n<p>Monit &#8211; utility for monitoring services on a Unix system<\/p>\n<blockquote>\n<p>SYNOPSIS<\/p>\n<\/blockquote>\n<p><strong>monit<\/strong> [options] &lt;arguments&gt;&lt;\/arguments&gt;<\/p>\n<blockquote>\n<p>DESCRIPTION<\/p>\n<\/blockquote>\n<p><strong>Monit<\/strong> is a utility for managing and monitoring processes, programs, files, directories and filesystems on a Unix system. Monit conducts automatic maintenance and repair and can execute meaningful causal actions in error situations. E.g. Monit can start a process if it does not run, restart a process if it does not respond and stop a process if it uses too much resources. You can use Monit to monitor files, directories and filesystems for changes, such as timestamps changes, checksum changes or size changes.<\/p>\n<p>Monit is controlled via an easy to configure control file based on a free-format, token-oriented syntax. Monit logs to syslog or to its own log file and notifies you about error conditions via customisable alert messages. Monit can perform various TCP\/IP network checks, protocol checks and can utilise SSL for such checks. Monit provides a HTTP(S) interface and you may use a browser to access the Monit program.<\/p>\n<blockquote>\n<p>WHAT TO MONITOR?<\/p>\n<\/blockquote>\n<p>You can use Monit to monitor daemon <strong>processes<\/strong> or similar programs running on localhost. Monit is particularly useful for monitoring daemon processes, such as those started at system boot time. For instance sendmail, sshd, apache and mysql. In contrast to many other monitoring systems, Monit can act if an error situation should occur, e.g.; if sendmail is not running, monit can start sendmail again automatically or if apache is using too many resources (e.g. if a DoS attack is in progress) Monit can stop or restart apache and send you an alert message. Monit can also monitor process characteristics, such as how much memory or cpu cycles a process is using.<\/p>\n<p>You can also use Monit to monitor <strong>files<\/strong>, <strong>directories<\/strong> and <strong>filesystems<\/strong> on localhost. Monit can monitor these items for changes, such as timestamps changes, checksum changes or size changes. This is also useful for security reasons &#8211; you can monitor the md5 or sha1 checksum of files that should not change and get an alert or perform an action if they should change.<\/p>\n<p>Monit can monitor <strong>network connections<\/strong> to various servers, either on localhost or on remote hosts. TCP, UDP and Unix Domain Sockets are supported. Network test can be performed on a protocol level; Monit has built-in tests for the main Internet protocols, such as HTTP, SMTP etc. Even if a protocol is not supported you can still test the server because you can configure Monit to send any data and test the response from the server.<\/p>\n<p>Monit can be used to test <strong>programs<\/strong> or scripts at certain times, much like cron, but in addition, you can test the exit value of a program and perform an action or send an alert if the exit value indicates an error. This means that you can use Monit to perform any type of check you can write a script for.<\/p>\n<p>Finally, Monit can be used to monitor general <strong>system<\/strong> resources on localhost such as overall CPU usage, Memory and System Load.<\/p>\n<p>https:\/\/mmonit.com\/monit\/documentation\/monit.html<\/p>\n<h2>Supervisor \u4ecb\u7ecd<\/h2>\n<h1>Supervisor: A Process Control System<\/h1>\n<p> <\/p>\n<p>Supervisor is a client\/server system that allows its users to monitor and control a number of processes on UNIX-like operating systems.<\/p>\n<p>It shares some of the same goals of programs like <em>launchd<\/em>, <em>daemontools<\/em>, and <em>runit<\/em>. Unlike some of these programs, it is not meant to be run as a substitute for init as \u201cprocess id 1\u201d. Instead it is meant to be used to control processes related to a project or a customer, and is meant to start like any other program at boot time.<\/p>\n<p>http:\/\/supervisord.org\/<\/p>\n<h2>Monit VS Supervisor<\/h2>\n<h3>Monit \u662f\u4ec0\u4e48<\/h3>\n<ul>\n<li>Monit \u662f\u4e00\u4e2a\u7ba1\u7406\u548c\u76d1\u63a7 Unix \u7cfb\u7edf\u7684\u5c0f\u578b\u5f00\u6e90\u7ec4\u4ef6.<\/li>\n<li>Monit \u53ef\u4ee5\u5728\u51fa\u73b0\u9519\u8bef\u7684\u60c5\u51b5\u4e0b, \u81ea\u52a8\u7ef4\u62a4, \u4fee\u590d\u548c\u505a\u4e00\u4e9b\u6709\u610f\u4e49\u7684\u884c\u4e3a<\/li>\n<\/ul>\n<h3>\u4e3a\u4ec0\u4e48\u9009\u62e9 Monit<\/h3>\n<p>\u9664\u4e86 Monit \u8fd8\u6709\u4e00\u4e9b\u5176\u4ed6\u7684\u7b2c\u4e09\u65b9\u76d1\u63a7\u65b9\u6848(eg. Supervisor), \u6211\u4eec\u8003\u8651\u9009\u62e9\u989d Monit \u4f5c\u4e3a\u76d1\u63a7\u7684\u539f\u56e0\u6709<\/p>\n<ul>\n<li>\u8d85\u8f7b\u91cf, \u7a33\u5b9a, \u9ad8\u53ef\u7528<\/li>\n<li>\u4f9d\u8d56\u5c11, \u5b89\u88c5\u914d\u7f6e\u65b9\u4fbf, \u5c3d\u91cf\u51cf\u5c11\u8fd0\u7ef4\u53ca\u5b66\u4e60\u6210\u672c(\u5373\u4f7f\u6ca1\u6709\u4efb\u4f55 Monit \u57fa\u7840\u7684\u4eba, \u90fd\u80fd\u8f7b\u6613\u7684\u8bfb\u61c2\u5927\u90e8\u5206\u76d1\u63a7\u6587\u4ef6)<\/li>\n<li>\u975e\u4fb5\u5165\u5f0f, \u88ab\u76d1\u63a7\u7684\u7a0b\u5e8f\u53ef\u4ee5\u4e0d\u7528\u77e5\u9053\u76d1\u63a7\u7a0b\u5e8f\u7684\u5b58\u5728(\u5982\u679c\u4f7f\u7528 Supervisor \u76d1\u63a7, \u5219\u670d\u52a1\u5fc5\u987b\u4ece Supervisor \u542f\u52a8)<\/li>\n<li>\u57fa\u672c\u529f\u80fd\u5b8c\u5907(9 \u79cd\u7c7b\u578b\u76d1\u63a7, \u90ae\u4ef6\u62a5\u8b66, \u652f\u6301\u7528\u6237\u81ea\u5b9a\u4e49 shell \u6269\u5c55)<\/li>\n<\/ul>\n<h3>Supervisor \u4f18\u7f3a\u70b9<\/h3>\n<p><strong>\u4f18\u70b9<\/strong><\/p>\n<ol>\n<li>\u8f7b\u91cf\u3001\u7279\u6027\u4e30\u5bcc\u3001\u5185\u5b58\u53cb\u597d(\u597d\u5ba2\u5957\u7684\u4f18\u70b9\u3002\u3002\u3002)<\/li>\n<li>\u5bf9\u88ab\u76d1\u63a7\u8fdb\u7a0b\u7684\u72b6\u6001\u83b7\u53d6\u8fc5\u901f\u4e14\u7cbe\u786e\u2014\u2014\u901a\u8fc7\u5b50\u8fdb\u7a0b\u7ba1\u7406\uff0c\u6ca1\u529e\u6cd5\u4e0d\u7cbe\u786e<\/li>\n<\/ol>\n<p><strong>\u7f3a\u70b9<\/strong><\/p>\n<ol>\n<li>\u88ab\u76d1\u63a7\u8fdb\u7a0b\u5fc5\u987b\u8fd0\u884c\u5728\u524d\u53f0(\u53ef\u4ee5\u7406\u89e3\u4e3a\u6709\u81ea\u5df1\u7684\u63a7\u5236\u7ec8\u7aef)\u2014\u2014\u8fd9\u4e5f\u662f\u6700\u4e3a\u81f4\u547d\u7684\u4e00\u70b9<\/li>\n<li>\u65e0\u6cd5\u7ba1\u7406\u4f9d\u8d56\uff0c\u4e5f\u5c31\u662f\u8bf4\u65e0\u6cd5\u63a7\u5236\u670d\u52a1\u542f\u52a8\u5148\u540e\u987a\u5e8f<\/li>\n<li>\u65e0\u6cd5\u7ba1\u7406\u88ab\u76d1\u63a7\u8fdb\u7a0b\u521b\u5efa\u7684\u5b50\u8fdb\u7a0b\u2014\u2014\u91cd\u542f\u670d\u52a1\u65f6\u88ab\u76d1\u63a7\u8fdb\u7a0b\u7684\u5b50\u8fdb\u7a0b\u65e0\u6cd5\u6b63\u5e38\u9000\u51fa\uff0c\u9690\u60a3\u5927<\/li>\n<li>\u65e0\u6cd5\u63a7\u5236\u8fdb\u7a0b\u5931\u8d25\u91cd\u8bd5\u7684\u95f4\u9694\u65f6\u95f4\u2014\u2014\u6709\u4e9b\u8fdb\u7a0b\u9700\u8981\u6e05\u7406\u8d44\u6e90\uff0c\u4e0d\u8fc7\u8fd9\u70b9\u8fd8\u597d<\/li>\n<\/ol>\n<h3>Monit \u4f18\u7f3a\u70b9<\/h3>\n<p><strong>\u4f18\u70b9<\/strong><\/p>\n<ol>\n<li>\u5b89\u88c5\u914d\u7f6e\u7b80\u5355\uff0c\u540c\u6837\u8f7b\u91cf(\u4f3c\u4e4e\u4e5f\u662f\u5f88\u5ba2\u5957\u4e86)<\/li>\n<li>\u53ef\u4ee5\u76d1\u63a7\u524d\u53f0\u8fdb\u7a0b\u548c\u975e\u524d\u53f0\u8fdb\u7a0b\u2014\u2014\u5b8c\u7f8e\u7684\u5f25\u8865\u4e86 supervisor \u7684\u81f4\u547d\u7f3a\u70b9<\/li>\n<li>\u9664\u4e86\u76d1\u63a7\u8fdb\u7a0b\u8fd8\u80fd\u76d1\u63a7\u6587\u4ef6\u3001\u6587\u4ef6\u7cfb\u7edf\uff0c\u751a\u81f3\u7cfb\u7edf\u8d44\u6e90\uff0cCPU \u5229\u7528\u7387\uff0c\u5185\u5b58\u4f7f\u7528\u4e5f\u662f\u53ef\u4ee5\u7684<\/li>\n<li>\u88ab\u76d1\u63a7\u7684\u8fdb\u7a0b\u53ef\u4ee5\u8bbe\u7f6e\u4f9d\u8d56\uff0c\u63a7\u5236\u542f\u52a8\u987a\u5e8f<\/li>\n<\/ol>\n<p><strong>\u7f3a\u70b9<\/strong><\/p>\n<ol>\n<li>\u65e0\u6cd5\u76d1\u63a7\u6ca1\u6709 pid \u6587\u4ef6\u7684\u8fdb\u7a0b\uff0c\u5982 shell \u811a\u672c<\/li>\n<li>\u5bf9\u8fdb\u7a0b\u76d1\u63a7\u7684\u72b6\u6001\u611f\u77e5\u6709\u5ef6\u65f6\uff0c\u5373\u7cbe\u5ea6\u4e0d\u591f\u2014\u2014\u91c7\u7528\u8f6e\u8bad\u51b3\u5b9a\u4e86\u5b83\u65e0\u6cd5\u50cf supervisor \u4e00\u6837\u5b9e\u65f6\u611f\u77e5\u88ab\u76d1\u63a7\u8fdb\u7a0b\u72b6\u6001<\/li>\n<\/ol>\n<p>\u8fd9\u6837\u770b\u8d77\u6765\u8fd8\u662f monit \u66f4\u4e3a\u666e\u9002\u4e00\u70b9\u3002<\/p>\n<p>\u4e0d\u8fc7\u8fd9\u50ac\u751f\u4e86\u4e00\u4e2a\u5927\u80c6\u7684\u60f3\u6cd5\uff0c\u4f7f\u7528 supervisor \u7ba1\u7406\u5bb9\u5668\u5185\u591a\u8fdb\u7a0b\uff0cmonit \u4f5c\u4e3a\u4e00\u4e2a\u88ab\u76d1\u63a7\u8fdb\u7a0b\u6302\u5728 supervisor \u4e4b\u4e0b\u3002\u8fd9\u6837\u5bf9\u4e8e\u65e0\u6cd5\u524d\u53f0\u8fd0\u884c\u7684\u7a0b\u5e8f\uff0c\u5c31\u53ef\u4ee5\u901a\u8fc7 monit \u76d1\u63a7\uff0c\u800c\u5bf9\u670d\u52a1\u4e2d\u65ad\u611f\u77e5\u5f3a\u70c8\u7684\u5219\u76f4\u63a5\u6302\u5728 supervisor \u4e4b\u4e0b\u3002\u770b\u8d77\u6765\u4f3c\u4e4e\u662f\u4e2a\u597d\u529e\u6cd5\uff0c\u6709\u673a\u4f1a\u8bd5\u8bd5\uff0c\u54c8\u54c8\u54c8\u3002<\/p>\n<p>\u4ece\u5b9e\u9645\u5bb9\u5668\u4e2d\u8fd0\u884c\u7684\u8868\u73b0\u770b\uff0cmonit \u7ecf\u5e38\u51fa\u73b0\u5404\u79cd\u672a\u77e5\u5f02\u5e38\uff0c\u800c supervisor \u8868\u73b0\u5f97\u5341\u5206\u7a33\u5b9a\u3002<\/p>\n<h2>Monit \u57fa\u672c\u7528\u6cd5<\/h2>\n<h3>Monit \u5e38\u7528\u547d\u4ee4<\/h3>\n<pre><code># monit -h Usage: monit [options]+ [command] Options are as follows:  -c file       Use this control file  -d n          Run as a daemon once per n seconds  -g name       Set group name for monit commands  -l logfile    Print log information to this file  -p pidfile    Use this lock file in daemon mode  -s statefile  Set the file monit should write state information to  -I            Do not run in background (needed when run from init)  --id          Print Monit's unique ID  --resetid     Reset Monit's unique ID. Use with caution  -B            Batch command line mode (do not output tables or colors)  -t            Run syntax check for the control file  -v            Verbose mode, work noisy (diagnostic output)  -vv           Very verbose mode, same as -v plus log stacktrace on error  -H [filename] Print SHA1 and MD5 hashes of the file or of stdin if the                filename is omited; monit will exit afterwards  -V            Print version number and patchlevel  -h            Print this text Optional commands are as follows:  start all             - Start all services  start &lt;name&gt;          - Only start the named service  stop all              - Stop all services  stop &lt;name&gt;           - Stop the named service  restart all           - Stop and start all services  restart &lt;name&gt;        - Only restart the named service  monitor all           - Enable monitoring of all services  monitor &lt;name&gt;        - Only enable monitoring of the named service  unmonitor all         - Disable monitoring of all services  unmonitor &lt;name&gt;      - Only disable monitoring of the named service  reload                - Reinitialize monit  status [name]         - Print full status information for service(s)  summary [name]        - Print short status information for service(s)  report [up|down|..]   - Report state of services. See manual for options  quit                  - Kill the monit daemon process  validate              - Check all services and start if not running  procmatch &lt;pattern&gt;   - Test process matching pattern  <\/code><\/pre>\n<p>\u60f3\u8981\u8ba9 Monit \u53ef\u9760\u7684\u4e3a\u6211\u4eec\u5de5\u4f5c, \u5b66\u4e60\u6210\u672c\u975e\u5e38\u4f4e, \u53ea\u9700\u8981\u5b66\u4e60\u4e00\u4e9b Monit \u547d\u4ee4\u884c\u548c\u914d\u7f6e\u6587\u4ef6\u5199\u6cd5<\/p>\n<pre><code># options - \u9009\u9879 - monit - monit -t - monit -c \/var\/monit\/monitrc  # \u6307\u5b9a\u914d\u7f6e\u6587\u4ef6 - monit -g &lt;groupname&gt; start\/stop # Monit \u53ef\u4ee5\u5bf9\u5404\u4e2a\u76d1\u63a7\u5206\u7ec4, \u5982\u679c\u9700\u8981\u5bf9\u67d0\u4e2a\u5206\u7ec4\u7edf\u4e00\u64cd\u4f5c, \u53ef\u4ee5\u7528\u8fd9\u4e2a\u547d\u4ee4  # arguments - \u53c2\u6570 - monit reload - monit quit - monit start\/stop\/restart\/monitor\/unmonitor &lt;name&gt;\/all  # &lt;name&gt;: \u6bcf\u4e2a\u76d1\u63a7\u90fd\u6709\u4e00\u4e2a\u72ec\u4e00\u65e0\u4e8c\u7684\u540d\u5b57, \u5177\u4f53\u540e\u9762\u4f1a\u63d0\u5230; all: \u6240\u6709\u76d1\u63a7\u670d\u52a1 <\/code><\/pre>\n<h3>Monit \u670d\u52a1\u76d1\u63a7\u914d\u7f6e\u6587\u4ef6\u683c\u5f0f<\/h3>\n<p>\u8be6\u7ec6\u914d\u7f6e, \u5171\u8ba1 9 \u79cd, \u6240\u6709\u914d\u7f6e\u4e2d, \u90fd\u7b26\u5408\u4ee5\u4e0b\u89c4\u5219<\/p>\n<ul>\n<li>\u5982\u679c\u6307\u5b9a\u7684 path \u4e0d\u5b58\u5728, \u800c\u4e14\u914d\u7f6e\u5757\u91cc\u5305\u542b start \u65b9\u6cd5, \u4f1a\u8c03\u7528\u8fd9\u4e2a start \u65b9\u6cd5<\/li>\n<li>\u5982\u679c path \u6307\u5b9a\u7684\u6587\u4ef6\u7c7b\u578b\u4e0d\u5bf9, Monit \u4e0d\u80fd\u76d1\u63a7\u8fd9\u4e2a\u9879\u76ee<\/li>\n<\/ul>\n<blockquote>\n<ol>\n<li>Process<\/li>\n<\/ol>\n<\/blockquote>\n<pre><code>CHECK PROCESS &lt;unique name&gt; &lt;PIDFILE &lt;path&gt; | MATCHING &lt;regex&gt;&gt;  &lt;path&gt; pid-file \u7684\u7edd\u5bf9\u8def\u5f84. \u4e0d\u5b58\u5728 pid-file \u6587\u4ef6\u6216\u8005 pid-file \u6587\u4ef6\u6ca1\u6709\u5bf9\u5e94\u7684\u6b63\u5728\u8fd0\u884c\u7684\u7a0b\u5e8f, Monit \u4f1a\u6267\u884c start \u65b9\u6cd5  &lt;regex&gt; \u8fdb\u7a0b\u540d\u79f0\u7684\u6b63\u5219\u8868\u8fbe\u6765\u76d1\u63a7\u8fdb\u7a0b, \u53ef\u4ee5\u901a\u8fc7\u547d\u4ee4\u884c\u6d4b\u8bd5\u6b63\u5219\u662f\u5426\u5199\u5bf9\u4e86: monit procmatch \"regex-pattern\" <\/code><\/pre>\n<blockquote>\n<ol>\n<li>File<\/li>\n<\/ol>\n<\/blockquote>\n<pre><code>CHECK FILE &lt;unique name&gt; PATH &lt;path&gt;  &lt;path&gt; file \u7684\u7edd\u5bf9\u8def\u5f84. <\/code><\/pre>\n<blockquote>\n<ol>\n<li>Fifo<\/li>\n<\/ol>\n<\/blockquote>\n<pre><code>CHECK FIFO &lt;unique name&gt; PATH &lt;path&gt; &lt;path&gt; fifo \u7684\u7edd\u5bf9\u8def\u5f84. <\/code><\/pre>\n<blockquote>\n<ol>\n<li>Filesystem<\/li>\n<\/ol>\n<\/blockquote>\n<pre><code>CHECK FILESYSTEM &lt;unique name&gt; PATH &lt;path&gt; &lt;path&gt; \u8bbe\u5907 \/\u78c1\u76d8, \u6302\u8f7d\u70b9\u7684\u8def\u5f84 \u6216 NFS\/CIFS\/FUSE \u94fe\u63a5\u5b57\u7b26\u4e32. \u5982\u679c\u6587\u4ef6\u7cfb\u7edf\u4e0d\u53ef\u7528, Monit \u4f1a\u6267\u884c start \u65b9\u6cd5 <\/code><\/pre>\n<blockquote>\n<ol>\n<li>Directory<\/li>\n<\/ol>\n<\/blockquote>\n<pre><code>CHECK DIRECTORY &lt;unique name&gt; PATH &lt;path&gt;  &lt;path&gt; \u76ee\u5f55\u95ee\u4ef7\u7684\u7edd\u5bf9\u8def\u5f84 <\/code><\/pre>\n<blockquote>\n<ol>\n<li>Remote host<\/li>\n<\/ol>\n<\/blockquote>\n<pre><code>CHECK HOST &lt;unique name&gt; ADDRESS &lt;host&gt;  &lt;host&gt; \u53ef\u4ee5\u662f\u57df\u540d\u6216\u8005 IP \u5730\u5740. eg: \"tildeslash.com\" or \"64.87.72.95\". <\/code><\/pre>\n<blockquote>\n<ol>\n<li>System<\/li>\n<\/ol>\n<\/blockquote>\n<pre><code>CHECK SYSTEM &lt;unique name&gt;  &lt;unique name&gt; \u901a\u5e38\u6765\u8bf4\u662f\u672c\u673a\u540d\u79f0(\u53ef\u4ee5\u7528 $HOST), \u4e5f\u53ef\u4ee5\u662f\u5176\u4ed6\u540d\u79f0. \u7528\u4e8e\u90ae\u4ef6\u62a5\u8b66\u6216\u8005 M\/Monit \u7684\u521d\u59cb\u5316\u540d\u79f0 \u8fd9\u7c7b\u914d\u7f6e\u53ef\u4ee5\u76d1\u63a7\u7cfb\u7edf\u8d44\u6e90(CPU, memory, load average...) <\/code><\/pre>\n<blockquote>\n<ol>\n<li>Program<\/li>\n<\/ol>\n<\/blockquote>\n<pre><code>CHECK PROGRAM &lt;unique name&gt; PATH &lt;executable file&gt; [TIMEOUT &lt;number&gt; SECONDS]  &lt;path&gt; \u53ef\u6267\u884c\u7a0b\u5e8f\u6216\u811a\u672c\u7684\u7edd\u5bf9\u8def\u5f84. \u5141\u8bb8\u68c0\u67e5\u7a0b\u5e8f\u9000\u51fa\u72b6\u6001.\u5982\u679c\u7a0b\u5e8f\u6ca1\u80fd\u5728 &lt;number&gt; \u79d2\u5185\u6267\u884c\u5b8c\u6210, Monit \u4f1a\u7ec8\u7ed3\u8fd9\u4e2a\u7a0b\u5e8f, \u9ed8\u8ba4\u662f 300s \u7a0b\u5e8f\u7684\u8f93\u51fa\u4f1a\u88ab\u8bb0\u5f55, \u7528\u4e8e\u7528\u6237\u754c\u9762\u6216\u8005\u62a5\u8b66, \u9ed8\u8ba4 512 bytes(\u53ef\u4ee5\u901a\u8fc7 set limits \u4fee\u6539) <\/code><\/pre>\n<blockquote>\n<ol>\n<li>Network<\/li>\n<\/ol>\n<\/blockquote>\n<pre><code>CHECK NETWORK &lt;unique name&gt; &lt;ADDRESS &lt;ipaddress&gt; | INTERFACE &lt;name&gt;&gt;  # &lt;ipaddress&gt; \u662f\u88ab\u76d1\u63a7\u7684 IPv4\/IPv6 \u7f51\u5361\u5730\u5740. \u7528 eth0 \u4e5f\u662f\u53ef\u4ee5\u7684 <\/code><\/pre>\n<p>\u66f4\u591a\u914d\u7f6e\u4fe1\u606f\u53ef\u4ee5\u53c2\u8003 Monit \u5b98\u65b9\u6587\u6863\u548c\u5b9e\u4f8b<\/p>\n<p>https:\/\/mmonit.com\/documentation\/<\/p>\n<p>https:\/\/mmonit.com\/wiki\/Monit\/ConfigurationExamples<\/p>\n<h2>Monit \u914d\u7f6e\u5b9e\u8df5<\/h2>\n<ol>\n<li>\u521b\u5efa templates \u6a21\u677f\uff0c\u5229\u7528 python \u751f\u6210 monit \u914d\u7f6e\u6587\u4ef6<\/li>\n<li>\u4f7f\u7528 ansible \u63a8\u9001\u5230\u76ee\u6807\u670d\u52a1\u5668\u4e2d<\/li>\n<\/ol>\n<pre><code># \u521b\u5efa\u901a\u7528\u914d\u7f6e\uff0c\u914d\u7f6e\u65e5\u5fd7\uff0c\u90ae\u4ef6\u544a\u8b66 vim basic.j2  # log to monit.log set logfile \/var\/log\/monit.log  set daemon {{ monit_poll_interval }}  set eventqueue basedir \/var\/lib\/monit\/events slots 5000  set mailserver smtp.xxx.com port 465  set alert [email&#160;protected] { nonexist, timeout, resource }  set mail-format {   from: [email&#160;protected]   subject: monit alert -- $SERVICE $EVENT at $DATE   message: $EVENT Service $SERVICE                 Date:        $DATE                 Action:      $ACTION                 Host:        $HOST                 Description: $DESCRIPTION             Your faithful employee,            Monit }  # \u521b\u5efa\u6807\u51c6\u5e94\u7528\u76d1\u63a7 vim daemon_set.j2  check process xxx with pidfile \/run\/xxx\/daemon.pid     start program = \"\/usr\/bin\/python2  \/bin\/xxx restart\"     stop program = \"\/usr\/bin\/python2 \/bin\/xxx stop\"      if 10 restarts within 10 cycles then unmonitor  check process xxxx with matching xxxx  start program = \"\/etc\/init.d\/xxxx start\"  stop program = \"\/etc\/init.d\/xxxx stop\"      if 10 restarts within 10 cycles then unmonitor  # \u521b\u5efa\u975e\u6807\u51c6\u5e94\u7528\u76d1\u63a7 vim logic_service.j2  check process {{ service_name }} with pidfile {{ root_dir }}\/{{ service_name }}\/deploy\/{{ monit_name }}.pid     start program = \"\/bin\/bash -c 'cd {{ root_dir }}\/{{ service_name }}\/deploy &amp;&amp; .\/start.sh &amp;&gt;start.log '\"     stop program = \"\/bin\/bash -c 'cd {{ root_dir }}\/{{ service_name }}\/deploy &amp;&amp; .\/stop.sh &amp;&gt;stop.log '\"      if 5 restarts within 15 cycles then unmonitor     {% if memory_usage is defined %}     if total memory usage &gt; {{ memory_usage }} for 10 cycles then restart     {% endif %}  <\/code><\/pre>\n<h2>\u53c2\u8003\u6587\u7ae0<\/h2>\n<p>Monit Document<\/p>\n<p>Monit \u7b14\u8bb0<\/p>\n<p>Docker \u5bb9\u5668\u5185\u591a\u8fdb\u7a0b\u7ba1\u7406\u2014\u2014supervisor VS monit<\/p>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>7<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"843302\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : GM <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u4e0d\u660e\u767d\uff0c\u65e2\u7136 [monit \u7ecf\u5e38\u51fa\u73b0\u5404\u79cd\u672a\u77e5\u5f02\u5e38\uff0c\u800c supervisor \u8868\u73b0\u5f97\u5341\u5206\u7a33\u5b9a] \uff0c\u4f60\u8fd8 [\u4f7f\u7528 Monit \u66ff\u4ee3 Supervisor ] \uff1f                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"843303\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : julyclyde <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             systemd \u51fa\u6765\u4e4b\u540e\uff0cmoni\u3001supervisor\u3001daemontools \u4e4b\u7c7b\u7684\u9010\u6e10\u6210\u4e86\u5c60\u9f99\u4e4b\u6280\u4e86<br \/>\u5509                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"843304\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : defunct9 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             monit \u4f3c\u4e4e\u6d3e\u751f\u51fa\u6765\u7684\u5b50\u8fdb\u7a0b\u5b8c\u5168\u6ca1\u6709\u7ee7\u627f\u73af\u5883\u53d8\u91cf                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"843305\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : wellsc <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             systemd \u4e0d\u9999\u5417                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"843306\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : wsgzao <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @GM #1 \u9700\u6c42\u573a\u666f\u4e0d\u4e00\u6837\uff0c\u4e24\u8005\u4f60\u90fd\u53ef\u4ee5\u8bd5\u8bd5\uff0c\u65f6\u95f4\u957f\u4e86\u5e94\u8be5\u5c31\u53ef\u4ee5\u66f4\u597d\u7684\u7406\u89e3\u4f18\u7f3a\u70b9<br \/>@julyclyde \u7b97\u662f\u521a\u9700\u5427\uff0c\u8981\u4e0d\u7136\u5c31 All in K8S<br \/>@defunct9 \u6ca1\u6709\u6ce8\u610f\u8fc7\u8fd9\u4e2a\u95ee\u9898\uff0c\u53ef\u4ee5\u6d4b\u8bd5\u9a8c\u8bc1\u4e0b                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"843307\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : zhchyu999 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             systemd \u4e0d\u5e26\u7cfb\u7edf\u53d8\u91cf\u8fdb\u53bb                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"843308\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : wsgzao <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @wellsc #4 \u5f15\u7528\u4e00\u7bc7\u6587\u7ae0\u7b54\u590d\uff0chttps:\/\/blog.huoding.com\/2015\/02\/11\/419<\/p>\n<p>\u6709\u65f6\u5019\uff0c\u8fdb\u7a0b\u7a81\u7136\u7ec8\u6b62\u670d\u52a1\uff0c\u53ef\u80fd\u662f\u6ca1\u6709\u8d44\u6e90\u4e86\uff0c\u4e5f\u53ef\u80fd\u662f\u610f\u5916\uff0c\u6bd4\u5982\u8bf4\uff1a\u56e0\u4e3a OOM \u88ab\u6740\uff1b\u6216\u8005\u7531\u4e8e BUG \u5bfc\u81f4\u5d29\u6e83\uff1b\u4ea6\u6216\u8005\u8bef\u64cd\u4f5c\u7b49\u7b49\uff0c\u6b64\u65f6\uff0c\u6211\u4eec\u9700\u8981\u91cd\u65b0\u542f\u52a8\u8fdb\u7a0b\u3002<\/p>\n<p>\u5b9e\u9645\u4e0a\uff0cLinux \u672c\u8eab\u7684\u521d\u59cb\u5316\u7cfb\u7edf\u80fd\u5b9e\u73b0\u7b80\u5355\u7684\u529f\u80fd\uff0c\u65e0\u8bba\u662f\u8001\u724c\u7684 SysVinit\uff0c\u8fd8\u662f\u65b0\u6f6e\u7684 Upstart \u6216\u8005 Systemd \u5747\u53ef\uff0c\u4f46\u5b83\u4eec\u5e76\u4e0d\u9002\u5408\u5904\u7406\u4e00\u4e9b\u590d\u6742\u7684\u60c5\u51b5\uff0c\u6bd4\u5982\u8bf4\uff1aCPU \u5360\u7528\u8d85\u8fc7\u591a\u5c11\u5c31\u91cd\u542f\uff1b\u6216\u8005\u540c\u65f6\u7ba1\u7406 100 \u4e2a PHP \u5b9e\u73b0\u7684 Worker \u8fdb\u7a0b\u7b49\u7b49\uff0c\u5982\u679c\u4f60\u6709\u7c7b\u4f3c\u7684\u9700\u6c42\uff0c\u90a3\u4e48\u53ef\u4ee5\u8003\u8651\u8bd5\u8bd5 Monit \u548c Supervisor\uff0c\u76f8\u4fe1\u4f1a\u6709\u4e0d\u4e00\u6837\u7684\u611f\u53d7\u3002<\/p>\n<p>\u8ba9\u6211\u4eec\u770b\u770b Monit \u7684\u7528\u6cd5\uff0c\u5047\u8bbe\u6211\u4eec\u8981\u76d1\u63a7 Nginx \u8fdb\u7a0b\uff0c\u4e00\u65e6\u5176 CPU \u4f7f\u7528\u7387\u8fde\u7eed 5 \u6b21\u8f6e\u8be2\u5468\u671f\u91cc\u5747\u8d85\u8fc7 50% \u7684\u8bdd\uff0c\u5c31\u91cd\u542f\u8fdb\u7a0b\uff0c\u6b64\u65f6\u5c31\u53ef\u4ee5\u6309\u7167\u5982\u4e0b\u65b9\u5f0f\u8bbe\u7f6e\uff1a<\/p>\n<p>check process nginx with pidfile \/var\/run\/nginx.pid<br \/> start program = &#8220;\/etc\/init.d\/nginx start&#8221;<br \/> stop program = &#8220;\/etc\/init.d\/nginx stop&#8221;<br \/> if cpu is greater than 50% for 5 cycles then restart<br \/>Monit \u6839\u636e pidfile \u8f6e\u8be2\u5bf9\u5e94\u7684\u8fdb\u7a0b\u662f\u5426\u5065\u5728\uff0c\u6ee1\u8db3\u6761\u4ef6\u5c31\u6267\u884c start\/stop \u7b49\u64cd\u4f5c\u3002\u5982\u679c\u8fdb\u7a0b\u672c\u8eab\u4e0d\u5b58\u5728 pidfile\uff0c\u90a3\u4e48\u4e5f\u53ef\u4ee5\u4f7f\u7528 matching \u8bed\u6cd5\u6765\u5339\u914d\u8fdb\u7a0b\u3002<\/p>\n<p>\u518d\u8ba9\u6211\u4eec\u770b\u770b Supervisor \u7684\u7528\u6cd5\uff0c\u5047\u8bbe\u6211\u4eec\u8981\u76d1\u63a7 100 \u4e2a PHP \u5b9e\u73b0\u7684 Worker \u8fdb\u7a0b\uff0c\u7528\u6765\u63d0\u4f9b Gearman \u4e4b\u7c7b\u7684\u670d\u52a1\uff0c\u7531\u4e8e PHP \u672c\u8eab\u8fd0\u884c\u6a21\u5f0f\u7684\u7f18\u6545\uff0c\u4e3a\u4e86\u907f\u514d\u4e25\u91cd\u7684\u5185\u5b58\u6cc4\u6f0f\u95ee\u9898\uff0c\u6211\u4eec\u8bbe\u5b9a PHP \u8fdb\u7a0b\u670d\u52a1\u4e00\u5b9a\u6b21\u6570\u6216\u4e00\u6bb5\u65f6\u95f4\u540e\u5c31\u81ea\u52a8\u9000\u51fa\uff0c\u8fd9\u65f6\u5019\u6211\u4eec\u9700\u8981\u542f\u52a8\u65b0\u7684 Worker \u8fdb\u7a0b\uff0c\u4ee5\u4fbf\u603b\u6570\u7ef4\u6301\u4e0d\u53d8\uff0c\u6b64\u65f6\u5c31\u53ef\u4ee5\u6309\u7167\u5982\u4e0b\u65b9\u5f0f\u8bbe\u7f6e\uff1a<\/p>\n<p>[program:worker]<br \/>command=\/usr\/bin\/php \/path\/to\/worker.php<br \/>process_name=%(program_name)s_%(process_num)02d<br \/>numprocs=100<br \/>autostart=true<br \/>autorestart=true<br \/>\u5982\u679c\u8bf4 Supervisor \u6709\u4ec0\u4e48\u7f3a\u70b9\u7684\u8bdd\uff0c\u90a3\u4e48\u9996\u5f53\u5176\u51b2\u7684\u662f\u5bf9\u4f7f\u7528\u8005\u800c\u8a00\u5b83\u4e0d\u591f\u900f\u660e\uff1a\u5f88\u591a\u8fdb\u7a0b\u90fd\u662f\u540e\u53f0\u8fd0\u884c\u7684\uff0c\u4f46 Supervisor \u5374\u8981\u6c42\u5fc5\u987b\u6539\u6210\u524d\u53f0\u8fd0\u884c\u3002\u597d\u5728\u591a\u6570\u670d\u52a1\u90fd\u63d0\u4f9b\u4e86\u5bf9\u5e94\u7684\u914d\u7f6e\u9009\u9879\uff0c\u5982\u679c\u6ca1\u6709\u7684\u8bdd\uff0c\u6211\u4eec\u4e5f\u53ef\u4ee5\u4f7f\u7528\u4e00\u4e9b\u53d8\u901a\u7684\u65b9\u6cd5\uff1a<\/p>\n<p>How can I supervise a daemon that puts itself into the background?<br \/>Managing daemons with supervisor: no foreground mode available.<br \/>\u4e0d\u7ba1\u7528\u4ec0\u4e48\u6765\u76d1\u63a7\u8fdb\u7a0b\uff0c\u5982\u679c\u76d1\u63a7\u8005\u672c\u8eab\u6302\u4e86\uff0c\u90a3\u4e48\u88ab\u76d1\u63a7\u8005\u65e0\u7591\u5c31\u5931\u63a7\u4e86\u3002\u6b64\u65f6\u9700\u8981\u8003\u8651\u5982\u4f55\u76d1\u63a7\u76d1\u63a7\u8005\u672c\u8eab\uff0c\u8fd9\u4f3c\u4e4e\u662f\u4e00\u4e2a\u9012\u5f52\u95ee\u9898\uff0c\u4e0d\u8fc7\u6587\u7ae0\u5f00\u5934\u6211\u4eec\u8bf4\u8fc7\uff0cLinux \u672c\u8eab\u7684\u521d\u59cb\u5316\u7cfb\u7edf\u5c31\u80fd\u5b9e\u73b0\u7b80\u5355\u7684\u76d1\u63a7\u529f\u80fd\uff0c\u4ee5 SysVinit \u4e3a\u4f8b\uff0c\u7f16\u8f91 \/etc\/inittab \u6587\u4ef6\uff1a<\/p>\n<p>SU:2345:respawn:\/usr\/bin\/supervisord -c \/etc\/supervisord.conf<br \/>\u6539\u597d\u540e\u8fd0\u884c\u300c init q \u300d\u547d\u4ee4\u8ba9\u5176\u751f\u6548\uff0c\u7136\u540e kill \u6389 supervisor \u8fdb\u7a0b\u770b\u770b\u4f1a\u4e0d\u4f1a\u53d1\u751f\u5947\u8ff9\u3002<\/p>\n<p>\u6ce8\u610f\uff1a\u8bb0\u5f97\u4e8b\u5148\u6211\u4eec\u8981\u914d\u7f6e Supervisor \u4e3a nodaemon=true \u5662\u3002                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>\u4f7f\u7528 Monit \u66ff\u4ee3 Super&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/95945"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=95945"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/95945\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=95945"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=95945"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=95945"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}