ubuntu系統(tǒng)搭建yum私有環(huán)境同步阿里云教程
更新時間:2025年09月09日 14:43:01 作者:海綿(寶?寶)
搭建阿里云Ubuntu鏡像源供內(nèi)網(wǎng)使用,需配置mirror.list與sources.list,創(chuàng)建目錄,安裝Web服務,同步鏡像并設置客戶端,確保磁盤空間充足,適用于Ubuntu1804及其他版本
公司虛擬機不允許聯(lián)網(wǎng),自己搭建一個阿里云的Ubuntu源,供內(nèi)網(wǎng)虛擬機使用。以Ubuntu 1804為例,其他版本可參照。
軟件包大概200G,確保拉取軟件包的磁盤有足夠的的空間
1.編輯mirror.list文件
修改遠程倉庫的地址為國內(nèi)的阿里鏡像站,本地的 Ubuntu 軟件倉庫將定期從阿里源同步軟件包。 root@yumdailiubuntu:/etc/apt# cat /etc/apt/mirror.list ############# config ################## ## set base_path /data/www # set mirror_path $base_path/mirror set skel_path $base_path/skel set var_path $base_path/var set cleanscript $var_path/clean.sh set defaultarch amd64 set defaultarch <running host architecture> set postmirror_script $var_path/postmirror.sh set run_postmirror 0 set nthreads 20 set _tilde 0 # 你需要同步的源和組件;源地址的修改,Ubuntu官方的軟件源有的時候下載速度過慢,可以替換為國內(nèi)軟件源地址,下面是阿里云的源地址。 deb-i386 http://mirrors.aliyun.com/ubuntu bionic main restricted universe multiverse deb-i386 http://mirrors.aliyun.com/ubuntu bionic-security main restricted universe multiverse deb-i386 http://mirrors.aliyun.com/ubuntu bionic-updates main restricted universe multiverse deb-i386 http://mirrors.aliyun.com/ubuntu bionic-proposed main restricted universe multiverse deb-i386 http://mirrors.aliyun.com/ubuntu bionic-backports main restricted universe multiverse deb-amd64 http://mirrors.aliyun.com/ubuntu bionic main restricted universe multiverse deb-amd64 http://mirrors.aliyun.com/ubuntu bionic-security main restricted universe multiverse deb-amd64 http://mirrors.aliyun.com/ubuntu bionic-updates main restricted universe multiverse deb-amd64 http://mirrors.aliyun.com/ubuntu bionic-proposed main restricted universe multiverse deb-amd64 http://mirrors.aliyun.com/ubuntu bionic-backports main restricted universe multiverse deb-amd64 http://mirrors.aliyun.com/ubuntu bionic main restricted universe multiverse #clean http://mirrors.aliyun.com/ubuntu
備注:
- mirror.list文件中包含配置信息和軟件源地址,首先修改配置信息。
- <base_path> 代表下載軟件源的存儲位置
- <nthreads> 代表下載的線程數(shù),默認20
每一行都需要以deb-i386或者deb-amd64開始(deb-src表示下載源代碼,目前不需要),deb-i386是32位的軟件源,deb-amd64是64位軟件源,這里同時下載32位和64位的軟件源。 每一行中都有單獨“版本代號”(bionic)或者“版本代號-限定詞”(updates/secrity/proposed/backports)的字段,bionic表示Ubuntu 18.04,每一個發(fā)行版,每一種架構(amd64/i386)都需要有5行的內(nèi)容。所以現(xiàn)在是10行的內(nèi)容。 *proposed可以選擇性的添加,不是必須的。官方解釋該文件夾里的內(nèi)容屬于測試性質(zhì)的軟件包。系統(tǒng)默認的軟件源中不包括proposed內(nèi)容。 每行最后的 main/restricted/universe/multiverse 代表開源軟件的級別分類,都需要添加進去。 當前Ubuntu18.04(.2)的軟件源大小為110GB左右,網(wǎng)速不同,下載速度也不同,等待下載完成。
mirror.list配置文件詳解 ############# config ################## # # 配置數(shù)據(jù)基目錄(可以修改為自己需要保存的位置) # set base_path /var/spool/apt-mirror # 配置鏡像存儲位置 # set mirror_path $base_path/mirror # 配置臨時下載索引位置 # set skel_path $base_path/skel # 配置日子,URLs和MD5校驗信息存儲位置 # set var_path $base_path/var # 配置刪除過期源腳本位置(默認不刪除,方便安裝舊版本軟件) # set cleanscript $var_path/clean.sh # 設置默認架構, 可填: amd64 或 i386,默認是和本機一個架構 # set defaultarch <running host architecture> # # 設定下載后運行的腳本位置 # set postmirror_script $var_path/postmirror.sh # 設置是否執(zhí)行 下載后的腳本操作,默認是1(但是默認沒有postmirror.sh腳本) # set run_postmirror 0 # 設置下載線程數(shù) set nthreads 20 # 是否替換URL中的波浪線,替換成%7E(HTML代碼),否則會跳過不進行下載 set _tilde 0
2.編輯sources.list文件
root@yumdailiubuntu:/etc/apt# cat /etc/apt/sources.list # See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to # newer versions of the distribution. deb http://mirrors.aliyun.com/ubuntu bionic main restricted # deb-src http://mirrors.aliyun.com/ubuntu bionic main restricted ## Major bug fix updates produced after the final release of the ## distribution. deb http://mirrors.aliyun.com/ubuntu bionic-updates main restricted # deb-src http://mirrors.aliyun.com/ubuntu bionic-updates main restricted ## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu ## team. Also, please note that software in universe WILL NOT receive any ## review or updates from the Ubuntu security team. deb http://mirrors.aliyun.com/ubuntu bionic universe # deb-src http://mirrors.aliyun.com/ubuntu bionic universe deb http://mirrors.aliyun.com/ubuntu bionic-updates universe # deb-src http://mirrors.aliyun.com/ubuntu bionic-updates universe ## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu ## team, and may not be under a free licence. Please satisfy yourself as to ## your rights to use the software. Also, please note that software in ## multiverse WILL NOT receive any review or updates from the Ubuntu ## security team. deb http://mirrors.aliyun.com/ubuntu bionic multiverse # deb-src http://mirrors.aliyun.com/ubuntu bionic multiverse deb http://mirrors.aliyun.com/ubuntu bionic-updates multiverse # deb-src http://mirrors.aliyun.com/ubuntu bionic-updates multiverse ## N.B. software from this repository may not have been tested as ## extensively as that contained in the main release, although it includes ## newer versions of some applications which may provide useful features. ## Also, please note that software in backports WILL NOT receive any review ## or updates from the Ubuntu security team. deb http://mirrors.aliyun.com/ubuntu bionic-backports main restricted universe multiverse # deb-src http://mirrors.aliyun.com/ubuntu bionic-backports main restricted universe multiverse ## Uncomment the following two lines to add software from Canonical's ## 'partner' repository. ## This software is not part of Ubuntu, but is offered by Canonical and the ## respective vendors as a service to Ubuntu users. # deb http://archive.canonical.com/ubuntu bionic partner # deb-src http://archive.canonical.com/ubuntu bionic partner deb http://mirrors.aliyun.com/ubuntu bionic-security main restricted # deb-src http://mirrors.aliyun.com/ubuntu bionic-security main restricted deb http://mirrors.aliyun.com/ubuntu bionic-security universe # deb-src http://mirrors.aliyun.com/ubuntu bionic-security universe deb http://mirrors.aliyun.com/ubuntu bionic-security multiverse # deb-src http://mirrors.aliyun.com/ubuntu bionic-security multiverse 這個文件沒有改什么內(nèi)容,就是修改為了阿里云的地址
3.創(chuàng)建目錄
上述配置文件中 base_path 指定的目錄,即本地倉庫存放軟件包的路徑。 mkdir /data/www apt-get install apt-transport-https ca-certificates curl software-properties-common apt-get updata #安裝同步工具 apt-get install apt-mirror
4.安裝web軟件
apt install apache2 systemctl start apache2 systemctl restart apache2 systemctl enable apache2
5.同步apt-mirror
root@yumdailiubuntu:~# vim /etc/apt/mirror.list root@yumdailiubuntu:~# apt-mirror Downloading 345 index files using 20 threads... Begin time: Fri Mar 22 09:57:22 2024 [20]... [19]... [18]... [17]... [16]... [15]... [14]... [13]... [12]... [11]... [10]... [9]... [8]... [7]... [6]... [5]... [4]... [3]... [2]... [1]... [0]... End time: Fri Mar 22 10:00:59 2024 Processing translation indexes: [TTTTTTTTTTT] Downloading 1104 translation files using 20 threads... Begin time: Fri Mar 22 10:00:59 2024 [20]... [19]... [18]... [17]... [16]... [15]... [14]... [13]... [12]... [11]... [10]... [9]... [8]... [7]... [6]... [5]... [4]... [3]... [2]... [1]... [0]... End time: Fri Mar 22 10:01:06 2024 Processing DEP-11 indexes: [DDDDDDDDDDD] Downloading 140 dep11 files using 20 threads... Begin time: Fri Mar 22 10:01:06 2024 [20]... [19]... [18]... [17]... [16]... [15]... [14]... [13]... [12]... [11]... [10]... [9]... [8]... [7]... [6]... [5]... [4]... [3]... [2]... [1]... [0]... End time: Fri Mar 22 10:01:14 2024 Processing indexes: [PPPPPPPPPPP] 360.4 GiB will be downloaded into archive. Downloading 135465 archive files using 20 threads... Begin time: Fri Mar 22 10:01:27 2024 [20]... #會有點慢
觀察磁盤在/data空間在逐步上升 root@yumdailiubuntu:~# df -h Filesystem Size Used Avail Use% Mounted on udev 7.9G 0 7.9G 0% /dev tmpfs 1.6G 924K 1.6G 1% /run /dev/mapper/ubuntu--vg-root 50G 6.3G 44G 13% / tmpfs 7.9G 0 7.9G 0% /dev/shm tmpfs 5.0M 0 5.0M 0% /run/lock tmpfs 7.9G 0 7.9G 0% /sys/fs/cgroup /dev/mapper/ubuntu--vg-home 45G 79M 45G 1% /home /dev/sda2 976M 154M 756M 17% /boot /dev/mapper/ubuntu--vg-data 500G 87G 414G 18% /data tmpfs 1.6G 0 1.6G 0% /run/user/0 root@yumdailiubuntu:~# cd /data/ root@yumdailiubuntu:/data# ll total 4 drwxr-xr-x 3 root root 17 Mar 21 10:30 ./ drwxr-xr-x 24 root root 4096 Mar 22 06:35 ../ drwxr-xr-x 5 root root 43 Mar 21 10:34 www/ root@yumdailiubuntu:/data# cd www/ root@yumdailiubuntu:/data/www# ll total 12 drwxr-xr-x 5 root root 43 Mar 21 10:34 ./ drwxr-xr-x 3 root root 17 Mar 21 10:30 ../ drwxr-xr-x 3 root root 32 Mar 21 13:36 mirror/ drwxr-xr-x 3 root root 32 Mar 21 11:16 skel/ drwxr-xr-x 2 root root 8192 Mar 22 09:57 var/ root@yumdailiubuntu:/data/www# df -h Filesystem Size Used Avail Use% Mounted on udev 7.9G 0 7.9G 0% /dev tmpfs 1.6G 924K 1.6G 1% /run /dev/mapper/ubuntu--vg-root 50G 6.3G 44G 13% / tmpfs 7.9G 0 7.9G 0% /dev/shm tmpfs 5.0M 0 5.0M 0% /run/lock tmpfs 7.9G 0 7.9G 0% /sys/fs/cgroup /dev/mapper/ubuntu--vg-home 45G 79M 45G 1% /home /dev/sda2 976M 154M 756M 17% /boot /dev/mapper/ubuntu--vg-data 500G 96G 405G 20% /data tmpfs 1.6G 0 1.6G 0% /run/user/0
6.編輯apache2文件
root@yumdailiubuntu:/data/www# vim /etc/apache2/sites-available/000-default.conf
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /data
<Directory /data>
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
allow from all
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
root@yumdailiubuntu:/data/www# systemctl restart apache2
root@yumdailiubuntu:/data/www# systemctl status apache2.service
● apache2.service - The Apache HTTP Server
Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
Drop-In: /lib/systemd/system/apache2.service.d
└─apache2-systemd.conf
Active: active (running) since Fri 2024-03-22 11:11:08 CST; 1min 24s ago
Process: 24640 ExecStop=/usr/sbin/apachectl stop (code=exited, status=1/FAILURE)
Process: 24807 ExecStart=/usr/sbin/apachectl start (code=exited, status=0/SUCCESS)
Main PID: 24819 (apache2)
Tasks: 55 (limit: 4915)
CGroup: /system.slice/apache2.service
├─24819 /usr/sbin/apache2 -k start
├─24820 /usr/sbin/apache2 -k start
└─24821 /usr/sbin/apache2 -k start
Mar 22 11:11:08 yumdailiubuntu systemd[1]: Starting The Apache HTTP Server...
Mar 22 11:11:08 yumdailiubuntu systemd[1]: Started The Apache HTTP Server.
#關閉防火墻
root@yumdailiubuntu:/data/www# ufw disable
Firewall stopped and disabled on system startup7.客戶端配置
編輯/etc/apt/source.list,參考以下內(nèi)容(以下是64位機,ubuntu18.04) root@localhost:/etc/apt# cat sources.list deb [arch=amd64] http://10.10.3.166/www/skel/mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse deb [arch=amd64] http://10.10.3.166/www/skel/mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse deb [arch=amd64] http://10.10.3.166/www/skel/mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse deb [arch=amd64] http://10.10.3.166/www/skel/mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse deb [arch=amd64] http://10.10.3.166/www/skel/mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse deb [arch=amd64] http://10.10.3.166/www/mirror/mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse deb [arch=amd64] http://10.10.3.166/www/mirror/mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse deb [arch=amd64] http://10.10.3.166/www/mirror/mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse deb [arch=amd64] http://10.10.3.166/www/mirror/mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse deb [arch=amd64] http://10.10.3.166/www/mirror/mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
8.更新apt-get源
root@localhost:/etc/apt# apt update Hit:1 http://10.10.3.166/www/skel/mirrors.aliyun.com/ubuntu bionic InRelease Hit:2 http://10.10.3.166/www/skel/mirrors.aliyun.com/ubuntu bionic-security InRelease Hit:3 http://10.10.3.166/www/skel/mirrors.aliyun.com/ubuntu bionic-updates InRelease Hit:4 http://10.10.3.166/www/skel/mirrors.aliyun.com/ubuntu bionic-backports InRelease Hit:5 http://10.10.3.166/www/skel/mirrors.aliyun.com/ubuntu bionic-proposed InRelease Get:6 http://10.10.3.166/www/mirror/mirrors.aliyun.com/ubuntu bionic InRelease [242 kB] Get:7 http://10.10.3.166/www/mirror/mirrors.aliyun.com/ubuntu bionic-security InRelease [88.7 kB] Get:8 http://10.10.3.166/www/mirror/mirrors.aliyun.com/ubuntu bionic-updates InRelease [88.7 kB] ..... proposed/universe Translation-en [5,344 B] Fetched 30.3 MB in 5s (6,414 kB/s) Reading package lists... Done Building dependency tree Reading state information... Done 201 packages can be upgraded. Run 'apt list --upgradable' to see them.

總結(jié)
以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關文章
Apache配置實現(xiàn)對海量圖片資源的深度防盜鏈與防下載策略
本文主要介紹了Apache配置實現(xiàn)對海量圖片資源的深度防盜鏈與防下載策略,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2026-05-05
LAMP服務器性能優(yōu)化技巧之Mysql優(yōu)化
目前LAMP (Linux + Apache + MySQL + PHP) 近幾年來發(fā)展迅速,已經(jīng)成為Web 服務器的事實標準。本文我們將介紹基于LAMP組合的服務器的性能優(yōu)化技巧:Mysql優(yōu)化2012-02-02
Linux在批量服務器管理中實用的PS1命令提示符格式實現(xiàn)方法
PS1是神馬?PS1是linux里頭的一個默認的環(huán)境變量,至于當前系統(tǒng)的PS1是如何設置的,你可以使用命令“env|grep PS1”來查看2015-09-09

