Centos7 replace yum with Ali source or another source

Principle: Change the original yum configuration file or add a new file (the new file can be directly wget from the Internet or copy the content directly), and change to use the network source-Alibaba source

Please make sure that the system can connect to the public network when using network sources, otherwise, you should use CD-ROM or intranet sources.

It is the easiest to modify the content of the file, directly change the URL in the .repo configuration file to a new format (note the variables).

It's up to you to put a few yum sources. But make sure that there are sources available.

View the current yum source:

yum repolist enabled

position:

/etc/yum.repos.d/

Use the method of adding files:

Create a new backup directory

mkdir /etc/yum.repos.d.bak

Mv all files to another backup directory

mv *.repo ../yum.repos.d.bak/

Create a new .reop file

vi centos-7-aliyun.repo

If the content of the file has not been downloaded from the real machine (' http://mirrors.aliyun.com/repo/Centos-7.repo '), open the content in the copy with Notepad, or refer to the "Backup Cnetos- 7. Repo content".

However, it is also possible to directly move the downloaded file "Cnetos-7.repo" to the configuration directory.

Check the current yum source again, the suffix is ​​displayed as -aliyun or the newly added source, and the status value of the last item is not 0, which means the connection is normal .

base-basic extras-temporary updates-updates

If there is an  unexpected  situation, " Another program locks yum; waiting for it to exit... " execute rm -f /var/run/yum.pid to forcibly close the yum process.

 

If you don't know, see the following process:

步骤1
进入配置文件目录
cd /etc/yum.repos.d/

步骤2
只保留新增源的.repo文件,其他的转移到备份目录
创建备份目录
mkdir ../yum.repos.d.bak

步骤3
复制文件
cp *.repo ../yum.repos.d.bak/

步骤4
(此步骤-方式1)删除当前目录的.repo文件,再新建一个.repo文件。为了方便,直接改一个文件的名字,在删除的时候保留下来
用mv改名,比如随便找一个CentOS-Base.repo,改名不是必须的,是为了看到文件名就能知道是什么源。
mv CentOS-Base.repo 1
rm -f *.repo

编辑文件内容,再把名字改成后缀为.repo
vi 1
清空内全部容,粘贴本博客下面“Cnetos-7.repo”里的内容即可。
但是若无法粘贴,可以直接改内容里的url字段,但要保留$变量的部分。
保存退出,改名
mv 1 Centos-7-aliyun.repo

(此步骤-方式2)删除当前目录的.repo文件,再新建一个.repo文件。编辑内容即可。
rm -f *.repo
touch Centos-7-aliyun.repo
vi Centos-7-aliyun.repo
粘贴本博客下面“Cnetos-7.repo”里的内容,保存退出。

步骤5
再查看当前可用源:
yum repolist enabled

连接正常

If you do not delete other .repo files, viewing the available sources may not show the modification effect, but during use, when the source cannot be downloaded or the relevant content cannot be found, it will automatically try other sources until all sources have no results, but In this way, the newly added source is not called the first choice, and the effect of modifying the source is obvious.

 

Downloaded Cnetos-7.repo content: (spare)

# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client.  You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the 
# remarked out baseurl= line instead.
#
#
 
[base]
name=CentOS-$releasever - Base - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/
        http://mirrors.aliyuncs.com/centos/$releasever/os/$basearch/
        http://mirrors.cloud.aliyuncs.com/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
 
#released updates 
[updates]
name=CentOS-$releasever - Updates - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/updates/$basearch/
        http://mirrors.aliyuncs.com/centos/$releasever/updates/$basearch/
        http://mirrors.cloud.aliyuncs.com/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
 
#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/extras/$basearch/
        http://mirrors.aliyuncs.com/centos/$releasever/extras/$basearch/
        http://mirrors.cloud.aliyuncs.com/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
 
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/centosplus/$basearch/
        http://mirrors.aliyuncs.com/centos/$releasever/centosplus/$basearch/
        http://mirrors.cloud.aliyuncs.com/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
 
#contrib - packages by Centos Users
[contrib]
name=CentOS-$releasever - Contrib - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/contrib/$basearch/
        http://mirrors.aliyuncs.com/centos/$releasever/contrib/$basearch/
        http://mirrors.cloud.aliyuncs.com/centos/$releasever/contrib/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

 

Guess you like

Origin blog.csdn.net/qq_43750882/article/details/109161148