{"id":240,"date":"2022-02-08T11:33:06","date_gmt":"2022-02-08T03:33:06","guid":{"rendered":"https:\/\/blog.sfgz.com.cn\/?p=240"},"modified":"2022-03-11T14:44:04","modified_gmt":"2022-03-11T06:44:04","slug":"centos%e6%90%ad%e5%bb%ba%e4%bc%81%e4%b8%9ayum%e4%bb%93%e5%ba%93","status":"publish","type":"post","link":"https:\/\/blog.sfgz.com.cn\/index.php\/2022\/02\/08\/centos%e6%90%ad%e5%bb%ba%e4%bc%81%e4%b8%9ayum%e4%bb%93%e5%ba%93\/","title":{"rendered":"Centos\u642d\u5efa\u4f01\u4e1aYUM\u4ed3\u5e93"},"content":{"rendered":"<h1>Centos<\/h1>\n<h2>\u4e00\u3001\u6e90\u670d\u52a1\u5668\u7684\u7cfb\u7edf\u73af\u5883\u3002\u6700\u5c0f\u5316\u5b89\u88c5<\/h2>\n<blockquote>\n<p>[root@yumserver ~]#<code>cat \/etc\/redhat-release<\/code><br \/>\nCentOS Linux release 7.9.2009 (Core)<\/p>\n<\/blockquote>\n<h3><code>\u6e90\u670d\u52a1\u5668IP\u5730\u5740\uff1a192.168.0.200<\/code><\/h3>\n<h2>\u4e8c\u3001\u653e\u5f00\u7cfb\u7edf\u9632\u706b\u5899,\u5173\u95edselinux<\/h2>\n<blockquote>\n<p>[root@yumserver ~]#<code>firewall-cmd --add-port=80\/tcp --permanent<\/code><br \/>\nsuccess<br \/>\n[root@yumserver ~]# <code>firewall-cmd --reload<\/code><br \/>\nsuccess<\/p>\n<p>[root@yumserver ~]# <code>vim \/etc\/selinux\/config<\/code><br \/>\n<em># This file controls the state of SELinux on the system.<\/em><br \/>\n<em># SELINUX= can take one of these three values:<\/em><br \/>\n<em>#     enforcing &#8211; SELinux security policy is enforced.<\/em><br \/>\n<em>#     permissive &#8211; SELinux prints warnings instead of enforcing.<\/em><br \/>\n<em>#     disabled &#8211; No SELinux policy is loaded.<\/em><br \/>\nSELINUX=<code>disabled<\/code><br \/>\n<em># SELINUXTYPE= can take one of three values:<\/em><br \/>\n<em>#     targeted &#8211; Targeted processes are protected,<\/em><br \/>\n<em>#     minimum &#8211; Modification of targeted policy. Only selected processes are protected.<\/em><br \/>\n<em>#     mls &#8211; Multi Level Security protection.<\/em><br \/>\nSELINUXTYPE=targeted<\/p>\n<\/blockquote>\n<h2>\u4e09.\u6dfb\u52a0\u963f\u91cc\u4e91yum\u6e90\u5e76\u68c0\u67e5<\/h2>\n<p><code>\u5907\u4efd\u597d\u539f\u7cfb\u7edf\u7684repo<\/code><\/p>\n<blockquote>\n<p>[root@yumserver ~]#cd \/etc\/yum.repos.d<br \/>\n[root@yumserver ~]#mkdir backup<br \/>\n[root@yumserver yum.repos.d]# mv *.repo  backup\/<\/p>\n<\/blockquote>\n<p><code>\u4e0b\u8f7d\u963f\u91cc\u4e91repo<\/code><\/p>\n<blockquote>\n<p>[root@yumserver yum.repos.d]#<code>curl -o \/etc\/yum.repos.d\/CentOS-Base.repo https:\/\/mirrors.aliyun.com\/repo\/Centos-7.repo<\/code><br \/>\n[root@yumserver yum.repos.d]#<code>curl -o \/etc\/yum.repos.d\/epel.repo        http:\/\/mirrors.aliyun.com\/repo\/epel-7.repo<\/code><br \/>\n[root@yumserver yum.repos.d]#<code>yum makecache<\/code><br \/>\n[root@yumserver yum.repos.d]#<code>yum repolist<\/code><\/p>\n<\/blockquote>\n<h2>\u56db.\u5b89\u88c5\u76f8\u5173\u8f6f\u4ef6<\/h2>\n<blockquote>\n<p>yum install -y wget make cmake gcc gcc-c++ pcre-devel zlib-devel openssl openssl-devel httpd yum-utils createrepo<\/p>\n<\/blockquote>\n<p>\u6ce8\u91ca\uff1a<\/p>\n<ul>\n<li>yum-utils\uff1areposync\u540c\u6b65\u5de5\u5177<\/li>\n<li>createrepo\uff1a\u7f16\u8f91yum\u5e93\u5de5\u5177<\/li>\n<li>httpd\uff1a\u901a\u8fc7Apache\u8f6f\u4ef6\u63d0\u4f9bweb\u670d\u52a1\uff0c\u4e5f\u53ef\u4ee5\u4f7f\u7528nginx<\/li>\n<\/ul>\n<h2>\u4e94\u3001\u540c\u6b65\u963f\u91cc\u4e91yum\u6e90\u8f6f\u4ef6\u5305\u5230\u672c\u5730\u670d\u52a1\u5668\u6307\u5b9a\u76ee\u5f55<\/h2>\n<p><code>\/mirror\uff08\u81ea\u5b9a\u4e49\u76ee\u5f55\uff09<\/code><\/p>\n<blockquote>\n<p>[root@yumserver ~]#<code>mkdir -p \/mirror<\/code><br \/>\n[root@yumserver ~]#<code>chown -R apache:apache \/mirror<\/code><br \/>\n[root@yumserver ~]#<code>chmod -R 755 \/mirror<\/code><br \/>\n[root@yumserver ~]#<code>reposync -n --repoid=extras --repoid=updates --repoid=base --repoid=epel -p \/mirror<\/code><\/p>\n<\/blockquote>\n<p><code>\u53c2\u6570\u6ce8\u91ca\uff1a-n\u6307\u4e0b\u8f7d\u6700\u65b0\u8f6f\u4ef6\u5305\uff0c-p\u6307\u5b9a\u76ee\u5f55\uff0c\u6307\u5b9a\u672c\u5730\u7684\u6e90--repoid\uff08\u5982\u679c\u4e0d\u6307\u5b9a\u5c31\u540c\u6b65\u672c\u5730\u670d\u52a1\u5668\u6240\u6709\u7684\u6e90\uff09,\u4e0b\u8f7d\u8fc7\u7a0b\u6bd4\u8f83\u4e45<\/code><\/p>\n<h2>\u516d.\u521b\u5efa\u4ed3\u5e93\u7d22\u5f15<\/h2>\n<blockquote>\n<p>[root@yumserver ~]#<code>createrepo -po \/mirror\/base\/ \/mirror\/base\/<\/code><br \/>\n[root@yumserver ~]#<code>createrepo -po \/mirror\/extras\/ \/mirror\/extras\/<\/code><br \/>\n[root@yumserver ~]#<code>createrepo -po \/mirror\/updates\/ \/mirror\/updates\/<\/code><br \/>\n[root@yumserver ~]#<code>createrepo -po \/mirror\/epel\/ \/mirror\/epel\/<\/code><\/p>\n<\/blockquote>\n<h2>\u4e03.\u66f4\u65b0\u6570\u636e\u6e90<\/h2>\n<blockquote>\n<p>[root@yumserver ~]#<code>createrepo --update \/mirror\/base\/<\/code><br \/>\n[root@yumserver ~]#<code>createrepo --update \/mirror\/extras\/<\/code><br \/>\n[root@yumserver ~]#<code>createrepo --update \/mirror\/updates\/<\/code><br \/>\n[root@yumserver ~]#<code>createrepo --update \/mirror\/epel\/<\/code><\/p>\n<\/blockquote>\n<h2>\u516b.\u542f\u52a8\u5e76\u914d\u7f6eApache\u670d\u52a1<\/h2>\n<blockquote>\n<p>[root@yumserver ~]#<code>systemctl start httpd<\/code><br \/>\n[root@yumserver ~]#<code>systemctl enable httpd<\/code><br \/>\n[root@yumserver ~]#<code>systemctl status httpd<\/code><br \/>\n[root@yumserver ~]#<code>vim \/etc\/httpd\/conf\/httpd.conf<\/code><\/p>\n<pre><code class=\"language-json\">DocumentRoot &quot;\/mirror\/&quot;\n&lt;Directory &quot;\/mirror\/&quot;&gt;\nOptions Indexes FollowSymLinks\nAllowOverride  None\nOrder allow,deny\nAllow from all\nRequire all granted\n&lt;\/Directory&gt;<\/code><\/pre>\n<\/blockquote>\n<h2>\u4e5d.\u7f16\u5199yum\u6e90\u5ba2\u6237\u7aef\u914d\u7f6e\u6587\u4ef6<\/h2>\n<blockquote>\n<p>[root@yumserver repo]#<code>vim \/mirror\/repo\/CentOS-Base.repo<\/code><\/p>\n<pre><code class=\"language-css\">[base]\nname=CentOS- - Base - 192.168.0.200\nfailovermethod=priority\nbaseurl=http:\/\/192.168.0.200\/base\/\nenable=1\ngpgcheck=0\n[updates]\nname=CentOS- - Updates - 192.168.0.200\nfailovermethod=priority\nbaseurl=http:\/\/192.168.0.200\/updates\/\nenable=1\ngpgcheck=0\n[extras]\nname=CentOS- - Extras - 192.168.0.200\nfailovermethod=priority\nbaseurl=http:\/\/192.168.0.200\/extras\/\nenable=1\ngpgcheck=0\n[epel]\nname=CentOS- - Epel - 192.168.0.200\nfailovermethod=priority\nbaseurl=http:\/\/192.168.0.200\/epel\/\nenable=1\ngpgcheck=0<\/code><\/pre>\n<hr \/>\n<\/blockquote>\n<h2>\u5341.\u5ba2\u6237\u7aef\u914d\u7f6eyum\u6e90<\/h2>\n<h3>\u7528\u6237\u53ef\u4ee5\u6d4f\u89c8\u5668\u8bbf\u95ee192.168.0.200\u67e5\u770b\u914d\u7f6e\u5ba2\u6237\u7aefyum\u6e90\u7684\u65b9\u6cd5<\/h3>\n<blockquote>\n<p>[root@servera ~]#<code>curl -o \/etc\/yum.repos.d\/CentOS-Base.repo http:\/ \/192.168.0.200\/repo\/CentOS-Base.repo<\/code><br \/>\n[root@servera ~]#<code>yum makecache<\/code><\/p>\n<\/blockquote>\n<h2>\u5341\u4e00.\u8bbe\u7f6e\u5b9a\u65f6\u540c\u6b65yum\u6e90\u7684\u4efb\u52a1<\/h2>\n<blockquote>\n<p>[root@yumserver ~]#<code>vim \/mirror\/script\/centos_yum_update.sh<\/code><\/p>\n<pre><code class=\"language-bash\">#!\/bin\/bash\necho &#039;Updating Aliyum Source&#039;\nDATETIME=`date +%F_%T`\nexec &gt; \/var\/log\/aliyumrepo_$DATETIME.log\nreposync -np \/mirror\nif [ $? -eq 0 ];then\ncreaterepo --update \/mirror\/base\ncreaterepo --update \/mirror\/extras\ncreaterepo --update \/mirror\/updates\ncreaterepo --update \/mirror\/epel\necho &quot;SUCESS: $DATETIME aliyum_yum update successful&quot;\nelse\necho &quot;ERROR: $DATETIME aliyum_yum update failed&quot;\nfi<\/code><\/pre>\n<\/blockquote>\n<h3>\u6dfb\u52a0\u5b9a\u65f6\u4efb\u52a1,\u6bcf\u5468\u4e00\u51cc\u66681\u70b9\u6267\u884c\u6dfb\u52a0\u5b9a\u65f6\u4efb\u52a1,\u6bcf\u5468\u4e00\u51cc\u66681\u70b9\u6267\u884c<\/h3>\n<blockquote>\n<p>[root@yumserver ~]#crontab -l<br \/>\n0 1 <em> <\/em> 1 \/bin\/bash \/mirror\/script\/centos_yum_update.sh<\/p>\n<\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>Centos \u4e00\u3001\u6e90\u670d\u52a1\u5668\u7684\u7cfb\u7edf\u73af\u5883\u3002\u6700\u5c0f\u5316\u5b89\u88c5 [root@yumserver &hellip; <a href=\"https:\/\/blog.sfgz.com.cn\/index.php\/2022\/02\/08\/centos%e6%90%ad%e5%bb%ba%e4%bc%81%e4%b8%9ayum%e4%bb%93%e5%ba%93\/\">\u7ee7\u7eed\u9605\u8bfb <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-240","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/blog.sfgz.com.cn\/index.php\/wp-json\/wp\/v2\/posts\/240","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.sfgz.com.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.sfgz.com.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.sfgz.com.cn\/index.php\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.sfgz.com.cn\/index.php\/wp-json\/wp\/v2\/comments?post=240"}],"version-history":[{"count":6,"href":"https:\/\/blog.sfgz.com.cn\/index.php\/wp-json\/wp\/v2\/posts\/240\/revisions"}],"predecessor-version":[{"id":326,"href":"https:\/\/blog.sfgz.com.cn\/index.php\/wp-json\/wp\/v2\/posts\/240\/revisions\/326"}],"wp:attachment":[{"href":"https:\/\/blog.sfgz.com.cn\/index.php\/wp-json\/wp\/v2\/media?parent=240"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.sfgz.com.cn\/index.php\/wp-json\/wp\/v2\/categories?post=240"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.sfgz.com.cn\/index.php\/wp-json\/wp\/v2\/tags?post=240"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}