歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> CentOS 6.4搭建網絡源

CentOS 6.4搭建網絡源

日期:2017/2/28 14:37:54   编辑:Linux教程

當你的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 www.baidu.com
PING www.a.shifen.com (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 http://mirrors.163.com/.help/CentOS6-Base-163.repo --下載163的源鏡像
--2013-12-10 21:23:32-- http://mirrors.163.com/.help/CentOS6-Base-163.repo
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]#

注:Linux本地源配置:http://www.linuxidc.com/Linux/2013-12/93805.htm

推薦閱讀

RedHat Linux 本地yum源的配置 http://www.linuxidc.com/Linux/2013-08/88217.htm

RedHat 6.2 Linux修改yum源免費使用CentOS源 http://www.linuxidc.com/Linux/2013-07/87383.htm

配置EPEL YUM源 http://www.linuxidc.com/Linux/2012-10/71850.htm

Redhat 本地yum源配置 http://www.linuxidc.com/Linux/2012-11/75127.htm

yum的配置文件說明 http://www.linuxidc.com/Linux/2013-04/83298.htm

RedHat 6.1下安裝yum(圖文) http://www.linuxidc.com/Linux/2013-06/86535.htm

YUM 安裝及清理 http://www.linuxidc.com/Linux/2013-07/87163.htm

更多CentOS相關信息見CentOS 專題頁面 http://www.linuxidc.com/topicnews.aspx?tid=14

Copyright © Linux教程網 All Rights Reserved