简易最小化虚拟机安装配置(CentOS-7-Minimal)
CentOS-7 最小化虚拟机安装及配置教程
·
文章目录
镜像选择
选用CentOS-7-x86_64-Minimal-1810.iso
最小化安装(此版本无GUI页面,仅命令行模式)
参考镜像源地址:http://mirrors.aliyun.com/centos/7/isos/x86_64/
虚拟机安装(VMware Workstation)
使用VMware Workstation 进行虚拟机创建安装,按照镜像指引进行系统安装(此部分略过,虚拟机配置可以再安装后进行调整配置)
使用192.168.2.0
网段进行配置,设置好网关地址、网卡地址及子网掩码
虚拟网络配置(NAT模式)
虚拟网卡配置
虚拟机配置
静态IP配置及测试
进入系统目录:/etc/sysconfig/network-scripts/
,修改如下参数并保存
BOOTPROTO=static
ONBOOT=yes
IPADDR=192.168.2.98
(复制虚拟机后,仅修改此IP即可)NETMASK=255.255.255.0
GATEWAY=192.168.2.2
[root@localhost ~]# cd /etc/sysconfig/network-scripts/
[root@localhost network-scripts]# vi ifcfg-ens33
[root@localhost network-scripts]# cat ifcfg-ens33
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static
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=a1d937b7-1aa9-46eb-b0c0-0ce44311503a
DEVICE=ens33
ONBOOT=yes
IPADDR=192.168.2.98
NETMASK=255.255.255.0
GATEWAY=192.168.2.2
重启网络服务,查看ip addr
[root@localhost network-scripts]# service network restart
Restarting network (via systemctl): [ 确定 ]
[root@localhost network-scripts]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 00:0c:29:e2:a1:36 brd ff:ff:ff:ff:ff:ff
inet 192.168.2.98/24 brd 192.168.2.255 scope global noprefixroute ens33
valid_lft forever preferred_lft forever
inet6 fe80::f2bd:bd9d:9838:c35f/64 scope link noprefixroute
valid_lft forever preferred_lft forever
配置DNS(/etc/resolv.conf
)并测试(外网连通性),至此可以使用SSH终端工具进行连接
[root@localhost network-scripts]# vi /etc/resolv.conf
[root@localhost network-scripts]# cat /etc/resolv.conf
nameserver 114.114.114.114
nameserver 8.8.8.8
nameserver 8.8.4.4
[root@localhost network-scripts]# ping www.baidu.com
PING www.a.shifen.com (220.181.38.149) 56(84) bytes of data.
64 bytes from 220.181.38.149 (220.181.38.149): icmp_seq=1 ttl=128 time=19.8 ms
64 bytes from 220.181.38.149 (220.181.38.149): icmp_seq=2 ttl=128 time=13.7 ms
64 bytes from 220.181.38.149 (220.181.38.149): icmp_seq=3 ttl=128 time=17.5 ms
64 bytes from 220.181.38.149 (220.181.38.149): icmp_seq=4 ttl=128 time=15.8 ms
64 bytes from 220.181.38.149 (220.181.38.149): icmp_seq=5 ttl=128 time=14.5 ms
系统初始化及库安装
停止防火墙 & 关闭防火墙自启动
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# systemctl disable firewalld.service
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
关闭 selinux 防火墙
- 注释:
SELINUX=enforcing
- 注释:
SELINUXTYPE=targeted
- 添加:
SELINUX=disabled
[root@localhost ~]# vi /etc/selinux/config
[root@localhost ~]# cat /etc/selinux/config
# 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
# 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
SELINUX=disabled
[root@localhost ~]# setenforce 0
[root@localhost ~]# reboot
更换镜像源并重建镜像源缓存
[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# ls
CentOS-Base.repo CentOS-Debuginfo.repo CentOS-Media.repo CentOS-Vault.repo
CentOS-CR.repo CentOS-fasttrack.repo CentOS-Sources.repo
[root@localhost yum.repos.d]# mv CentOS-Base.repo CentOS-Base.repo.bak
[root@localhost yum.repos.d]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
--2022-06-08 15:39:58-- http://mirrors.aliyun.com/repo/Centos-7.repo
正在解析主机 mirrors.aliyun.com (mirrors.aliyun.com)... 42.101.0.238, 42.101.0.242, 42.101.0.241, ...
正在连接 mirrors.aliyun.com (mirrors.aliyun.com)|42.101.0.238|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:2523 (2.5K) [application/octet-stream]
正在保存至: “/etc/yum.repos.d/CentOS-Base.repo”
100%[===============================================================================================>] 2,523 --.-K/s 用时 0.02s
2022-06-08 15:39:58 (157 KB/s) - 已保存 “/etc/yum.repos.d/CentOS-Base.repo” [2523/2523])
[root@localhost yum.repos.d]# ls -ll
总用量 36
-rw-r--r-- 1 root root 2523 12月 26 2020 CentOS-Base.repo
-rw-r--r--. 1 root root 1664 11月 23 2018 CentOS-Base.repo.bak
-rw-r--r--. 1 root root 1309 11月 23 2018 CentOS-CR.repo
-rw-r--r--. 1 root root 649 11月 23 2018 CentOS-Debuginfo.repo
-rw-r--r--. 1 root root 314 11月 23 2018 CentOS-fasttrack.repo
-rw-r--r--. 1 root root 630 11月 23 2018 CentOS-Media.repo
-rw-r--r--. 1 root root 1331 11月 23 2018 CentOS-Sources.repo
-rw-r--r--. 1 root root 5701 11月 23 2018 CentOS-Vault.repo
[root@localhost yum.repos.d]# yum makecache
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
http://mirrors.aliyuncs.com/centos/7/os/x86_64/repodata/repomd.xml: [Errno 14] curl#7 - "Failed connect to mirrors.aliyuncs.com:80; 没有到主机的路由"
正在尝试其它镜像。
http://mirrors.cloud.aliyuncs.com/centos/7/os/x86_64/repodata/repomd.xml: [Errno 14] curl#6 - "Could not resolve host: mirrors.cloud.aliyuncs.com; 未知的错误"
正在尝试其它镜像。
base | 3.6 kB 00:00:00
extras | 2.9 kB 00:00:00
updates | 2.9 kB 00:00:00
(1/6): extras/7/x86_64/filelists_db | 277 kB 00:00:01
(2/6): updates/7/x86_64/other_db | 1.0 MB 00:00:04
(3/6): extras/7/x86_64/other_db | 148 kB 00:00:06
(4/6): base/7/x86_64/other_db | 2.6 MB 00:00:17
(5/6): base/7/x86_64/filelists_db | 7.2 MB 00:00:29
(6/6): updates/7/x86_64/filelists_db | 8.7 MB 00:00:32
元数据缓存已建立
安装 ifconfig & Vim & Wget
[root@localhost yum.repos.d]# yum install -y wget
[root@localhost yum.repos.d]# yum install -y vim-enhanced
[root@localhost yum.repos.d]# yum install -y iptables-services
[root@localhost sysconfig]# cat /etc/sysconfig/iptables
# sample configuration for iptables service
# you can edit this manually or use system-config-firewall
# please do not ask us to add additional ports/services to this default configuration
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT
修改hostname
[root@localhost ~]# hostnamectl set-hostname evm
更新yum软件包
[root@localhost ~]# yum update
更多推荐
已为社区贡献2条内容
所有评论(0)