CentOS7-mini开启网络服务

CentOS7 最小化安装后无法上网,需要先开启网络服务

修改网络配置,开启网络

编辑 /etc/sysconfig/network-scripts/ifcfg-ens33文件
将 ONBOOT=no 改为 ONBOOT=yes

[root@servce ~]# vi  /etc/sysconfig/network-scripts/ifcfg-ens33
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=dhcp
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=ens33
UUID=0dc1a431-7fcb-4338-a6b0-9f42493dba80
DEVICE=ens33
ONBOOT=yes

重启network服务设置生效

重启命令 service network restart

[root@servce ~]#  service network restart
Restarting network (via systemctl):                        [  OK  ]

安装wget软件

执行命令 yum -y install wget

[root@servce ~]# yum -y install wget
Loaded plugins: fastestmirror
There are no enabled repos.
Installed:
  wget.x86_64 0:1.14-18.el7_6.1                                                                            

Complete!
[root@servce ~]# 

更换国内阿里源

缺省yum源的服务器通常在国外,安装时速度比较慢。为了提高安装rpm包的速度,可以将yum源配置为国内的阿里repo。

先备份系统原有的repo

命令:mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak

[root@servce ~]# mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak

获取阿里源并重命名

命令:wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

[root@servce ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
--2019-12-01 07:02:07--  http://mirrors.aliyun.com/repo/Centos-7.repo
Resolving mirrors.aliyun.com (mirrors.aliyun.com)... 113.229.252.113, 27.221.56.243, 119.167.132.14, ...
Connecting to mirrors.aliyun.com (mirrors.aliyun.com)|113.229.252.113|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 2523 (2.5K) [application/octet-stream]
Saving to: ‘/etc/yum.repos.d/CentOS-Base.repo’

100%[=================================================================>] 2,523       --.-K/s   in 0s      

2019-12-01 07:02:07 (581 MB/s) - ‘/etc/yum.repos.d/CentOS-Base.repo’ saved [2523/2523]


清除并重新生成yum cache

清除缓存命令:yum clean all
重新缓存命令:yum makecache

[root@servce ~]# yum clean all
Loaded plugins: fastestmirror
Cleaning repos: base extras updates
Cleaning up list of fastest mirrors
[root@servce ~]# yum makecache
Loaded plugins: fastestmirror
Determining fastest mirrors
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
Metadata Cache Created

测试一下新的yum源是否可用

测试命令:yum install -y screen

[root@servce ~]# yum install -y screen
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
Resolving Dependencies
--> Running transaction check
---> Package screen.x86_64 0:4.1.0-0.25.20120314git3c2946.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===========================================================================================================
 Package            Arch               Version                                      Repository        Size
===========================================================================================================
Installing:
 screen             x86_64             4.1.0-0.25.20120314git3c2946.el7             base             552 k

Transaction Summary
===========================================================================================================
Install  1 Package

Total download size: 552 k
Installed size: 914 k
Downloading packages:
screen-4.1.0-0.25.20120314git3c2946.el7.x86_64.rpm                                  | 552 kB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : screen-4.1.0-0.25.20120314git3c2946.el7.x86_64                                          1/1 
  Verifying  : screen-4.1.0-0.25.20120314git3c2946.el7.x86_64                                          1/1 

Installed:
  screen.x86_64 0:4.1.0-0.25.20120314git3c2946.el7                                                         

Complete!

5、获取阿里centos7的epel-repo

命令:wget -O /etc/yum.repos.d/epel-7.repo https://mirrors.aliyun.com/repo/epel-7.repo

[root@servce ~]# wget -O /etc/yum.repos.d/epel-7.repo https://mirrors.aliyun.com/repo/epel-7.repo
--2019-12-01 07:11:27--  https://mirrors.aliyun.com/repo/epel-7.repo
Resolving mirrors.aliyun.com (mirrors.aliyun.com)... 119.167.132.18, 27.221.92.8, 27.221.92.7, ...
Connecting to mirrors.aliyun.com (mirrors.aliyun.com)|119.167.132.18|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 664 [application/octet-stream]
Saving to: ‘/etc/yum.repos.d/epel-7.repo’

100%[=================================================================>] 664         --.-K/s   in 0s      

2019-12-01 07:11:27 (100 MB/s) - ‘/etc/yum.repos.d/epel-7.repo’ saved [664/664]


6、清除并创建cache
清除命令:yum clean all
缓存命令:yum makecache

[root@servce ~]# yum clean all
Loaded plugins: fastestmirror
Cleaning repos: base epel extras updates
Cleaning up list of fastest mirrors
[root@servce ~]# yum makecache
Loaded plugins: fastestmirror
Determining fastest mirrors
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
base                                                                                | 3.6 kB  00:00:00     
epel                                                                                | 5.3 kB  00:00:00     
extras                                                                              | 2.9 kB  00:00:00     
updates                                                                             | 2.9 kB  00:00:00     
(1/17): base/7/x86_64/group_gz                                                      | 165 kB  00:00:00     
(2/17): base/7/x86_64/filelists_db                                                  | 7.3 MB  00:00:02     
(3/17): epel/x86_64/group_gz                                                        |  90 kB  00:00:00     
(4/17): base/7/x86_64/primary_db                                                    | 6.0 MB  00:00:02     
(5/17): epel/x86_64/updateinfo                                                      | 1.0 MB  00:00:00     
(6/17): base/7/x86_64/other_db                                                      | 2.6 MB  00:00:01     
(7/17): epel/x86_64/prestodelta                                                     |  856 B  00:00:00     
(8/17): epel/x86_64/primary_db                                                      | 6.9 MB  00:00:02     
(9/17): epel/x86_64/filelists_db                                                    |  12 MB  00:00:04     
(10/17): epel/x86_64/other_db                                                       | 3.3 MB  00:00:01     
(11/17): extras/7/x86_64/primary_db                                                 | 153 kB  00:00:00     
(12/17): extras/7/x86_64/filelists_db                                               | 207 kB  00:00:00     
(13/17): epel/x86_64/updateinfo_zck                                                 | 1.5 MB  00:00:00     
(14/17): extras/7/x86_64/other_db                                                   | 100 kB  00:00:00     
(15/17): updates/7/x86_64/filelists_db                                              | 2.7 MB  00:00:01     
(16/17): updates/7/x86_64/primary_db                                                | 4.2 MB  00:00:01     
(17/17): updates/7/x86_64/other_db                                                  | 267 kB  00:00:00     
Metadata Cache Created

更新系统

更新系统(如果实用系统源时间比较久,使用阿里源比较快)
[root@localhost yum.repos.d]# yum -y update

关闭防火墙

测试环境将已关闭,避免很多配置问题
停止防火墙: systemctl stop firewalld
禁用防火墙: systemctl disable firewalld

[root@servce ~]# systemctl stop firewalld
[root@servce ~]# systemctl disable firewalld
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.

关闭SELinux 模块

建议测试环境关闭
SELinux 是部署在 Linux 系统中的安全增强功能模块,它通过对进程和文件资源采用 MAC(强制访问控制方式)为 Linux 系统提供了改进的安全性。
编辑文件:vi /etc/sysconfig/selinux
将 SELINUX=enforcing 改为 SELINUX=disabled
重启命令:reboot

[root@servce ~]# vi /etc/sysconfig/selinux

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
#SELINUX=enforcing
SELINUX=disabled
# SELINUXTYPE= can take one of three values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected.
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted

[root@servce ~]# reboot

安装zip工具

安装命令:yum install -y unzip zip

[root@servce ~]# yum install -y unzip zip
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
Resolving Dependencies
--> Running transaction check
---> Package unzip.x86_64 0:6.0-20.el7 will be installed
---> Package zip.x86_64 0:3.0-11.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===========================================================================================================
 Package                Arch                    Version                        Repository             Size
===========================================================================================================
Installing:
 unzip                  x86_64                  6.0-20.el7                     base                  170 k
 zip                    x86_64                  3.0-11.el7                     base                  260 k

Transaction Summary
===========================================================================================================
Install  2 Packages

Total download size: 430 k
Installed size: 1.1 M
Downloading packages:
(1/2): zip-3.0-11.el7.x86_64.rpm                                                    | 260 kB  00:00:00     
(2/2): unzip-6.0-20.el7.x86_64.rpm                                                  | 170 kB  00:00:00     
-----------------------------------------------------------------------------------------------------------
Total                                                                      710 kB/s | 430 kB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : zip-3.0-11.el7.x86_64                                                                   1/2 
  Installing : unzip-6.0-20.el7.x86_64                                                                 2/2 
  Verifying  : unzip-6.0-20.el7.x86_64                                                                 1/2 
  Verifying  : zip-3.0-11.el7.x86_64                                                                   2/2 

Installed:
  unzip.x86_64 0:6.0-20.el7                             zip.x86_64 0:3.0-11.el7                            

Complete!
[root@servce ~]# 

安装 上传下载工具 lrzsz

安装命令:yum install -y lrzsz

[root@servce ~]# yum install -y lrzsz
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
Resolving Dependencies
--> Running transaction check
---> Package lrzsz.x86_64 0:0.12.20-36.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===========================================================================================================
 Package               Arch                   Version                           Repository            Size
===========================================================================================================
Installing:
 lrzsz                 x86_64                 0.12.20-36.el7                    base                  78 k

Transaction Summary
===========================================================================================================
Install  1 Package

Total download size: 78 k
Installed size: 181 k
Downloading packages:
lrzsz-0.12.20-36.el7.x86_64.rpm                                                     |  78 kB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : lrzsz-0.12.20-36.el7.x86_64                                                             1/1 
  Verifying  : lrzsz-0.12.20-36.el7.x86_64                                                             1/1 

Installed:
  lrzsz.x86_64 0:0.12.20-36.el7                                                                            

Complete!

Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐