1、使用 iso文件配置YUM源
备份默认的 YUM 源配置
~]# mkdir /etc/yum.repos.d/backup/
~]# mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/backup/
挂载 iso 文件
~]# ll /dev/cdrom
lrwxrwxrwx. 1 root root 3 1月 3 14:57 /dev/cdrom -> sr0
~]# mount -r -t iso9660 /dev/cdrom /media/cdrom
~]# ll /media/cdrom/
总用量 108
-rw-rw-r--. 1 root root 14 11月 26 2018 CentOS_BuildTag
drwxr-xr-x. 3 root root 2048 11月 26 2018 EFI
-rw-rw-r--. 1 root root 227 8月 30 2017 EULA
-rw-rw-r--. 1 root root 18009 12月 10 2015 GPL
drwxr-xr-x. 3 root root 2048 11月 26 2018 images
drwxr-xr-x. 2 root root 2048 11月 26 2018 isolinux
drwxr-xr-x. 2 root root 2048 11月 26 2018 LiveOS
drwxrwxr-x. 2 root root 71680 11月 26 2018 Packages
drwxr-xr-x. 2 root root 4096 11月 26 2018 repodata
-rw-rw-r--. 1 root root 1690 12月 10 2015 RPM-GPG-KEY-CentOS-7
-rw-rw-r--. 1 root root 1690 12月 10 2015 RPM-GPG-KEY-CentOS-Testing-7
-r--r--r--. 1 root root 2883 11月 26 2018 TRANS.TBL
1.1、配置网络 yum 仓库
# 安装 httpd 服务
~]# yum install httpd -y
# 关闭防火墙 并 启动 httpd 服务
~]# systemctl stop firewalld
~]# systemctl start httpd
~]# ln -s /media/cdrom /var/www/html/cdrom
# 创建本地 网络 YUM 源配置(IP地址修改为httpd服务的IP地址)
~]# tee /etc/yum.repos.d/CentOS-CD-Base.repo <<EOF
[CentOS7-Base]
name=CentOS-\$releasever - CD Base
baseurl=http://192.168.240.163/cdrom/
gpgcheck=1
enabled=1
gpgkey=http://192.168.240.163/cdrom/RPM-GPG-KEY-CentOS-7
EOF
~]# cat /etc/yum.repos.d/CentOS-CD-Base.repo
[CentOS7-Base]
name=CentOS-$releasever - CD Base
baseurl=http://192.168.240.163/cdrom/
gpgcheck=1
enabled=1
gpgkey=http://192.168.240.163/cdrom/RPM-GPG-KEY-CentOS-7
# 列出可用的YUM源
~]# yum repolist
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
源标识 源名称 状态
CentOS7-Base CentOS-7 - CD Base 445
repolist: 445
# 测试安装 net-tools
~]# yum install net-tools
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
正在解决依赖关系
--> 正在检查事务
---> 软件包 net-tools.x86_64.0.2.0-0.24.20131004git.el7 将被 安装
--> 解决依赖关系完成
依赖关系解决
=====================================================================================
Package 架构 版本 源 大小
=====================================================================================
正在安装:
net-tools x86_64 2.0-0.24.20131004git.el7 CentOS7-Base 306 k
事务概要
=====================================================================================
安装 1 软件包
总下载量:306 k
安装大小:918 k
Is this ok [y/d/N]: y
Downloading packages:
net-tools-2.0-0.24.20131004git.el7.x86_64.rpm | 306 kB 00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
正在安装 : net-tools-2.0-0.24.20131004git.el7.x86_64 1/1
验证中 : net-tools-2.0-0.24.20131004git.el7.x86_64 1/1
已安装:
net-tools.x86_64 0:2.0-0.24.20131004git.el7
完毕!
1.2、配置本地 yum 仓库
# 创建本地 YUM 源配置
~]# tee /etc/yum.repos.d/CentOS-Media.repo <<EOF
[c7-media]
name=CentOS-\$releasever - Media
baseurl=file:///media/cdrom/
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
EOF
~]# cat /etc/yum.repos.d/CentOS-Media.repo
[c7-media]
name=CentOS-$releasever - Media
baseurl=file:///media/cdrom/
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
# 列出本地可用的 YUM 源
~]# yum repolist
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
源标识 源名称 状态
c7-media CentOS-7 - Media 445
repolist: 445
~]# yum search net-tools
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
======================= N/S matched: net-tools ==========================
net-tools.x86_64 : Basic networking tools
名称和简介匹配 only,使用“search all”试试。
# 测试安装 net-tools
~]# yum install net-tools -y
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
正在解决依赖关系
--> 正在检查事务
---> 软件包 net-tools.x86_64.0.2.0-0.24.20131004git.el7 将被 安装
--> 解决依赖关系完成
依赖关系解决
=========================================================================
Package 架构 版本 源 大小
=========================================================================
正在安装:
net-tools x86_64 2.0-0.24.20131004git.el7 c7-media 306 k
事务概要
=========================================================================
安装 1 软件包
总下载量:306 k
安装大小:918 k
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
正在安装 : net-tools-2.0-0.24.20131004git.el7.x86_64 1/1
验证中 : net-tools-2.0-0.24.20131004git.el7.x86_64 1/1
已安装:
net-tools.x86_64 0:2.0-0.24.20131004git.el7
完毕!
2、编译安装 httpd 2.4
# 下载解压 httpd
~]# wget http://mirror.bit.edu.cn/apache//httpd/httpd-2.4.41.tar.gz
~]# tar -xzvf httpd-2.4.41.tar.gz -C /usr/local/src/
~]# cd /usr/local/src/httpd-2.4.41/
# 按照编译依赖的包
~]# yum install gcc pcre-devel apr-devel apr-util-devel -y
# 执行编译安装
~]# ./configure --prefix=/opt/httpd-2.4.41
~]# make
~]# make install
# 切换到安装目录
~]# cd /opt/httpd-2.4.41/
~]# ll
总用量 36
drwxr-xr-x. 2 root root 262 1月 3 16:29 bin
drwxr-xr-x. 2 root root 167 1月 3 16:29 build
drwxr-xr-x. 2 root root 78 1月 3 16:29 cgi-bin
drwxr-xr-x. 4 root root 84 1月 3 16:29 conf
drwxr-xr-x. 3 root root 4096 1月 3 16:29 error
drwxr-xr-x. 2 root root 24 1月 3 16:29 htdocs
drwxr-xr-x. 3 root root 8192 1月 3 16:29 icons
drwxr-xr-x. 2 root root 4096 1月 3 16:29 include
drwxr-xr-x. 2 root root 6 1月 3 16:29 logs
drwxr-xr-x. 4 root root 30 1月 3 16:29 man
drwxr-xr-x. 14 root root 8192 1月 3 16:29 manual
drwxr-xr-x. 2 root root 4096 1月 3 16:29 modules
# 查看 httpd 版本
~]# bin/httpd -v
Server version: Apache/2.4.41 (Unix)
Server built: Jan 3 2020 16:28:33
# 启动 httpd
~]# bin/httpd
# 测试访问默认首页
~]# curl -v http://localhost
* About to connect() to localhost port 80 (#0)
* Trying ::1...
* Connected to localhost (::1) port 80 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.29.0
> Host: localhost
> Accept: */*
>
< HTTP/1.1 200 OK
< Date: Fri, 03 Jan 2020 08:46:22 GMT
< Server: Apache/2.4.41 (Unix)
< Last-Modified: Mon, 11 Jun 2007 18:53:14 GMT
< ETag: "2d-432a5e4a73a80"
< Accept-Ranges: bytes
< Content-Length: 45
< Content-Type: text/html
<
<html><body><h1>It works!</h1></body></html>
* Connection #0 to host localhost left intact
3、文件系统操作实例
创建一个2G的文件系统,块大小为2048byte,预留1%可用空间,文件系统 ext4,卷标为TEST,要求此分区开机后自动挂载至/test目录,且默认有acl挂载选项
# 列出当前系统所有硬盘设备
~]# fdisk -l
Disk /dev/sdb: 2147 MB, 2147483648 bytes, 4194304 sectors <<== 新添加的一个2G硬盘
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk /dev/sda: 42.9 GB, 42949672960 bytes, 83886080 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x00068d34
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 83886079 40893440 8e Linux LVM
Disk /dev/mapper/centos-root: 39.7 GB, 39720058880 bytes, 77578240 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk /dev/mapper/centos-swap: 2147 MB, 2147483648 bytes, 4194304 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
# 创建分区
~]# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0x4a90db8f.
Command (m for help): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p):
Using default response p
Partition number (1-4, default 1):
First sector (2048-4194303, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-4194303, default 4194303):
Using default value 4194303
Partition 1 of type Linux and of size 2 GiB is set
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
# 列出当前系统硬盘设备和所有分区
~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 40G 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 39G 0 part
├─centos-root 253:0 0 37G 0 lvm /
└─centos-swap 253:1 0 2G 0 lvm [SWAP]
sdb 8:16 0 2G 0 disk
└─sdb1 8:17 0 2G 0 part
sr0 11:0 1 1024M 0 rom
# 格式化为 ext4 文件系统
~]# mke2fs -t ext4 -b 2048 -L TEST -m 1 /dev/sdb1
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=TEST
OS type: Linux
Block size=2048 (log=1)
Fragment size=2048 (log=1)
Stride=0 blocks, Stripe width=0 blocks
131072 inodes, 1048064 blocks
10480 blocks (1.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=269484032
64 block groups
16384 blocks per group, 16384 fragments per group
2048 inodes per group
Superblock backups stored on blocks:
16384, 49152, 81920, 114688, 147456, 409600, 442368, 802816
Allocating group tables: done
Writing inode tables: done
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information: done
# 查看 /dev/sdb1 卷标
~]# e2label /dev/sdb1
TEST
# 挂载到 /test 目录
~]# mount -o acl,noatime /dev/sdb1 /test
~]# df -hT
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/centos-root xfs 37G 1004M 36G 3% /
devtmpfs devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs tmpfs 1.9G 0 1.9G 0% /dev/shm
tmpfs tmpfs 1.9G 12M 1.9G 1% /run
tmpfs tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
/dev/sda1 xfs 1014M 146M 869M 15% /boot
tmpfs tmpfs 378M 0 378M 0% /run/user/0
/dev/sdb1 ext4 2.0G 9.1M 1.9G 1% /test
# 配置开机自动挂载
~]# cat /etc/fstab
/dev/mapper/centos-root / xfs defaults 0 0
UUID=0cb71780-8808-412d-b756-1a1b9931af93 /boot xfs defaults 0 0
/dev/mapper/centos-swap swap swap defaults 0 0
LABEL='TEST' /test ext4 defaults,acl 0 0
3、LVM 操作实例
创建一个至少有两个PV组成的大小为20G的名为testvg的VG;要求PE大小 为16MB, 而后在卷组中创建大小为5G的逻辑卷testlv;挂载至/users目录
# 新增两块10G硬盘,执行如下命令扫盘
~]# for i in /sys/class/scsi_host/host*/scan ; do echo "- - -" > $i ; done
# 列出当前系统的所有硬盘
~]# fdisk -l
Disk /dev/sda: 42.9 GB, 42949672960 bytes, 83886080 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x00068d34
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 83886079 40893440 8e Linux LVM
Disk /dev/sdb: 2147 MB, 2147483648 bytes, 4194304 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x4a90db8f
Device Boot Start End Blocks Id System
/dev/sdb1 2048 4194303 2096128 83 Linux
Disk /dev/mapper/centos-root: 39.7 GB, 39720058880 bytes, 77578240 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk /dev/mapper/centos-swap: 2147 MB, 2147483648 bytes, 4194304 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk /dev/sdc: 10.7 GB, 10737418240 bytes, 20971520 sectors <<==新增的10G硬盘
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk /dev/sdd: 10.7 GB, 10737418240 bytes, 20971520 sectors <<==新增的10G硬盘
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
# 创建PV
~]# pvcreate /dev/sdc
Physical volume "/dev/sdc" successfully created.
~]# pvcreate /dev/sdd
Physical volume "/dev/sdd" successfully created.
# 显示PV详细信息
~]# pvdisplay
--- Physical volume ---
PV Name /dev/sda2
VG Name centos
PV Size <39.00 GiB / not usable 3.00 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 9983
Free PE 1
Allocated PE 9982
PV UUID 66HbDl-E0cM-DmeN-V1gm-1ck0-FdI0-PGVlRQ
"/dev/sdc" is a new physical volume of "10.00 GiB"
--- NEW Physical volume ---
PV Name /dev/sdc
VG Name
PV Size 10.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID GDOSpP-4s6k-Fbqg-gRvK-aVk7-wnom-ORb1Sj
"/dev/sdd" is a new physical volume of "10.00 GiB"
--- NEW Physical volume ---
PV Name /dev/sdd
VG Name
PV Size 10.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID wOWgMu-23p2-usKT-PkQB-nMRE-6XxT-pdElie
# 创建 testvg VG
~]# vgcreate -s 16m testvg /dev/sdc /dev/sdd
Volume group "testvg" successfully created
# 显示VG详细信息
~]# vgdisplay
--- Volume group ---
VG Name testvg
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 1
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 0
Open LV 0
Max PV 0
Cur PV 2
Act PV 2
VG Size <19.97 GiB
PE Size 16.00 MiB
Total PE 1278
Alloc PE / Size 0 / 0
Free PE / Size 1278 / <19.97 GiB
VG UUID gGiZPm-SfSD-LYdS-YzMa-ZHei-nPUT-LCK1yZ
--- Volume group ---
VG Name centos
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 3
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 1
Act PV 1
VG Size <39.00 GiB
PE Size 4.00 MiB
Total PE 9983
Alloc PE / Size 9982 / 38.99 GiB
Free PE / Size 1 / 4.00 MiB
VG UUID drNIrD-QK5h-Ros4-bzt8-quzA-0B71-fTxJzB
# 创建一个5G的 testlv
~]# lvcreate -L 5G -n testlv testvg
Logical volume "testlv" created.
# 显示 lv 详细信息
~]# lvdisplay
--- Logical volume ---
LV Path /dev/testvg/testlv
LV Name testlv
VG Name testvg
LV UUID vyw8M6-V9Wd-1QiN-cWIc-awxO-OMzC-rAtZFW
LV Write Access read/write
LV Creation host, time localhost, 2020-01-02 07:09:33 +0800
LV Status available
# open 0
LV Size 5.00 GiB
Current LE 320
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:2
# 格式化LV
~]# mkfs.xfs /dev/testvg/testlv
meta-data=/dev/testvg/testlv isize=512 agcount=4, agsize=327680 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=1310720, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal log bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
~]# mkdir /users
# 在 /etc/fstab 追加 /dev/testvg/testlv,开机挂载
~]# vi /etc/fstab
/dev/testvg/testlv /users xfs defaults 0 0
~]# mount -a
~]# df -hT
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/centos-root xfs 37G 1004M 36G 3% /
devtmpfs devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs tmpfs 1.9G 0 1.9G 0% /dev/shm
tmpfs tmpfs 1.9G 12M 1.9G 1% /run
tmpfs tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
/dev/sdb1 ext4 2.0G 9.1M 1.9G 1% /mnt/data
/dev/sda1 xfs 1014M 146M 869M 15% /boot
tmpfs tmpfs 378M 0 378M 0% /run/user/0
/dev/mapper/testvg-testlv xfs 5.0G 33M 5.0G 1% /users