第三周作业

一、Raid组工作原理总结

工作原理利用率冗余性性能所需硬盘数
Raid0将数据条带化处理后同时存储到多个硬盘内100%>=1
Raid1

将两组以上的多块硬盘相互作为镜像

50%>1
Raid5将数据分块,并将数据块异或生成校验块,将数据块和校验块分别存放在不同的硬盘内(n-1)/n只允许损坏1块硬盘适中>2
Raid10先将硬盘组成Raid1阵列,再将该阵列组成Raid0阵列取决于具体组合方式每组镜像只允许损坏1块适中>4
Raid01先将硬盘组成Raid0阵列,再将该阵列组成Raid1阵列取决于具体组合方式只允许损坏1组Raid0适中>4

二、LVM磁盘扩容、缩容示例

1,为虚拟机添加磁盘并进行分区,将新分区作为块设备划分物理卷;在物理卷上创建卷组,并分出50%容量生成逻辑卷。

[root@rocky-240220 ~]# fdisk /dev/sdb 

选择命令n  p  为磁盘划分主分区大小(可不进行分区,直接划分硬盘)

选择命令t  8e 将磁盘分区修改为LVM格式

选择命令w  将修改信息保存

[root@rocky-240220 ~]# pvcreate /dev/sdb1                                  #创建物理卷

 Physical volume "/dev/sdb1" successfully created.

[root@rocky-240220 ~]# vgcreate vgtest /dev/sdb1                       #创建卷组
  Volume group "vgtest" successfully created
[root@rocky-240220 ~]# vgdisplay vgtest                                       #查看卷组大小
  --- Volume group ---
  VG Name               vgtest
  System ID
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  2
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                1
  Open LV               0
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               9.76 GiB
  PE Size               4.00 MiB
  Total PE              2499
  Alloc PE / Size       1249 / <4.88 GiB
  Free  PE / Size       1250 / 4.88 GiB
  VG UUID               xozfpr-nX3h-htWJ-ak4K-nClW-88xQ-hLze3G

[root@rocky-240220 ~]# lvcreate -l 50%VG -n lvtest vgtest              #创建逻辑卷
  Logical volume "lvtest" created.
[root@rocky-240220 ~]# lvdisplay /dev/vgtest/lvtest                         #查看逻辑卷大小
  --- Logical volume ---
  LV Path                /dev/vgtest/lvtest
  LV Name                lvtest
  VG Name                vgtest
  LV UUID                IIasSa-JLCX-3NGJ-coHM-1vzT-gOVV-F7qWrW
  LV Write Access        read/write
  LV Creation host, time rocky-240220, 2024-03-19 09:49:25 +0800
  LV Status              available
  # open                 0
  LV Size                <4.88 GiB
  Current LE             1249
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:3

2,为逻辑卷创建文件系统并进行挂载

[root@rocky-240220 ~]# mkfs.ext4 /dev/vgtest/lvtest                             #创建ext4文件系统
mke2fs 1.45.6 (20-Mar-2020)
Creating filesystem with 1278976 4k blocks and 320000 inodes
Filesystem UUID: bd71727b-0857-4e6d-9366-f8e535263d84
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736

Allocating group tables: done
Writing inode tables: done
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information: done
[root@rocky-240220 ~]# mount /dev/vgtest/lvtest /mnt/gz01/                  #临时挂载逻辑卷
[root@rocky-240220 ~]# lsblk                                                
NAME              MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda                 8:0    0  120G  0 disk
├─sda1              8:1    0    1G  0 part /boot
└─sda2              8:2    0  119G  0 part
  ├─rl-root       253:0    0   70G  0 lvm  /
  ├─rl-swap       253:1    0    2G  0 lvm  [SWAP]
  └─rl-home       253:2    0   47G  0 lvm  /home
sdb                 8:16   0   10G  0 disk
└─sdb1              8:17   0  9.8G  0 part
  └─vgtest-lvtest 253:3    0  4.9G  0 lvm  /mnt/gz01
sr0                11:0    1 1024M  0 rom
[root@rocky-240220 ~]# blkid                                                     #查看逻辑卷的文件系统ID
/dev/sda1: UUID="f5e469d7-abb7-45e5-8369-182d30c2e0c2" BLOCK_SIZE="512" TYPE="xfs" PARTUUID="70ec190e-01"
/dev/sda2: UUID="KNY6Zj-8jQf-oePa-WoPh-XIjM-dubT-o2KSsE" TYPE="LVM2_member" PARTUUID="70ec190e-02"
/dev/sdb1: UUID="vp9aCG-aJ3a-6Xwo-BgzB-NIDJ-B93C-IqCK4h" TYPE="LVM2_member" PARTUUID="afaff0e9-01"
/dev/mapper/rl-root: UUID="3e6c66ec-d6d4-4853-8309-c6ebc8bffcef" BLOCK_SIZE="512" TYPE="xfs"
/dev/mapper/rl-swap: UUID="c7fceea6-6938-490f-adeb-b46f4d2c5ccb" TYPE="swap"
/dev/mapper/rl-home: UUID="ab746da8-1a50-47a4-b0bc-b5ff343279a9" BLOCK_SIZE="512" TYPE="xfs"
/dev/mapper/vgtest-lvtest: UUID="bd71727b-0857-4e6d-9366-f8e535263d84" BLOCK_SIZE="4096" TYPE="ext4"
[root@rocky-240220 ~]# vim /etc/fstab                                                      #永久挂载逻辑卷

# /etc/fstab
# Created by anaconda on Wed Feb 21 06:30:01 2024
#
# Accessible filesystems, by reference, are maintained under '/dev/disk/'.
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info.
#
# After editing this file, run 'systemctl daemon-reload' to update systemd
# units generated from this file.
#
/dev/mapper/rl-root     /                       xfs     defaults        0 0
UUID=f5e469d7-abb7-45e5-8369-182d30c2e0c2 /boot                   xfs     defaults        0 0
/dev/mapper/rl-home     /home                   xfs     defaults        0 0
/dev/mapper/rl-swap     none                    swap    defaults        0 0
UUID="bd71727b-0857-4e6d-9366-f8e535263d84 /lvtest                ext4    defaults        0 0
[root@rocky-240220 ~]# mount -a

3,在线扩容

[root@rocky-240220 ~]# lvextend -r -l +100%FREE /dev/vgtest/lvtest                       #扩容
  Size of logical volume vgtest/lvtest changed from <4.88 GiB (1249 extents) to 9.76 GiB (2499 extents).
  Logical volume vgtest/lvtest successfully resized.
resize2fs 1.45.6 (20-Mar-2020)
Filesystem at /dev/mapper/vgtest-lvtest is mounted on /mnt/gz01; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 2
The filesystem on /dev/mapper/vgtest-lvtest is now 2558976 (4k) blocks long.

[root@rocky-240220 ~]# df -h
Filesystem                 Size  Used Avail Use% Mounted on
devtmpfs                   864M     0  864M   0% /dev
tmpfs                      893M     0  893M   0% /dev/shm
tmpfs                      893M  9.3M  884M   2% /run
tmpfs                      893M     0  893M   0% /sys/fs/cgroup
/dev/mapper/rl-root         70G  6.3G   64G   9% /
/dev/mapper/rl-home         47G  383M   47G   1% /home
/dev/sda1                 1014M  255M  760M  26% /boot
tmpfs                      179M   12K  179M   1% /run/user/42
tmpfs                      179M     0  179M   0% /run/user/0
/dev/mapper/vgtest-lvtest  9.6G   22M  9.1G   1% /mnt/gz01

4,离线缩容(有数据丢失风险,xfs文件系统不支持缩减)

[root@rocky-240220 ~]# umount /mnt/gz01                                                #取消挂载
[root@rocky-240220 ~]# e2fsck -f /dev/vgtest/lvtest                                  #检查文件系统
e2fsck 1.45.6 (20-Mar-2020)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/vgtest/lvtest: 11/632000 files (0.0% non-contiguous), 61682/2558976 blocks
[root@rocky-240220 ~]# resize2fs /dev/vgtest/lvtest 5G                             #缩减文件系统
resize2fs 1.45.6 (20-Mar-2020)
Resizing the filesystem on /dev/vgtest/lvtest to 1310720 (4k) blocks.
The filesystem on /dev/vgtest/lvtest is now 1310720 (4k) blocks long.
[root@rocky-240220 ~]# lvreduce -L 5G /dev/vgtest/lvtest                          #缩减逻辑卷
  WARNING: Reducing active logical volume to 5.00 GiB.
  THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce vgtest/lvtest? [y/n]: y
  Size of logical volume vgtest/lvtest changed from 9.76 GiB (2499 extents) to 5.00 GiB (1280 extents).
  Logical volume vgtest/lvtest successfully resized.
[root@rocky-240220 ~]# mount /dev/vgtest/lvtest /mnt/gz01/                      #重新挂载
[root@rocky-240220 ~]# df -h
Filesystem                 Size  Used Avail Use% Mounted on
devtmpfs                   864M     0  864M   0% /dev
tmpfs                      893M     0  893M   0% /dev/shm
tmpfs                      893M  9.3M  884M   2% /run
tmpfs                      893M     0  893M   0% /sys/fs/cgroup
/dev/mapper/rl-root         70G  6.3G   64G   9% /
/dev/mapper/rl-home         47G  383M   47G   1% /home
/dev/sda1                 1014M  255M  760M  26% /boot
tmpfs                      179M   12K  179M   1% /run/user/42
tmpfs                      179M     0  179M   0% /run/user/0
/dev/mapper/vgtest-lvtest  4.9G   20M  4.7G   1% /mnt/gz01

三、程序包管理器总结

常见程序包管理工具

rpm:红帽系列常用程序包管理工具

yum:红帽系列常用程序包管理工具,可自行处理依赖关系

dnf:centos8后取代了rpm

dpkg:deb程序包管理工具

apt:deb程序包管理工具,可自行处理依赖关系

程序包管理器相关文件

包文件组成(包独有)包内文件
元数据(版本、名称和依赖性等)
安装或卸载脚本
数据库(公有):/var/lib/rpm程序包名称和版本
依赖关系
名称说明
包安装后生成的文件路径和效验码信息

程序包获取途径

1,系统光盘镜像或官方网站

https://mirrors.aliyun.com

2,第三方组织

http://www.elrepo.org           支持最新的内核和硬件包

http://repoforge.org              红帽系列包推荐

3,软件项目官方网站

4,搜索引擎

https://pkgs.org

5,利用源码文件自行制作

常用命令

rpm  -ivh                                 安装软件并显示详细信息、过程和进度

rpm  -qi                                  查询软件包详细信息

rpm  -ql                                  查询软件包文件列表

rpm  -qR                                查询软件包依赖文件

yum  install                             安装软件

yum  info                                查询软件包详细信息

yum  clean  all                        清除软件包缓存

yum  list                                 查询软件包

yum  repolist                           列出软件包仓库

yum  provides                         查询文件来自于哪个软件包

dpkg  -i                                安装软件

dpkg  -r                                不删除配置文件

dpkg  -p                               删除所有

apt  remove                          彻底移除软件包

apt  list                                 列出包含条件的包

四、yum仓库搭建

1,修改repo文件,为虚拟机配置镜像源,并安装httpd测试。

[root@rocky-240220 ~]# cd /etc/yum.repos.d/
[root@rocky-240220 yum.repos.d]# cat BaseOS.repo
# Rocky-BaseOS.repo
#
# The mirrorlist system uses the connecting IP address of the client and the
# update status of each mirror to pick current mirrors that are geographically
# close to the client.  You should use this for Rocky updates unless you are
# manually picking other mirrors.
#
# If the mirrorlist does not work for you, you can try the commented out
# baseurl line instead.

[baseos]
name=nanjing.BaseOS
baseurl=http://mirrors.nju.edu.cn/rocky/8/BaseOS/x86_64/os/
gpgcheck=0

[appstream]
name=nanjing.appstream
baseurl=http://mirrors.nju.edu.cn/rocky/8/AppStream/x86_64/os/
gpgcheck=0

[extras]
name=nanjing.extras
baseurl=https://mirrors.nju.edu.cn/rocky/8/extras/x86_64/os/
gpgcheck=0
[root@rocky-240220 yum.repos.d]# yum -y install httpd

[root@rocky-240220 yum.repos.d]# systemctl enable --now httpd
Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.

[root@rocky-240220 html]# cd /var/www/html/
[root@rocky-240220 html]# mkdir -p rocky/8/

2,下载镜像源的软件包和元数据存储至本地虚拟机

[root@rocky-240220 html]]# yum reposync --repoid=baseos --download-metadata -p /var/www/html/rocky/8/                                                              #下载baseos库和元数据

[root@rocky-240220 html]# vim index.html                               #配置网页内容

3,打开另一台虚拟机将镜像源配置至已配置好yum仓库的虚拟机

[root@localhost ~]# cd /etc/yum.repos.d/                                         #打开配置文件位置

[root@localhost yum.repos.d]# vi BaseOS.repo                               #配置镜像源为yum仓库
[baseos]
name=localyum
baseurl=https://10.0.0.151/rocky/8/baseos/
gpgcheck=0

[root@localhost yum.repos.d]# yum clean all                                    #清除yum旧缓存
25 files removed
[root@localhost yum.repos.d]# yum repolist                                     #查看是否配置成功
repo id                                                     repo name
baseos                                                      localyum
[root@localhost yum.repos.d]# yum install tree                                #安装测试

五、Rocky、Ubuntu安装后初始化步骤

1,关闭防火墙:systemctl disable --now firewalld

2,关闭selinux: vim /etc/selinux/config      修改内容SELINUX=disabled

3,参照yum仓库搭建配置镜像源

4,重启桌面云:reboot

六、一键安装httpd脚本

[root@Rocky-test ~]# cat httpd.sh
#!/bin/bash
version=$1
systemctl disable --now firewalld
sed -i "s@^SELINUX=.*@SELINUX=disable@" /etc/selinux/config
yum -y install gcc wget apr-devel.x86_64 apr-util-devel.x86_64 make
yum -y install pcre-devel.x86_64 redhat-rpm-config
wget http://archive.apache.org/dist/httpd/httpd-$version.tar.gz
if ( echo $? );then
        echo "download is compliete"
else
        echo "false"
        exit
fi
mkdir -p /home/apps/{soft,httpd}
tar xvf httpd-$version.tar.gz --directory=/home/apps/soft
cd /home/apps/soft/httpd-$version/
./configure --prefix=/home/apps/httpd
make -j 2
make install
cd /home/apps/httpd/bin
./httpd -k start
echo "hello N85" >> /home/apps/httpd/htdocs/index.html

使用时为脚本添加权限后即可使用,安装时在bash后添加httpd版本即可

[root@Rocky-test ~]# chmod +x httpd.sh
[root@Rocky-test ~]# bash httpd.sh 2.4.37

七、总结OSI模型

应用层提供应用程序协议
表示层信息的语法语义以及它们的关联
会话层不同机器上的用户直接建立及关联会话
传输层确保上层数据和网络层的传输
网络层控制子网运行
数据链路层物理寻址,同时将原始比特流转换为逻辑传输
物理层原始比特流传输

八、调整动态端口范围:20000-60000

[root@rocky-240220 ipv4]# cd /proc/sys/net/ipv4/                           
[root@rocky-240220 ipv4]# cat ip_local_port_range                                  #查询动态范围
32768   60999
[root@rocky-240220 ipv4]# echo 20000 60000 > ip_local_port_range     #写入新范围

[root@rocky-240220 ipv4]# cat ip_local_port_range                                 #查询新动态范围
20000   60000

九、总结TCP三次握手、四次挥手

三次握手

第一次握手:客户端状态由关闭转为启动并发送键值SYN=1和自身端口号,状态转为同步已发送

第二次握手:服务器端状态由关闭转为收听,收到SYN=1后发送键值SYN=1,ACK=1并回传收到的端口号和自身的端口号,状态转为同步收到

第三次握手:客户端收到键值ACK=1和正确的端口号后,发送键值ACK=1并回传确认端口号正常,同时客户端状态转为已建立连接;服务器端收到键值和回传端口号正常的信息后将状态转为已建立连接

四次挥手

第一次挥手:客户端状态由已建立连接转为关闭,发送键值FIN=1和自身端口号,状态转为终止等待1

第二次挥手:服务器端收到FIN=1和客户端端口后,发送键值ACK=1以及收到的端口号和自身的端口号,状态转为关闭等待;客户端收到键值ACK=1以及服务器端的端口号和本地端口确认信息后将状态转为终止等待2

第三次挥手:服务器端传输完数据后发送键值FIN=1、ACK=1以及自身新端口号和客户端端口号确认信息,状态转为最后确认;

第四次挥手:客户端收到键值FIN=1、ACK=1和端口号确认正确的信息后,发送键值ACK=1和端口确认成功信息,同时状态转为时间等待,等待一段时间后转为关闭状态;服务器端收到键值ACK=1和端口确认成功的信息后裔,状态转为关闭

十、总结主机间包的传递过程

主机A

应用层

表示层

会话层

data

主机B

应用层

表示层

会话层

主机A-传输层tcp/udp+data主机B-传输层
主机A-网络层ip+tcp/udp+data主机B-网络层
主机A-数据链路层llc+ip+tcp/udp+data主机B-数据链路层
mac+llc+ip+tcp/udp+data
主机A-物理层<--------比特流传输-------->主机B-物理层

十一、总结4类IP地址及组成

IP范围子网掩码
A类00000000网络位为8位,首位固定为01.0.0.0-126.255.255.255255.0.0.0
B类10000000网络位为16位,首位固定为10128.0.0.0-191.255.255.255255.255.0.0
C类11000000网络位为24位,首位固定为110192.0.0.0-223.255.255.255255.255.255.0
D类11100000组播,首位固定为1110224.0.0.0-255.255.255.255

十二、实例:计算201.222.200.111/18的子网掩码

IP有4组共32位,18位为网络位即201.222.11001000.111中的201.222.11为网络位、001000.111为主机位

主机数为2^(32-18)-2=2^(16)-2=65535

子网掩码为255.255.11000000.0,即255.255.192.0

十三、实例:判断A(10.0.0.1/16)与B(10.0.2.2/24)通信,A与B是否能通信

A(10.0.0.1/16)的网络位为10.0,主机位为0.1,子网掩码为255.255.0.0

B(10.0.2.2/24)的网络位为10.0.2,主机位为2,子网掩码为255.255.255.0

A与B是否在同一网段看A、B网络ID是否相同(网络ID为IP与子网掩码&的结果)

A通信B,即A的网络ID为A的IP&A的子网掩码:10.0.0.0

B的网络ID为B的IP&A的子网掩码:10.0.0.0

A与B是同一网段,能够通信

十四、实例:将10.0.0.0/8划分为32个子网

10.0.0.0/8的网络位为10,主机位为0.0.0,划分子网即网络位向主机位借位,借n位即可划分在2^n个子网(子网只能多不能少)

32=2^5,即划分32个子网至少需要借位5位,网络位至少为13位

每个子网的主机数即为2^(32-13)-2=2^19-2=524286

子网的网络位为13位即10.00000为网络位、000.0.0为主机位,子网掩码为255.248.0.0

十五、总结网络配置命令

ifconfig  网卡名   IP   netmask  255.255.255.0                        为网卡配置IP并设置子网掩码

ip addr add/del  192.168.0.1/24 dev eth0 label etho:0(网卡名)  同上

ifconfig  网卡名   up/dowm                                                     启用/禁用网卡

ip link set 网卡名   up/dowm                                                   同上

route  -n                                                                                查询路由

route add -net 192.168.0.1/24 gw 192.168.0.254 dev eth0       添加一条路由

route del -net 192.168.0.1/24 gw 192.168.0.254 dev eth0        删除指定路由

netstat  -tua                                                                          监听TCP/UDP所有状态

ss   -tua                                                                                同上

nmcli connect reload;nmcli connect up                                  修改配置文件执行生效

十六、解析网卡配置格式

[root@rocky-240220 network-scripts]# cat ifcfg-ens160
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
NAME=ens160                                   #网卡名称
UUID=f7d588d7-10f7-487c-98b3-04ec545271ad
DEVICE=ens160                                 #接口名称
ONBOOT=yes                                     #启动时是否激活接口

  • 5
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值