CentOS7利用yum缓存搭建本地源
环境说明
[root@localhost ~]# cat /etc/redhat-release CentOS Linux release 7.6.1810 (Core) [root@localhost ~]# hostnamectl --static set-hostname yum-cache [root@yum-cache ~]# systemctl status firewalld.service ● firewalld.service - firewalld - dynamic firewall daemon Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled) Active: inactive (dead) Docs: man:firewalld(1) [root@yum-cache ~]# sestatus SELinux status: disabled [root@yum-cache ~]# iptables -nL Chain INPUT (policy ACCEPT) target prot opt source destination Chain FORWARD (policy ACCEPT) target prot opt source destination Chain OUTPUT (policy ACCEPT) target prot opt source destination
配置yum缓存
[root@yum-cache ~]# egrep -v "^$|#" /etc/yum.conf [main] cachedir=/var/cache/yum # 设置rpm包缓存的路径 keepcache=1 # 默认为0,改为1 debuglevel=2 logfile=/var/log/yum.log exactarch=1 obsoletes=1 gpgcheck=1 plugins=1 installonly_limit=5 bugtracker_url=http://bugs.centos.org/set_project.php?project_id=23&ref=http://bugs.centos.org/bug_report_page.php?category=yum distroverpkg=centos-release
[root@yum-cache ~]# yum -y install mysql-community-server mysql # 这边用mysql做实验,下过mysql的都知道,没有rpm包,下载真的慢 [root@yum-cache ~]# pwd /root [root@yum-cache ~]# mkdir mysql-5.7.31 [root@yum-cache ~]# ls anaconda-ks.cfg mysql-5.7.31 [root@yum-cache ~]# find /var/cache/yum/ -name "*.rpm" -exec cp {} /root/mysql-5.7.31/ \; [root@yum-cache ~]# ls /root/mysql-5.7.31/ mysql-community-client-5.7.31-1.el7.x86_64.rpm mysql-community-server-5.7.31-1.el7.x86_64.rpm mysql-community-common-5.7.31-1.el7.x86_64.rpm net-tools-2.0-0.25.20131004git.el7.x86_64.rpm mysql-community-libs-5.7.31-1.el7.x86_64.rpm postfix-2.10.1-9.el7.x86_64.rpm mysql-community-libs-compat-5.7.31-1.el7.x86_64.rpm
[root@yum-cache ~]# yum -y install createrepo [root@yum-cache ~]# createrepo -v mysql-5.7.31/ Spawning worker 0 with 7 pkgs Worker 0: reading mysql-community-client-5.7.31-1.el7.x86_64.rpm Worker 0: reading mysql-community-common-5.7.31-1.el7.x86_64.rpm Worker 0: reading mysql-community-libs-5.7.31-1.el7.x86_64.rpm Worker 0: reading mysql-community-libs-compat-5.7.31-1.el7.x86_64.rpm Worker 0: reading mysql-community-server-5.7.31-1.el7.x86_64.rpm Worker 0: reading net-tools-2.0-0.25.20131004git.el7.x86_64.rpm Worker 0: reading postfix-2.10.1-9.el7.x86_64.rpm Workers Finished Saving Primary metadata Saving file lists metadata Saving other metadata Generating sqlite DBs Starting other db creation: Mon Jul 20 22:17:18 2020 Ending other db creation: Mon Jul 20 22:17:18 2020 Starting filelists db creation: Mon Jul 20 22:17:18 2020 Ending filelists db creation: Mon Jul 20 22:17:18 2020 Starting primary db creation: Mon Jul 20 22:17:18 2020 Ending primary db creation: Mon Jul 20 22:17:18 2020 Sqlite DBs complete [root@yum-cache ~]# cd mysql-5.7.31/ # createrepo后,会产生repodata目录 [root@yum-cache mysql-5.7.31]# ls mysql-community-client-5.7.31-1.el7.x86_64.rpm mysql-community-server-5.7.31-1.el7.x86_64.rpm mysql-community-common-5.7.31-1.el7.x86_64.rpm net-tools-2.0-0.25.20131004git.el7.x86_64.rpm mysql-community-libs-5.7.31-1.el7.x86_64.rpm postfix-2.10.1-9.el7.x86_64.rpm mysql-community-libs-compat-5.7.31-1.el7.x86_64.rpm repodata [root@yum-cache mysql-5.7.31]# vim mysql-5.7.31.repo [root@yum-cache mysql-5.7.31]# cat mysql-5.7.31.repo [mysql] name="mysql-5.7.31-local" baseurl=file:///root/mysql-5.7.31/ enable=1 gpgcheck=0 [root@yum-cache ~]# tar czvf mysql-5.7.31.tar.gz mysql-5.7.31/ # 将rpm包和repo文件打包,放到其他机器上测试 [root@yum-cache ~]# ls anaconda-ks.cfg mysql-5.7.31 mysql-5.7.31.tar.gz
测试
[root@localhost ~]# ls # 将tar包上传到服务器上 anaconda-ks.cfg mysql-5.7.31.tar.gz [root@localhost ~]# tar xf mysql-5.7.31.tar.gz [root@localhost ~]# cd mysql-5.7.31/ [root@localhost mysql-5.7.31]# ls mysql-5.7.31.repo mysql-community-server-5.7.31-1.el7.x86_64.rpm mysql-community-client-5.7.31-1.el7.x86_64.rpm net-tools-2.0-0.25.20131004git.el7.x86_64.rpm mysql-community-common-5.7.31-1.el7.x86_64.rpm postfix-2.10.1-9.el7.x86_64.rpm mysql-community-libs-5.7.31-1.el7.x86_64.rpm repodata mysql-community-libs-compat-5.7.31-1.el7.x86_64.rpm [root@localhost mysql-5.7.31]# cp mysql-5.7.31.repo /etc/yum.repos.d/ # 把写好的repo文件复制到yum.repos.d目录下 [root@localhost mysql-5.7.31]# yum clean all # 清除缓存 Loaded plugins: fastestmirror Cleaning repos: base extras mysql updates Cleaning up list of fastest mirrors [root@localhost mysql-5.7.31]# yum makecache Loaded plugins: fastestmirror Determining fastest mirrors * base: mirrors.aliyun.com * extras: mirrors.aliyun.com * updates: mirrors.aliyun.com base | 3.6 kB 00:00:00 extras | 2.9 kB 00:00:00 mysql | 2.9 kB 00:00:00 updates | 2.9 kB 00:00:00 (1/13): base/7/x86_64/group_gz | 153 kB 00:00:01 (2/13): extras/7/x86_64/filelists_db | 217 kB 00:00:02 (3/13): extras/7/x86_64/other_db | 125 kB 00:00:00 (4/13): base/7/x86_64/other_db | 2.6 MB 00:00:03 (5/13): mysql/filelists_db | 6.5 kB 00:00:00 (6/13): mysql/other_db | 4.1 kB 00:00:00 (7/13): mysql/primary_db | 10 kB 00:00:00 (8/13): updates/7/x86_64/filelists_db | 1.7 MB 00:00:00 (9/13): updates/7/x86_64/other_db | 250 kB 00:00:00 (10/13): extras/7/x86_64/primary_db | 205 kB 00:00:02 (11/13): updates/7/x86_64/primary_db | 3.0 MB 00:00:01 (12/13): base/7/x86_64/filelists_db | 7.1 MB 00:00:10 (13/13): base/7/x86_64/primary_db | 6.1 MB 00:00:12 Metadata Cache Created [root@localhost ~]# yum -y install mysql-community-server mysql # 然后你就会发现,直接开始installing了