Home  >  Article  >  Operation and Maintenance  >  How to set up a local mirror source on Linux

How to set up a local mirror source on Linux

WBOY
WBOYOriginal
2023-07-06 19:27:075596browse

How to set up a local mirror source on Linux

In recent years, with the popularity of the Internet, the frequency of software and system updates has become faster and faster. In order to get software updates and install new software more quickly, many Linux users choose to use local mirror sources.

The local image source is a server that stores software and system installation files. It contains copies of all source server software and updates. By using local mirror sources, you can speed up software and system downloads and reduce network transmission time and traffic. Next, I will introduce how to set up a local mirror source on Linux and provide corresponding code examples.

First, we need to choose a suitable local mirror source. Generally speaking, domestic users can choose image sources provided by well-known universities and cloud service providers such as the University of Science and Technology of China, Tsinghua University, and Alibaba Cloud. These mirrors provide copies of a wide range of software and systems, and often support multiple Linux distributions.

The method of setting up a local mirror source varies depending on the Linux distribution. The following takes two common distributions, Debian and CentOS, as examples for explanation.

  1. Debian system

In the Debian system, we can use the apt tool to set the local mirror source. Open a terminal and run the following command as the root user:

# 备份原有的sources.list文件(可选)
cp /etc/apt/sources.list /etc/apt/sources.list.bak

# 修改sources.list文件
nano /etc/apt/sources.list

Then, replace the URL of the original source with the URL of the local mirror source. Taking the mirror source of Tsinghua University as an example, you can add the following content to the sources.list file:

deb https://mirrors.tuna.tsinghua.edu.cn/debian/ buster main contrib non-free
deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ buster main contrib non-free

After saving and closing the file, run the following command to make the modifications effective:

apt update
  1. CentOS system

In the CentOS system, we can use the yum tool to set the local mirror source. Open the terminal and run the following command as the root user:

# 备份原有的yum源文件(可选)
cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak

# 下载CentOS的yum源文件
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-8.repo

Then, we need to edit the yum source file, delete the original URL and add the URL of the local mirror source. Taking Alibaba Cloud's image source as an example, you can add the following content to the CentOS-Base.repo file:

[BaseOS]
name=CentOS-$releasever - Base
baseurl=http://mirrors.aliyun.com/centos/$releasever/BaseOS/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-8

# 省略其他部分...

[epel]
name=Extra Packages for Enterprise Linux $releasever - $basearch
baseurl=http://mirrors.aliyun.com/epel/$releasever/$basearch
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-8

# 省略其他部分...

After saving and closing the file, run the following command to make the modifications effective:

yum makecache

At this point, we have successfully set up the local mirror source. Now, we can install software and update the system through corresponding software management tools such as apt and yum. When executing these commands, the system will obtain software and system files from the local mirror source to achieve the effect of accelerating downloads.

To sum up, setting a local mirror source can improve the download speed of software and systems, and reduce network transmission time and traffic. This article introduces how to set up a local image source on Linux Debian and CentOS systems, and provides corresponding code examples. I hope this content will be helpful to you and enable you to install software and system updates more efficiently on Linux.

The above is the detailed content of How to set up a local mirror source on Linux. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn