{"id":53,"date":"2020-07-17T16:10:38","date_gmt":"2020-07-17T08:10:38","guid":{"rendered":"http:\/\/blog.gamekingtao.top\/?p=53"},"modified":"2020-07-17T16:15:02","modified_gmt":"2020-07-17T08:15:02","slug":"%e5%88%a9%e7%94%a8supervisor%e7%ae%a1%e7%90%86redis%e8%bf%9b%e7%a8%8b%e7%9a%84%e6%96%b9%e6%b3%95%e6%95%99%e7%a8%8b","status":"publish","type":"post","link":"https:\/\/blog.gamekingtao.top\/index.php\/2020\/07\/17\/%e5%88%a9%e7%94%a8supervisor%e7%ae%a1%e7%90%86redis%e8%bf%9b%e7%a8%8b%e7%9a%84%e6%96%b9%e6%b3%95%e6%95%99%e7%a8%8b\/","title":{"rendered":"\u5229\u7528Supervisor\u7ba1\u7406Redis\u8fdb\u7a0b\u7684\u65b9\u6cd5\u6559\u7a0b\u53ca\u5f00\u673a\u81ea\u542f\u52a8"},"content":{"rendered":"<p><strong>\u524d\u8a00<\/strong><\/p>\n<p>Supervisor \u662f\u4e00\u4e2a\u7528 Python \u5b9e\u73b0\u7684\u8fdb\u7a0b\u7ba1\u7406\u5de5\u5177\uff0c\u53ef\u4ee5\u5f88\u65b9\u4fbf\u5730\u542f\u52a8\uff0c\u5173\u95ed\uff0c\u91cd\u542f\uff0c\u67e5\u770b\uff0c\u4ee5\u53ca\u76d1\u63a7\u8fdb\u7a0b\uff0c\u5f53\u8fdb\u7a0b\u7531\u4e8e\u67d0\u79cd\u539f\u56e0\u5d29\u6e83\u6216\u8005\u88ab\u8bef\u6740\u540e\uff0c\u53ef\u4ee5\u81ea\u52a8\u91cd\u542f\u5e76\u53d1\u9001\u4e8b\u4ef6\u901a\u77e5\u3002Supervisor \u53ef\u8c13\u8fd0\u7ef4\u5229\u5668\uff0c\u4f7f\u7528 Supervisor \u6765\u7ba1\u7406\u8fdb\u7a0b\uff0c\u53ef\u4ee5\u63d0\u9ad8\u7cfb\u7edf\u7684\u9ad8\u53ef\u7528\u7279\u6027\u3002<\/p>\n<p>\u968f\u7740 Redis \u8d8a\u6765\u8d8a\u6d41\u884c\uff0c\u8d8a\u6765\u8d8a\u591a\u7684\u516c\u53f8\u90fd\u4f7f\u7528\u4e0a\u4e86 redis\uff0c\u56e0\u6b64 Redis \u7684\u8fdb\u7a0b\u7ba1\u7406\u5c31\u6210\u4e86\u5f88\u591a\u516c\u53f8\u90fd\u9700\u8981\u9762\u4e34\u7684\u95ee\u9898\uff0c\u672c\u6587\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528 Supervisor \u6765\u7ba1\u7406 Redis \u8fdb\u7a0b\u3002<\/p>\n<p><strong>Supervisor \u7b80\u4ecb<\/strong><\/p>\n<p>Supervisor \u5305\u62ec\u4ee5\u4e0b\u56db\u4e2a\u7ec4\u4ef6\u3002<\/p>\n<p><strong>1\u3001supervisord<\/strong><\/p>\n<p>\u670d\u52a1\u7aef\u7a0b\u5e8f\uff0c\u4e3b\u8981\u529f\u80fd\u662f\u542f\u52a8 supervisord \u670d\u52a1\u53ca\u5176\u7ba1\u7406\u7684\u5b50\u8fdb\u7a0b\uff0c\u8bb0\u5f55\u65e5\u5fd7\uff0c\u91cd\u542f\u5d29\u6e83\u7684\u5b50\u8fdb\u7a0b\uff0c\u7b49\u3002<\/p>\n<p><strong>2\u3001supervisorctl<\/strong><\/p>\n<p>\u547d\u4ee4\u884c\u5ba2\u6237\u7aef\u7a0b\u5e8f\uff0c\u5b83\u63d0\u4f9b\u4e00\u4e2a\u7c7b\u4f3c shell \u7684\u63a5\u53e3\uff0c\u901a\u8fc7 UNIX \u57df\u5957\u63a5\u5b57\u6216\u8005 TCP \u5957\u63a5\u5b57\u5e76\u4f7f\u7528 XML_RPC \u534f\u8bae\u4e0e supervisord \u8fdb\u7a0b\u8fdb\u884c\u6570\u636e\u901a\u4fe1\u3002\u5b83\u7684\u4e3b\u8981\u529f\u80fd\u662f\u7ba1\u7406\uff08\u542f\u52a8\uff0c\u5173\u95ed\uff0c\u91cd\u542f\uff0c\u67e5\u770b\u72b6\u6001\uff09\u5b50\u8fdb\u7a0b\u3002<\/p>\n<p><strong>3\u3001Web Server<\/strong><\/p>\n<p>\u5b9e\u73b0\u5728\u754c\u9762\u4e0a\u7ba1\u7406\u8fdb\u7a0b\uff0c\u8fd8\u80fd\u67e5\u770b\u8fdb\u7a0b\u65e5\u5fd7\u548c\u6e05\u9664\u65e5\u5fd7\u3002<\/p>\n<p><strong>4\u3001XML-RPC \u63a5\u53e3<\/strong><\/p>\n<p>\u53ef\u4ee5\u901a\u8fc7 XML_RPC \u534f\u8bae\u5bf9 supervisord \u8fdb\u884c\u8fdc\u7a0b\u7ba1\u7406\uff0c\u8fbe\u5230\u548c supervisorctl \u4ee5\u53ca Web Server \u4e00\u6837\u7684\u7ba1\u7406\u529f\u80fd\u3002<\/p>\n<p>\u8fdb\u7a0b\u88ab Supervisor \u7ba1\u7406\u540e\uff0c\u5176\u8fd0\u884c\u72b6\u6001\u7684\u8f6c\u5316\u56fe\u5982\u4e0b\u56fe 1 \u6240\u793a\uff1a<\/p>\n<p><img src=\"https:\/\/img.jbzj.com\/file_images\/article\/201708\/201783192359833.png?20177319249\" alt=\"\" \/><\/p>\n<p>\u56fe 1 \uff1a\u5b50\u8fdb\u7a0b\u72b6\u6001\u8f6c\u79fb\u56fe<\/p>\n<p><strong>\u6211\u4eec\u6311\u51e0\u4e2a\u91cd\u8981\u7684\u8fdb\u7a0b\u72b6\u6001\u6765\u8bf4\u660e\u3002<\/strong><\/p>\n<ul>\n<li>running\uff1a\u8fdb\u7a0b\u5904\u4e8e\u8fd0\u884c\u72b6\u6001<\/li>\n<li>starting\uff1aSupervisor \u6536\u5230\u542f\u52a8\u8bf7\u6c42\u540e\uff0c\u8fdb\u7a0b\u5904\u4e8e\u6b63\u5728\u542f\u52a8\u8fc7\u7a0b\u4e2d<\/li>\n<li>stopped\uff1a\u8fdb\u7a0b\u5904\u4e8e\u5173\u95ed\u72b6\u6001<\/li>\n<li>stopping\uff1aSupervisor \u6536\u5230\u5173\u95ed\u8bf7\u6c42\u540e\uff0c\u8fdb\u7a0b\u5904\u4e8e\u6b63\u5728\u5173\u95ed\u8fc7\u7a0b\u4e2d<\/li>\n<li>backoff\uff1a\u8fdb\u7a0b\u8fdb\u5165 starting \u72b6\u6001\u540e\uff0c\u7531\u4e8e\u9a6c\u4e0a\u5c31\u9000\u51fa\u5bfc\u81f4\u6ca1\u80fd\u8fdb\u5165 running \u72b6\u6001<\/li>\n<li>fatal\uff1a\u8fdb\u7a0b\u6ca1\u6709\u6b63\u5e38\u542f\u52a8<\/li>\n<li>exited\uff1a\u8fdb\u7a0b\u4ece running \u72b6\u6001\u9000\u51fa<\/li>\n<\/ul>\n<p>\u6ca1\u6709\u63a5\u89e6\u8fc7 Supervisor \u7684\u670b\u53cb\u53ef\u80fd\u5bf9\u4e0a\u9762\u7684\u63cf\u8ff0\u611f\u5230\u6709\u4e9b\u62bd\u8c61\uff0c\u4e0d\u7528\u62c5\u5fc3\uff0c\u7ecf\u8fc7\u4e0b\u9762\u7684\u5b9e\u8df5\u540e\uff0c\u4f1a\u5feb\u901f\u7406\u89e3 Supervisor \u6d89\u53ca\u7684\u8fd9\u4e9b\u540d\u8bcd\u7684\u3002<\/p>\n<p><strong>Supervisor \u521d\u4f53\u9a8c<\/strong><\/p>\n<p>\u6211\u4eec\u4ee5 CentOS \u5e73\u53f0\u4e0b\u4e3a\u4f8b\uff0c\u8bf4\u660e\u5982\u4f55\u4f7f\u7528 Supervisor \u8fd9\u4e00\u5f3a\u5927\u7684\u8fdb\u7a0b\u7ba1\u7406\u5de5\u5177\u3002<\/p>\n<p><strong>1. \u5b89\u88c5<\/strong><\/p>\n<p>\u53ef\u4ee5\u4f7f\u7528easy_intall\u6765\u5b89\u88c5 Supervisor\uff1a<\/p>\n<div class=\"jb51code\">\n<div>\n<div id=\"highlighter_719927\" class=\"syntaxhighlighter  bash\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"gutter\">\n<div class=\"line number1 index0 alt2\">1<\/div>\n<\/td>\n<td class=\"code\">\n<div class=\"container\">\n<div class=\"line number1 index0 alt2\"><code class=\"bash plain\">easy_install supervisor<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<\/div>\n<p>\u4e5f\u53ef\u4ee5\u4f7f\u7528pip\u6765\u5b89\u88c5 Supervisor\uff1a<\/p>\n<div class=\"jb51code\">\n<div>\n<div id=\"highlighter_224222\" class=\"syntaxhighlighter  php\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"gutter\">\n<div class=\"line number1 index0 alt2\">1<\/div>\n<\/td>\n<td class=\"code\">\n<div class=\"container\">\n<div class=\"line number1 index0 alt2\"><code class=\"php plain\">pip install supervisor<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<\/div>\n<p>\u5b89\u88c5\u8fc7\u7a0b\u6bd4\u8f83\u7b80\u5355\uff0c\u6b64\u5904\u6211\u4eec\u4e0d\u518d\u8d58\u8ff0\u3002<\/p>\n<p>\u5b89\u88c5\u5b8c\u6bd5\u540e\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u6765\u6d4b\u8bd5\u5b89\u88c5\u662f\u5426\u6210\u529f\uff1a<\/p>\n<div class=\"jb51code\">\n<div>\n<div id=\"highlighter_988687\" class=\"syntaxhighlighter  php\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"gutter\">\n<div class=\"line number1 index0 alt2\">1<\/div>\n<\/td>\n<td class=\"code\">\n<div class=\"container\">\n<div class=\"line number1 index0 alt2\"><code class=\"php plain\">echo_supervisord_conf<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<\/div>\n<p>echo_supervisord_conf\u5c06\u4f1a\u5728\u7ec8\u7aef\u8f93\u51fa Supervisor \u914d\u7f6e\u7684\u6837\u4f8b\u3002<\/p>\n<p><strong>2. \u521b\u5efa\u914d\u7f6e\u76ee\u5f55\u4ee5\u53ca\u4e3b\u914d\u7f6e\u6587\u4ef6<\/strong><\/p>\n<p>\u4e3a\u4e86\u5c06 Supervisor \u7684\u914d\u7f6e\u653e\u7f6e\u5230\u72ec\u7acb\u7684\u76ee\u5f55\u4e2d\uff0c\u6211\u4eec\u5148\u521b\u5efa\u76ee\u5f55\uff1a<\/p>\n<div class=\"jb51code\">\n<div>\n<div id=\"highlighter_609646\" class=\"syntaxhighlighter  bash\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"gutter\">\n<div class=\"line number1 index0 alt2\">1<\/div>\n<div class=\"line number2 index1 alt1\">2<\/div>\n<\/td>\n<td class=\"code\">\n<div class=\"container\">\n<div class=\"line number1 index0 alt2\"><code class=\"bash functions\">cd<\/code> <code class=\"bash plain\">\/etc<\/code><\/div>\n<div class=\"line number2 index1 alt1\"><code class=\"bash functions\">mkdir<\/code> <code class=\"bash plain\">supervisor<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<\/div>\n<p>\u63a5\u7740\uff0c\u53ef\u4ee5\u7ee7\u7eed\u4f7f\u7528echo_supervisord_conf\u547d\u4ee4\uff0c\u5c06 Supervisor \u6837\u4f8b\u914d\u7f6e\u91cd\u5b9a\u5411\u8f93\u51fa\u5230\u6587\u4ef6\u6587\u4ef6\u4e2d\uff1a<\/p>\n<div class=\"jb51code\">\n<div>\n<div id=\"highlighter_187518\" class=\"syntaxhighlighter  plain\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"gutter\">\n<div class=\"line number1 index0 alt2\">1<\/div>\n<\/td>\n<td class=\"code\">\n<div class=\"container\">\n<div class=\"line number1 index0 alt2\"><code class=\"plain plain\">echo_supervisord_conf &gt; \/etc\/supervisor\/supervisord.conf<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<\/div>\n<p>\u8fd9\u6837\uff0c\u6211\u4eec\u4fbf\u751f\u6210\u4e86 Supervisor \u7684\u4e3b\u914d\u7f6e\u6587\u4ef6supervisord.conf\u3002<\/p>\n<p>\u4e3a\u4e86\u5c06 Supervisor \u7ba1\u7406\u7684\u8fdb\u7a0b\u914d\u7f6e\u4e0e\u4e3b\u914d\u7f6e\u6587\u4ef6\u533a\u5206\u5f00\u6765\uff0c\u6211\u4eec\u521b\u5efa\u72ec\u7acb\u7684\u76ee\u5f55\u6765\u5b58\u653e\u8fdb\u7a0b\u914d\u7f6e\u3002<\/p>\n<div class=\"jb51code\">\n<div>\n<div id=\"highlighter_846401\" class=\"syntaxhighlighter  plain\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"gutter\">\n<div class=\"line number1 index0 alt2\">1<\/div>\n<div class=\"line number2 index1 alt1\">2<\/div>\n<\/td>\n<td class=\"code\">\n<div class=\"container\">\n<div class=\"line number1 index0 alt2\"><code class=\"plain plain\">cd \/etc\/supervisor<\/code><\/div>\n<div class=\"line number2 index1 alt1\"><code class=\"plain plain\">mkdir conf.d<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<\/div>\n<p>\u7136\u540e\uff0c\u4fee\u6539\u4e3b\u914d\u7f6e\u6587\u4ef6 supervisord.conf\uff0c\u6dfb\u52a0\u4ee5\u4e0b\u914d\u7f6e\uff0c\u5c06 conf.d \u76ee\u5f55\u4e0b\u7684\u8fdb\u7a0b\u914d\u7f6e\u5f15\u5165 Supervisor \u7ba1\u7406\uff1a<\/p>\n<div class=\"jb51code\">\n<div>\n<div id=\"highlighter_785741\" class=\"syntaxhighlighter  plain\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"gutter\">\n<div class=\"line number1 index0 alt2\">1<\/div>\n<div class=\"line number2 index1 alt1\">2<\/div>\n<\/td>\n<td class=\"code\">\n<div class=\"container\">\n<div class=\"line number1 index0 alt2\"><code class=\"plain plain\">[include]<\/code><\/div>\n<div class=\"line number2 index1 alt1\"><code class=\"plain plain\">files = .\/conf.d\/*.ini<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<\/div>\n<p><strong>3. \u521b\u5efa\u7ba1\u7406\u8fdb\u7a0b<\/strong><\/p>\n<p>\u4e3a\u65b9\u4fbf\u6d4b\u8bd5 Supervisor \u7684\u529f\u80fd\uff0c\u6211\u4eec\u7f16\u5199\u4ee5\u4e0b python \u811a\u672c\uff0c\u5e76\u4fdd\u5b58\u4e3a hello.py\u3002<\/p>\n<div class=\"jb51code\">\n<div>\n<div id=\"highlighter_677949\" class=\"syntaxhighlighter  py\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"gutter\">\n<div class=\"line number1 index0 alt2\">1<\/div>\n<div class=\"line number2 index1 alt1\">2<\/div>\n<div class=\"line number3 index2 alt2\">3<\/div>\n<div class=\"line number4 index3 alt1\">4<\/div>\n<div class=\"line number5 index4 alt2\">5<\/div>\n<div class=\"line number6 index5 alt1\">6<\/div>\n<\/td>\n<td class=\"code\">\n<div class=\"container\">\n<div class=\"line number1 index0 alt2\"><code class=\"py keyword\">import<\/code> <code class=\"py plain\">time<\/code><\/div>\n<div class=\"line number2 index1 alt1\"><code class=\"py keyword\">import<\/code> <code class=\"py plain\">sys<\/code><\/div>\n<div class=\"line number3 index2 alt2\"><code class=\"py keyword\">while<\/code> <code class=\"py color1\">True<\/code><code class=\"py plain\">:<\/code><\/div>\n<div class=\"line number4 index3 alt1\"><code class=\"py spaces\">\u00a0\u00a0<\/code><code class=\"py functions\">print<\/code><code class=\"py plain\">(<\/code><code class=\"py string\">\"hello\\n\"<\/code><code class=\"py plain\">)<\/code><\/div>\n<div class=\"line number5 index4 alt2\"><code class=\"py spaces\">\u00a0\u00a0<\/code><code class=\"py plain\">sys.stdout.flush()<\/code><\/div>\n<div class=\"line number6 index5 alt1\"><code class=\"py spaces\">\u00a0\u00a0<\/code><code class=\"py plain\">time.sleep(<\/code><code class=\"py value\">1<\/code><code class=\"py plain\">)<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<\/div>\n<p>hello.py \u7684\u4e3b\u8981\u529f\u80fd\u662f\u5f80\u6807\u51c6\u8f93\u51fa\u4e2d\u4e0d\u65ad\u5730\u8f93\u51fa \u201chello\u201d \u5b57\u7b26\u4e32\u3002<\/p>\n<p><strong>4. \u521b\u5efa\u8fdb\u7a0b\u914d\u7f6e<\/strong><\/p>\n<p>\u4e3a\u5c06 hello.py \u811a\u672c\u88ab Supervisor \u63a5\u7ba1\uff0c\u6211\u4eec\u5728 \/etc\/supervisor\/conf.d \u76ee\u5f55\u521b\u5efa\u5176\u914d\u7f6e hello.ini\uff1a<\/p>\n<div class=\"jb51code\">\n<div>\n<div id=\"highlighter_245119\" class=\"syntaxhighlighter  plain\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"gutter\">\n<div class=\"line number1 index0 alt2\">1<\/div>\n<div class=\"line number2 index1 alt1\">2<\/div>\n<div class=\"line number3 index2 alt2\">3<\/div>\n<div class=\"line number4 index3 alt1\">4<\/div>\n<\/td>\n<td class=\"code\">\n<div class=\"container\">\n<div class=\"line number1 index0 alt2\"><code class=\"plain plain\">[program:hello]<\/code><\/div>\n<div class=\"line number2 index1 alt1\"><code class=\"plain plain\">command=python \/home\/lihao\/codes\/python\/hello.py\u00a0\u00a0\u00a0 <\/code><\/div>\n<div class=\"line number3 index2 alt2\"><code class=\"plain plain\">stdout_logfile=\/home\/lihao\/codes\/python\/hello.log<\/code><\/div>\n<div class=\"line number4 index3 alt1\"><code class=\"plain plain\">stderr_logfile=\/home\/lihao\/codes\/python\/hello_error.log<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<\/div>\n<ul>\n<li>command\uff1a\u8fd0\u884c\u8fdb\u7a0b\u4f7f\u7528\u7684\u547d\u4ee4<\/li>\n<li>stdout_logfile\uff1a\u6307\u5b9a\u6807\u51c6\u8f93\u51fa\u6587\u4ef6<\/li>\n<li>stderr_logfile\uff1a\u6807\u51c6\u9519\u8bef\u8f93\u51fa\u6587\u4ef6<\/li>\n<\/ul>\n<p>\u9700\u8981\u6307\u51fa\u7684\u662f\uff0c\u88ab Supervisor \u7ba1\u7406\u7684\u8fdb\u7a0b\uff0c\u4e0d\u80fd\u4f7f\u7528 daemon \u6a21\u5f0f\uff0c\u800c\u5fc5\u987b\u5728\u524d\u53f0\u8fd0\u884c\uff0c\u5426\u5219\u4f1a\u62a5\u9519\u3002<\/p>\n<p><strong>5. \u8fd0\u884c supervisord<\/strong><\/p>\n<p>\u7531\u4e8e\u6211\u4eec\u9700\u8981\u4f7f\u7528\u6307\u5b9a\u76ee\u5f55\u4e0b\u7684 Supervisor \u4e3b\u914d\u7f6e\u6587\u4ef6\uff0c\u5728\u8fd0\u884c Supervisord \u65f6\uff0c\u9700\u8981\u4f7f\u7528-c\u53c2\u6570\u6765\u6307\u5b9a\u4e3b\u914d\u7f6e\u6587\u4ef6\u7684\u8def\u5f84\uff1a<\/p>\n<div class=\"jb51code\">\n<div>\n<div id=\"highlighter_295470\" class=\"syntaxhighlighter  plain\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"gutter\">\n<div class=\"line number1 index0 alt2\">1<\/div>\n<\/td>\n<td class=\"code\">\n<div class=\"container\">\n<div class=\"line number1 index0 alt2\"><code class=\"plain plain\">supervisord -c \/etc\/supervisor\/supervisord.conf<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<\/div>\n<p><strong>6. \u4f7f\u7528 supervisorctl \u7ba1\u7406\u8fdb\u7a0b<\/strong><\/p>\n<p>\u4f7f\u7528 supervisorctl \u53ef\u4ee5\u67e5\u770b\u76d1\u63a7\u7684\u8fdb\u7a0b\u72b6\u6001\uff1a<\/p>\n<div class=\"jb51code\">\n<div>\n<div id=\"highlighter_297037\" class=\"syntaxhighlighter  plain\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"gutter\">\n<div class=\"line number1 index0 alt2\">1<\/div>\n<\/td>\n<td class=\"code\">\n<div class=\"container\">\n<div class=\"line number1 index0 alt2\"><code class=\"plain plain\">supervisorctl -c \/etc\/supervisor\/supervisord.conf<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<\/div>\n<p>\u8f93\u51fa\uff1a<\/p>\n<div class=\"jb51code\">\n<div>\n<div id=\"highlighter_715649\" class=\"syntaxhighlighter  plain\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"gutter\">\n<div class=\"line number1 index0 alt2\">1<\/div>\n<div class=\"line number2 index1 alt1\">2<\/div>\n<\/td>\n<td class=\"code\">\n<div class=\"container\">\n<div class=\"line number1 index0 alt2\"><code class=\"plain plain\">hello RUNNING pid 8475, uptime 7:59:46<\/code><\/div>\n<div class=\"line number2 index1 alt1\"><code class=\"plain plain\">supervisor&gt;<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<\/div>\n<p>\u53ef\u4ee5\u770b\u5230\uff0c\u811a\u672c hello.py \u5df2\u7ecf\u8fd0\u884c\u4e86\u8d77\u6765\uff08\u5f53\u7136\u4f7f\u7528 ps aux | grep hello\u4e5f\u53ef\u4ee5\u770b\u5230\u5176\u8fdb\u7a0b\u4fe1\u606f\uff09\u3002\u6253\u5f00\u6587\u4ef6 \/home\/lihao\/codes\/python\/hello.log\uff0c\u53ef\u4ee5\u770b\u5230\u6587\u4ef6\u4e2d\u4e0d\u65ad\u6709\u201dhello\u201d\u8f93\u51fa\u3002<\/p>\n<p>\u5728 supervisorctl \u547d\u4ee4\u884c\u4e0b\uff0c\u4e5f\u53ef\u4ee5\u4f7f\u7528start\uff0cstop\uff0crestart\uff0cstatus\uff0c\u7b49\u547d\u4ee4\u6765\u542f\u52a8\uff0c\u5173\u95ed\uff0c\u91cd\u542f\uff0c\u67e5\u770b\u72b6\u6001\u76d1\u63a7\u7684\u8fdb\u7a0b\uff0c\u4e5f\u53ef\u4ee5\u8f93\u5165help\u6765\u67e5\u770b\u547d\u4ee4\u5e2e\u52a9\u3002\u9650\u4e8e\u7bc7\u5e45\uff0c\u6b64\u5904\u4e0d\u518d\u5c55\u5f00\uff0c\u8be6\u7ec6\u7684 supervisorctl \u547d\u4ee4\u53ef\u4ee5\u53c2\u8003\uff1a<a href=\"http:\/\/www.supervisord.org\/running.html#running-supervisorctl\" target=\"_blank\" rel=\"external nofollow noopener noreferrer\">http:\/\/www.supervisord.org\/running.html#running-supervisorctl<\/a>\u3002<\/p>\n<p><strong>Supervisor \u7ba1\u7406 Redis \u8fdb\u7a0b<\/strong><\/p>\n<p>\u5728\u8bf4\u5b8c Supervisor \u7684\u57fa\u672c\u4f7f\u7528\u540e\uff0c\u6211\u4eec\u6765\u770b\u4e0b\u5982\u4f55\u4f7f\u7528 Supervisor \u6765\u7ba1\u7406 Redis \u8fdb\u7a0b\u3002<\/p>\n<p><strong>Redis \u7684 Supervisor \u914d\u7f6e<\/strong><\/p>\n<p>\u6709\u4e86\u4e0a\u9762\u7684\u57fa\u7840\uff0c\u6211\u4eec\u5f88\u5bb9\u6613\u5199\u51fa Redis \u670d\u52a1\u8fdb\u7a0b\u7684 Supervisor \u914d\u7f6e\uff1a<\/p>\n<div class=\"jb51code\">\n<div>\n<div id=\"highlighter_378116\" class=\"syntaxhighlighter  plain\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"gutter\">\n<div class=\"line number1 index0 alt2\">1<\/div>\n<div class=\"line number2 index1 alt1\">2<\/div>\n<div class=\"line number3 index2 alt2\">3<\/div>\n<div class=\"line number4 index3 alt1\">4<\/div>\n<div class=\"line number5 index4 alt2\">5<\/div>\n<\/td>\n<td class=\"code\">\n<div class=\"container\">\n<div class=\"line number1 index0 alt2\"><code class=\"plain plain\">[program:redis]<\/code><\/div>\n<div class=\"line number2 index1 alt1\"><code class=\"plain plain\">command=\/usr\/local\/bin\/redis-server<\/code><\/div>\n<div class=\"line number3 index2 alt2\"><code class=\"plain plain\">autostart=true<\/code><\/div>\n<div class=\"line number4 index3 alt1\"><code class=\"plain plain\">autorestart=true<\/code><\/div>\n<div class=\"line number5 index4 alt2\"><code class=\"plain plain\">startsecs=3<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<\/div>\n<p>\u4f7f\u7528 supervisorctl reload \u8f7d\u5165\u65b0\u7684 Redis \u914d\u7f6e\u540e\uff0cRedis \u8fdb\u7a0b\u4fbf\u8ba9 Supervisor \u542f\u52a8\u4e86\u8d77\u6765\u3002\u5982\u679c\u9700\u8981\u6307\u5b9a Redis \u7684\u8f93\u51fa\u65e5\u5fd7\uff0c\u53ef\u4ee5\u901a\u8fc7stdout_logfile\u914d\u7f6e\u9009\u9879\u6307\u5b9a\uff0c\u5177\u4f53\u4e5f\u53ef\u4ee5\u53c2\u8003\u4e0a\u8ff0\u7684 hello \u4f8b\u5b50\u3002<\/p>\n<p>\u7531\u4e8e Supervisor \u7ba1\u7406\u7684\u8fdb\u7a0b\u4e0d\u80fd\u8bbe\u7f6e\u4e3a daemon \u6a21\u5f0f\uff0c\u6545\u5982\u679c Redis \u65e0\u6cd5\u6b63\u5e38\u542f\u52a8\uff0c\u53ef\u4ee5\u67e5\u770b\u4e00\u4e0b Redis \u7684\u914d\u7f6e\uff0c\u5e76\u5c06daemonize\u9009\u9879\u8bbe\u7f6e\u4e3a no\u3002<\/p>\n<div class=\"jb51code\">\n<div>\n<div id=\"highlighter_314588\" class=\"syntaxhighlighter  plain\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"gutter\">\n<div class=\"line number1 index0 alt2\">1<\/div>\n<\/td>\n<td class=\"code\">\n<div class=\"container\">\n<div class=\"line number1 index0 alt2\"><code class=\"plain plain\">daemonize no<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<\/div>\n<p><strong>Supervisord \u5f00\u673a\u542f\u52a8<\/strong><\/p>\n<p><strong>1\uff09.\u914d\u7f6e\u670d\u52a1\u6587\u4ef6<\/strong><br \/>\n\/usr\/lib\/systemd\/system\/\u4e0b\uff0c\u65b0\u5efasupervisord.service\u6587\u4ef6\u3002<br \/>\n\u8fd9\u91cc\u5173\u952e\uff0c\u662fsupervisord\u6587\u4ef6\uff0c\u5efa\u8fc7\u4e86supervisor.service\u6587\u4ef6\uff0c\u914d\u7684\u662fsupervisord\u6587\u4ef6\uff0c\u7ed3\u679c\u5bfc\u81f4\u5176\u5b9e2\u4e2a\u4e0d\u540c\u7684\u542f\u52a8\u6587\u4ef6\uff0c\u7ed3\u679c\u540e\u9762\u9020\u6210\u4e86\u8bbe\u7f6e\u7684\u6df7\u4e71\u3002<\/p>\n<p>\u6587\u4ef6\u5185\u5bb9\u5982\u4e0b\uff1a<\/p>\n<div class=\"cnblogs_code\">\n<div class=\"cnblogs_code_toolbar\"><span class=\"cnblogs_code_copy\"><a title=\"\u590d\u5236\u4ee3\u7801\"><img src=\"https:\/\/common.cnblogs.com\/images\/copycode.gif\" alt=\"\u590d\u5236\u4ee3\u7801\" \/><\/a><\/span><\/div>\n<pre># supervisord service for systemd (CentOS 7.0+)\n# by ET-CS (https:\/\/github.com\/ET-CS)\n[Unit]\nDescription=Supervisor daemon\n\n[Service]\nType=forking\nExecStart=\/usr\/bin\/supervisord -c \/etc\/supervisor\/supervisord.conf\nExecStop=\/usr\/bin\/supervisorctl $OPTIONS shutdown\nExecReload=\/usr\/bin\/supervisorctl $OPTIONS reload\nKillMode=process\nRestart=on-failure\nRestartSec=42s\n\n[Install]\nWantedBy=multi-user.target<\/pre>\n<div class=\"cnblogs_code_toolbar\"><span class=\"cnblogs_code_copy\"><a title=\"\u590d\u5236\u4ee3\u7801\"><img src=\"https:\/\/common.cnblogs.com\/images\/copycode.gif\" alt=\"\u590d\u5236\u4ee3\u7801\" \/><\/a><\/span><\/div>\n<\/div>\n<p><strong>2\uff09.\u5f00\u673a\u542f\u52a8<\/strong><br \/>\nsupervisorctl start all<br \/>\nsystemctl enable supervisord<br \/>\n\u8bbe\u7f6e\u542f\u52a8supervisor<br \/>\n\u9a8c\u8bc1\u662f\u5426\u5f00\u673a\u542f\u52a8\uff1a<br \/>\nsystemctl is-enabled supervisord<\/p>\n<p>\u5982\u679c\u6ca1\u610f\u5916\u60c5\u51b5\uff0c\u8fd9\u6837\u542f\u52a8\u5df2\u7ecf\u53ef\u4ee5\u914d\u7f6e\u548c\u542f\u52a8\u5b8c\u6bd5<\/p>\n<p><strong>Supervisor Web \u7ba1\u7406\u754c\u9762<\/strong><\/p>\n<p>\u5982\u679c\u9700\u8981\u5f00\u542f Web \u7ba1\u7406\u754c\u9762\u529f\u80fd\uff0c\u9700\u8981\u5728supervisord.conf\u914d\u7f6e\u4e2d\u6dfb\u52a0\u4ee5\u4e0b\u914d\u7f6e\uff1a<\/p>\n<div class=\"jb51code\">\n<div>\n<div id=\"highlighter_767888\" class=\"syntaxhighlighter  plain\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"gutter\">\n<div class=\"line number1 index0 alt2\">1<\/div>\n<div class=\"line number2 index1 alt1\">2<\/div>\n<div class=\"line number3 index2 alt2\">3<\/div>\n<div class=\"line number4 index3 alt1\">4<\/div>\n<\/td>\n<td class=\"code\">\n<div class=\"container\">\n<div class=\"line number1 index0 alt2\"><code class=\"plain plain\">[inet_http_server]<\/code><\/div>\n<div class=\"line number2 index1 alt1\"><code class=\"plain plain\">port=*:9001<\/code><\/div>\n<div class=\"line number3 index2 alt2\"><code class=\"plain plain\">username=user<\/code><\/div>\n<div class=\"line number4 index3 alt1\"><code class=\"plain plain\">password=123<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<\/div>\n<p>\u7136\u540e\uff0c\u6253\u5f00\u6d4f\u89c8\u5668\uff0c\u8f93\u5165\u5730\u5740 http:\/\/127.0.0.1:9001\uff0c\u8fd9\u65f6\uff0c\u4f1a\u5f39\u51fa\u8f93\u5165\u6846\uff0c\u8981\u6c42\u8f93\u5165\u7528\u6237\u540d\u548c\u5bc6\u7801\uff08\u7528\u6237\u540d\uff1auser\uff0c\u5bc6\u7801\uff1a123\uff09\uff0c\u4fbf\u53ef\u4ee5\u8fdb\u5165 Supervisor \u63d0\u4f9b\u7684\u8fdb\u7a0b\u7ba1\u7406\u754c\u9762\u3002<\/p>\n<p><img loading=\"lazy\" src=\"https:\/\/img.jbzj.com\/file_images\/article\/201708\/201783193119692.png?201773193129\" alt=\"\" width=\"1696\" height=\"942\" \/><\/p>\n<p>\u56fe 2 \uff1aSupervisor Web \u7ba1\u7406\u754c\u9762<\/p>\n<p>\u5728\u6b64\u754c\u9762\u4e0b\uff0c\u53ef\u4ee5\u5bf9\u5355\u4e2a\u8fdb\u7a0b\u8fdb\u884c\u91cd\u542f\uff0c\u5173\u95ed\uff0c\u67e5\u770b\u65e5\u5fd7\u7b49\u64cd\u4f5c\uff0c\u4e5f\u53ef\u4ee5\u5bf9\u6240\u6709\u7684\u8fdb\u7a0b\u8fdb\u884c\u91cd\u542f\uff0c\u5173\u95ed\u7b49\u64cd\u4f5c\u3002<\/p>\n<p><strong>\u603b\u7ed3<\/strong><\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u8fd9\u7bc7\u6587\u7ae0\u7684\u5168\u90e8\u5185\u5bb9\u4e86\uff0c\u5e0c\u671b\u672c\u6587\u7684\u5185\u5bb9\u5bf9\u5927\u5bb6\u7684\u5b66\u4e60\u6216\u8005\u5de5\u4f5c\u80fd\u5e26\u6765\u4e00\u5b9a\u7684\u5e2e\u52a9\uff0c\u5982\u679c\u6709\u7591\u95ee\u5927\u5bb6\u53ef\u4ee5\u7559\u8a00\u4ea4\u6d41\uff0c\u8c22\u8c22\u5927\u5bb6\u5bf9\u811a\u672c\u4e4b\u5bb6\u7684\u652f\u6301\u3002<\/p>\n<p><strong>\u53c2\u8003\u8d44\u6599<\/strong><\/p>\n<ul>\n<li>http:\/\/www.supervisord.org\/<\/li>\n<li>Python Web \u5f00\u53d1\u5b9e\u6218\uff0c\u8463\u4f1f\u660e\u8457\uff0c\u7535\u5b50\u5de5\u4e1a\u51fa\u7248\u793e<\/li>\n<li>http:\/\/www.jianshu.com\/p\/9abffc905645<\/li>\n<li>http:\/\/www.supervisord.org\/running.html#running-supervisorctl<\/li>\n<li>http:\/\/supervisord.org\/configuration.html<\/li>\n<li>http:\/\/www.supervisord.org\/subprocess.html<\/li>\n<li>https:\/\/lincolnloop.com\/blog\/automatically-running-supervisord-startup\/<\/li>\n<li>https:\/\/serverfault.com\/questions\/96499\/how-to-automatically-start-supervisord-on-linux-ubuntu<\/li>\n<li>https:\/\/segmentfault.com\/a\/1190000003955182<\/li>\n<\/ul>\n<p>\u8f6c\u81eahttps:\/\/www.jb51.net\/article\/122534.htm<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u524d\u8a00 Supervisor \u662f\u4e00\u4e2a\u7528 Python \u5b9e\u73b0\u7684\u8fdb\u7a0b\u7ba1\u7406\u5de5\u5177\uff0c\u53ef\u4ee5\u5f88\u65b9\u4fbf\u5730\u542f\u52a8\uff0c\u5173\u95ed\uff0c\u91cd\u542f\uff0c\u67e5\u770b\uff0c\u4ee5 &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/blog.gamekingtao.top\/index.php\/2020\/07\/17\/%e5%88%a9%e7%94%a8supervisor%e7%ae%a1%e7%90%86redis%e8%bf%9b%e7%a8%8b%e7%9a%84%e6%96%b9%e6%b3%95%e6%95%99%e7%a8%8b\/\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">\u201c\u5229\u7528Supervisor\u7ba1\u7406Redis\u8fdb\u7a0b\u7684\u65b9\u6cd5\u6559\u7a0b\u53ca\u5f00\u673a\u81ea\u542f\u52a8\u201d<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[13],"tags":[],"_links":{"self":[{"href":"https:\/\/blog.gamekingtao.top\/index.php\/wp-json\/wp\/v2\/posts\/53"}],"collection":[{"href":"https:\/\/blog.gamekingtao.top\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.gamekingtao.top\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.gamekingtao.top\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.gamekingtao.top\/index.php\/wp-json\/wp\/v2\/comments?post=53"}],"version-history":[{"count":2,"href":"https:\/\/blog.gamekingtao.top\/index.php\/wp-json\/wp\/v2\/posts\/53\/revisions"}],"predecessor-version":[{"id":56,"href":"https:\/\/blog.gamekingtao.top\/index.php\/wp-json\/wp\/v2\/posts\/53\/revisions\/56"}],"wp:attachment":[{"href":"https:\/\/blog.gamekingtao.top\/index.php\/wp-json\/wp\/v2\/media?parent=53"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.gamekingtao.top\/index.php\/wp-json\/wp\/v2\/categories?post=53"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.gamekingtao.top\/index.php\/wp-json\/wp\/v2\/tags?post=53"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}