理解Linux的yum源配置以及基础命令

171 阅读14分钟

一、yum概述

1.Linux软件安装方式

在CentOS系统中,软件管理方式通常有三种方式:rpm安装、yum安装以及编译安装。

编译安装,从过程上来讲比较麻烦,包需要用户自行下载,下载是源码包,需要进行编译操作,编译好了才能进行安装,这个过程对于我这种初学者比较麻烦,而且还容易出错。好处在于是源码包,对于需要自定义的模块的用户来说非常方便。

2.什么是yum?

yum(yellow dog Updater modified )是一个Fedora和Redhat以及CentOS中的Shell前端软件包管理器;

基于rpm包管理,能够从指定的服务器(yum源)自动下载RPM包并安装,可以自动处理依赖关系,并一次安装所有依赖的软件包,无需繁琐地一次次的下载、安装。

yum配置文件的位置:

[root@lee7 yum.repos.d]# ll
总用量 32
-rw-r--r--. 1 root root 1664 11 23 2018 CentOS-Base.repo
-rw-r--r--. 1 root root 1309 11 23 2018 CentOS-CR.repo
-rw-r--r--. 1 root root  649 11 23 2018 CentOS-Debuginfo.repo
-rw-r--r--. 1 root root  314 11 23 2018 CentOS-fasttrack.repo
-rw-r--r--. 1 root root  630 11 23 2018 CentOS-Media.repo
-rw-r--r--. 1 root root 1331 11 23 2018 CentOS-Sources.repo
-rw-r--r--. 1 root root 5701 11 23 2018 CentOS-Vault.repo

移除系统自带的yum源:

[root@lee7 yum.repos.d]# mv CentOS-Base.repo CentOS-Base.repo.bask
[root@lee7 yum.repos.d]# ll
总用量 32
-rw-r--r--. 1 root root 1664 11 23 2018 CentOS-Base.repo.bask
-rw-r--r--. 1 root root 1309 11 23 2018 CentOS-CR.repo
-rw-r--r--. 1 root root  649 11 23 2018 CentOS-Debuginfo.repo
-rw-r--r--. 1 root root  314 11 23 2018 CentOS-fasttrack.repo
-rw-r--r--. 1 root root  630 11 23 2018 CentOS-Media.repo
-rw-r--r--. 1 root root 1331 11 23 2018 CentOS-Sources.repo
-rw-r--r--. 1 root root 5701 11 23 2018 CentOS-Vault.repo
[root@lee7 yum.repos.d]# 

在官网上下载阿里云yum源

[root@lee7 yum.repos.d]# wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
--2022-12-08 16:53:39--  https://mirrors.aliyun.com/repo/Centos-7.repo
正在解析主机 mirrors.aliyun.com (mirrors.aliyun.com)... 106.60.72.236, 113.219.178.239, 110.167.255.235, ...
正在连接 mirrors.aliyun.com (mirrors.aliyun.com)|106.60.72.236|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:2523 (2.5K) [application/octet-stream]
正在保存至: “/etc/yum.repos.d/CentOS-Base.repo”

100%[===============================================================================================================>] 2,523       --.-K/s 用时 0.01s   

2022-12-08 16:53:41 (219 KB/s) - 已保存 “/etc/yum.repos.d/CentOS-Base.repo” [2523/2523])

[root@lee7 yum.repos.d]# 

清理缓存数据

[root@lee7 yum.repos.d]# yum clean all
已加载插件:fastestmirror, langpacks
正在清理软件源: base extras updates
Cleaning up list of fastest mirrors
[root@lee7 yum.repos.d]# 

查看下载好的yum源“CentOS-Base.repo”

[root@lee7 yum.repos.d]# ll
总用量 36
-rw-r--r--. 1 root root 2523 8   4 15:04 CentOS-Base.repo
-rw-r--r--. 1 root root 1664 11 23 2018 CentOS-Base.repo.bask
-rw-r--r--. 1 root root 1309 11 23 2018 CentOS-CR.repo
-rw-r--r--. 1 root root  649 11 23 2018 CentOS-Debuginfo.repo
-rw-r--r--. 1 root root  314 11 23 2018 CentOS-fasttrack.repo
-rw-r--r--. 1 root root  630 11 23 2018 CentOS-Media.repo
-rw-r--r--. 1 root root 1331 11 23 2018 CentOS-Sources.repo
-rw-r--r--. 1 root root 5701 11 23 2018 CentOS-Vault.repo
[root@lee7 yum.repos.d]# 

重新生成缓存

[root@lee7 yum.repos.d]# yum makecache
已加载插件:fastestmirror, langpacks
Determining fastest mirrors
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
base                                                                                                                              | 3.6 kB  00:00:00     
extras                                                                                                                            | 2.9 kB  00:00:00     
updates                                                                                                                           | 2.9 kB  00:00:00     
(1/10): base/7/x86_64/group_gz                                                                                                    | 153 kB  00:00:07     
base/7/x86_64/primary_db       FAILED                                          
http://mirrors.cloud.aliyuncs.com/centos/7/os/x86_64/repodata/6d0c3a488c282fe537794b5946b01e28c7f44db79097bb06826e1c0c88bad5ef-primary.sqlite.bz2: [Errno 14] curl#6 - "Could not resolve host: mirrors.cloud.aliyuncs.com; Unknown error"
正在尝试其它镜像。
(2/10): extras/7/x86_64/other_db                                                                                                  | 149 kB  00:00:00     
(3/10): extras/7/x86_64/filelists_db                                                                                              | 276 kB  00:00:08     
(4/10): base/7/x86_64/other_db                                                                                                    | 2.6 MB  00:00:18     
base/7/x86_64/filelists_db     FAILED                                                                                  ] 316 kB/s | 8.0 MB  00:02:02 ETA 
http://mirrors.aliyuncs.com/centos/7/os/x86_64/repodata/d6d94c7d406fe7ad4902a97104b39a0d8299451832a97f31d71653ba982c955b-filelists.sqlite.bz2: [Errno 14] curl#7 - "Failed connect to mirrors.aliyuncs.com:80; Connection refused"
正在尝试其它镜像。
extras/7/x86_64/primary_db     FAILED                                                                                  ] 400 kB/s | 9.3 MB  00:01:33 ETA 
http://mirrors.aliyuncs.com/centos/7/extras/x86_64/repodata/511a574b4c3f907f9acfe5603566958fb6f09137292c5cd5d5d57c298864790f-primary.sqlite.bz2: [Errno 14] curl#7 - "Failed connect to mirrors.aliyuncs.com:80; Connection refused"
正在尝试其它镜像。
updates/7/x86_64/primary_db    FAILED                                          =                                       ] 542 kB/s |  11 MB  00:01:04 ETA 
http://mirrors.aliyuncs.com/centos/7/updates/x86_64/repodata/786e8dfe79441eaea10aac32f5cccb17a51796051e6eebb88345d7dc4b24e3bd-primary.sqlite.bz2: [Errno 14] curl#7 - "Failed connect to mirrors.aliyuncs.com:80; Connection refused"
正在尝试其它镜像。
(5/10): extras/7/x86_64/primary_db                                                                                                | 249 kB  00:00:01     
updates/7/x86_64/other_db      FAILED                                          =========                               ] 936 kB/s |  19 MB  00:00:29 ETA 
http://mirrors.aliyuncs.com/centos/7/updates/x86_64/repodata/d40c5d2c14b983abe5caf1319dc7f1c90ee4d5ec6648b2c58364c43fb7c122de-other.sqlite.bz2: [Errno 14] curl#7 - "Failed connect to mirrors.aliyuncs.com:80; Connection refused"
正在尝试其它镜像。
(6/10): updates/7/x86_64/filelists_db                                                                                             |  10 MB  00:00:39     
(7/10): base/7/x86_64/primary_db                                                                                                  | 6.1 MB  00:00:23     
(8/10): updates/7/x86_64/other_db                                                                                                 | 1.2 MB  00:00:04     
(9/10): base/7/x86_64/filelists_db                                                                                                | 7.2 MB  00:00:28     
(10/10): updates/7/x86_64/primary_db                                                                                              |  18 MB  00:01:07     

元数据缓存已建立
[root@lee7 yum.repos.d]# 
[root@lee7 yum.repos.d]# 

Linux基础命令

ls

作用:查看目录内容

格式:ls [选项]目录名

备注:ls与选项要用空格隔开,[]选项可以多个参数混合使用

-a :查看目录下的所以文件包含“.”".."文件

[root@lee7 /]#ls -a
.  ..  bin  boot  dev  etc  home  lib  lib64  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var
[root@lee7 /]# 

-l:查看目录下的文件的详细信息

[root@lee7 /]# ls -l
总用量 32
lrwxrwxrwx.   1 root root    7 12  6 22:54 bin -> usr/bin
dr-xr-xr-x.   5 root root 4096 12  8 19:04 boot
drwxr-xr-x.  20 root root 3320 12  8 19:03 dev
drwxr-xr-x. 141 root root 8192 12  8 19:03 etc
drwxr-xr-x.   3 root root   25 12  6 23:20 home
lrwxrwxrwx.   1 root root    7 12  6 22:54 lib -> usr/lib
lrwxrwxrwx.   1 root root    9 12  6 22:54 lib64 -> usr/lib64
drwxr-xr-x.   2 root root    6 4  11 2018 media
drwxr-xr-x.   2 root root    6 4  11 2018 mnt
drwxr-xr-x.   3 root root   16 12  6 23:11 opt
dr-xr-xr-x. 229 root root    0 12  8 19:02 proc
dr-xr-x---.  15 root root 4096 12  8 19:10 root
drwxr-xr-x.  43 root root 1340 12  8 19:13 run
lrwxrwxrwx.   1 root root    8 12  6 22:54 sbin -> usr/sbin
drwxr-xr-x.   2 root root    6 4  11 2018 srv
dr-xr-xr-x.  13 root root    0 12  8 19:03 sys
drwxrwxrwt.  49 root root 8192 12  8 19:11 tmp
drwxr-xr-x.  13 root root  155 12  6 22:54 usr
drwxr-xr-x.  20 root root  282 12  6 23:33 var

-i:查看文件的inode号(inode号是指文件以块存储在磁盘的位置)

[root@lee7 /]# ll -ai
总用量 32
      64 dr-xr-xr-x.  17 root root  224 12  6 23:20 .
      64 dr-xr-xr-x.  17 root root  224 12  6 23:20 ..
   81953 lrwxrwxrwx.   1 root root    7 12  6 22:54 bin -> usr/bin
      64 dr-xr-xr-x.   5 root root 4096 12  8 19:04 boot
       3 drwxr-xr-x.  20 root root 3320 12  8 19:03 dev
16777281 drwxr-xr-x. 141 root root 8192 12  8 19:03 etc
16799132 drwxr-xr-x.   3 root root   25 12  6 23:20 home
      81 lrwxrwxrwx.   1 root root    7 12  6 22:54 lib -> usr/lib
      83 lrwxrwxrwx.   1 root root    9 12  6 22:54 lib64 -> usr/lib64
33745221 drwxr-xr-x.   2 root root    6 4  11 2018 media
50339144 drwxr-xr-x.   2 root root    6 4  11 2018 mnt
      84 drwxr-xr-x.   3 root root   16 12  6 23:11 opt
       1 dr-xr-xr-x. 229 root root    0 12  8 19:02 proc
33574977 dr-xr-x---.  15 root root 4096 12  8 19:10 root
    9467 drwxr-xr-x.  43 root root 1340 12  8 19:13 run
   81957 lrwxrwxrwx.   1 root root    8 12  6 22:54 sbin -> usr/sbin
16799133 drwxr-xr-x.   2 root root    6 4  11 2018 srv
       1 dr-xr-xr-x.  13 root root    0 12  8 19:03 sys
16777288 drwxrwxrwt.  49 root root 8192 12  8 19:11 tmp
33593219 drwxr-xr-x.  13 root root  155 12  6 22:54 usr
50331713 drwxr-xr-x.  20 root root  282 12  6 23:33 var
[root@lee7 /]# 

-h:查看文件存储的大小

[root@lee7 /]# ll -h
总用量 32K
lrwxrwxrwx.   1 root root    7 12月  6 22:54 bin -> usr/bin
dr-xr-xr-x.   5 root root 4.0K 12月  8 19:04 boot
drwxr-xr-x.  20 root root 3.3K 12月  8 19:03 dev
drwxr-xr-x. 141 root root 8.0K 12月  8 19:03 etc
drwxr-xr-x.   3 root root   25 12月  6 23:20 home
lrwxrwxrwx.   1 root root    7 12月  6 22:54 lib -> usr/lib
lrwxrwxrwx.   1 root root    9 12月  6 22:54 lib64 -> usr/lib64
drwxr-xr-x.   2 root root    6 4月  11 2018 media
drwxr-xr-x.   2 root root    6 4月  11 2018 mnt
drwxr-xr-x.   3 root root   16 12月  6 23:11 opt
dr-xr-xr-x. 229 root root    0 12月  8 19:02 proc
dr-xr-x---.  15 root root 4.0K 12月  8 19:10 root
drwxr-xr-x.  43 root root 1.4K 12月  8 19:13 run
lrwxrwxrwx.   1 root root    8 12月  6 22:54 sbin -> usr/sbin
drwxr-xr-x.   2 root root    6 4月  11 2018 srv
dr-xr-xr-x.  13 root root    0 12月  8 19:03 sys
drwxrwxrwt.  49 root root 8.0K 12月  8 19:11 tmp
drwxr-xr-x.  13 root root  155 12月  6 22:54 usr
drwxr-xr-x.  20 root root  282 12月  6 23:33 var
[root@lee7 /]# 
[root@lee7 /]# 

-t:在目录下查看文件安装时间排序

[root@lee7 /]# ll -t
总用量 32
drwxr-xr-x.  43 root root 1340 12  8 19:13 run
drwxrwxrwt.  49 root root 8192 12  8 19:11 tmp
dr-xr-x---.  15 root root 4096 12  8 19:10 root
dr-xr-xr-x.   5 root root 4096 12  8 19:04 boot
drwxr-xr-x. 141 root root 8192 12  8 19:03 etc
drwxr-xr-x.  20 root root 3320 12  8 19:03 dev
dr-xr-xr-x.  13 root root    0 12  8 19:03 sys
dr-xr-xr-x. 229 root root    0 12  8 19:02 proc
drwxr-xr-x.  20 root root  282 12  6 23:33 var
drwxr-xr-x.   3 root root   25 12  6 23:20 home
drwxr-xr-x.   3 root root   16 12  6 23:11 opt
drwxr-xr-x.  13 root root  155 12  6 22:54 usr
lrwxrwxrwx.   1 root root    8 12  6 22:54 sbin -> usr/sbin
lrwxrwxrwx.   1 root root    7 12  6 22:54 lib -> usr/lib
lrwxrwxrwx.   1 root root    9 12  6 22:54 lib64 -> usr/lib64
lrwxrwxrwx.   1 root root    7 12  6 22:54 bin -> usr/bin
drwxr-xr-x.   2 root root    6 4  11 2018 media
drwxr-xr-x.   2 root root    6 4  11 2018 mnt
drwxr-xr-x.   2 root root    6 4  11 2018 srv
[root@lee7 /]# 

alias

作用:把复杂的命令进行简单化,根据自己的喜好进行自定义命令

格式:alias 自定义的命 =''命令''

备注:经常使用比较长的路径进行简单化从而提高工作效率

alias:查看系统自定义的命令

[root@lee7 /]# alias
alias cp='cp -i'
alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'
alias grep='grep --color=auto'
alias l.='ls -d .* --color=auto'
alias ll='ls -l --color=auto'
alias ls='ls --color=auto'
alias mv='mv -i'
alias rm='rm -i'
alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'
[root@lee7 /]# 

alias qiangguo=‘ls -l ’ :自定义的别名使用方式

[root@lee7 /]# 
[root@lee7 /]# alias qiangguo='ls -l'
[root@lee7 /]# 
[root@lee7 /]# 
[root@lee7 /]# qiangguo 
总用量 32
lrwxrwxrwx.   1 root root    7 12  6 22:54 bin -> usr/bin
dr-xr-xr-x.   5 root root 4096 12  8 19:04 boot
drwxr-xr-x.  20 root root 3320 12  8 19:03 dev
drwxr-xr-x. 141 root root 8192 12  8 19:03 etc
drwxr-xr-x.   3 root root   25 12  6 23:20 home
lrwxrwxrwx.   1 root root    7 12  6 22:54 lib -> usr/lib
lrwxrwxrwx.   1 root root    9 12  6 22:54 lib64 -> usr/lib64
drwxr-xr-x.   2 root root    6 4  11 2018 media
drwxr-xr-x.   2 root root    6 4  11 2018 mnt
drwxr-xr-x.   3 root root   16 12  6 23:11 opt
dr-xr-xr-x. 229 root root    0 12  8 19:02 proc
dr-xr-x---.  15 root root 4096 12  8 19:10 root
drwxr-xr-x.  43 root root 1340 12  8 19:13 run
lrwxrwxrwx.   1 root root    8 12  6 22:54 sbin -> usr/sbin
drwxr-xr-x.   2 root root    6 4  11 2018 srv
dr-xr-xr-x.  13 root root    0 12  8 19:03 sys
drwxrwxrwt.  49 root root 8192 12  8 19:11 tmp
drwxr-xr-x.  13 root root  155 12  6 22:54 usr
drwxr-xr-x.  20 root root  282 12  6 23:33 var
[root@lee7 /]# 
[root@lee7 /]# 
unalias

作用:把自己自定义好的别名命令进行删除

格式:alias 自定义好的别名命令

备注:此命令运用比较简单

[root@lee7 /]# qiangguo 
总用量 32
lrwxrwxrwx.   1 root root    7 126 22:54 bin -> usr/bin
dr-xr-xr-x.   5 root root 4096 128 19:04 boot
drwxr-xr-x.  20 root root 3320 128 19:03 dev
drwxr-xr-x. 141 root root 8192 128 19:03 etc
drwxr-xr-x.   3 root root   25 126 23:20 home
lrwxrwxrwx.   1 root root    7 126 22:54 lib -> usr/lib
lrwxrwxrwx.   1 root root    9 126 22:54 lib64 -> usr/lib64
drwxr-xr-x.   2 root root    6 411 2018 media
drwxr-xr-x.   2 root root    6 411 2018 mnt
drwxr-xr-x.   3 root root   16 126 23:11 opt
dr-xr-xr-x. 229 root root    0 128 19:02 proc
dr-xr-x---.  15 root root 4096 128 19:10 root
drwxr-xr-x.  43 root root 1340 128 19:13 run
lrwxrwxrwx.   1 root root    8 126 22:54 sbin -> usr/sbin
drwxr-xr-x.   2 root root    6 411 2018 srv
dr-xr-xr-x.  13 root root    0 128 19:03 sys
drwxrwxrwt.  49 root root 8192 128 19:11 tmp
drwxr-xr-x.  13 root root  155 126 22:54 usr
drwxr-xr-x.  20 root root  282 126 23:33 var
[root@lee7 /]# 
[root@lee7 /]# 
[root@lee7 /]# 
[root@lee7 /]# una
unalias  uname    
[root@lee7 /]# unalias qiangguo 
[root@lee7 /]# 
[root@lee7 /]# 
[root@lee7 /]# 
[root@lee7 /]# qiangguo
bash: qiangguo: 未找到命令...
[root@lee7 /]# 
echo

作用:写的内容进行输出

格式:echo 字符串

备注:此命令功能强大

echo [选项]

-n: 输出的内容不换行

-e:表示对于转义字符按对应的方式进行处理(若不加-e,那么在输出时转义字符会按照普通字符进行处理,并不会达到自己想要达到的目的)

-E:禁用转义解释

cd

作用:切换目录

格式:cd 目录路径

备注:change directory.


[root@lee7 /]# cd etc/yum.repos.d
[root@lee7 yum.repos.d]# ll
总用量 4
-rw-r--r--. 1 root root 2523 84 15:04 CentOS-Base.repo
[root@lee7 yum.repos.d]# 

跳转到上层目录:cd ..

[root@lee7 yum.repos.d]# 
[root@lee7 yum.repos.d]# cd ..
[root@lee7 etc]# ll
总用量 1472
drwxr-xr-x.  3 root root      101 126 22:56 abrt
-rw-r--r--.  1 root root       16 126 23:20 adjtime
drwxr-xr-x.  2 root root      116 126 23:10 akonadi

切换到家目录:cd ~

[root@lee7 /]# cd ~
[root@lee7 ~]# ll
总用量 8
-rw-------. 1 root root 1709 126 23:22 anaconda-ks.cfg
-rw-r--r--. 1 root root 1743 126 23:38 initial-setup-ks.cfg
drwxr-xr-x. 2 root root  187 128 19:10 lee.repo.bask
drwxr-xr-x. 2 root root    6 126 15:40 公共
drwxr-xr-x. 2 root root    6 126 15:40 模板
drwxr-xr-x. 2 root root    6 126 15:40 视频
drwxr-xr-x. 2 root root    6 126 15:40 图片
drwxr-xr-x. 2 root root    6 126 15:40 文档
drwxr-xr-x. 2 root root    6 126 15:40 下载
drwxr-xr-x. 2 root root    6 126 15:40 音乐
drwxr-xr-x. 2 root root    6 126 15:40 桌面
[root@lee7 ~]#