服务器优化(二)更换软件源

本文章已收录至本站专栏
服务器优化系列

0、什么是软件源

软件存储库是用来存储软件包的地方。用户可以在一些操作系统上使用程序包管理器来从软件存储库下载软件应用程序。例如CPAN就是包含了许多用Perl写成的软件存储库。
——维基百科

1、为什么要更换软件源

系统默认的软件源大多是国外的,国内访问可能会出现速度慢、连接中断甚至无法访问的情况。
而国内头部企业、知名大学都提供了镜像站,服务器部署在国内,无论是下载速度还是稳定性都更胜一筹。

2、如何选择软件源

参考本站文章:
https://blog.tsinbei.com/archives/238/

3、更换软件源

3.1、Centos

(1)备份

Bash
1
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup

(2)更换
下载新的CentOS-Base.repo到/etc/yum.repos.d/

Bash
1
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

或者

Bash
1
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

注意:http://mirrors.aliyun.com/repo/Centos-7.repo 中的7改为自己的Centos版本号,比如Centos 8就是http://mirrors.aliyun.com/repo/Centos-8.repo

(3)缓存

Bash
1
yum makecache

3.2、Ubuntu

(1)备份

Bash
1
sudo cp /etc/apt/sources.list /etc/apt/sources_init.list

(2)更改权限

Bash
1
sudo  chmod  777  /etc/apt/source.list

3.更换源

Bash
1
sudo nano /etc/apt/sources.list

使用nano打开文本,删除原来文件里的内容,将下面其中一个源复制进去,然后保存。
阿里源:

Text
1
2
3
4
5
6
7
8
9
10
deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse

清华源:

Text
1
2
3
4
5
6
7
8
9
10
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse

(3)更新

Bash
1
sudo apt-get update

修复损坏的软件包,尝试卸载出错的包,重新安装正确版本的。

Bash
1
sudo apt-get -f install

更新软件

Bash
1
sudo apt-get upgrade

3.3、Debian

(1)备份

Bash
1
sudo cp /etc/apt/sources.list /etc/apt/sources.list_bak

(2)更换

/etc/apt/sources.list

文件中Debian默认的源地址

http://deb.debian.org

替换为

http://mirrors.ustc.edu.cn

等镜像地址即可。

Bash
1
sudo sed -i 's/deb.debian.org/mirrors.ustc.edu.cn/g' /etc/apt/sources.list

也可以直接编辑
/etc/apt/sources.list
文件,加入以下内容

Text
1
2
3
4
5
6
7
deb http://mirrors.ustc.edu.cn/debian stable main contrib non-free
# deb-src http://mirrors.ustc.edu.cn/debian stable main contrib non-free
deb http://mirrors.ustc.edu.cn/debian stable-updates main contrib non-free
# deb-src http://mirrors.ustc.edu.cn/debian stable-updates main contrib non-free

# deb http://mirrors.ustc.edu.cn/debian stable-proposed-updates main contrib non-free
# deb-src http://mirrors.ustc.edu.cn/debian stable-proposed-updates main contrib non-free

(3)更新

Bash
1
sudo apt-get update

3.4、Fedora

Bash
1
2
3
4
5
6
7
8
su
cd /etc/yum.repos.d/
mv fedora.repo fedora.repo.backup
mv fedora-updates.repo fedora-updates.repo.backup
wget -O /etc/yum.repos.d/fedora.repo http://mirrors.aliyun.com/repo/fedora.repo
wget -O /etc/yum.repos.d/fedora-updates.repo http://mirrors.aliyun.com/repo/fedora-updates.repo
dnf clean all
dnf makecache

3.5、OpenSUSE

(1)禁用原有软件源

Bash
1
sudo zypper mr -da

(2)添加科大镜像源

Bash
1
2
3
4
sudo zypper ar -fc https://mirrors.ustc.edu.cn/opensuse/distribution/leap/42.1/repo/oss USTC:42.1:OSS
sudo zypper ar -fc https://mirrors.ustc.edu.cn/opensuse/distribution/leap/42.1/repo/non-oss USTC:42.1:NON-OSS
sudo zypper ar -fc https://mirrors.ustc.edu.cn/opensuse/update/leap/42.1/oss USTC:42.1:UPDATE-OSS
sudo zypper ar -fc https://mirrors.ustc.edu.cn/opensuse/update/leap/42.1/non-oss USTC:42.1:UPDATE-NON-OSS

(3)手动刷新软件源

Bash
1
sudo zypper ref

(4)更新系统

Bash
1
sudo zypper up

3.6、FreeBSD

(1)修改 pkg 源

Bash
1
mkdir -p /usr/local/etc/pkg/repos

/usr/local/etc/pkg/repos/FreeBSD.conf

写入以下内容:

Text
1
2
3
4
# content of FreeBSD.conf
FreeBSD: {
    url: "pkg+http://mirrors.ustc.edu.cn/freebsd-pkg/${ABI}/quarterly",
}

2.修改 ports 源

/etc/make.conf

写入以下内容:

Text
1
2
3
4
# content of make.conf
FETCH_CMD=axel -n 10 -a
DISABLE_SIZE=yes
MASTER_SITE_OVERRIDE?=http://mirrors.ustc.edu.cn/freebsd-ports/distfiles/${DIST_SUBDIR}/

3.修改 portsnap 源

/etc/portsnap.conf

加入:

Text
1
2
# content of porsnap.conf
SERVERNAME=porsnap.tw.freebsd.org

服务器优化(二)更换软件源

https://blog.tsinbei.com/archives/237/

文章作者
Hsukqi Lee
发布于

2022-03-20

修改于

2022-07-28

许可协议

CC BY-NC-ND 4.0

评论

昵称
邮箱
网址
暂无