{"id":1137,"date":"2022-03-14T10:56:01","date_gmt":"2022-03-14T02:56:01","guid":{"rendered":"https:\/\/www.yinyubo.com\/?p=1137"},"modified":"2022-05-16T18:00:46","modified_gmt":"2022-05-16T10:00:46","slug":"nginx-module-vts","status":"publish","type":"post","link":"https:\/\/www.yinyubo.com\/?p=1137","title":{"rendered":"apt\u65b9\u5f0f\u5b89\u88c5nginx\u4ee5\u53ca\u52a8\u6001\u589e\u52a0\u6a21\u5757nginx-module-vts"},"content":{"rendered":"\n<h3 class=\"wp-block-heading\">0.\u80cc\u666f\u4ecb\u7ecd<\/h3>\n\n\n\n<p>\u56e0\u4e3a\u6709\u5f88\u591a\u4eba\u662f\u5148\u901a\u8fc7apt\u7684\u8bbf\u95ee\u5b89\u88c5\u4e86\u7a33\u5b9a\u7248\u7684nginx\u3002\u540e\u9762\u7a81\u7136\u8981\u589e\u52a0\u7b2c\u4e09\u65b9\u6a21\u5757\u5982geoip\u6216\u8005nginx-module-vts\u7b49\u522b\u7684\u6a21\u5757\uff0c\u8fd9\u4e2a\u65f6\u5019\u5c31\u53ef\u4ee5\u91c7\u7528\u672c\u6587\u7684\u65b9\u5f0f\u53bb\u52a8\u6001\u589e\u52a0\u6a21\u5757\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">1.\u5b89\u88c5ubuntu\uff08\u5982\u679c\u5df2\u7ecf\u5b89\u88c5\u4e86\uff0c\u53ef\u4ee5\u8df3\u8fc7\uff09<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code># \u5b89\u88c5\u5fc5\u8981\u5de5\u5177\nsudo apt install curl gnupg2 ca-certificates lsb-release ubuntu-keyring\n\n# \u5bfc\u5165\u5b98\u65b9Nginx\u7b7e\u540d\u5bc6\u94a5\ncurl https:\/\/nginx.org\/keys\/nginx_signing.key | gpg --dearmor \\\n    | sudo tee \/usr\/share\/keyrings\/nginx-archive-keyring.gpg &gt;\/dev\/null\n\n# \u9a8c\u8bc1\u4e0b\u8f7d\u7684\u6587\u4ef6\u4e2d\u5305\u542b\u6b63\u786e\u7684\u5bc6\u94a5\ngpg --dry-run --quiet --import --import-options import-show \/usr\/share\/keyrings\/nginx-archive-keyring.gpg\n\n# \u8bbe\u7f6e\u7a33\u5b9a\u7248\u672c\u7684nginx\u4ed3\u5e93\necho \"deb &#91;signed-by=\/usr\/share\/keyrings\/nginx-archive-keyring.gpg] \\\nhttp:\/\/nginx.org\/packages\/ubuntu `lsb_release -cs` nginx\" \\\n    | sudo tee \/etc\/apt\/sources.list.d\/nginx.list\n\n# \u901a\u8fc7apt\u5b89\u88c5nginx\nsudo apt update\nsudo apt install nginx<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">2.\u786e\u8ba4\u5b89\u88c5\u7684nginx\u7248\u672c\u4fe1\u606f<\/h2>\n\n\n\n<p>\u8f93\u5165 nginx -V \u68c0\u67e5\u56de\u663e<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\nnginx version: nginx\/1.20.2\nbuilt by gcc 9.3.0 (Ubuntu 9.3.0-10ubuntu2)\nbuilt with OpenSSL 1.1.1f  31 Mar 2020\nTLS SNI support enabled\nconfigure arguments: --prefix=\/etc\/nginx --sbin-path=\/usr\/sbin\/nginx --modules-path=\/usr\/lib\/nginx\/modules --conf-path=\/etc\/nginx\/nginx.conf --error-log-path=\/var\/log\/nginx\/error.log --http-log-path=\/var\/log\/nginx\/access.log --pid-path=\/var\/run\/nginx.pid --lock-path=\/var\/run\/nginx.lock --http-client-body-temp-path=\/var\/cache\/nginx\/client_temp --http-proxy-temp-path=\/var\/cache\/nginx\/proxy_temp --http-fastcgi-temp-path=\/var\/cache\/nginx\/fastcgi_temp --http-uwsgi-temp-path=\/var\/cache\/nginx\/uwsgi_temp --http-scgi-temp-path=\/var\/cache\/nginx\/scgi_temp --user=nginx --group=nginx --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt='-g -O2 -fdebug-prefix-map=\/data\/builder\/debuild\/nginx-1.20.2\/debian\/debuild-base\/nginx-1.20.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fPIC' --with-ld-opt='-Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now -Wl,--as-needed -pie'\n<\/code><\/pre>\n\n\n\n<p>\u901a\u8fc7\u4e0a\u8ff0\u56de\u663e\uff0c\u6211\u4eec\u53ef\u4ee5\u770b\u5230nginx\u7684\u914d\u7f6e\u6587\u4ef6\u8def\u5f84\u548c\u7a0b\u5e8f\u8def\u5f84\u5982\u4e0b\u3002\u8fd9\u4e2a\u8def\u5f84\u7528\u5728\u540e\u9762\u7684\u52a8\u6001\u7f16\u8bd1\u91cc<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>--prefix=\/etc\/nginx --sbin-path=\/usr\/sbin\/nginx<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">3.\u4e0b\u8f7dnginx\u6e90\u4ee3\u7801\u5230\u672c\u5730<\/h2>\n\n\n\n<p>\u56e0\u4e3a\u6211\u4eec\u4e4b\u524d\u7684nginx\u662fapt\u5b89\u88c5\u7684\uff0c\u672c\u5730\u6ca1\u6709\u6e90\u7801\uff0c\u800c\u52a8\u6001\u7f16\u8bd1\u6a21\u5757\u9700\u8981\u6e90\u7801\uff0c\u6240\u4ee5\u8fd9\u91cc\u4e0b\u8f7d\u6e90\u7801\u5230\u672c\u5730<\/p>\n\n\n\n<p>\u8fdb\u5165<a href=\"http:\/\/nginx.org\/en\/download.html\">http:\/\/nginx.org\/en\/download.html<\/a>\uff0c\u4e0b\u8f7d\u4e0e\u6211\u4eec\u4e0a\u9762apt\u5b89\u88c5\u7684nginx\u540c\u7248\u672c\u7684tar.gz\u5305\uff0c\u4f8b\u5982\u8fd9\u91cc\u6211\u4eec\u88c5\u7684\u662f1.20.2\u7248\u672c<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"774\" height=\"350\" src=\"https:\/\/www.yinyubo.com\/wp-content\/uploads\/2022\/03\/image.png\" alt=\"\" class=\"wp-image-1142\" srcset=\"https:\/\/www.yinyubo.com\/wp-content\/uploads\/2022\/03\/image.png 774w, https:\/\/www.yinyubo.com\/wp-content\/uploads\/2022\/03\/image-300x136.png 300w, https:\/\/www.yinyubo.com\/wp-content\/uploads\/2022\/03\/image-768x347.png 768w\" sizes=\"auto, (max-width: 774px) 100vw, 774px\" \/><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code>\u89e3\u538bnginx\u6e90\u4ee3\u7801\ntar -zxvf nginx-1.20.2.tar.gz\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">4.\u4e0b\u8f7d\u7b2c\u4e09\u65b9\u6a21\u5757nginx-module-vts\u5230\u672c\u5730<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>git clone git:\/\/github.com\/vozlt\/nginx-module-vts.git\n<\/code><\/pre>\n\n\n\n<p>\u4e0b\u8f7d\u5b8c\u6210\u540e\uff0c\u4e24\u4e2a\u76ee\u5f55\u540c\u7ea7\uff0c\u4f8b\u5982\u4e0b\u9762\u7684\u76ee\u5f55<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\u76ee\u5f55\n|---nginx-1.20.2\n|---nginx-module-vts<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">5.\u8fdb\u884c\u7f16\u8bd1<\/h2>\n\n\n\n<p>\u5b89\u88c5\u7f16\u8bd1\u6240\u9700\u8981\u7684lib\u5e93<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt install g++ gcc libpcre3 libpcre3-dev zlib1g-dev openssl libssl-dev make<\/code><\/pre>\n\n\n\n<p>\u8fdb\u5165nginx-1.20.2\u76ee\u5f55<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cd nginx-1.20.2<\/code><\/pre>\n\n\n\n<p>\u4f7f\u7528configure\u5de5\u5177\u8fdb\u884c\u7f16\u8bd1\u3002\u7f16\u8bd1\u5b8c\u6210\u540e\u4f1a\u5728objs\u76ee\u5f55\u4e0b\u751f\u6210\u6587\u4ef6<a href=\"http:\/\/ngx_http_vhost_traffic_status_module.so\/\">ngx_http_vhost_traffic_status_module.so<\/a>\uff0c\u628a\u8fd9\u4e2a<a href=\"http:\/\/ngx_http_vhost_traffic_status_module.so\/\">ngx_http_vhost_traffic_status_module.so<\/a>\u62f7\u8d1d\u5230\/etc\/nginx\/modules\/\u76ee\u5f55\u4e0b<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>.\/configure --with-compat --prefix=\/etc\/nginx --sbin-path=\/usr\/sbin\/nginx --add-dynamic-module=..\/nginx-module-vts\nmake modules\nsudo cp objs\/ngx_http_vhost_traffic_status_module.so \/etc\/nginx\/modules\/.<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">6.\u5728nginx\u91cc\u52a0\u8f7d\u7b2c\u4e09\u65b9\u6a21\u5757nginx-module-vts<\/h2>\n\n\n\n<p>\u7f16\u8f91nginx.conf\u6587\u4ef6.<\/p>\n\n\n\n<p>\u5728\u6587\u4ef6\u9876\u90e8\u6dfb\u52a0load_module modules\/<a href=\"http:\/\/ngx_http_vhost_traffic_status_module.so\/\">ngx_http_vhost_traffic_status_module.so<\/a>;<\/p>\n\n\n\n<p>\u5728http\u4e0b\u6dfb\u52a0vhost_traffic_status_zone;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cd \/etc\/nginx\/\nsudo nano nginx.conf\n#  \u4ee5\u4e0b\u662f\u6587\u4ef6\u5185\u5bb9\n...\nload_module modules\/ngx_http_vhost_traffic_status_module.so;\n...\nhttp {\n    vhost_traffic_status_zone;\n}<\/code><\/pre>\n\n\n\n<p>\u5728\/etc\/nginx\/conf.d\u76ee\u5f55\u4e0b\u589e\u52a0\u4e00\u4e2amonitor.conf\u3002\u4e3b\u8981\u6dfb\u52a0vhost_traffic_status_display;\u548cvhost_traffic_status_display_format html; \u53c2\u8003\u5982\u4e0b<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>server {\n    listen       5320;\n    server_name  localhost;\n \n    #access_log  \/var\/log\/nginx\/host.access.log  main;\n \n    location \/status {\n        vhost_traffic_status_display;\n        vhost_traffic_status_display_format html;\n        root   \/usr\/share\/nginx\/html;\n        index  index.html index.htm;\n    }\n}<\/code><\/pre>\n\n\n\n<p>\u6dfb\u52a0\u5b8c\u6210\u540e\uff0c\u8f93\u5165sudo systemctl restart nginx\u91cd\u542fnginx<\/p>\n\n\n\n<p>\u8bbf\u95eemonitor.conf\u91cc\u5bf9\u5e94\u7684\u7aef\u53e3 &nbsp;<a href=\"http:\/\/\u670d\u52a1\u5668IP:5320\/\">http:\/\/\u670d\u52a1\u5668IP:5320\/<\/a>&nbsp;\u5373\u53ef\u770b\u5230\u6d41\u91cf\u4fe1\u606f<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"500\" src=\"https:\/\/www.yinyubo.com\/wp-content\/uploads\/2022\/03\/image-1-1024x500.png\" alt=\"\" class=\"wp-image-1144\" srcset=\"https:\/\/www.yinyubo.com\/wp-content\/uploads\/2022\/03\/image-1-1024x500.png 1024w, https:\/\/www.yinyubo.com\/wp-content\/uploads\/2022\/03\/image-1-300x146.png 300w, https:\/\/www.yinyubo.com\/wp-content\/uploads\/2022\/03\/image-1-768x375.png 768w, https:\/\/www.yinyubo.com\/wp-content\/uploads\/2022\/03\/image-1.png 1086w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>0.\u80cc\u666f\u4ecb\u7ecd \u56e0\u4e3a\u6709\u5f88\u591a\u4eba\u662f\u5148\u901a\u8fc7apt\u7684\u8bbf\u95ee\u5b89\u88c5\u4e86\u7a33\u5b9a\u7248\u7684nginx\u3002\u540e\u9762\u7a81\u7136\u8981\u589e\u52a0\u7b2c\u4e09\u65b9\u6a21\u5757\u5982geoip\u6216 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[],"class_list":["post-1137","post","type-post","status-publish","format-standard","hentry","category-7"],"_links":{"self":[{"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=\/wp\/v2\/posts\/1137","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1137"}],"version-history":[{"count":7,"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=\/wp\/v2\/posts\/1137\/revisions"}],"predecessor-version":[{"id":1148,"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=\/wp\/v2\/posts\/1137\/revisions\/1148"}],"wp:attachment":[{"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1137"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1137"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1137"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}