{"id":10008205,"date":"2023-08-31T16:00:50","date_gmt":"2023-08-31T08:00:50","guid":{"rendered":"https:\/\/blog.itmax.cn\/?p=10008205"},"modified":"2023-08-31T16:00:50","modified_gmt":"2023-08-31T08:00:50","slug":"%e5%bd%93%e5%ae%b9%e5%99%a8%e5%86%85%e7%9a%84%e8%bf%9b%e7%a8%8b%e5%8f%aa%e7%9b%91%e5%90%ac-127-0-0-1-%e8%80%8c%e4%b8%8d%e6%98%af-0-0-0-0-%ef%bc%8c%e5%ae%bf%e4%b8%bb%e6%9c%ba%e5%8f%af%e4%bb%a5%e4%bd%bf","status":"publish","type":"post","link":"https:\/\/itmax.cn\/?p=10008205","title":{"rendered":"\u5f53\u5bb9\u5668\u5185\u7684\u8fdb\u7a0b\u53ea\u76d1\u542c 127.0.0.1 \u800c\u4e0d\u662f 0.0.0.0 \uff0c\u5bbf\u4e3b\u673a\u53ef\u4ee5\u4f7f\u7528 127.0.0.1 \u8bbf\u95ee\u8d44\u6e90\u5417\uff1f"},"content":{"rendered":"<p>\u524d\u8a00\uff1a\u56e0\u4e3a\u9047\u5230\u4e86<a target=\"_blank\" href=\"https:\/\/segmentfault.com\/q\/1010000044168469\/a-1020000044168849\" rel=\"noopener noreferrer\">docker+etcd \u65e0\u6cd5\u8fdc\u7a0b\u8bbf\u95ee\uff1f<\/a>\u8fd9\u4e2a\u95ee\u9898\uff0c\u6240\u4ee5\u6211\u8981\u6df1\u5165\u63a2\u7a76\u4e00\u4e0b<\/p>\n<hr>\n<p>\u5f53\u5bb9\u5668\u5185\u7684\u8fdb\u7a0b\u53ea\u76d1\u542c 127.0.0.1 \u800c\u4e0d\u662f 0.0.0.0 \uff0c\u5bbf\u4e3b\u673a\u53ef\u4ee5\u4f7f\u7528 127.0.0.1 \u8bbf\u95ee\u8d44\u6e90\u5417\uff1f\u53ef\u4ee5<\/p>\n<p>\u5f53\u5bb9\u5668\u5185\u7684\u8fdb\u7a0b\u53ea\u76d1\u542c 127.0.0.1 \u800c\u4e0d\u662f 0.0.0.0 \uff0c\u5bbf\u4e3b\u673a\u53ef\u4ee5\u4f7f\u7528 \u7f51\u5173\u5206\u914d\u7684ip \u8bbf\u95ee\u8d44\u6e90\u5417\uff1f\u4e0d\u53ef\u4ee5<\/p>\n<blockquote><p>\u7f51\u5173\u5206\u914d\u7684ip \u6307\u7684\u662f 192.168.x.1 \u8fd9\u79cd<\/p><\/blockquote>\n<hr>\n<p>\u4e0b\u9762\u505a\u4e00\u4e2a\u5b9e\u9a8c<\/p>\n<pre><code class=\"Dockerfile\">FROM python:3.10.10-bullseye \nRUN echo &quot;deb http:\/\/mirrors.aliyun.com\/debian\/ bullseye main non-free contrib&quot; &gt; \/etc\/apt\/sources.list\n\nRUN apt-get update\nRUN apt-get install -y vim netcat telnet less sysstat htop ncdu\n\nRUN mkdir \/code\nWORKDIR \/code\n\nCOPY requirements-dev.txt \/code\/\nRUN pip install -r requirements-dev.txt -i https:\/\/mirror.baidu.com\/pypi\/simple\n\nCOPY requirements-prd.txt \/code\/\nRUN pip install -r requirements-prd.txt -i https:\/\/mirror.baidu.com\/pypi\/simple\n\n\nADD . \/code\/<\/code><\/pre>\n<p><code>requirements-dev.txt<\/code><\/p>\n<pre><code class=\"txt\">mycli\nipython\nautopep8\npsutil\nglances\npylint<\/code><\/pre>\n<p><code>requirements-prd.txt<\/code><\/p>\n<pre><code class=\"txt\">pymilvus==2.2.8\nnumpy \npydantic&lt;2.0.0\nloguru \nrequests \npyyaml \npython-dotenv \npython-multipart  # Form data requires &quot;python-multipart&quot; to be installed.\ncryptography\npymysql \npeewee \noss2 \nfastapi \nuvicorn \npsutil\ndnspython==2.2.1\n<\/code><\/pre>\n<p><code>api.py<\/code><\/p>\n<pre><code class=\"python\">from fastapi import FastAPI, Form, Request\nfrom loguru import logger\nimport uvicorn\nfrom fastapi import FastAPI, Form, Depends, Request\n\napp = FastAPI()\n\n\nasync def get_form(request: Request):\n    form_data = await request.form()\n    return dict(form_data)\n\n\n@app.post('\/search')\ndef search_reverse(\n    request: Request,\n    form_data: dict = Depends(get_form),\n    max_chunk_size: int = Form(1200, description='\u5206\u6279\u67e5\u8be2 milvus\uff0c\u6bcf\u4e2a\u67e5\u8be2\u6279\u6b21\u7684\u5411\u91cf\u4e2a\u6570'),\n    search_top_k: int = Form(\n        default=30, description='\u641c\u7d22 milvus \u7684\u65f6\u5019\uff0c\u8fd4\u56de\u7684\u6700\u76f8\u4f3c\u7684 N \u4e2a\u7ed3\u679c'),\n    distance_threshold: float = Form(\n        0.32, description='\u8ddd\u79bb\u4e0a\u9650\uff08\u8ddd\u79bb\u4f7f\u7528 L2 \u6b27\u6c0f\u8ddd\u79bb\u8861\u91cf\uff0c\u8d8a\u63a5\u8fd1 0 \u8d8a\u76f8\u4f3c\uff09\uff0c\u4f46 milvus \u7684\u641c\u7d22\u7ed3\u679c\u8fd4\u56de\u540e\uff0c\u4e22\u5f03\u5927\u4e8e\u8be5\u503c\u7684\u5411\u91cf\u641c\u7d22\u7ed3\u679c')\n):\n    form_dict = dict(form_data)\n    logger.debug(form_dict)\n\n\nif __name__ == &quot;__main__&quot;:\n    uvicorn.run(\n        app='api:app',\n        host=&quot;127.0.0.1&quot;,\n        port=9950,\n        workers=1,\n        reload=True\n    )\n<\/code><\/pre>\n<p>\u6253\u5305\u955c\u50cf<\/p>\n<pre><code>docker build -t &quot;ponponon\/fastapi_example&quot; .<\/code><\/pre>\n<p>\u8fd0\u884c\u955c\u50cf<\/p>\n<pre><code class=\"shell\">docker run -p 9950:9950 --rm -it ponponon\/fastapi_example python api.py<\/code><\/pre>\n<p>\u4f7f\u7528 nc \u547d\u4ee4\u63a2\u6d4b\u7aef\u53e3\u662f\u5426\u5f00\u653e<\/p>\n<pre><code class=\"shell\">\u2500\u27a4  nc -zv 192.168.2.15 9950                                                                         130 \u21b5\nnc: connect to 192.168.2.15 port 9950 (tcp) failed: Connection refused\n<\/code><\/pre>\n<pre><code class=\"shell\">\u2500\u27a4  nc -zv 127.0.0.1 9950                                                                              1 \u21b5\nConnection to 127.0.0.1 9950 port [tcp\/*] succeeded!\n<\/code><\/pre>\n<p><a href=\"https:\/\/segmentfault.com\/a\/1190000044169291\">https:\/\/segmentfault.com\/a\/1190000044169291<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u524d\u8a00\uff1a\u56e0\u4e3a\u9047\u5230\u4e86docker+etcd \u65e0\u6cd5\u8fdc\u7a0b\u8bbf\u95ee\uff1f\u8fd9\u4e2a\u95ee\u9898\uff0c\u6240\u4ee5\u6211\u8981\u6df1\u5165\u63a2\u7a76\u4e00\u4e0b \u5f53\u5bb9\u5668\u5185\u7684\u8fdb\u7a0b\u53ea\u76d1\u542c 1 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[4],"tags":[],"class_list":["post-10008205","post","type-post","status-publish","format-standard","hentry","category-share"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10008205","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=10008205"}],"version-history":[{"count":0,"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10008205\/revisions"}],"wp:attachment":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10008205"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=10008205"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=10008205"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}