文章目录
1、centos 的yum仓库 搭建
1.1 本地yum仓库
虚拟机设置中勾选已连接和启动时连接
挂载 sr0 到mnt 下
[root@localhost ~]# mount /dev/sr0 /mnt
mount: /dev/sr0 写保护,将以只读方式挂载
[root@localhost ~]#
df 查看挂载情况
[root@localhost ~]# df -h
文件系统 容量 已用 可用 已用% 挂载点
/dev/mapper/centos-root 50G 5.2G 45G 11% /
devtmpfs 897M 0 897M 0% /dev
tmpfs 912M 0 912M 0% /dev/shm
tmpfs 912M 18M 895M 2% /run
tmpfs 912M 0 912M 0% /sys/fs/cgroup
/dev/mapper/centos-home 27G 33M 27G 1% /home
/dev/sda1 1014M 179M 836M 18% /boot
tmpfs 183M 48K 183M 1% /run/user/0
/dev/sr0 4.3G 4.3G 0 100% /mnt
[root@localhost ~]#
查看目前的源是什么
[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# ls
CentOS-aliyun-lhr.repo epel-aliyun.repo
[root@localhost yum.repos.d]#
创建本地源
vim local.repo
[local]
name=local
baseurl=file:///mnt
gpgcheck=0
重新加载源
[root@localhost yum.repos.d]# yum clean all & yum makecache
[root@localhost yum.repos.d]# yum clean all & yum makecache
[1] 63613
已加载插件:fastestmirror, langpacks
已加载插件:fastestmirror, langpacks
正在清理软件源: local
Cleaning up everything
Maybe you want: rm -rf /var/cache/yum, to also free up space taken by orphaned data from disabled or removed repos
/var/run/yum.pid 已被锁定,PID 为 63613 的另一个程序正在运行。
Another app is currently holding the yum lock; waiting for it to exit...
另一个应用程序是:yum
内存: 23 M RSS (340 MB VSZ)
已启动: Fri Apr 18 11:33:45 2025 - 00:02之前
状态 :运行中,进程ID:63613
Cleaning up list of fastest mirrors
local | 3.6 kB 00:00
(1/4): local/group_gz | 156 kB 00:00
(2/4): local/primary_db | 3.1 MB 00:00
(3/4): local/filelists_db | 3.1 MB 00:00
(4/4): local/other_db | 1.2 MB 00:00
Determining fastest mirrors
元数据缓存已建立
[1]+ 完成 yum clean all
[root@localhost yum.repos.d]#
尝试下载软件
yum -y install gcc pcre-devel openssl-devel zlib-devel openssl openssl-devel
安装成功
可以看到就是我们刚建立的local.repo
1.2 centos局域网的yum仓库 用http的方法实现
在服务器上安装httpd服务
[root@localhost ~]# systemctl start httpd
开启httpd服务
查看httpd服务的状态
[root@localhost ~]# systemctl status httpd.service
● httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
Active: active (running) since 五 2025-04-18 16:59:18 CST; 37s ago
Docs: man:httpd(8)
man:apachectl(8)
Main PID: 63012 (httpd)
Status: "Total requests: 0; Current requests/sec: 0; Current traffic: 0 B/sec"
CGroup: /system.slice/httpd.service
├─63012 /usr/sbin/httpd -DFOREGROUND
├─63013 /usr/sbin/httpd -DFOREGROUND
├─63014 /usr/sbin/httpd -DFOREGROUND
├─63015 /usr/sbin/httpd -DFOREGROUND
├─63016 /usr/sbin/httpd -DFOREGROUND
└─63017 /usr/sbin/httpd -DFOREGROUND
4月 18 16:59:18 localhost.localdomain systemd[1]: Starting The Apache HTTP S...
4月 18 16:59:18 localhost.localdomain httpd[63012]: AH00558: httpd: Could no...
4月 18 16:59:18 localhost.localdomain systemd[1]: Started The Apache HTTP Se...
Hint: Some lines were ellipsized, use -l to show in full.
[root@localhost ~]#
将光驱SR0挂载到http的目录下
[root@localhost ~]# mount /dev/sr0 /var/www/html/
mount: /dev/sr0 写保护,将以只读方式挂载
[root@localhost ~]#
在客户机上同样安装httpd服务
启动httpd服务
新建一个http.repo的文件
[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# ls
CentOS-aliyun-lhr.repo epel-aliyun.repo
[root@localhost yum.repos.d]# mkdir bak
[root@localhost yum.repos.d]# mv *.repo bak/
[root@localhost yum.repos.d]# ls
bak
[root@localhost yum.repos.d]# vim http.repo
[root@localhost yum.repos.d]#
文件配置
[http]
name=http
baseurl=http://192.168.107.190
gpgcheck=0
新建元数据缓存
[root@localhost yum.repos.d]# yum clean all
已加载插件:fastestmirror, langpacks
正在清理软件源: http
Cleaning up everything
Maybe you want: rm -rf /var/cache/yum, to also free up space taken by orphaned data from disabled or removed repos
Cleaning up list of fastest mirrors
[root@localhost yum.repos.d]# yum makecache
已加载插件:fastestmirror, langpacks
http | 3.6 kB 00:00
(1/4): http/group_gz | 156 kB 00:00
(2/4): http/primary_db | 3.1 MB 00:00
(3/4): http/other_db | 1.2 MB 00:00
(4/4): http/filelists_db | 3.1 MB 00:00
Determining fastest mirrors
元数据缓存已建立
[root@localhost yum.repos.d]#
尝试安装软件tree
[root@localhost yum.repos.d]# yum install -y tree
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
正在解决依赖关系
--> 正在检查事务
---> 软件包 tree.x86_64.0.1.6.0-10.el7 将被 安装
--> 解决依赖关系完成
依赖关系解决
================================================================================
Package 架构 版本 源 大小
================================================================================
正在安装:
tree x86_64 1.6.0-10.el7 http 46 k
事务概要
================================================================================
安装 1 软件包
总下载量:46 k
安装大小:87 k
Downloading packages:
tree-1.6.0-10.el7.x86_64.rpm | 46 kB 00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
警告:RPM 数据库已被非 yum 程序修改。
正在安装 : tree-1.6.0-10.el7.x86_64 1/1
验证中 : tree-1.6.0-10.el7.x86_64 1/1
已安装:
tree.x86_64 0:1.6.0-10.el7
完毕!
[root@localhost yum.repos.d]#
1.3 通过ftp的方式建立本地yum仓库
过程与http相对类似 在此就不再赘述
服务器:
systemctl stop firewalld #关闭防火墙
setenforce 0 #关闭核心防护
yum -y install vsftpd #安装软件
systemctl start vsftpd #启用服务
cd /var/ftp/
mkdir yum #创建目录
mount /dev/sr0 /var/ftp/yum/ #挂载目录
客户机:
systemctl stop firewalld #关闭防火墙
setenforce 0 #关闭核心防护
yum -y install vsftpd #安装软件
systemctl start vsftpd #启用服务
vim /etc/yum.repos.d/ftp #创建yum仓库
{[ftp]
name=ftp
baseurl=ftp://IP地址/yum #告知位置所在
gpgcheck=0 #不验证安全性
}
yum clean all && yum makecache #清理旧缓存,创建新缓存
yum -y install tree #验证
1.4 自建元数据
用途比较小众需求应该不会很大
yum -y install createrepo #安装命令
yum -y install tree --downloadonly --downloaddir=/date #只下载到/date下不安装
cd /date
mkdir -p /test/packages #创建目录
mv tree-1.6... /test/packages #将压缩包移动到/test/packages下
createrepo -v test #创建元数据
vim /etc/yum.repos.d/yum.repo
{
[test]
name=test
baseurl=file:///date/test #告知位置
gpgcheck=0 #不验证安装包的安全性
}
yum clean all&& yum makecache #清空旧缓存,添加新缓存
yum -y install tree
2、ubuntu搭建apt仓库 - HTTP模式 会用的比较多
建议初始环境安装的依赖环境
apt install -y iproute2 ntpdate tcpdump telnet traceroute nfs-kernel-server nfs-common lrzsz openssl libssl-dev libpcre3 libpcre3-dev zlib1g-dev gcc openssh-server iotop unzip zip net-tools
创建挂载目录
mkdir /var/www/html/apt -p
下载可能会用得到的安装包到apt目录
apt download $(apt-cache depends --recurse --no-recommends --no-suggests --no-conflicts --no-breaks --no-replaces --no-enhances openssh-server openssh-client qemu qemu-kvm libvirt-daemon-system libvirt-clients bridge-utils virt-manager qemu-system-arm qemu-efi qemu-utils vpp-plugin-core python3-vpp-api net-tools golang build-essential libc6-i386 libc6-i386 docker mysql-server redis-server redis-client mongo mongo-express postgresql openjdk-21-jdk openjdk-11-jdk default-jdk maven python3 python3-pip nginx git ufw dpkg-dev autoconf nodejs build-essential flex bison automake binutils bzr zip glade libglade2-dev apt-transport-https ca-certificates wget iptables elasticsearch kibana | grep -v amd64 | grep "^\w" | sort -u)
查看是否安装完成
root@ubuntu:~# cd /var/www/html/
root@ubuntu:/var/www/html# ls
apt
root@ubuntu:/var/www/html# cd apt/
root@ubuntu:/var/www/html/apt# ls
apt
root@ubuntu:/var/www/html/apt# cd apt/
root@ubuntu:/var/www/html/apt/apt#
root@ubuntu:/var/www/html/apt/apt# ls
acl_2.3.1-1_amd64.deb
adduser_3.118ubuntu5_all.deb
adwaita-icon-theme_41.0-1ubuntu1_all.deb
adwaita-icon-theme-full_41.0-1ubuntu1_all.deb
anacron_2.3-31ubuntu2_amd64.deb
apt_2.4.13_amd64.deb
apt-transport-https_2.4.13_all.deb
aspell_0.60.8-4build1_amd64.deb
aspell-am_0.03-1-5.2_all.deb
aspell-ar_0.0.20060329-6_all.deb
aspell-ar-large_1.2-0-5_all.deb
aspell-bg_4.1-7build2_all.deb
aspell-br_0.50-2-10_all.deb
aspell-ca_0.20111230b-14_all.deb
aspell-cs_0.51.0-1.3_all.deb
aspell-cy_0.50-3-7_all.deb
aspell-da_1.6.36-11.1build2_all.deb
aspell-de-1901_1%3a2-37_all.deb
aspell-de_20161207-9_all.deb
aspell-el_0.50-3-6.2_all.deb
aspell-en_2018.04.16-0-1_all.deb
aspell-eo_2.1.2000.02.25-60_all.deb
aspell-eo-cx7_2.1.2000.02.25-60_all.deb
aspell-es_1.11-19_all.deb
安装生成元数据的命令
apt install dpkg-dev -y
安装网页服务apache2
apt install apache2 -y
开启服务
systemctl start apache2
root@ubuntu:/var/www/html/apt/apt# systemctl start apache2
root@ubuntu:/var/www/html/apt/apt# systemctl status apache2
● apache2.service - The Apache HTTP Server
Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
Active: active (running) since Fri 2025-04-18 11:24:44 UTC; 1min 46s ago
Docs: https://httpd.apache.org/docs/2.4/
Main PID: 7043 (apache2)
Tasks: 55 (limit: 4521)
Memory: 5.0M
CPU: 113ms
CGroup: /system.slice/apache2.service
├─7043 /usr/sbin/apache2 -k start
├─7044 /usr/sbin/apache2 -k start
└─7045 /usr/sbin/apache2 -k start
Apr 18 11:24:44 ubuntu systemd[1]: Starting The Apache HTTP Server...
Apr 18 11:24:44 ubuntu apachectl[7042]: AH00558: apache2: Could not reliably determine the server's fu>
Apr 18 11:24:44 ubuntu systemd[1]: Started The Apache HTTP Server.
lines 1-16/16 (END)
在html目录下创建Packages
dpkg-scanpackages apt/ >Packages
(P要大写)
root@ubuntu:/var/www/html/apt# dpkg-scanpackages apt/ >Packages
dpkg-scanpackages: info: Wrote 937 entries to output Packages file.
root@ubuntu:/var/www/html/apt#
在/etc/apt/sources.list 下操作
root@ubuntu:/var/www/html/apt# cd /etc/apt/
root@ubuntu:/etc/apt# ls
apt.conf.d keyrings sources.list sources.list.d
auth.conf.d preferences.d sources.list.curtin.old trusted.gpg.d
root@ubuntu:/etc/apt# mv sources.list sources.list.bak
root@ubuntu:/etc/apt# ls
apt.conf.d keyrings sources.list.bak sources.list.d
auth.conf.d preferences.d sources.list.curtin.old trusted.gpg.d
root@ubuntu:/etc/apt# vim sources.list
root@ubuntu:/etc/apt#
deb [trusted=yes] http://192.168.107.180/ /
apt update
root@ubuntu:/var/www/html# apt update
Get:1 file:/var/www/html InRelease
Ign:1 file:/var/www/html InRelease
Get:2 file:/var/www/html Release
Ign:2 file:/var/www/html Release
Get:3 file:/var/www/html Packages
Ign:3 file:/var/www/html Packages
Get:4 file:/var/www/html Translation-en
Ign:4 file:/var/www/html Translation-en
Get:5 file:/var/www/html Translation-en_US
Ign:5 file:/var/www/html Translation-en_US
Get:3 file:/var/www/html Packages
Ign:3 file:/var/www/html Packages
Get:4 file:/var/www/html Translation-en
Ign:4 file:/var/www/html Translation-en
Get:5 file:/var/www/html Translation-en_US
Ign:5 file:/var/www/html Translation-en_US
Get:3 file:/var/www/html Packages
Ign:3 file:/var/www/html Packages
Get:4 file:/var/www/html Translation-en
Ign:4 file:/var/www/html Translation-en
Get:5 file:/var/www/html Translation-en_US
Ign:5 file:/var/www/html Translation-en_US
Get:3 file:/var/www/html Packages
Ign:3 file:/var/www/html Packages
Get:4 file:/var/www/html Translation-en
Ign:4 file:/var/www/html Translation-en
Get:5 file:/var/www/html Translation-en_US
Ign:5 file:/var/www/html Translation-en_US
Get:3 file:/var/www/html Packages
Ign:3 file:/var/www/html Packages
Get:4 file:/var/www/html Translation-en
Ign:4 file:/var/www/html Translation-en
Get:5 file:/var/www/html Translation-en_US
Ign:5 file:/var/www/html Translation-en_US
Get:3 file:/var/www/html Packages
Ign:3 file:/var/www/html Packages
Get:4 file:/var/www/html Translation-en
Ign:4 file:/var/www/html Translation-en
Get:5 file:/var/www/html Translation-en_US
Ign:5 file:/var/www/html Translation-en_US
Get:3 file:/var/www/html Packages [1,081 kB]
Get:4 file:/var/www/html Translation-en
Ign:4 file:/var/www/html Translation-en
Get:5 file:/var/www/html Translation-en_US
Ign:5 file:/var/www/html Translation-en_US
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
98 packages can be upgraded. Run 'apt list --upgradable' to see them.
root@ubuntu:/var/www/html#
尝试下载软件
root@ubuntu:/etc/apt# apt install -y nginx
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
libnginx-mod-http-geoip2 libnginx-mod-http-image-filter libnginx-mod-http-xslt-filter
libnginx-mod-mail libnginx-mod-stream libnginx-mod-stream-geoip2 nginx-common nginx-core
Suggested packages:
fcgiwrap nginx-doc
The following NEW packages will be installed:
libnginx-mod-http-geoip2 libnginx-mod-http-image-filter libnginx-mod-http-xslt-filter
libnginx-mod-mail libnginx-mod-stream libnginx-mod-stream-geoip2 nginx nginx-common nginx-core
0 upgraded, 9 newly installed, 0 to remove and 98 not upgraded.
Need to get 697 kB of archives.
After this operation, 2,395 kB of additional disk space will be used.
Get:1 http://192.168.107.180 nginx-common 1.18.0-6ubuntu14.6 [40.1 kB]
Get:2 http://192.168.107.180 libnginx-mod-http-geoip2 1.18.0-6ubuntu14.6 [12.0 kB]
Get:3 http://192.168.107.180 libnginx-mod-http-image-filter 1.18.0-6ubuntu14.6 [15.5 kB]
Get:4 http://192.168.107.180 libnginx-mod-http-xslt-filter 1.18.0-6ubuntu14.6 [13.8 kB]
Get:5 http://192.168.107.180 libnginx-mod-mail 1.18.0-6ubuntu14.6 [45.8 kB]
Get:6 http://192.168.107.180 libnginx-mod-stream 1.18.0-6ubuntu14.6 [73.0 kB]
Get:7 http://192.168.107.180 libnginx-mod-stream-geoip2 1.18.0-6ubuntu14.6 [10.1 kB]
Get:8 http://192.168.107.180 nginx-core 1.18.0-6ubuntu14.6 [483 kB]
Get:9 http://192.168.107.180 nginx 1.18.0-6ubuntu14.6 [3,882 B]
成功