CentOS VPS新手教程(3)YUM源配置
在服務器上,可能需要安裝許多軟件。如果要搭建一個博客,通常需要一個支持PHP的web服務器,如Apache,Nginx等,還需要一個關系型數據庫,如MySQL。
安裝這一些類的軟件可能需要很長的時間,其中涉及到很多配置、初始化、依賴的問題,還有可能需要自己編譯某些軟件。我們可以通過使用CentOS中自帶的YUM包管理軟件方管理安裝的軟件,使軟件的安裝、更新和刪除方便了不少。(各個Linux發行版通常都帶有各自的包管理軟件,如Ubuntu的apt)
YUM的對於軟件的管理依賴於配置文件中設置的YUM源,這些YUM源通常是由某些公司、組織管理的。我們可以通過這些源來找尋我們需要安裝的軟件。
添加YUM源
一般CentOS VPS都自帶了一些默認的YUM源,可以通過查看/etc/yum.repos.d/目錄,
1
$ ls /etc/yum.repos.d/
來查看默認有那些源。其中,每一個*.repo文件都表示某個YUM源,文件中描述了該源的名稱、地址、是否啟動、校驗等信息。
可以通過在該目錄下添加一個自己的*.repo文件來增加一個源。
下面是我的源:
CentOS-Base.repo
01
# CentOS-Base.repo
02
#
03
# The mirror system uses the connecting IP address of the client and the
04
# update status of each mirror to pick mirrors that are updated to and
05
# geographically close to the client. You should use this for CentOS updates
06
# unless you are manually picking other mirrors.
07
#
08
# If the mirrorlist= does not work for you, as a fall back you can try the
09
# remarked out baseurl= line instead.
10
#
11
#
12
13
[base]
14
name=CentOS-$releasever - Base
15
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
16
#baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
17
gpgcheck=1
18
enabled=1
19
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5
20
21
#released updates
22
[updates]
23
name=CentOS-$releasever - Updates
24
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
25
#baseurl=http://mirror.centos.org/centos/$releasever/updates/$basearch/
26
gpgcheck=1
27
enabled=1
28
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5
29
30
#additional packages that may be useful
31
[extras]
32
name=CentOS-$releasever - Extras
33
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
34
#baseurl=http://mirror.centos.org/centos/$releasever/extras/$basearch/
35
gpgcheck=1
36
enabled=1
37
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5
38
39
#additional packages that extend functionality of existing packages
40
[centosplus]
41
name=CentOS-$releasever - Plus
42
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus
43
#baseurl=http://mirror.centos.org/centos/$releasever/centosplus/$basearch/
44
gpgcheck=1
45
enabled=0
46
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5
47
48
#contrib - packages by Centos Users
49
[contrib]
50
name=CentOS-$releasever - Contrib
51
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=contrib
52
#baseurl=http://mirror.centos.org/centos/$releasever/contrib/$basearch/
53
gpgcheck=1
54
enabled=0
如果你是教育網IPv6環境(IPv4亦可)的,可以添加清華大學開源鏡像站的源,速度很快
tsinghua.repo
01
[base]
02
name=CentOS-6 - Base
03
repo=os
04
baseurl=http://mirrors.tuna.tsinghua.edu.cn/centos/6.4/os/$basearch/
05
gpgcheck=1
06
gpgkey=http://mirrors.tuna.tsinghua.edu.cn/centos/RPM-GPG-KEY-CentOS-6
07
08
[update]
09
name=CentOS-6 - Updates
10
baseurl=http://mirrors.tuna.tsinghua.edu.cn/centos/6.4/updates/$basearch/
11
gpgcheck=1
12
gpgkey=http://mirrors.tuna.tsinghua.edu.cn/centos/RPM-GPG-KEY-CentOS-6
13
14
[extras]
15
name=CentOS-6 - Extras
16
baseurl=http://mirrors.tuna.tsinghua.edu.cn/centos/6.4/extras/$basearch/
17
gpgcheck=1
18
gpgkey=http://mirrors.tuna.tsinghua.edu.cn/centos/RPM-GPG-KEY-CentOS-6
19
20
[centosplus]
21
name=CentOS-6 - Plus
22
baseurl=http://mirrors.tuna.tsinghua.edu.cn/centos/6.4/centosplus/$basearch/
23
gpgcheck=1
24
enabled=0
25
gpgkey=http://mirrors.tuna.tsinghua.edu.cn/centos/RPM-GPG-KEY-CentOS-6
26
27
[contrib]
28
name=CentOS-6 - Contrib
29
baseurl=http://mirrors.tuna.tsinghua.edu.cn/centos/6.4/contrib/$basearch/
30
gpgcheck=1
31
enabled=0
32
gpgkey=http://mirrors.tuna.tsinghua.edu.cn/centos/RPM-GPG-KEY-CentOS-6
添加完YUM後,更新yum,
1
# yum check-update
這樣就完成了YUM源的添加。
安裝軟件包
例如,安裝git,則運行如下命令,
1
# yum install git
更新軟件包
可以通過先檢查更新,在根據返回的所需更新軟件包進行更新操作。
1
# yum check-update
如返回以下更新信息,
1
<span>java-1.7.0-openjdk.i386 1:1.7.0.25-2.3.10.4.el5_9 updates</span>
則表示openjdk1.7有更新,運行如下命令進行更新,
1
# yum update java-1.7.0-openjdk.i386
刪除軟件包
例如,刪除git,則運行,
1
# yum delete git