ubuntu系统搭建yum私有环境同步阿里云教程
作者:海绵(宝ᴗ宝)
搭建阿里云Ubuntu镜像源供内网使用,需配置mirror.list与sources.list,创建目录,安装Web服务,同步镜像并设置客户端,确保磁盘空间充足,适用于Ubuntu1804及其他版本
公司虚拟机不允许联网,自己搭建一个阿里云的Ubuntu源,供内网虚拟机使用。以Ubuntu 1804为例,其他版本可参照。
软件包大概200G,确保拉取软件包的磁盘有足够的的空间
1.编辑mirror.list文件
修改远程仓库的地址为国内的阿里镜像站,本地的 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官方的软件源有的时候下载速度过慢,可以替换为国内软件源地址,下面是阿里云的源地址。 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> 代表下载的线程数,默认20
每一行都需要以deb-i386或者deb-amd64开始(deb-src表示下载源代码,目前不需要),deb-i386是32位的软件源,deb-amd64是64位软件源,这里同时下载32位和64位的软件源。 每一行中都有单独“版本代号”(bionic)或者“版本代号-限定词”(updates/secrity/proposed/backports)的字段,bionic表示Ubuntu 18.04,每一个发行版,每一种架构(amd64/i386)都需要有5行的内容。所以现在是10行的内容。 *proposed可以选择性的添加,不是必须的。官方解释该文件夹里的内容属于测试性质的软件包。系统默认的软件源中不包括proposed内容。 每行最后的 main/restricted/universe/multiverse 代表开源软件的级别分类,都需要添加进去。 当前Ubuntu18.04(.2)的软件源大小为110GB左右,网速不同,下载速度也不同,等待下载完成。
mirror.list配置文件详解 ############# config ################## # # 配置数据基目录(可以修改为自己需要保存的位置) # 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 # 设置是否执行 下载后的脚本操作,默认是1(但是默认没有postmirror.sh脚本) # set run_postmirror 0 # 设置下载线程数 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 这个文件没有改什么内容,就是修改为了阿里云的地址
3.创建目录
上述配置文件中 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 startup
7.客户端配置
编辑/etc/apt/source.list,参考以下内容(以下是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.
总结
以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。