利用apt-mirror制作Ubuntu本地源

学校内有Ubuntu服务器使用需求,而且不能连接互联网,导致安装软件和更新都比较麻烦,需要建立一台本地更新源服务器。

Server端

一、安装ssh server

目的:使Ubuntu服务器可以通过外网进行ssh登录

sudo apt install openssh-server

二、设置国内镜像源

这里选用了中科大的镜像源:https://mirrors.ustc.edu.cn/repogen/


deb https://mirrors.ustc.edu.cn/ubuntu/ xenial main restricted universe multiverse

deb-src https://mirrors.ustc.edu.cn/ubuntu/ xenial main restricted universe multiverse

deb https://mirrors.ustc.edu.cn/ubuntu/ xenial-security main restricted universe multiverse

deb-src https://mirrors.ustc.edu.cn/ubuntu/ xenial-security main restricted universe multiverse

deb https://mirrors.ustc.edu.cn/ubuntu/ xenial-updates main restricted universe multiverse

deb-src https://mirrors.ustc.edu.cn/ubuntu/ xenial-updates main restricted universe multiverse

deb https://mirrors.ustc.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse

deb-src https://mirrors.ustc.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse

## Not recommended

# deb https://mirrors.ustc.edu.cn/ubuntu/ xenial-proposed main restricted universe multiverse

# deb-src https://mirrors.ustc.edu.cn/ubuntu/ xenial-proposed main restricted universe multiverse

接下来更新源

sudo apt update

二、为Ubuntu服务器配置远程桌面

Ubuntu 16.04 + xRDP + Xfce 实现Windows远程桌面连接

1. 安装xRDP及vncserver

sudo apt-get install xrdp
sudo apt-get install vnc4server tightvncserver

2. 安装Xfce桌面环境

sudo apt-get install xubuntu-desktop

3. 设置xRDP

echo xfce4-session >~/.xsession

4. 设置配置文件

sudo vi /etc/xrdp/startwm.sh

在. /etc/X11/Xsession 前一行插入

xfce4-session 

5. 重启 xrdp

sudo service xrdp restart

6. 最后测试远程链接

Microsoft Remote Desktop

三、安装apt-mirror

1. 安装apt-mirror

sudo apt install -y apt-mirror

2. 配置apt-mirror

sudo vi /etc/apt/mirror.list


set base_path /opt/source

set nthreads 20

set _tilde 0

deb https://mirrors.ustc.edu.cn/ubuntu/ xenial main restricted universe multiverse

deb-src https://mirrors.ustc.edu.cn/ubuntu/ xenial main restricted universe multiverse

deb https://mirrors.ustc.edu.cn/ubuntu/ xenial-security main restricted universe multiverse

deb-src https://mirrors.ustc.edu.cn/ubuntu/ xenial-security main restricted universe multiverse

deb https://mirrors.ustc.edu.cn/ubuntu/ xenial-updates main restricted universe multiverse

deb-src https://mirrors.ustc.edu.cn/ubuntu/ xenial-updates main restricted universe multiverse

deb https://mirrors.ustc.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse

deb-src https://mirrors.ustc.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse

## Not recommended

# deb https://mirrors.ustc.edu.cn/ubuntu/ xenial-proposed main restricted universe multiverse

# deb-src https://mirrors.ustc.edu.cn/ubuntu/ xenial-proposed main restricted universe multiverse

# 清除无用的安装包,节省磁盘空间

clean https://mirrors.ustc.edu.cn/ubuntu/

四、同步源

1. 创建postmirror.sh文件,否则会报类似can't open /opt/source/var/postmirror.sh错误

该文件用于执行同步软件源成功后所执行的操作;

touch /opt/source/var/postmirror.sh
sudo apt-mirror

五、安装Apache

1. 安装apache2

apt install -y apache2

2. 创建软链接

ln -s /opt/source/mirror/mirrors.ustc.edu.cn/ubuntu /var/www/html/ubuntu

六、设置定时任务,定时同步软件源

利用crontab设置定时任务

crontab -e
0 2 * * * /usr/bin/apt-mirror > /opt/source/var/cron.log &

Client端

一、修改软件源

vim /etc/apt/source.list
deb http://59.64.81.180:80/ubuntu/ xenial main restricted universe multiverse

deb http://59.64.81.180:80/ubuntu/ xenial-updates main restricted universe multiverse

deb http://59.64.81.180:80/ubuntu/ xenial-security main restricted universe multiverse

deb http://59.64.81.180:80/ubuntu/ xenial-backports main restricted universe multiverse

deb http://59.64.81.180:80/openstack/ xenial-updates/mitaka main

二、更新软件源

apt update

本文转载自:https://www.xiaocoder.com/2017/06/03/apt-mirror/

在此基础上,做了一些编辑和改动

你可能感兴趣的:(利用apt-mirror制作Ubuntu本地源)