Linux 配置本地源 (Ubuntu / CentOS)

文章内容大纲 (右击展开→→)

内容预览:
  • 目录 Linux local source list A. Ubuntu 本地ISO 制作本地源 B. CentOS...~
  • 步骤: # 新建离线源目录mkdir ~/packs# 将缓存复制到目录cp -rv /var/c...~
  • 如果还要安装的话需要加上 --allow-unauthenticated 选项~

目录

Linux local source list

A. Ubuntu

本地ISO

# 首先挂载本地镜像
mount -o loop -t iso9660 ./ubuntu.iso /media/cdrom
# 手动添加ISO镜像至源列表,这样就可以在软件库中找到ISO中的所有包
apt-cdrom -m -d=/media/cdrom add
# 刷新软件库
apt update
# 完成后查看sources.list ,本地源应该在第一条,否则默认还是从网上下载

e.g.

[email protected]:/# mount -t iso9660 /dev/cdrom /media/cdrom/
mount: /dev/sr0 is write-protected, mounting read-only
[email protected]:/# sudo apt-cdrom -m -d /media/cdrom/ add
Using CD-ROM mount point /media/cdrom/
Identifying... [83cd189f3f418ae846baff8ecfba5390-2]
Scanning disc for index files...
Found 4 package indexes, 0 source indexes, 0 translation indexes and 1 signatures
Found label 'Ubuntu-Server 16.04.5 LTS _Xenial Xerus_ - Release amd64 (20180731)'
This disc is called:
'Ubuntu-Server 16.04.5 LTS _Xenial Xerus_ - Release amd64 (20180731)'
Copying package lists...gpgv: Signature made Tue 31 Jul 2018 08:39:26 AM CST using RSA key ID EFE21092
gpgv: Good signature from "Ubuntu CD Image Automatic Signing Key (2012) <[email protected]>"
Reading Package Indexes... Done
Writing new source list
Source list entries for this disc are:
deb cdrom:[Ubuntu-Server 16.04.5 LTS _Xenial Xerus_ - Release amd64 (20180731)]/ xenial main restricted
Repeat this process for the rest of the CDs in your set.
[email protected]:/# vim /etc/apt/sources.list
# 此时sources.list中多出一行本地源
# deb cdrom:[Ubuntu-Server 16.04.5 LTS _Xenial Xerus_ - Release amd64 (20180731)]/ xenial main restricted

[email protected]:/#
[email protected]:/# sudo apt update

制作本地源

平时apt-get install安装软件时,下载的deb文件都会存放在/var/cache/apt/archives/下,为了今后重装或给别人用 。

步骤:

# 新建离线源目录
mkdir ~/packs
# 将缓存复制到目录
cp -rv /var/cache/apt/archives/* ~/packs

# 拷贝过来发现在packs当中为文件都是root账户的,需要修改
# 修改所有者
# sudo chown -R someone.someone * $pack_dir
# 修改权限
# sudo chmod ug+rw,o+r * $pack_dir

# 建立Packages包,里面记录了packs目录下的软件包信息,包括依赖信息
dpkg-scanpackages ~/packs /dev/null |gzip > packs/Packages.gz -r
# 将~/packs复制到目标计算机,或本机的某处
vim /etc/apt/sources.list
# 添加 deb file:/// /home/someone/packs/
# 注意: packs后面有一个斜杠,全路径前面还要有空格
# 更新源
sudo apt-get update ---allow-insecure-repositories
sudo apt-get install -f
sudo apt-get xxxx --allow-unauthenticated
# 本地的源是没有签名的,直接更新ubuntu1604下的apt会提示找不到release文件,是一种不安全的源,默认是被禁用的。如果还要安装的话需要加上 --allow-unauthenticated 选项。
# N: Updating from such a repository can't be done securely, and is therefore disabled by default.

B. CentOS

本地ISO

1. 首先创建挂载点
2. 然后挂载光驱
3. 移除原有源
4. 新建local.repo文件,内容如下:
​```
[name]
name="local repo"
baseurl=file:///media/cdrom/
enabeld=1
gpgcheck=0
​```
5. 对yum进行初始化操作

e.g.

[[email protected] ~]# mkdir /media/cdrom
[[email protected] ~]# mount -t iso9660 /dev/cdrom /media/cdrom
mount: /dev/sr0 is write-protected, mounting read-only
[[email protected] ~]# cd /etc/yum.repos.d/
[[email protected] yum.repos.d]# pwd
/etc/yum.repos.d
[[email protected] yum.repos.d]# ls
CentOS-Base.repo CentOS-Base.repo.bak CentOS-CR.repo CentOS-Debuginfo.repo CentOS-fasttrack.repo CentOS-Media.repo CentOS-Sources.repo CentOS-Vault.repo epel.repo epel-testing.repo mysql-community.repo mysql-community-source.repo
[[email protected] yum.repos.d]# mkdir bak
[[email protected] yum.repos.d]# mv *.repo bak/
[[email protected] yum.repos.d]# vim local.repo
写入以下内容:
[name]
name="local repo"
baseurl=file:///media/cdrom/
enabeld=1
gpgcheck=0

[[email protected] yum.repos.d]# yum clean all # 清除缓存
Loaded plugins: fastestmirror
Cleaning repos: name
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
[[email protected] yum.repos.d]# yum makecache # 建立新缓存
Loaded plugins: fastestmirror
Determining fastest mirrors
name | 3.6 kB 00:00:00
(1/4): name/group_gz | 3.5 kB 00:00:00
(2/4): name/primary_db | 776 kB 00:00:00
(3/4): name/other_db | 198 kB 00:00:00
(4/4): name/filelists_db | 298 kB 00:00:00
Metadata Cache Created
[[email protected] yum.repos.d]# yum list | wc -l # 查看可用个数
546
[[email protected] yum.repos.d]#

和大佬一起学习网络安全知识

以上就是:Linux 配置本地源 (Ubuntu / CentOS) 的全部内容

本站部分内容来源于互联网和用户投稿,如有侵权请联系我们删除,谢谢^^
Email:[email protected]


0 条回复 A 作者 M 管理员
    所有的伟大,都源于一个勇敢的开始!
欢迎您,新朋友,感谢参与互动!欢迎您 {{author}},您在本站有{{commentsCount}}条评论