当你的Linux系统能连接上网络时我想你那时就不用本地源和rpm安装软件了,网络源是通过网络上的资源进行安装自己想要的软件,这样安装可以及时更新和维护系统。
1.确保自己的服务器能连接上互联网
[root@CentOS ~]# ifconfig eth0
eth0 Link encap:Ethernet HWaddr 08:00:27:56:AA:AA
inet addr:2.2.2.145 Bcast:2.255.255.255 Mask:255.0.0.0
inet6 addr: fe80::a00:27ff:fe56:aaaa/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:424 errors:0 dropped:0 overruns:0 frame:0
TX packets:95 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:36395 (35.5 KiB) TX bytes:12020 (11.7 KiB)
[root@centos ~]# ping
PING (115.239.210.27) 56(84) bytes of data.
64 bytes from 115.239.210.27: icmp_seq=1 ttl=54 time=18.1 ms
64 bytes from 115.239.210.27: icmp_seq=1 ttl=54 time=17.9 ms
2.编辑yum的库文件(用官方的源)
[root@RedHat1 ~]# cd /etc/yum.repos.d/
[root@redhat1 ~]# vim CentOS-Base.repo --用官方的源(去掉所有baseurl前面的#号)
[base]
name=CentOS-$releasever - Base
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
#released updates
[updates]
name=CentOS-$releasever - Updates
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
baseurl=http://mirror.centos.org/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
baseurl=http://mirror.centos.org/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus
baseurl=http://mirror.centos.org/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=1 --启用仓库
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
#contrib - packages by Centos Users
[contrib]
name=CentOS-$releasever - Contrib
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=contrib
baseurl=http://mirror.centos.org/centos/$releasever/contrib/$basearch/
gpgcheck=1
enabled=1 --启用仓库
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
3.用网易的网络源(其它开源镜像站点也是一样的)
[root@centos1 ~]# cd /etc/yum.repos.d/ --进入仓库根目录
[root@centos1 yum.repos.d]# ll
total 16
-rw-r--r--. 1 root root 1926 Feb 25 2013 CentOS-Base.repo1
-rw-r--r--. 1 root root 638 Feb 25 2013 CentOS-Debuginfo.repo1
-rw-r--r--. 1 root root 545 Nov 10 13:27 CentOS-Media.repo
-rw-r--r--. 1 root root 3664 Feb 25 2013 CentOS-Vault.repo
[root@centos1 yum.repos.d]# wget --下载163的源镜像
--2013-12-10 21:23:32--
Resolving mirrors.163.com... 123.58.173.106
Connecting to mirrors.163.com|123.58.173.106|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 2006 (2.0K) [application/octet-stream]
Saving to: ?.entOS6-Base-163.repo?
100%[====================================================================================>] 2,006 --.-K/s in 0.02s
2013-12-10 21:23:32 (97.8 KB/s) - ?.entOS6-Base-163.repo?.saved [2006/2006]
[root@centos1 yum.repos.d]# ll
total 20
-rw-r--r--. 1 root root 2006 Sep 1 2011 CentOS6-Base-163.repo
-rw-r--r--. 1 root root 1926 Feb 25 2013 CentOS-Base.repo1
-rw-r--r--. 1 root root 638 Feb 25 2013 CentOS-Debuginfo.repo1
-rw-r--r--. 1 root root 545 Nov 10 13:27 CentOS-Media.repo
-rw-r--r--. 1 root root 3664 Feb 25 2013 CentOS-Vault.repo
[root@centos1 yum.repos.d]# vim CentOS6-Base-163.repo --去掉baseurl前面的#号,将enabled=0改为1
[base]
name=CentOS-$releasever - Base - 163.com
baseurl=http://mirrors.163.com/centos/$releasever/os/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6
#released updates
[updates]
name=CentOS-$releasever - Updates - 163.com
baseurl=http://mirrors.163.com/centos/$releasever/updates/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6
#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras - 163.com
baseurl=http://mirrors.163.com/centos/$releasever/extras/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus - 163.com
baseurl=http://mirrors.163.com/centos/$releasever/centosplus/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus
gpgcheck=1
enabled=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6
#contrib - packages by Centos Users
[contrib]
name=CentOS-$releasever - Contrib - 163.com
baseurl=http://mirrors.163.com/centos/$releasever/contrib/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=contrib
gpgcheck=1
enabled=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6
[root@centos1 yum.repos.d]# yum repolist --查看仓库是否成功
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
base | 3.7 kB 00:00
base/primary_db | 3.5 MB 00:47
extras | 3.4 kB 00:00
extras/primary_db | 18 kB 00:00
updates | 3.4 kB 00:00
updates/primary_db | 97 kB 00:01
repo id repo name status
base CentOS-6 - Base - 163.com 4,802
c6-media CentOS-6 - Media 4,802
extras CentOS-6 - Extras - 163.com 12
updates CentOS-6 - Updates - 163.com 93
repolist: 9,709
[root@centos1 yum.repos.d]#
推荐阅读: