redhat虚拟机作业3

 题目

1、将你的虚拟机的网卡模式设置为nat模式,给虚拟机网卡配置三个主机位分别为100、200、168的ip地址
2、测试你的虚拟机是否能够ping通网关和dns,如果不能请修改网关和dns的地址
3、将如下内容写入/etc/hosts文件中(如果有多个ip地址则写多行):
        你的第一个ip地址(不要写掩码)     www.rhcsa1.com
        你的第二个ip地址(不要写掩码)    www.rhcsa2.com
4、使用ping命令测试能否ping通www.rhcsa1.com和www.rhcsa2.com
5、使用yum安装nginx并运行
6、在linux的火狐浏览器上分别访问www.rhcsa1.com和www.rhcsa2.com网站
7、将你当前主机的ip地址,mac地址和主机名写入文件/usr/share/nginx/html/index.html
8、在linux的火狐浏览器上再分别访问www.rhcsa1.com和www.rhcsa2.com网站,看网站内容的变化
9、在windows的浏览器上输入你的虚拟机的ip地址访问查看效果
10、给虚拟机添加两个硬盘,大小分别为5G、10G
11、给第一个硬盘分区为2个主分区(大小分别为2G,1G),2个逻辑分区(大小分别为1G);给第二个硬盘分5个区,大小分别为2G
12、将第一个硬盘的第一个分区挂载至/guazai1,将第二个硬盘的第一个分区挂载至/guazai2
13、将/usr/share/nginx/html/index.html复制到/guazai1中,将 /etc/ssh/sshd_config复制到/guazai2

一、

将你的虚拟机的网卡模式设置为nat模式,给虚拟机网卡配置三个主机位分别为100、200、168的ip地址

1.先查看虚拟机设置,查看网络配置器是否为NAT模式,确认打开NAT模式后,查看本机的网关地址

2.在控制面版中使用nmtui命令配置所需虚拟机网卡并连接

3.配置完毕后输入ip a命令确认网卡的ip是否配置正确

二、

测试你的虚拟机是否能够ping通网关和dns,如果不能请修改网关和dns的地址

先使用nmtui命令将dns配置为114.114.114.114并保存,然后分别去ping本机网关(192.168.28.2)和www.baidu.com

三、

将如下内容写入/etc/hosts文件中(如果有多个ip地址则写多行):
        你的第一个ip地址(不要写掩码)     www.rhcsa1.com
        你的第二个ip地址(不要写掩码)    www.rhcsa2.com

1.分别在redhat虚拟机和rocky虚拟机中输入ip a命令查看本机的IP地址

2.已知Redhat虚拟机中IP地址为192.168.28.133/24 rocky虚拟机中IP地址为192.168.28.132/24,然后分别使用两个虚拟机的IP完成上述操作,最后用ping命令进行检查

四、

使用ping命令测试能否ping通www.rhcsa1.com和www.rhcsa2.com

五、

使用yum安装nginx并运行

在xshell和xftp中配置好环境并完成安装,最后打开运行并开启自启动

[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# ls
CentOS-9-Stream.repo  redhat.repo
[root@localhost yum.repos.d]# cd
[root@localhost ~]# yum install nginx -y
正在更新 Subscription Management 软件仓库。
无法读取客户身份

本系统尚未在权利服务器中注册。可使用 subscription-manager 进行注册。

上次元数据过期检查:6:48:35 前,执行于 2025年04月08日 星期二 12时15分37秒。
软件包 nginx-2:1.20.1-22.el9.x86_64 已安装。
依赖关系解决。
无需任何处理。
完毕!
[root@localhost ~]# systemctl start nginx
[root@localhost ~]# systemctl enable nginx
Created symlink /etc/systemd/system/multi-user.target.wants/nginx.service → /usr/lib/systemd/system/nginx.service.

六、

在linux的火狐浏览器上分别访问www.rhcsa1.com和www.rhcsa2.com网站

首先关闭虚拟机的防火墙确保能够成功访问

[root@localhost ~]# systemctl stop firewalld.service 

七、

将你当前主机的ip地址,mac地址和主机名写入文件/usr/share/nginx/html/index.html

[root@localhost ~]# ip a|grep "inet"|tr -s " "|cut -d " " -f3|grep "/24" > /usr/share/nginx/html/index.html 
[root@localhost ~]# ip a | grep 'link/ether'|tr -s ' '|cut -d " " -f3 >> /usr/share/nginx/html/index.html 
[root@localhost ~]# hostname >> /usr/share/nginx/html/index.html 
[root@localhost ~]# cat /usr/share/nginx/html/index.html
192.168.28.100/24
192.168.28.200/24
192.168.28.168/24
00:0c:29:4d:01:7a
localhost.localdomain

八、

在linux的火狐浏览器上再分别访问www.rhcsa1.com和www.rhcsa2.com网站,看网站内容的变化

九、

在windows的浏览器上输入你的虚拟机的ip地址访问查看效果

十、

给虚拟机添加两个硬盘,大小分别为5G、10G

1.关闭虚拟机后打开虚拟机设置

2.添加磁盘继续操作

3.选择SATA模式的磁盘进行配置创建

4.创建新磁盘位置

5.设置单个磁盘(5G)

6.最后命名不变完成操作

7.在创建一个磁盘(10G),其他操作不变仅在磁盘大小设置时有变化

8.最终效果

十一、

给第一个硬盘分区为2个主分区(大小分别为2G,1G),2个逻辑分区(大小分别为1G);给第二个硬盘分5个区,大小分别为2G

1.首先输入lsblk命令查看磁盘

2.给第一个磁盘分区

[root@localhost ~]# fdisk /dev/sda

欢迎使用 fdisk (util-linux 2.37.4)。
更改将停留在内存中,直到您决定将更改写入磁盘。
使用写入命令前请三思。

设备不包含可识别的分区表。
创建了一个磁盘标识符为 0x83525b89 的新 DOS 磁盘标签。

命令(输入 m 获取帮助):n
分区类型
   p   主分区 (0 primary, 0 extended, 4 free)
   e   扩展分区 (逻辑分区容器)
选择 (默认 p):

将使用默认回应 p。
分区号 (1-4, 默认  1): 
第一个扇区 (2048-10485759, 默认 2048): 
最后一个扇区,+/-sectors 或 +size{K,M,G,T,P} (2048-10485759, 默认 10485759): +2G 
创建了一个新分区 1,类型为“Linux”,大小为 2 GiB。

命令(输入 m 获取帮助):n
分区类型
   p   主分区 (1 primary, 0 extended, 3 free)
   e   扩展分区 (逻辑分区容器)
选择 (默认 p):

将使用默认回应 p。
分区号 (2-4, 默认  2): 
第一个扇区 (4196352-10485759, 默认 4196352): 
最后一个扇区,+/-sectors 或 +size{K,M,G,T,P} (4196352-10485759, 默认 10485759): +1G

创建了一个新分区 2,类型为“Linux”,大小为 1 GiB。

命令(输入 m 获取帮助):n
分区类型
   p   主分区 (2 primary, 0 extended, 2 free)
   e   扩展分区 (逻辑分区容器)
选择 (默认 p):e
分区号 (3,4, 默认  3): 
第一个扇区 (6293504-10485759, 默认 6293504): 
最后一个扇区,+/-sectors 或 +size{K,M,G,T,P} (6293504-10485759, 默认 10485759):  
创建了一个新分区 3,类型为“Extended”,大小为 2 GiB。

命令(输入 m 获取帮助):n
所有主分区的空间都在使用中。
添加逻辑分区 5
第一个扇区 (6295552-10485759, 默认 6295552): 
最后一个扇区,+/-sectors 或 +size{K,M,G,T,P} (6295552-10485759, 默认 10485759): +1G

创建了一个新分区 5,类型为“Linux”,大小为 1 GiB。

命令(输入 m 获取帮助):n
所有主分区的空间都在使用中。
添加逻辑分区 6
第一个扇区 (8394752-10485759, 默认 8394752): 
最后一个扇区,+/-sectors 或 +size{K,M,G,T,P} (8394752-10485759, 默认 10485759):  
创建了一个新分区 6,类型为“Linux”,大小为 1021 MiB。

命令(输入 m 获取帮助):p
Disk /dev/sda:5 GiB,5368709120 字节,10485760 个扇区
磁盘型号:VMware Virtual S
单元:扇区 / 1 * 512 = 512 字节
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x83525b89

设备       启动    起点     末尾    扇区  大小 Id 类型
/dev/sda1          2048  4196351 4194304    2G 83 Linux
/dev/sda2       4196352  6293503 2097152    1G 83 Linux
/dev/sda3       6293504 10485759 4192256    2G  5 扩展
/dev/sda5       6295552  8392703 2097152    1G 83 Linux
/dev/sda6       8394752 10485759 2091008 1021M 83 Linux

命令(输入 m 获取帮助):w
分区表已调整。
将调用 ioctl() 来重新读分区表。
正在同步磁盘。

3.给第二个磁盘分区

[root@localhost ~]# gdisk /dev/sdb
GPT fdisk (gdisk) version 1.0.7

Partition table scan:
  MBR: not present
  BSD: not present
  APM: not present
  GPT: not present

Creating new GPT entries in memory.

Command (? for help): n
Partition number (1-128, default 1): 
First sector (34-20971486, default = 2048) or {+-}size{KMGTP}: 
Last sector (2048-20971486, default = 20971486) or {+-}size{KMGTP}: +2G
Current type is 8300 (Linux filesystem)
Hex code or GUID (L to show codes, Enter = 8300): 
Changed type of partition to 'Linux filesystem'

Command (? for help): n
Partition number (2-128, default 2): 
First sector (34-20971486, default = 4196352) or {+-}size{KMGTP}: 
Last sector (4196352-20971486, default = 20971486) or {+-}size{KMGTP}: +2G
Current type is 8300 (Linux filesystem)
Hex code or GUID (L to show codes, Enter = 8300): 
Changed type of partition to 'Linux filesystem'

Command (? for help): n
Partition number (3-128, default 3): 
First sector (34-20971486, default = 8390656) or {+-}size{KMGTP}: 
Last sector (8390656-20971486, default = 20971486) or {+-}size{KMGTP}: +2G
Current type is 8300 (Linux filesystem)
Hex code or GUID (L to show codes, Enter = 8300): 
Changed type of partition to 'Linux filesystem'

Command (? for help): n
Partition number (4-128, default 4): 
First sector (34-20971486, default = 12584960) or {+-}size{KMGTP}: 
Last sector (12584960-20971486, default = 20971486) or {+-}size{KMGTP}: +2G
Current type is 8300 (Linux filesystem)
Hex code or GUID (L to show codes, Enter = 8300): 
Changed type of partition to 'Linux filesystem'

Command (? for help): n
Partition number (5-128, default 5): 
First sector (34-20971486, default = 16779264) or {+-}size{KMGTP}: 
Last sector (16779264-20971486, default = 20971486) or {+-}size{KMGTP}: +2G
Last sector (16779264-20971486, default = 20971486) or {+-}size{KMGTP}: 
Current type is 8300 (Linux filesystem)
Hex code or GUID (L to show codes, Enter = 8300): 
Changed type of partition to 'Linux filesystem'

Command (? for help): p
Disk /dev/sdb: 20971520 sectors, 10.0 GiB
Model: VMware Virtual S
Sector size (logical/physical): 512/512 bytes
Disk identifier (GUID): 99C6D6DF-908F-48E0-BAE2-83B32F1D563C
Partition table holds up to 128 entries
Main partition table begins at sector 2 and ends at sector 33
First usable sector is 34, last usable sector is 20971486
Partitions will be aligned on 2048-sector boundaries
Total free space is 2014 sectors (1007.0 KiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048         4196351   2.0 GiB     8300  Linux filesystem
   2         4196352         8390655   2.0 GiB     8300  Linux filesystem
   3         8390656        12584959   2.0 GiB     8300  Linux filesystem
   4        12584960        16779263   2.0 GiB     8300  Linux filesystem
   5        16779264        20971486   2.0 GiB     8300  Linux filesystem

Command (? for help): w

Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!

Do you want to proceed? (Y/N): y
OK; writing new GUID partition table (GPT) to /dev/sdb.
The operation has completed successfully.

3.最终检查效果

十二、

将第一个硬盘的第一个分区挂载至/guazai1,将第二个硬盘的第一个分区挂载至/guazai2

1.先将两个磁盘格式化,创建两个挂载点然后再进行挂载操作

[root@localhost ~]# mkfs.xfs /dev/sda1
meta-data=/dev/sda1              isize=512    agcount=4, agsize=131072 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=1, sparse=1, rmapbt=0
         =                       reflink=1    bigtime=1 inobtcount=1 nrext64=0
data     =                       bsize=4096   blocks=524288, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0, ftype=1
log      =internal log           bsize=4096   blocks=16384, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
[root@localhost ~]# mkfs.xfs /dev/sdb1
meta-data=/dev/sdb1              isize=512    agcount=4, agsize=131072 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=1, sparse=1, rmapbt=0
         =                       reflink=1    bigtime=1 inobtcount=1 nrext64=0
data     =                       bsize=4096   blocks=524288, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0, ftype=1
log      =internal log           bsize=4096   blocks=16384, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
[root@localhost ~]# mkdir /guazai1
[root@localhost ~]# mkdir /guazai2
[root@localhost ~]# mount /dev/sda1 /guazai1
[root@localhost ~]# mount /dev/sdb1 /guazai2

2.最终效果图

十三、

将/usr/share/nginx/html/index.html复制到/guazai1中,将 /etc/ssh/sshd_config复制到/guazai2

首先使用cp命令将两个文件复制过去然后使用cat命令进行查看

[root@localhost ~]# cp /usr/share/nginx/html/index.html /guazai1
[root@localhost ~]# cp /etc/ssh/sshd_config /guazai2
[root@localhost ~]# cat /usr/share/nginx/html/index.html /guazai1
192.168.28.100/24
192.168.28.200/24
192.168.28.168/24
00:0c:29:4d:01:7a
localhost.localdomain
cat: /guazai1: 是一个目录
[root@localhost ~]# cat /etc/ssh/sshd_config /guazai2
#	$OpenBSD: sshd_config,v 1.104 2021/07/02 05:11:21 dtucker Exp $

# This is the sshd server system-wide configuration file.  See
# sshd_config(5) for more information.

# This sshd was compiled with PATH=/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin

# The strategy used for options in the default sshd_config shipped with
# OpenSSH is to specify options with their default value where
# possible, but leave them commented.  Uncommented options override the
# default value.

# To modify the system-wide sshd configuration, create a  *.conf  file under
#  /etc/ssh/sshd_config.d/  which will be automatically included below
Include /etc/ssh/sshd_config.d/*.conf

# If you want to change the port on a SELinux system, you have to tell
# SELinux about this change.
# semanage port -a -t ssh_port_t -p tcp #PORTNUMBER
#
#Port 22
#AddressFamily any
#ListenAddress 0.0.0.0
#ListenAddress ::

#HostKey /etc/ssh/ssh_host_rsa_key
#HostKey /etc/ssh/ssh_host_ecdsa_key
#HostKey /etc/ssh/ssh_host_ed25519_key

# Ciphers and keying
#RekeyLimit default none

# Logging
#SyslogFacility AUTH
#LogLevel INFO

# Authentication:

#LoginGraceTime 2m
#PermitRootLogin prohibit-password
#StrictModes yes
#MaxAuthTries 6
#MaxSessions 10

#PubkeyAuthentication yes

# The default is to check both .ssh/authorized_keys and .ssh/authorized_keys2
# but this is overridden so installations will only check .ssh/authorized_keys
AuthorizedKeysFile	.ssh/authorized_keys

#AuthorizedPrincipalsFile none

#AuthorizedKeysCommand none
#AuthorizedKeysCommandUser nobody

# For this to work you will also need host keys in /etc/ssh/ssh_known_hosts
#HostbasedAuthentication no
# Change to yes if you don't trust ~/.ssh/known_hosts for
# HostbasedAuthentication
#IgnoreUserKnownHosts no
# Don't read the user's ~/.rhosts and ~/.shosts files
#IgnoreRhosts yes

# To disable tunneled clear text passwords, change to no here!
#PasswordAuthentication yes
#PermitEmptyPasswords no

# Change to no to disable s/key passwords
#KbdInteractiveAuthentication yes

# Kerberos options
#KerberosAuthentication no
#KerberosOrLocalPasswd yes
#KerberosTicketCleanup yes
#KerberosGetAFSToken no
#KerberosUseKuserok yes

# GSSAPI options
#GSSAPIAuthentication no
#GSSAPICleanupCredentials yes
#GSSAPIStrictAcceptorCheck yes
#GSSAPIKeyExchange no
#GSSAPIEnablek5users no

# Set this to 'yes' to enable PAM authentication, account processing,
# and session processing. If this is enabled, PAM authentication will
# be allowed through the KbdInteractiveAuthentication and
# PasswordAuthentication.  Depending on your PAM configuration,
# PAM authentication via KbdInteractiveAuthentication may bypass
# the setting of "PermitRootLogin without-password".
# If you just want the PAM account and session checks to run without
# PAM authentication, then enable this but set PasswordAuthentication
# and KbdInteractiveAuthentication to 'no'.
# WARNING: 'UsePAM no' is not supported in RHEL and may cause several
# problems.
#UsePAM no

#AllowAgentForwarding yes
#AllowTcpForwarding yes
#GatewayPorts no
#X11Forwarding no
#X11DisplayOffset 10
#X11UseLocalhost yes
#PermitTTY yes
#PrintMotd yes
#PrintLastLog yes
#TCPKeepAlive yes
#PermitUserEnvironment no
#Compression delayed
#ClientAliveInterval 0
#ClientAliveCountMax 3
#UseDNS no
#PidFile /var/run/sshd.pid
#MaxStartups 10:30:100
#PermitTunnel no
#ChrootDirectory none
#VersionAddendum none

# no default banner path
#Banner none

# override default of no subsystems
Subsystem	sftp	/usr/libexec/openssh/sftp-server

# Example of overriding settings on a per-user basis
#Match User anoncvs
#	X11Forwarding no
#	AllowTcpForwarding no
#	PermitTTY no
#	ForceCommand cvs server
cat: /guazai2: 是一个目录
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值