Centos7 配置静态 IP 及配置 yum 源
- Centos7 配置静态 IP 及配置 yum 源
- 1. 配置环境
- 1.1 首先配置静态网络地址
- 1.2 测试网络是否通畅
- 1.3 安装完成
- 1.4 配置 yum 源
- 1.4.1 [清华源](https://mirrors.tuna.tsinghua.edu.cn/)
- 1.4.2 [阿里源](https://opsx.alibaba.com/mirror)
Centos7 配置静态 IP 及配置 yum 源
复制代码
1
2
3
4准备: VMware Workstation Pro 15 CentOS-7-x86_64-Minimal-1810
1. 配置环境
1.1 首先配置静态网络地址
复制代码
1
2vi /etc/sysconfig/network-scripts/ifcfg-ens33
修改如下内容。
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13# 设置 IP 地址为静态 IP BOOTPROTO=static # 随 network 服务启动 ONBOOT=yes # 指定静态 IP IPADDR=192.168.16.17 # 设置子网掩码 NETMASK=255.255.255.0 # 设置网关 GATEWAY=192.168.16.2 # 设置DNS DNS1=192.168.16.2
其中 GATEWAY 和 DNS 的地址为 VMware 中 NAT 模式设置的默认网关 IP, IPADDR 为指定子网的 IP。设置方法为 编辑->虚拟网络编辑器 然后在名称里选择 VMnet8 NAT模式。就可以设置 子网 IP 和 子网掩码,在 NAT设置 中设置网关。
1.2 测试网络是否通畅
复制代码
1
2
3
4
5
6
7# 重启网络 systemctl restart network # 查看 ip,查看 ens33 端口IP是否出现 ip a # 测试网络环境 ping www.baidu.com
1.3 安装完成
复制代码
1
2
3# 保持系统最新版本 yum -y update && yum -y upgrade && yum -y autoremove
网络成功后,安装vim(个人喜好)。yum -y install vim wget
。最好使用类似 XShell 的 ssh 终端连接操作。
1.4 配置 yum 源
复制代码
1
2前言:Linux 属于国外的系统,要想安装软件,通过系统自带的国外软件源,有的会感觉有些卡顿,所以有了国内软件源的出现。其中用的比较多的就是清华源、阿里源、中科大源等等,笔者最常用的就是清华源,当然了,下载一些 Linux 的镜像也会去下载,速度什么的还是不错的。
1.4.1 清华源
在镜像站一般会有介绍如何使用该镜像源的方法(系统名称右上角有问号,点击即可),这里简单介绍下。
复制代码
1
2
3
4
5
6# 备份原来的源 sudo mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak # 使用 vi ,创建一个新的文件 vi /etc/yum.repos.d/CentOS-Base.repo
进入后,按 i
进入编辑模式,将以下内容复制进去。
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41# 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
使用命令进行版本的修改。
复制代码
1
2
3
4
5# 修改源系统版本 sudo sed -i `s/$releasever/7/g` /etc/yum.repos.d/CentOS-Base.repo # 更新软件包缓存 sudo yum makecache
1.4.2 阿里源
阿里源配置首先也是要备份源的,执行命令。
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14# 备份系统源 sudo mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak # 下载新的源文件 Centos-Base.repo 到 /etc/yum.repo.d/ (这里只介绍 Centos7) # 使用 wget ,首先要先安装,默认最小安装的系统不带 wget。 sudo yum -y install wget # 下载阿里源文件 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 # 修改源系统的版本 sudo sed -i `s$releasever/7/g` /etc/yum.repos.d/CentOS-Base.repo # 生成缓存 sudo yum makecache
配置完 yum 源之后,使用命令 yum repolist
即可查看 yum 源的信息。
最后
以上就是调皮店员最近收集整理的关于Centos7 配置静态 IP 及配置 yum 源Centos7 配置静态 IP 及配置 yum 源的全部内容,更多相关Centos7内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复