Server optimization (2) Replace the software source

This article has been included in the column of this site
Server Optimization Series

0. What is a software source

A software repository is where software packages are stored. Users can use package managers on some operating systems to download software applications from software repositories. For example, CPAN contains many software repositories written in Perl.

  • Wikipedia

1. Why should you change the software source?

Most of the default software sources of the system are from abroad, and domestic access may be slow, disconnected or even inaccessible.
Domestic leading companies and well-known universities have provided mirror sites, and the servers are deployed in China, which is superior in terms of download speed and stability.

2. How to choose software source

Refer to this site article:
https://blog.tsinbei.com/archives/238/

3, replace the software source

3.1, Centos

(1) Backup

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

(2) Replacement
Download the new CentOS-Base.repo to /etc/yum.repos.d/

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

or

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

Note: Change the 7 in http://mirrors.aliyun.com/repo/Centos-7.repo to your own Centos version number, for example, Centos 8 is http://mirrors.aliyun.com/repo/Centos- 8. repo.

(3) Cache

Bash
1
yum makecache

3.2, Ubuntu

(1) Backup

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

(2) Change permissions

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

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

    Use nano to open the text, delete the contents of the original file, copy one of the sources below, and save.
    Aliyuan:

    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

    Tsinghua source:

    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) Update

    Bash
    1
    sudo apt-get update

    Fix broken packages, try uninstalling the wrong package, and reinstall the correct version.

    Bash
    1
    sudo apt-get - f install

    update software

    Bash
    1
    sudo apt-get upgrade

    3.3, Debian

    (1) Backup

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

    (2) Replacement
    Will

/etc/apt/sources.list

Debian default source address in the file

http://deb.debian.org

replace with

http://mirrors.ustc.edu.cn

Just wait for the mirror address.

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

You can also edit directly
/etc/apt/sources.list
file, add the following

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) Update

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) Disable the original software source

Bash
1
sudo zypper mr - da

(2) Add HKUST mirror source

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) Manually refresh the software source

Bash
1
sudo zypper ref

(4) Update the system

Bash
1
sudo zypper up

3.6, FreeBSD

(1) Modify the pkg source

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

exist

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

Write the following:

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

Write the following:

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}/
  1. Modify the portsnap source
    exist
/etc/portsnap.conf

join in:

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

Server optimization (2) Replace the software source

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

Author
Hsukqi Lee
Posted on

2022-03-20

Edited on

2022-07-28

Licensed under

CC BY-NC-ND 4.0

Comments

Name
Mail
Site
None yet