前言
本文以centos7.9为例,准备前期学习环境,确保学习效果,降低学习难度,后续在逐步增加学习难度,逐层升级打怪。
实验环境搭建过程
1. 清空防火墙
[root@gaosh-63 ~]# iptables -F ## 清空防火墙规则
[root@gaosh-63 ~]# systemctl stop firewalld ## 关闭防火墙
[root@gaosh-63 ~]# systemctl disable firewalld ## 设置开机不启动防火墙
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@gaosh-63 ~]#
2. 关闭selinux
1)临时关闭selinux
[root@gaosh-63 ~]# setenforce 0 ##临时关闭selinux
[root@gaosh-63 ~]# getenforce ## 查看selinux状态
Permissive
2) 永久关闭selinux
配置文件: /etc/selinux/config 把下图的: 改为:
SELINUX=disabled
注意: 永久关闭selinux,需要重启生效。
3. 配置静态IP
为了做实验方便,一定要配置静态IP,防止关机后IP改变。
配置文件如下:
[root@gaosh-63 ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens32
关闭NetworkManager
[root@gaosh-63 ~]# systemctl stop NetworkManager
[root@gaosh-63 ~]# systemctl disable NetworkManager
Removed symlink /etc/systemd/system/multi-user.target.wants/NetworkManager.service.
Removed symlink /etc/systemd/system/dbus-org.freedesktop.nm-dispatcher.service.
Removed symlink /etc/systemd/system/network-online.target.wants/NetworkManager-wait-online.service.
4. 修改主机名
很多人做实验,都是用localhost,三台服务器做实验,三台的主机名都是localhost,不方便区分。
所以我们把域名改成 公司名-Ip最后两位的形式。 比如公司叫致码教育(zmedu),本机的IP为192.168.1.64, 那我们可以定义主机名为: zmedu-64
配置文件:/etc/hostname
[root@gaosh-63 ~]# cat /etc/hostname
gaosh-64
配置完后需要重启,当然现在不需要重启,等全部配置完后重启即可
5. 配置主机名与IP的映射关系
添加ip与主机名的对应关系
vim /etc/hosts
192.168.0.64 gaosh-64
6. 配置yum源
一般centos7的网络yum源,其实都可以直接用,当然你也可以配置本地yum源。
配置文件 [root@gaosh-1 ~]# vim /etc/yum.repos.d/centos7.repo
[centos]
name=centos-repo
baseurl=file:///mnt
enabled=1
gpgcheck=0
挂载:
[root@gaosh-1 ~]# mount /dev/cdrom /mnt
mount: block device /dev/sr0 is write-protected, mounting read-only
查看是否挂载成功
7. 重启创建快照
reboot 按照下图创建快照
总结
做好一次实验环境,下次没做实验的时候都可以还原快照,不用一次次重装系统,当然,如果你是用的云服务器,也一样可以创建快照。