怎么搭建本地Ubuntu镜像服务器

人气:210 ℃/2023-03-17 10:47:28
【导读】 怎么搭建本地Ubuntu镜像服务器,下面是小编为你收集整理的,希望对你有帮助!想要在电脑中安装和搭建本地Ubuntu镜像服务器,使得在安装其他的常用工具时能减少时间!那么要怎么的搭建呢!我们一起来看看吧!一.需求分析最近公司软件Team 有个需求是这样的:能不能在局域网搭建一个...

想要在电脑中安装和搭建本地Ubuntu镜像服务器,使得在安装其他的常用工具时能减少时间!那么要怎么的搭建呢!我们一起来看看吧!

一.需求分析

最近公司软件Team 有个需求是这样的:能不能在局域网搭建一个Ubuntu 镜像服务器,

这样作的好处是可以节省Ubuntu某些常用工具的安装时间。

二.部署过程

2.1 测试环境

目前在公司内有一台能连接到外网的Ubuntu机器, IP : 192.168.8.173 ,

Ubuntu版本为Ubuntu 9.04 i686。

2.2 搭建步骤

为了创建Ubuntu mirror 服务器,最少需要60G硬盘空间,Ubuntu每个版本都有32 bit

和64 bit两个版本,有两组deb包。当然可以创建Ubuntu一个版本的32 bit 和64 bit 的

镜像服务器,也可以创建全部版本的镜像。

这里使用sohu 公司的mirror地址作为本地Ubuntu Source 服务器,使用sohu的原因是:

1. sohu的Ubuntu Source 服务器速度相当快

2. sohu 的ubuntu Source 服务器每天会和Ubuntu官方服务器同步一次,这样可以保

证我们使用的是最新的软件包。

修改方式如下:

root@ms ~: cat /etc/apt/sources.list

debjaunty main restricted universe multiverse

debjaunty-security main restricted universe multiverse

debjaunty-updates main restricted universe multiverse

debjaunty-proposed main restricted universe multiverse

debjaunty-backports main restricted universe multiverse

deb-srcjaunty main restricted universe multiverse

deb-srcjaunty-security main restricted universe multiverse

deb-srcjaunty-updates main restricted universe multiverse

deb-srcjaunty-proposed main restricted universe multiverse

deb-srcjaunty-backports main restricted universe multiverse

安装下面工具:

root@ms ~: apt-get install apt-mirror

root@ms ~: apt-get install apache2

下面就构建Ubuntu 9.04 32bit 的本地Ubuntu mirror 服务器为例子,来说明如何配置:

修改配置文件:

root@ms ~: cat /etc/apt/mirror.list

############# config ##################

#

# set base_path /var/spool/apt-mirror

#

# 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

# set postmirror_script $var_path/postmirror.sh

set run_postmirror 0

set nthreads 20

set _tilde 0

#

############# end config ##############

deb-i386jaunty main restricted universe multiverse

deb-i386jaunty-security main restricted universe multiverse

deb-i386jaunty-updates main restricted universe multiverse

#debjaunty-proposed main restricted universe multiverse

#debjaunty-backports main restricted universe multiverse

deb-srcjaunty main restricted universe multiverse

deb-srcjaunty-security main restricted universe multiverse

deb-srcjaunty-updates main restricted universe multiverse

#deb-srcjaunty-proposed main restricted universe multiverse

#deb-srcjaunty-backports main restricted universe multiverse

#clean

备注:

deb-i386 http:// 表示下载32 bit 版本的deb 软件

deb http:// 表示下载64bit 版本的deb 软件

jaunty 表示Ubuntu 9.04的代号

设置完成后,输入下面命令:

root@ms ~: apt-mirror

这时系统会启动20个线程运行wget 到下面下载相应的

deb包。时间比较的长,该命令执行完成后,/var/spool/apt-mirror目录下就有了所有需

要的deb包和相应的配置文件。

由于我是从sohu下载的,所以实际的文件在 :

/var/spool/apt-mirror/mirror/ 目录下。

这样,本地就有了所有Ubuntu Source 服务器所需要的文件,然后开启相应的服务:

这里使用apache2作为Web服务器,默认根目录在/var/www/,所以可以在该目录下做

个链接,如下所示:

root@ms ~: cd /var/www

root@ms ~: ln /var/spool/apt-mirror/mirror/ -s

开启web服务:

root@ms ~: apache2ctl start

打开浏览器输入下面地址即可看到和sohu mirror一样的页面:

同时也可以使用crontab进行每天的更新,修改配置文件:

root@ms ~: cat /etc/cron.d/apt-mirror

#

# Regular cron jobs for the apt-mirror package

#

#0 4 * * * apt-mirror /usr/bin/apt-mirror > /var/spool/apt-mirror/var/cron.log

把命令前面的“#”去掉即可,这样系统会自动使用apt-mirror去和sohu服务器更新。

最后,我们所要做得就是在客户端的机器上修改更新源配置文件,将地址改成本地

mirror服务器的地址即可,如下所示:

root@ms ~: cat /etc/apt/sources.list

debjaunty main restricted universe multiverse

debjaunty-security main restricted universe multiverse

debjaunty-updates main restricted universe multiverse

debjaunty-proposed main restricted universe multiverse

debjaunty-backports main restricted universe multiverse

deb-srcjaunty main restricted universe multiverse

deb-srcjaunty-security main restricted universe multiverse

deb-srcjaunty-updates main restricted universe multiverse

deb-srcjaunty-proposed main restricted universe multiverse

deb-srcjaunty-backports main restricted universe multiverse

执行“apt-get update”来重建本地索引,这样以后就会使用本地的Mirror 服务器进行更新。

小结:

Copyright © 2008-2024 蜗牛素材网 All Rights Reserved
一个致力于分享各种行业知识与经验、学习资源交流平台,知识让你的眼界更宽广!