{"id":256,"date":"2023-10-26T09:14:26","date_gmt":"2023-10-26T01:14:26","guid":{"rendered":"http:\/\/www.betterit360.com\/?p=256"},"modified":"2023-10-26T09:14:26","modified_gmt":"2023-10-26T01:14:26","slug":"%e5%9c%a8centos-7%e4%b8%8a%e8%ae%be%e7%bd%ae%e6%9c%ac%e5%9c%b0http-yum%e5%ad%98%e5%82%a8%e5%ba%93","status":"publish","type":"post","link":"http:\/\/www.betterit360.com\/?p=256","title":{"rendered":"<strong>\u5728CentOS 7\u4e0a\u8bbe\u7f6e\u672c\u5730HTTP Yum\u5b58\u50a8\u5e93<\/strong>"},"content":{"rendered":"\n<p>\u8bbe\u7f6e\u672c\u5730\u5b58\u50a8\u5e93\u7684\u4e00\u4e2a\u4f18\u70b9\u662f\u4e0d\u9700\u8981\u4e92\u8054\u7f51\u8fde\u63a5\u6765\u5b89\u88c5\u8f6f\u4ef6\u5305\u3002<\/p>\n\n\n\n<p>\u672c\u6587\u5c06\u4ecb\u7ecd\u5982\u4f55\u5728CentOS 7\u4e0a\u901a\u8fc7HTTP (Nginx) web\u670d\u52a1\u5668\u8bbe\u7f6e\u672c\u5730Yum\u5b58\u50a8\u5e93\uff0c\u5e76\u8bf4\u660e\u5982\u4f55\u5728CentOS 7\u5ba2\u6237\u7aef\u673a\u5668\u4e0a\u67e5\u627e\u548c\u5b89\u88c5\u8f6f\u4ef6\u5305\u3002<\/p>\n\n\n\n<p><strong>\u73af\u5883\u8bf4\u660e<\/strong><strong><\/strong><\/p>\n\n\n\n<p>Yum HTTP\u5b58\u50a8\u5e93\u670d\u52a1\u5668: CentOS 7 [192.168.195.185]<\/p>\n\n\n\n<p>\u5ba2\u6237\u7aef\u673a\u5668: CentOS 7 [192.168.195.186]<\/p>\n\n\n\n<p><strong>\u6b65\u9aa4<\/strong><strong>1:<\/strong><strong>\u5b89\u88c5<\/strong><strong>Nginx Web Server<\/strong><strong><\/strong><\/p>\n\n\n\n<p>1.\u4f7f\u7528YUM\u5305\u7ba1\u7406\u5668\u4eceEPEL\u5b58\u50a8\u5e93\u5b89\u88c5Nginx HTTP\u670d\u52a1\u5668\uff0c\u5982\u4e0b\u6240\u793a\u3002<\/p>\n\n\n\n<p># yum install epel-release<\/p>\n\n\n\n<p># yum install nginx<\/p>\n\n\n\n<p>2.\u542f\u52a8Nginx\uff0c\u5e76\u4f7f\u5b83\u5728\u7cfb\u7edf\u542f\u52a8\u65f6\u81ea\u52a8\u542f\u52a8\u3002<\/p>\n\n\n\n<p># systemctl start nginx<\/p>\n\n\n\n<p># systemctl enable nginx<\/p>\n\n\n\n<p># systemctl status nginx<\/p>\n\n\n\n<p>3.\u6253\u5f00\u7aef\u53e380\u548c443\u4ee5\u5141\u8bb8web\u6d41\u91cf\u5230Nginx\u670d\u52a1<\/p>\n\n\n\n<p># firewall-cmd &#8211;zone=public &#8211;permanent &#8211;add-service=http<\/p>\n\n\n\n<p># firewall-cmd &#8211;zone=public &#8211;permanent &#8211;add-service=https<\/p>\n\n\n\n<p># firewall-cmd &#8211;reload<\/p>\n\n\n\n<p>4.\u786e\u8ba4Nginx\u670d\u52a1\u5668\u5df2\u7ecf\u542f\u52a8\u5e76\u8fd0\u884c\uff0c\u4f7f\u7528\u4ee5\u4e0bURL\u80fd\u770b\u5230\u9ed8\u8ba4\u7684Nginx\u7f51\u9875\u3002<\/p>\n\n\n\n<p>http:\/\/SERVER_DOMAIN_NAME_OR_IP<\/p>\n\n\n\n<p><strong>\u6b65\u9aa4<\/strong><strong>2:<\/strong><strong>\u521b\u5efa<\/strong><strong>Yum<\/strong><strong>\u672c\u5730\u5b58\u50a8\u5e93<\/strong><strong><\/strong><\/p>\n\n\n\n<p>5.\u5b89\u88c5\u521b\u5efa\u3001\u914d\u7f6e\u548c\u7ba1\u7406\u672c\u5730\u5b58\u50a8\u5e93\u6240\u9700\u7684\u8f6f\u4ef6\u5305\u3002<\/p>\n\n\n\n<p># yum install createrepo&nbsp; yum-utils<\/p>\n\n\n\n<p>6.\u521b\u5efa\u5fc5\u8981\u7684\u76ee\u5f55(yum\u5b58\u50a8\u5e93)\uff0c\u7528\u4e8e\u5b58\u50a8\u5305\u548c\u4efb\u4f55\u76f8\u5173\u4fe1\u606f\u3002<\/p>\n\n\n\n<p># mkdir -p \/var\/www\/html\/repos\/{base,centosplus,extras,updates}<\/p>\n\n\n\n<p>7.\u4f7f\u7528reposync\u5de5\u5177\u5c06CentOS YUM\u5b58\u50a8\u5e93\u540c\u6b65\u5230\u672c\u5730\u76ee\u5f55\uff0c\u5982\u56fe\u6240\u793a\u3002<\/p>\n\n\n\n<p># reposync -g -l -d -m &#8211;repoid=base &#8211;newest-only &#8211;download-metadata &#8211;download_path=\/var\/www\/html\/repos\/<\/p>\n\n\n\n<p># reposync -g -l -d -m &#8211;repoid=centosplus &#8211;newest-only &#8211;download-metadata &#8211;download_path=\/var\/www\/html\/repos\/<\/p>\n\n\n\n<p># reposync -g -l -d -m &#8211;repoid=extras &#8211;newest-only &#8211;download-metadata &#8211;download_path=\/var\/www\/html\/repos\/<\/p>\n\n\n\n<p># reposync -g -l -d -m &#8211;repoid=updates &#8211;newest-only &#8211;download-metadata &#8211;download_path=\/var\/www\/html\/repos\/<\/p>\n\n\n\n<p>\u4e0a\u8ff0\u547d\u4ee4\u9009\u9879\u542b\u4e49:<\/p>\n\n\n\n<ul>\n<li>-g&nbsp;\u2013\u542f\u7528\u5220\u9664\u4e0b\u8f7d\u540e\u672a\u901a\u8fc7GPG\u7b7e\u540d\u68c0\u67e5\u7684\u8f6f\u4ef6\u5305<\/li>\n\n\n\n<li>-l&nbsp;\u2013\u542f\u7528yum\u63d2\u4ef6\u652f\u6301<\/li>\n\n\n\n<li>-d&nbsp;\u2013\u5141\u8bb8\u5220\u9664\u5b58\u50a8\u5e93\u4e2d\u4e0d\u518d\u5b58\u5728\u7684\u672c\u5730\u5305<\/li>\n\n\n\n<li>-m&nbsp;\u2013\u5141\u8bb8\u4e0b\u8f7dcomps.xml\u6587\u4ef6<\/li>\n\n\n\n<li>&#8211;repoid&nbsp;\u2013\u6307\u5b9a\u5b58\u50a8\u5e93ID<\/li>\n\n\n\n<li>&#8211;newest-only&nbsp;\u2013\u544a\u8bc9reposync\u53ea\u62c9\u53d6repos\u4e2d\u6bcf\u4e2a\u5305\u7684\u6700\u65b0\u7248\u672c<\/li>\n\n\n\n<li>&#8211;download-metadata&nbsp;\u2013\u542f\u7528\u4e0b\u8f7d\u6240\u6709\u975e\u9ed8\u8ba4\u5143\u6570\u636e<\/li>\n\n\n\n<li>&#8211;download_path&nbsp;\u2013\u6307\u5b9a\u4e0b\u8f7d\u8f6f\u4ef6\u5305\u7684\u8def\u5f84<\/li>\n<\/ul>\n\n\n\n<p><strong>8.<\/strong>\u68c0\u67e5\u672c\u5730\u76ee\u5f55\u7684\u5185\u5bb9\uff0c\u4ee5\u786e\u4fdd\u6240\u6709\u5305\u90fd\u5df2\u5728\u672c\u5730\u540c\u6b65<\/p>\n\n\n\n<p># ls -l \/var\/www\/html\/repos\/base\/<\/p>\n\n\n\n<p># ls -l \/var\/www\/html\/repos\/base\/Packages\/<\/p>\n\n\n\n<p># ls -l \/var\/www\/html\/repos\/centosplus\/<\/p>\n\n\n\n<p># ls -l \/var\/www\/html\/repos\/centosplus\/Packages\/<\/p>\n\n\n\n<p># ls -l \/var\/www\/html\/repos\/extras\/<\/p>\n\n\n\n<p># ls -l \/var\/www\/html\/repos\/extras\/Packages\/<\/p>\n\n\n\n<p># ls -l \/var\/www\/html\/repos\/updates\/<\/p>\n\n\n\n<p># ls -l \/var\/www\/html\/repos\/updates\/Packages\/<\/p>\n\n\n\n<p>9.\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\u4e3a\u672c\u5730\u5b58\u50a8\u5e93\u521b\u5efa\u4e00\u4e2a\u65b0\u7684repodata<\/p>\n\n\n\n<p># createrepo \/var\/www\/html\/repos\/base\/&nbsp;<\/p>\n\n\n\n<p># createrepo \/var\/www\/html\/repos\/centosplus\/&nbsp;&nbsp;&nbsp;<\/p>\n\n\n\n<p># createrepo \/var\/www\/html\/repos\/extras\/&nbsp;<\/p>\n\n\n\n<p># createrepo -g comps.xml \/var\/www\/html\/repos\/updates\/&nbsp;<\/p>\n\n\n\n<p>10. \u4e3a\u4e86\u80fd\u591f\u901a\u8fc7web\u6d4f\u89c8\u5668\u67e5\u770b\u5b58\u50a8\u5e93\u548c\u5176\u4e2d\u7684\u5305\uff0c\u521b\u5efa\u4e00\u4e2a\u6307\u5411\u5b58\u50a8\u5e93\u6839\u76ee\u5f55\u7684Nginx\u670d\u52a1\u5668\u914d\u7f6e\u6587\u4ef6\u3002<\/p>\n\n\n\n<p># vim \/etc\/nginx\/conf.d\/repos.conf<\/p>\n\n\n\n<p>\u5c06\u4ee5\u4e0b\u914d\u7f6e\u6dfb\u52a0\u5230repos .conf\u6587\u4ef6\u4e2d\u3002<\/p>\n\n\n\n<p>server {<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; listen&nbsp;&nbsp; 80;<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; server_name&nbsp; repos.test.lab;&nbsp;&nbsp;&nbsp; #change&nbsp; test.lab to your real domain<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; root&nbsp;&nbsp; \/var\/www\/html\/repos;<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; location \/ {<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; index&nbsp; index.php index.html index.htm;<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; autoindex on;&nbsp;&nbsp; #enable listing of directory index<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<\/p>\n\n\n\n<p>}<\/p>\n\n\n\n<p>\u4fdd\u5b58\u6587\u4ef6\u5e76\u5173\u95ed\u5b83\u3002<\/p>\n\n\n\n<p>11.\u91cd\u65b0\u542f\u52a8Nginx\u670d\u52a1\u5668\uff0c\u5e76\u4f7f\u7528\u4ee5\u4e0bURL\u4eceweb\u6d4f\u89c8\u5668\u67e5\u770b\u5b58\u50a8\u5e93\u3002<\/p>\n\n\n\n<p>http:\/\/repos.test.lab<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" loading=\"lazy\" width=\"661\" height=\"228\" src=\"http:\/\/www.betterit360.com\/wp-content\/uploads\/2023\/10\/repos.test_.lab_.png\" alt=\"\" class=\"wp-image-257\"\/><\/figure>\n\n\n\n<p><strong>\u6b65\u9aa4<\/strong><strong>3:<\/strong><strong>\u521b\u5efa\u4e00\u4e2a<\/strong><strong>Cron<\/strong><strong>\u4f5c\u4e1a\u6765\u540c\u6b65\u548c\u521b\u5efa\u5b58\u50a8\u5e93<\/strong><strong><\/strong><\/p>\n\n\n\n<p>12.\u6dfb\u52a0\u4e00\u4e2acron\u4f5c\u4e1a\uff0c\u5b83\u5c06\u81ea\u52a8\u540c\u6b65\u672c\u5730repos\u4e0e\u5b98\u65b9CentOS repos\uff0c\u4ee5\u83b7\u53d6\u66f4\u65b0\u548c\u5b89\u5168\u8865\u4e01\u3002<\/p>\n\n\n\n<p># vim \/etc\/cron.daily\/update-localrepos<\/p>\n\n\n\n<p>\u5c06\u8fd9\u4e9b\u547d\u4ee4\u6dfb\u52a0\u5230\u811a\u672c\u4e2d\u3002<\/p>\n\n\n\n<p>#!\/bin\/bash<\/p>\n\n\n\n<p>##specify all local repositories in a single variable<\/p>\n\n\n\n<p>LOCAL_REPOS=\u201dbase centosplus extras updates\u201d<\/p>\n\n\n\n<p>##a loop to update repos one at a time<\/p>\n\n\n\n<p>for REPO in ${LOCAL_REPOS}; do<\/p>\n\n\n\n<p>reposync -g -l -d -m &#8211;repoid=$REPO &#8211;newest-only &#8211;download-metadata &#8211;download_path=\/var\/www\/html\/repos\/<\/p>\n\n\n\n<p>createrepo \/var\/www\/html\/repos\/$REPO\/&nbsp;<\/p>\n\n\n\n<p>done<\/p>\n\n\n\n<p>\u4fdd\u5b58\u811a\u672c\u5e76\u5173\u95ed\u5b83\uff0c\u5e76\u4e3a\u5176\u8bbe\u7f6e\u9002\u5f53\u7684\u6743\u9650\u3002<\/p>\n\n\n\n<p># chmod 755 \/etc\/cron.daily\/update-localrepos<\/p>\n\n\n\n<p><strong>\u6b65\u9aa4<\/strong><strong>4:<\/strong><strong>\u5728\u5ba2\u6237\u7aef\u673a\u5668\u4e0a\u8bbe\u7f6e\u672c\u5730<\/strong><strong>Yum<\/strong><strong>\u5b58\u50a8\u5e93<\/strong><strong><\/strong><\/p>\n\n\n\n<p>13. \u5728CentOS\u5ba2\u6237\u673a\u4e0a\uff0c\u5c06\u60a8\u7684\u672c\u5730repos\u6dfb\u52a0\u5230YUM\u914d\u7f6e\u4e2d\u3002<\/p>\n\n\n\n<p># vim \/etc\/yum.repos.d\/local-repos.repo<\/p>\n\n\n\n<p>\u5c06\u4e0b\u9762\u7684\u914d\u7f6e\u590d\u5236\u5e76\u7c98\u8d34\u5230local-repos\u6587\u4ef6\u4e2d\u3002(\u5728\u5fc5\u8981\u65f6\u8fdb\u884c\u66f4\u6539)\u3002<\/p>\n\n\n\n<p>[local-base]<\/p>\n\n\n\n<p>name=CentOS Base<\/p>\n\n\n\n<p>baseurl=http:\/\/repos.test.lab\/base\/<\/p>\n\n\n\n<p>gpgcheck=0<\/p>\n\n\n\n<p>enabled=1<\/p>\n\n\n\n<p>[local-centosplus]<\/p>\n\n\n\n<p>name=CentOS CentOSPlus<\/p>\n\n\n\n<p>baseurl=http:\/\/repos.test.lab\/centosplus\/<\/p>\n\n\n\n<p>gpgcheck=0<\/p>\n\n\n\n<p>enabled=1<\/p>\n\n\n\n<p>[local-extras]<\/p>\n\n\n\n<p>name=CentOS Extras<\/p>\n\n\n\n<p>baseurl=http:\/\/repos.test.lab\/extras\/<\/p>\n\n\n\n<p>gpgcheck=0<\/p>\n\n\n\n<p>enabled=1<\/p>\n\n\n\n<p>[local-updates]<\/p>\n\n\n\n<p>name=CentOS Updates<\/p>\n\n\n\n<p>baseurl=http:\/\/repos.test.lab\/updates\/<\/p>\n\n\n\n<p>gpgcheck=0<\/p>\n\n\n\n<p>enabled=1<\/p>\n\n\n\n<p>\u4fdd\u5b58\u6587\u4ef6\u5e76\u5f00\u59cb\u4f7f\u7528\u672c\u5730YUM\u955c\u50cf\u3002<\/p>\n\n\n\n<p>14.\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\u5728\u5ba2\u6237\u7aef\u673a\u5668\u4e0a\u7684\u53ef\u7528YUM repos\u5217\u8868\u4e2d\u67e5\u770b\u672c\u5730repos\u3002<\/p>\n\n\n\n<p>#&nbsp; yum repolist<\/p>\n\n\n\n<p>OR<\/p>\n\n\n\n<p># yum repolist all<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" loading=\"lazy\" width=\"1344\" height=\"171\" src=\"http:\/\/www.betterit360.com\/wp-content\/uploads\/2023\/10\/yum_repolist_all.png\" alt=\"\" class=\"wp-image-258\"\/><\/figure>\n\n\n\n<p>\u5b89\u88c5\u5305\uff1ayum -y install bzip2-devel<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" loading=\"lazy\" width=\"1347\" height=\"556\" src=\"http:\/\/www.betterit360.com\/wp-content\/uploads\/2023\/10\/yum_install.png\" alt=\"\" class=\"wp-image-259\"\/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>\u8bbe\u7f6e\u672c\u5730\u5b58\u50a8\u5e93\u7684\u4e00\u4e2a\u4f18\u70b9\u662f\u4e0d\u9700\u8981\u4e92\u8054\u7f51\u8fde\u63a5\u6765\u5b89\u88c5\u8f6f\u4ef6\u5305\u3002 \u672c\u6587\u5c06\u4ecb\u7ecd\u5982\u4f55\u5728CentOS 7\u4e0a\u901a\u8fc7HTTP (N &hellip; <a href=\"http:\/\/www.betterit360.com\/?p=256\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">\u201c<strong>\u5728CentOS 7\u4e0a\u8bbe\u7f6e\u672c\u5730HTTP Yum\u5b58\u50a8\u5e93<\/strong>\u201d<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"http:\/\/www.betterit360.com\/index.php?rest_route=\/wp\/v2\/posts\/256"}],"collection":[{"href":"http:\/\/www.betterit360.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.betterit360.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.betterit360.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.betterit360.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=256"}],"version-history":[{"count":1,"href":"http:\/\/www.betterit360.com\/index.php?rest_route=\/wp\/v2\/posts\/256\/revisions"}],"predecessor-version":[{"id":260,"href":"http:\/\/www.betterit360.com\/index.php?rest_route=\/wp\/v2\/posts\/256\/revisions\/260"}],"wp:attachment":[{"href":"http:\/\/www.betterit360.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=256"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.betterit360.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=256"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.betterit360.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=256"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}