CentOS基本配置

vi /etc/resolv.conf
nameserver 8.8.8.8
nameserver 8.8.4.4

vi /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0  #指出设备名称  
NM_CONTROLLED=yes  #network mamager的参数,实时生效,不需要重启  
ONBOOT=yes  #设置为yes,开机自动启用网络连接  
IPADDR=192.168.21.129  #IP地址  
BOOTPROTO=none  #设置为none禁止DHCP,设置为static启用静态IP地址,设置为dhcp开启DHCP服务  
NETMASK=255.255.255.0  #子网掩码  
DNS1=8.8.8.8  #第一个dns服务器  
TYPE=Ethernet  #网络类型为:Ethernet  
GATEWAY=192.168.21.2  #设置网关  
DNS2=8.8.4.4  #第二个dns服务器  
IPV6INIT=no  #禁止IPV6  
USERCTL=no  #是否允许非root用户控制该设备,设置为no,只能用root用户更改  
HWADDR=00:0C:29:2C:E1:0F  #网卡的Mac地址  
PREFIX=24  
DEFROUTE=yes  
IPV4_FAILURE_FATAL=yes  
NAME="System eth0"  #定义设备名称

配置阿里yun源

备份:将 CentOS-Base.repo 备份为 CentOS-Base.repo.backup
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
下载阿里云新的http://mirrors.aliyun.com/repo/Centos-7.repo,并命名为CentOS-Base.repo
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
或者
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
清除缓存
yum clean all     # 清除系统所有的yum缓存
yum makecache     # 生成yum缓存
yum update

epel源 安装和配置

查看可用的epel源
[root@localhost yum.repos.d]$ yum list | grep epel-release
epel-release.noarch     7-11    extras   
[root@localhost yum.repos.d]$
安装 epel
[root@localhost yum.repos.d]$ yum install -y epel-release
......省略.....
配置阿里镜像提供的epel源
wget -O /etc/yum.repos.d/epel-7.repo  http://mirrors.aliyun.com/repo/epel-7.repo
清除缓存
yum clean all     # 清除系统所有的yum缓存
yum makecache     # 生成yum缓存
yum update

查看yum源

查看所有的yum源:
yum repolist all
查看可用的yum源:
yum repolist enabled

配置 清华大学镜像仓库

清华大学镜像仓库地址:https://mirrors.cnnic.cn/

找到center点击?进入帮助说明页面 https://mirrors.cnnic.cn/help/centos/

页面提供了 CentOS5CentOS6CentOS7 的镜像仓库配置,下面列出的是CentOS7的配置

首先备份 CentOS-Base.repo
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
之后启用 TUNA 软件仓库, 将清华大学镜像仓库信息写入 /etc/yum.repos.d/CentOS-Base.repo
# 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
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/os/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#released updates
[updates]
name=CentOS-$releasever - Updates
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/updates/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/extras/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/centosplus/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
清除缓存
yum clean all     # 清除系统所有的yum缓存
yum makecache     # 生成yum缓存
yum update


最后修改:2020 年 09 月 16 日 08 : 37 AM
如果觉得我的文章对你有用,请随意赞赏