Linux 配置本地源 (Ubuntu / CentOS)


Linux local source list

A. Ubuntu

1. 本地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.

root@ubuntu:/# mount -t iso9660 /dev/cdrom /media/cdrom/
mount: /dev/sr0 is write-protected, mounting read-only
root@ubuntu:/# 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) <cdimage@ubuntu.com>"
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.
root@ubuntu:/# vim /etc/apt/sources.list
# 此時sources.list中多出一行本地源
# deb cdrom:[Ubuntu-Server 16.04.5 LTS _Xenial Xerus_ - Release amd64 (20180731)]/ xenial main restricted

root@ubuntu:/# 
root@ubuntu:/# sudo apt update

2. 制作本地源

平時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

1. 本地ISO

1. 首先創建掛載點
2. 然后掛載光驅
3. 移除原有源
4. 新建local.repo文件,內容如下:
​```
[name]
name="local repo"
baseurl=file:///media/cdrom/
enabeld=1
gpgcheck=0
​```
5. 對yum進行初始化操作

e.g.

[root@cent7 ~]# mkdir /media/cdrom
[root@cent7 ~]# mount -t iso9660 /dev/cdrom /media/cdrom
mount: /dev/sr0 is write-protected, mounting read-only
[root@cent7 ~]# cd /etc/yum.repos.d/
[root@cent7 yum.repos.d]# pwd
/etc/yum.repos.d
[root@cent7 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
[root@cent7 yum.repos.d]# mkdir bak
[root@cent7 yum.repos.d]# mv *.repo bak/
[root@cent7 yum.repos.d]# vim local.repo
寫入以下內容:
        [name]
        name="local repo"
        baseurl=file:///media/cdrom/
        enabeld=1
        gpgcheck=0

[root@cent7 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
[root@cent7 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
[root@cent7 yum.repos.d]# yum list | wc -l  # 查看可用個數
546
[root@cent7 yum.repos.d]# 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM