
{"id":2624,"date":"2023-01-13T10:19:39","date_gmt":"2023-01-13T02:19:39","guid":{"rendered":"http:\/\/dba.qishuo.xin\/?p=2624"},"modified":"2023-12-06T09:05:43","modified_gmt":"2023-12-06T01:05:43","slug":"%e5%9c%a8-centos-7%e4%b8%8a%e5%ae%89%e8%a3%85-squid%e4%bb%a3%e7%90%86%e6%9c%8d%e5%8a%a1%e5%99%a8","status":"publish","type":"post","link":"http:\/\/dba.qishuo.xin\/?p=2624","title":{"rendered":"\u5728 CentOS 7\u4e0a\u5b89\u88c5 Squid\u4ee3\u7406\u670d\u52a1\u5668"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_76 ez-toc-wrap-right counter-hierarchy ez-toc-counter ez-toc-light-blue ez-toc-container-direction\">\n<label for=\"ez-toc-cssicon-toggle-item-6a0b04a76d6dc\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-6a0b04a76d6dc\" checked aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"http:\/\/dba.qishuo.xin\/?p=2624\/#1_%E7%AE%80%E4%BB%8B\" >1. \u7b80\u4ecb<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"http:\/\/dba.qishuo.xin\/?p=2624\/#2_%E5%9C%A8_CentOS_%E4%B8%8A%E5%AE%89%E8%A3%85_Squid\" >2. \u5728 CentOS \u4e0a\u5b89\u88c5 Squid<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"http:\/\/dba.qishuo.xin\/?p=2624\/#3_%E9%85%8D%E7%BD%AE_Squid\" >3. \u914d\u7f6e Squid<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"http:\/\/dba.qishuo.xin\/?p=2624\/#4_Squid_%E8%BA%AB%E4%BB%BD%E9%AA%8C%E8%AF%81\" >4. Squid \u8eab\u4efd\u9a8c\u8bc1<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"http:\/\/dba.qishuo.xin\/?p=2624\/#5_%E9%85%8D%E7%BD%AE%E9%98%B2%E7%81%AB%E5%A2%99\" >5. \u914d\u7f6e\u9632\u706b\u5899<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"http:\/\/dba.qishuo.xin\/?p=2624\/#6_%E6%B5%8B%E8%AF%95Squid\" >6. \u6d4b\u8bd5Squid<\/a><ul class='ez-toc-list-level-4' ><li class='ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"http:\/\/dba.qishuo.xin\/?p=2624\/#61_Mac%E5%92%8CLinux%E6%96%B9%E5%BC%8F%EF%BC%8C%E8%AE%BE%E7%BD%AE%E4%B8%B4%E6%97%B6%E4%BB%A3%E7%90%86%E3%80%82\" >6.1 Mac\u548cLinux\u65b9\u5f0f\uff0c\u8bbe\u7f6e\u4e34\u65f6\u4ee3\u7406\u3002<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"http:\/\/dba.qishuo.xin\/?p=2624\/#62_%E5%9C%A8YUM%E4%B8%AD%E9%85%8D%E7%BD%AE\" >6.2. \u5728YUM\u4e2d\u914d\u7f6e<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"http:\/\/dba.qishuo.xin\/?p=2624\/#63_%E5%9C%A8_etcprofile_%E4%B8%AD%E9%85%8D%E7%BD%AE\" >6.3. \u5728 \/etc\/profile \u4e2d\u914d\u7f6e<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"http:\/\/dba.qishuo.xin\/?p=2624\/#64_Windows%E6%96%B9%E5%BC%8F%EF%BC%8C%E8%AE%BE%E7%BD%AE%E4%B8%B4%E6%97%B6%E4%BB%A3%E7%90%86%E3%80%82\" >6.4 Windows\u65b9\u5f0f\uff0c\u8bbe\u7f6e\u4e34\u65f6\u4ee3\u7406\u3002<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"http:\/\/dba.qishuo.xin\/?p=2624\/#65_%E5%9C%A8%E6%9C%8D%E5%8A%A1%E7%AB%AF%E7%9B%91%E6%8E%A7%E4%B8%8B%E6%97%A5%E5%BF%97\" >6.5 \u5728\u670d\u52a1\u7aef\u76d1\u63a7\u4e0b\u65e5\u5fd7<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"http:\/\/dba.qishuo.xin\/?p=2624\/#66_%E5%9C%A8%E7%BB%88%E7%AB%AF%E9%87%8C%E9%9D%A2%E6%89%A7%E8%A1%8C%E4%B8%8B%E9%9D%A2%E5%91%BD%E4%BB%A4%EF%BC%8C%E6%B5%8B%E8%AF%95%E8%AE%BF%E9%97%AE%E3%80%82\" >6.6 \u5728\u7ec8\u7aef\u91cc\u9762\u6267\u884c\u4e0b\u9762\u547d\u4ee4\uff0c\u6d4b\u8bd5\u8bbf\u95ee\u3002<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-13\" href=\"http:\/\/dba.qishuo.xin\/?p=2624\/#%E4%B8%83%E3%80%81%E9%85%8D%E7%BD%AE%E4%BD%A0%E7%9A%84%E6%B5%8F%E8%A7%88%E5%99%A8%E4%BD%BF%E7%94%A8%E4%BB%A3%E7%90%86%E6%9C%8D%E5%8A%A1%E5%99%A8\" >\u4e03\u3001\u914d\u7f6e\u4f60\u7684\u6d4f\u89c8\u5668\u4f7f\u7528\u4ee3\u7406\u670d\u52a1\u5668<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-14\" href=\"http:\/\/dba.qishuo.xin\/?p=2624\/#%E9%99%84%E5%BD%95\" >\u9644\u5f55<\/a><ul class='ez-toc-list-level-4' ><li class='ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-15\" href=\"http:\/\/dba.qishuo.xin\/?p=2624\/#%E9%99%84%E5%BD%95A_%E7%9B%B8%E5%85%B3%E8%81%94%E7%9A%84%E6%96%87%E7%AB%A0\" >\u9644\u5f55A. \u76f8\u5173\u8054\u7684\u6587\u7ae0<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-16\" href=\"http:\/\/dba.qishuo.xin\/?p=2624\/#%E9%99%84%E5%BD%95B_%E5%85%B6%E4%BB%96%E5%8F%82%E8%80%83\" >\u9644\u5f55B. \u5176\u4ed6\u53c2\u8003<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n<p><strong>\u73af\u5883\u63cf\u8ff0<\/strong><\/p>\n<table>\n<thead>\n<tr>\n<th style=\"text-align: left;\">\u63cf\u8ff0\u9879<\/th>\n<th style=\"text-align: left;\">\u5185\u5bb9<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"text-align: left;\">\u64cd\u4f5c\u7cfb\u7edf<\/td>\n<td style=\"text-align: left;\">CentOS Linux release 7.9.2009 (Core)<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3><span class=\"ez-toc-section\" id=\"1_%E7%AE%80%E4%BB%8B\"><\/span>1. \u7b80\u4ecb<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Squid \u662f\u4e00\u4e2a\u529f\u80fd\u5168\u9762\u7684\u7f13\u5b58\u4ee3\u7406\u670d\u52a1\u5668\uff0c\u5b83\u652f\u6301\u8457\u540d\u7684\u7f51\u7edc\u534f\u8bae\u50cf HTTP\uff0cHTTPS\uff0cFTP \u7b49\u7b49\u3002\u5c06 Squid \u653e\u5728\u7f51\u9875\u670d\u52a1\u5668\u7684\u524d\u7aef\uff0c\u901a\u8fc7\u7f13\u5b58\u91cd\u590d\u8bf7\u6c42\uff0c\u8fc7\u6ee4\u7f51\u7edc\u6d41\u91cf\u7b49\uff0c\u53ef\u4ee5\u6781\u5927\u5730\u63d0\u9ad8\u670d\u52a1\u5668\u7684\u6027\u80fd\u3002<\/p>\n<p><a href=\"http:\/\/dba.qishuo.xin\/wp-content\/uploads\/2023\/01\/image-1673576410485.png\" data-fancybox=\"images\" data-fancybox=\"images\"><img decoding=\"async\" src=\"http:\/\/dba.qishuo.xin\/wp-content\/uploads\/2023\/01\/image-1673576410485.png\" alt=\"file\" \/><\/a><\/p>\n<h3><span class=\"ez-toc-section\" id=\"2_%E5%9C%A8_CentOS_%E4%B8%8A%E5%AE%89%E8%A3%85_Squid\"><\/span>2. \u5728 CentOS \u4e0a\u5b89\u88c5 Squid<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Squid \u8f6f\u4ef6\u5305\u5305\u542b\u5728\u9ed8\u8ba4\u7684 CentOS 7 \u6e90\u4ed3\u5e93\u4e2d\u3002\u60f3\u8981\u5b89\u88c5\u5b83\uff0c\u4ee5 sudo \u7528\u6237\u8eab\u4efd\u8fd0\u884c\u4e0b\u9762\u7684\u547d\u4ee4\uff1a<\/p>\n<pre><code class=\"language-bash\">~]$ sudo yum install squid<\/code><\/pre>\n<p>\u4e00\u65e6\u5b89\u88c5\u5b8c\u6210\uff0c\u542f\u52a8\u5e76\u5f00\u542f Squid \u670d\u52a1\uff1a<\/p>\n<pre><code class=\"language-bash\">~]$ sudo systemctl start squid\n~]$ sudo systemctl enable squid<\/code><\/pre>\n<p>\u60f3\u8981\u9a8c\u8bc1\u5b89\u88c5\u662f\u5426\u6210\u529f\uff0c\u8f93\u5165\u4e0b\u9762\u7684\u547d\u4ee4\uff0c\u5c06\u4f1a\u6253\u5370\u51fa\u670d\u52a1\u7684\u72b6\u6001\uff1a<\/p>\n<pre><code class=\"language-bash\">~]$ sudo systemctl status squid<\/code><\/pre>\n<h3><span class=\"ez-toc-section\" id=\"3_%E9%85%8D%E7%BD%AE_Squid\"><\/span>3. \u914d\u7f6e Squid<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Squid \u901a\u8fc7\u7f16\u8f91 <code>\/etc\/squid\/squid.conf<\/code> \u6587\u4ef6\u8fdb\u884c\u914d\u7f6e\u3002\u65b0\u589e\u6587\u4ef6\u53ef\u4ee5\u4f7f\u7528&quot;include&quot;\u6307\u4ee4\u6dfb\u52a0\u5230\u914d\u7f6e\u6587\u4ef6\u4e2d\u3002<\/p>\n<p>\u5728\u505a\u4efb\u4f55\u4fee\u6539\u4e4b\u524d\uff0c\u4f7f\u7528cp\u547d\u4ee4\u5907\u4efd\u539f\u6765\u7684\u914d\u7f6e\u6587\u4ef6\uff1a<\/p>\n<pre><code class=\"language-bash\">~]$ sudo cp \/etc\/squid\/squid.conf{,.orginal}<\/code><\/pre>\n<p>\u60f3\u8981\u7f16\u8f91\u6587\u4ef6\uff0c\u4f7f\u7528\u6587\u672c\u7f16\u8f91\u5668\u6253\u5f00\u5b83\uff1a<\/p>\n<pre><code class=\"language-bash\">~]$ sudo nano \/etc\/squid\/squid.conf<\/code><\/pre>\n<p>\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0cSquid \u88ab\u914d\u7f6e\u6210\u5728\u670d\u52a1\u5668\u6240\u6709\u7f51\u7edc\u63a5\u53e3\u4e0a\u76d1\u542c\u7aef\u53e33128\u3002<\/p>\n<p>\u5982\u679c\u4f60\u60f3\u4fee\u6539\u7aef\u53e3\u53f7\uff0c\u5e76\u4e14\u8bbe\u7f6e\u76d1\u542c\u63a5\u53e3\uff0c\u5b9a\u4f4d\u5230 <code>http_port<\/code> \u5904\uff0c\u5e76\u4e14\u6307\u5b9a\u63a5\u53e3 IP \u5730\u5740\u548c\u65b0\u7aef\u53e3\u3002\u5982\u679c\u6ca1\u6709\u63a5\u53e3\u6307\u5b9a\uff0cSquid \u5c06\u76d1\u542c\u6240\u6709\u7f51\u7edc\u63a5\u53e3\u3002<\/p>\n<pre><code class=\"language-bash\">~]$ sudo vim \/etc\/squid\/squid.conf<\/code><\/pre>\n<p>\u4ee5\u4e0b\u4e3a\u914d\u7f6e\u6587\u4ef6\u7684\u8be6\u7ec6\u5185\u5bb9\uff1a<\/p>\n<pre><code class=\"language-text\"># Squid normally listens to port 3128\nhttp_port IP_ADDR:PORT\n\u5728\u6240\u6709\u63a5\u53e3\u4e0a\u548c\u9ed8\u8ba4\u7aef\u53e3\u4e0a\u8fd0\u884c Squid \u5bf9\u5927\u90e8\u5206\u7528\u6237\u90fd\u5f88\u9002\u7528\u3002\n\n\u4f60\u53ef\u4ee5\u4f7f\u7528 Access Control Lists (ACLs)\u6765\u63a7\u5236 Squid \u670d\u52a1\u5668\u7684\u8bbf\u95ee\u3002\n\n\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0cSquid \u4ec5\u4ec5\u5141\u8bb8\u4ece\u672c\u5730\u4e3b\u673a\u548c\u672c\u5730\u7f51\u7edc\u6765\u7684\u8bbf\u95ee\u3002\n\n\u5982\u679c\u6240\u6709\u5c06\u8981\u4f7f\u7528\u4ee3\u7406\u670d\u52a1\u5668\u7684\u5ba2\u6237\u7aef\u90fd\u6709\u4e00\u4e2a\u56fa\u5b9a IP \u5730\u5740\uff0c\u4f60\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2a \u5305\u542b\u5141\u8bb8 IP \u5730\u5740\u7684 ACL\u3002\n\n\u4e0d\u7528\u5728\u4e3b\u8981\u914d\u7f6e\u4e2d\u6dfb\u52a0 IP \u5730\u5740\uff0c\u6211\u4eec\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2a\u65b0\u914d\u7f6e\u6587\u4ef6\uff0c\u7528\u6765\u914d\u7f6e\u5730\u5740\uff1a \/etc\/squid\/allowed_ips.txt\n\n192.168.33.1\n# All other allowed IPs\n\u4e00\u65e6\u5b8c\u6210\uff0c\u6253\u5f00\u4e3b\u8981\u914d\u7f6e\u6587\u4ef6\uff0c\u5e76\u4e14\u521b\u5efa\u4e00\u4e2a\u65b0\u7684 ACL \uff0c\u547d\u540d\u4e3aallowed_ips,\u5e76\u4e14\u4f7f\u7528http_access\u6307\u4ee4\u5141\u8bb8\u5b83\u8bbf\u95ee\uff1a \/etc\/squid\/squid.conf\n\n# ...\nacl allowed_ips  src &quot;\/etc\/squid\/allowed_ips.txt&quot;\n# ...\nhttp_access allow localnet\nhttp_access allow localhost\nhttp_access allow allowed_ips\n# And finally deny all other access to this proxy\nhttp_access deny all\n\u8fd9\u4e2ahttp_access\u89c4\u5219\u7684\u987a\u5e8f\u5f88\u91cd\u8981\u3002\u786e\u8ba4\u4f60\u5728http_access deny all\u4e4b\u524d\u6dfb\u52a0\u4e86\u8fd9\u4e00\u884c\u3002\n\nhttp_access\u6307\u4ee4\u7c7b\u4f3c\u4e8e\u9632\u706b\u5899\u89c4\u5219\u3002Squid \u4ece\u4e0a\u5230\u4e0b\u8bfb\u53d6\u89c4\u5219\uff0c\u5e76\u4e14\u540e\u9762\u5339\u914d\u7684\u89c4\u5219\u4e0d\u4f1a\u88ab\u5904\u7406\u3002<\/code><\/pre>\n<p>\u4e0d\u7ba1\u4f60\u5bf9\u914d\u7f6e\u6587\u4ef6\u505a\u4e86\u4ec0\u4e48\u4fee\u6539\uff0c\u4f60\u9700\u8981\u91cd\u65b0\u542f\u52a8 Squid \u670d\u52a1\u5668\u6765\u4f7f\u4fee\u6539\u751f\u6548\uff1a<\/p>\n<pre><code class=\"language-bash\">~]$ sudo systemctl restart squid<\/code><\/pre>\n<h3><span class=\"ez-toc-section\" id=\"4_Squid_%E8%BA%AB%E4%BB%BD%E9%AA%8C%E8%AF%81\"><\/span>4. Squid \u8eab\u4efd\u9a8c\u8bc1<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Squid \u53ef\u4ee5\u4f7f\u7528\u4e0d\u540c\u7684\u540e\u7aef\uff0c\u5305\u62ec Samba\uff0cLDAP \u548c HTTP \u57fa\u672c\u9a8c\u8bc1\u6765\u9a8c\u8bc1\u7528\u6237\u3002<\/p>\n<p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u914d\u7f6e Squid \u4f7f\u7528\u57fa\u672c\u9a8c\u8bc1\u3002\u5b83\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u9a8c\u8bc1\u65b9\u6cd5\uff0c\u5185\u7f6e\u5728 HTTP \u534f\u8bae\u4e2d\u3002<\/p>\n<p>\u6211\u4eec\u5c06\u4f7f\u7528openssl\u6765\u751f\u6210\u5bc6\u7801\uff0c\u5e76\u4e14\u9644\u52a0username:password\u5bf9\u5230\u6587\u4ef6\/etc\/squid\/htpasswd\u6587\u4ef6\u4e2d\uff0c\u5e76\u4e14\u663e\u793a\u51fa\u6765\uff1a<\/p>\n<pre><code class=\"language-bash\">printf &quot;USERNAME:$(openssl passwd -crypt PASSWORD)\\n&quot; | sudo tee -a \/etc\/squid\/htpasswd<\/code><\/pre>\n<p>\u4f8b\u5982\uff0c\u521b\u5efa\u4e00\u4e2a\u7528\u6237\u540d\u79f0\u4e3amike,\u5e76\u4e14\u5bc6\u7801\u4e3aPz$lPk76,\u4f60\u5c06\u8981\u8fd0\u884c\uff1a<\/p>\n<pre><code class=\"language-bash\">printf &quot;mike:$(openssl passwd -crypt &#039;Pz$lPk76&#039;)\\n&quot; | sudo tee -a \/etc\/squid\/htpasswd\nmike:2nkgQsTSPCsIo<\/code><\/pre>\n<p>\u4e0b\u4e00\u6b65\u662f\u914d\u7f6e Squid \u53bb\u542f\u7528 HTTP \u57fa\u672c\u9a8c\u8bc1\uff0c\u5e76\u4e14\u4f7f\u7528\u8fd9\u4e2a\u6587\u4ef6\u3002<\/p>\n<p>\u6253\u5f00\u4e3b\u8981\u914d\u7f6e\u6587\u4ef6\uff0c\u6dfb\u52a0\u4e0b\u9762\u7684\u5185\u5bb9\uff1a<\/p>\n<pre><code class=\"language-bash\">cat \/etc\/squid\/squid.conf\n\n# ...\nauth_param basic program \/usr\/lib64\/squid\/basic_ncsa_auth \/etc\/squid\/htpasswd\nauth_param basic realm proxy\nacl authenticated proxy_auth REQUIRED\n# ...\nhttp_access allow localnet\nhttp_access allow localhost\nhttp_access allow authenticated\n# And finally deny all other access to this proxy\nhttp_access deny all\n\u524d\u9762\u4e09\u884c\u6211\u4eec\u521b\u5efa\u4e86\u4e00\u4e2a ACL \u540d\u79f0\u4e3aauthenticated,\u6700\u540e\u4e00\u884c\u5141\u8bb8\u901a\u8fc7\u9a8c\u8bc1\u7528\u6237\u8bbf\u95ee\u3002<\/code><\/pre>\n<p>\u91cd\u542f Squid \u670d\u52a1\uff1a<\/p>\n<pre><code class=\"language-bash\">~]$ sudo systemctl restart squid<\/code><\/pre>\n<h3><span class=\"ez-toc-section\" id=\"5_%E9%85%8D%E7%BD%AE%E9%98%B2%E7%81%AB%E5%A2%99\"><\/span>5. \u914d\u7f6e\u9632\u706b\u5899<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>\u5982\u679c\u4f60\u6b63\u5728\u8fd0\u884c\u9632\u706b\u5899\uff0c\u4f60\u9700\u8981\u6253\u5f00\u7aef\u53e33128\u3002\u60f3\u8981\u8fd9\u4e48\u505a\uff0c\u8fd0\u884c\u4e0b\u9762\u7684\u547d\u4ee4\uff1a<\/p>\n<pre><code class=\"language-bash\">~]$ sudo firewall-cmd --permanent --add-port=3128\/tcp\n~]$ firewall-cmd --reload<\/code><\/pre>\n<p>\u5982\u679c Squid \u8fd0\u884c\u5728\u53e6\u5916\u4e00\u4e2a\uff0c\u975e\u9ed8\u8ba4\u7aef\u53e3\uff0c\u4f60\u9700\u8981\u5141\u8bb8\u90a3\u4e2a\u7aef\u53e3\u901a\u8fc7\u6d41\u91cf\u3002<\/p>\n<h3><span class=\"ez-toc-section\" id=\"6_%E6%B5%8B%E8%AF%95Squid\"><\/span>6. \u6d4b\u8bd5Squid<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<h4><span class=\"ez-toc-section\" id=\"61_Mac%E5%92%8CLinux%E6%96%B9%E5%BC%8F%EF%BC%8C%E8%AE%BE%E7%BD%AE%E4%B8%B4%E6%97%B6%E4%BB%A3%E7%90%86%E3%80%82\"><\/span>6.1 Mac\u548cLinux\u65b9\u5f0f\uff0c\u8bbe\u7f6e\u4e34\u65f6\u4ee3\u7406\u3002<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<pre><code class=\"language-bash\">export http_proxy=http:\/\/xxx.xxx.xxx.xxxx:3128\nexport https_proxy=http:\/\/xxx.xxx.xxx.xxxx:3128<\/code><\/pre>\n<p><a href=\"http:\/\/dba.qishuo.xin\/wp-content\/uploads\/2023\/01\/image-1673576446326.png\" data-fancybox=\"images\" data-fancybox=\"images\"><img decoding=\"async\" src=\"http:\/\/dba.qishuo.xin\/wp-content\/uploads\/2023\/01\/image-1673576446326.png\" alt=\"file\" \/><\/a><\/p>\n<h4><span class=\"ez-toc-section\" id=\"62_%E5%9C%A8YUM%E4%B8%AD%E9%85%8D%E7%BD%AE\"><\/span>6.2. \u5728YUM\u4e2d\u914d\u7f6e<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p><strong>\u5982\u679c\u7f51\u7edc\u73af\u5883\u4e2d\u4f7f\u7528\u4e86\u4ee3\u7406\u670d\u52a1\u5668\uff0c\u4f5c\u4e3a\u5ba2\u6237\u7aef\u7684YUM\u4ed3\u5e93\u914d\u7f6e\u4e2d\u5c31\u9700\u8981\u914d\u7f6e\u4ee3\u7406\uff0c\u624d\u80fd\u4f7f\u7528\u57fa\u4e8e\u4e92\u8054\u7f51\u8bbf\u95ee\u7684YUM\u6e90<\/strong><\/p>\n<pre><code class=\"language-bash\">~]# vim \/etc\/yum.conf\n# \u5728\u6587\u4ef6\u672b\u5c3e\u6dfb\u52a0\u5982\u4e0b\u6bb5\n    proxy= http:\/\/&lt;proxyserver&gt;:&lt;proxyport&gt;\n    proxy_username=USERNAME\n    proxy_password=PASSWORD<\/code><\/pre>\n<p>\u7136\u540e\u6e05\u9664yum\u7684\u7f13\u5b58\uff1a<\/p>\n<pre><code class=\"language-bash\">~]# yum clean all\n~]# yum makecache<\/code><\/pre>\n<h4><span class=\"ez-toc-section\" id=\"63_%E5%9C%A8_etcprofile_%E4%B8%AD%E9%85%8D%E7%BD%AE\"><\/span>6.3. \u5728 \/etc\/profile \u4e2d\u914d\u7f6e<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<ul>\n<li>\u7f16\u8f91 \/etc\/profile \u6587\u4ef6<\/li>\n<\/ul>\n<pre><code class=\"language-bash\"> ~]# vim \/etc\/profile\n# \u5728\u6587\u4ef6\u672b\u5c3e\u6dfb\u52a0\u4ee5\u4e0b\u5185\u5bb9\nexport http_proxy=http:\/\/xxx.xxx.xxx.xxxx:3128\nexport https_proxy=http:\/\/xxx.xxx.xxx.xxxx:3128<\/code><\/pre>\n<ul>\n<li>source\u73af\u5883\u53d8\u91cf<\/li>\n<\/ul>\n<pre><code class=\"language-bash\">~]# source \/etc\/profile<\/code><\/pre>\n<h4><span class=\"ez-toc-section\" id=\"64_Windows%E6%96%B9%E5%BC%8F%EF%BC%8C%E8%AE%BE%E7%BD%AE%E4%B8%B4%E6%97%B6%E4%BB%A3%E7%90%86%E3%80%82\"><\/span>6.4 Windows\u65b9\u5f0f\uff0c\u8bbe\u7f6e\u4e34\u65f6\u4ee3\u7406\u3002<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<pre><code class=\"language-bash\">set http_proxy=http:\/\/xxx.xxx.xxx.xxxx:3128\nset https_proxy=http:\/\/xxx.xxx.xxx.xxxx:3128<\/code><\/pre>\n<h4><span class=\"ez-toc-section\" id=\"65_%E5%9C%A8%E6%9C%8D%E5%8A%A1%E7%AB%AF%E7%9B%91%E6%8E%A7%E4%B8%8B%E6%97%A5%E5%BF%97\"><\/span>6.5 \u5728\u670d\u52a1\u7aef\u76d1\u63a7\u4e0b\u65e5\u5fd7<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<pre><code class=\"language-bash\">tail -f \/var\/log\/squid\/access.log<\/code><\/pre>\n<h4><span class=\"ez-toc-section\" id=\"66_%E5%9C%A8%E7%BB%88%E7%AB%AF%E9%87%8C%E9%9D%A2%E6%89%A7%E8%A1%8C%E4%B8%8B%E9%9D%A2%E5%91%BD%E4%BB%A4%EF%BC%8C%E6%B5%8B%E8%AF%95%E8%AE%BF%E9%97%AE%E3%80%82\"><\/span>6.6 \u5728\u7ec8\u7aef\u91cc\u9762\u6267\u884c\u4e0b\u9762\u547d\u4ee4\uff0c\u6d4b\u8bd5\u8bbf\u95ee\u3002<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<pre><code class=\"language-bash\">curl -l &quot;https:\/\/www.baidu.com&quot;<\/code><\/pre>\n<h3><span class=\"ez-toc-section\" id=\"%E4%B8%83%E3%80%81%E9%85%8D%E7%BD%AE%E4%BD%A0%E7%9A%84%E6%B5%8F%E8%A7%88%E5%99%A8%E4%BD%BF%E7%94%A8%E4%BB%A3%E7%90%86%E6%9C%8D%E5%8A%A1%E5%99%A8\"><\/span>\u4e03\u3001\u914d\u7f6e\u4f60\u7684\u6d4f\u89c8\u5668\u4f7f\u7528\u4ee3\u7406\u670d\u52a1\u5668<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>\u73b0\u5728\u4f60\u5df2\u7ecf\u5efa\u7acb\u4e86 Squid\uff0c\u6700\u540e\u4e00\u6b65\u662f\u914d\u7f6e\u4f60\u559c\u6b22\u7684\u6d4f\u89c8\u5668\u53bb\u4f7f\u7528\u5b83\u3002<\/p>\n<h3><span class=\"ez-toc-section\" id=\"%E9%99%84%E5%BD%95\"><\/span>\u9644\u5f55<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<h4><span class=\"ez-toc-section\" id=\"%E9%99%84%E5%BD%95A_%E7%9B%B8%E5%85%B3%E8%81%94%E7%9A%84%E6%96%87%E7%AB%A0\"><\/span>\u9644\u5f55A. \u76f8\u5173\u8054\u7684\u6587\u7ae0<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<h4><span class=\"ez-toc-section\" id=\"%E9%99%84%E5%BD%95B_%E5%85%B6%E4%BB%96%E5%8F%82%E8%80%83\"><\/span>\u9644\u5f55B. \u5176\u4ed6\u53c2\u8003<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<ul>\n<li>\n<p><a target=\"_blank\" href=\"https:\/\/cloud.tencent.com\/developer\/article\/1626753\" title=\"\u5982\u4f55\u5728 CentOS 7\u4e0a\u5b89\u88c5 Squid\u4ee3\u7406\u670d\u52a1\u5668\">\u5982\u4f55\u5728 CentOS 7\u4e0a\u5b89\u88c5 Squid\u4ee3\u7406\u670d\u52a1\u5668<\/a><\/p>\n<\/li>\n<li>\n<p><a target=\"_blank\" href=\"https:\/\/www.cnblogs.com\/cherishry\/p\/5706736.html\" title=\"squid\u4ecb\u7ecd\u53ca\u5176\u7b80\u5355\u914d\u7f6e\">squid\u4ecb\u7ecd\u53ca\u5176\u7b80\u5355\u914d\u7f6e<\/a><\/p>\n<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\u73af\u5883\u63cf\u8ff0 \u63cf\u8ff0\u9879 \u5185\u5bb9 \u64cd\u4f5c\u7cfb\u7edf CentOS L&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[47],"tags":[48,246],"class_list":["post-2624","post","type-post","status-publish","format-standard","hentry","category-linux","tag-linux","tag-squid"],"_links":{"self":[{"href":"http:\/\/dba.qishuo.xin\/index.php?rest_route=\/wp\/v2\/posts\/2624","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/dba.qishuo.xin\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/dba.qishuo.xin\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/dba.qishuo.xin\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/dba.qishuo.xin\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2624"}],"version-history":[{"count":8,"href":"http:\/\/dba.qishuo.xin\/index.php?rest_route=\/wp\/v2\/posts\/2624\/revisions"}],"predecessor-version":[{"id":3445,"href":"http:\/\/dba.qishuo.xin\/index.php?rest_route=\/wp\/v2\/posts\/2624\/revisions\/3445"}],"wp:attachment":[{"href":"http:\/\/dba.qishuo.xin\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2624"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/dba.qishuo.xin\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2624"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/dba.qishuo.xin\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2624"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}