第六周作业(7.13-7.19)

1、自建yum仓库,分别为网络源和本地源

(1)配置本地光盘作为yum仓库
[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# ls
CentOS-Base.repo  CentOS-CR.repo  CentOS-Debuginfo.repo  CentOS-fasttrack.repo  
CentOS-Media.repo  CentOS-Sources.repo  CentOS-Vault.repo
#备份所有的repo文件
[root@localhost yum.repos.d]# mkdir backup
[root@localhost yum.repos.d]# mv *.repo backup/
#确认光盘是否挂载到/misc/cd目录下
[root@localhost yum.repos.d]# df /dev/sr0
Filesystem     1K-blocks     Used Available Use% Mounted on
/dev/sr0        10767514 10767514         0 100% /run/media/yezz/CentOS 7 x86_64
#光盘未自动挂载到/misc/cd目录下,查看autofs是否安装
[root@localhost yum.repos.d]# rpm -q autofs
autofs-5.0.7-106.el7.x86_64
[root@localhost yum.repos.d]# systemctl status autofs
● autofs.service - Automounts filesystems on demand
   Loaded: loaded (/usr/lib/systemd/system/autofs.service; disabled; vendor preset: disabled)
   Active: inactive (dead)
#启动autofs服务,并设置开机自启
[root@localhost yum.repos.d]# systemctl start autofs
[root@localhost yum.repos.d]# systemctl enable autofs
Created symlink from /etc/systemd/system/multi-user.target.wants/autofs.service to /usr/lib/systemd/system/autofs.service.
[root@localhost yum.repos.d]# systemctl status autofs
● autofs.service - Automounts filesystems on demand
   Loaded: loaded (/usr/lib/systemd/system/autofs.service; enabled; vendor preset: disabled)
   Active: active (running) since Sun 2020-07-19 17:10:01 CST; 15s ago
 Main PID: 4039 (automount)
   CGroup: /system.slice/autofs.service
           └─4039 /usr/sbin/automount --systemd-service --dont-check-daemon

Jul 19 17:10:01 localhost.localdomain systemd[1]: Starting Automounts filesystems on demand...
Jul 19 17:10:01 localhost.localdomain automount[4039]: setautomntent: lookup(sss): setautomntent: No such file or directory
Jul 19 17:10:01 localhost.localdomain systemd[1]: Started Automounts filesystems on demand.
#光盘已自动挂载
[root@localhost yum.repos.d]# ls /misc/cd
CentOS_BuildTag  EFI  EULA  GPL  images  isolinux  LiveOS  Packages  repodata  RPM-GPG-KEY-CentOS-7  RPM-GPG-KEY-CentOS-Testing-7  TRANS.TBL
[root@localhost yum.repos.d]# df /dev/sr0
Filesystem     1K-blocks     Used Available Use% Mounted on
/dev/sr0        10767514 10767514         0 100% /misc/cd
#写repo文件
[root@localhost yum.repos.d]# vim base.repo
#内容如下
[base]
name=cd repo
baseurl=file:///misc/cd/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
#可以查看到前面设置的仓库信息
[root@localhost yum.repos.d]# yum repolist
Loaded plugins: fastestmirror, langpacks
Determining fastest mirrors
base                                                           | 3.6 kB  00:00:00     
(1/2): base/group_gz                                           | 165 kB  00:00:00     
(2/2): base/primary_db                                         | 6.0 MB  00:00:00     
repo id                             repo name                           status
base                                cd repo                             10,097
repolist: 10,097
(2)配置阿里云EPEL源的网络仓库作为yum源仓库
#写repo文件
[root@localhost yum.repos.d]# vim base.repo
#内容如下
[epel]
name=epel repo
baseurl=https://mirrors.aliyun.com/epel/$releasever/$basearch
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
#可以查看到前面设置的仓库信息
[root@localhost yum.repos.d]# yum repolist
Loaded plugins: fastestmirror, langpacks
Determining fastest mirrors
base                                             | 3.6 kB     00:00     
epel                                             | 4.7 kB     00:00     
(1/5): base/group_gz                               | 165 kB   00:00     
(2/5): base/primary_db                             | 6.0 MB   00:00     
(3/5): epel/7/x86_64/updateinfo                    | 1.0 MB   00:00     
(4/5): epel/7/x86_64/group_gz                      |  95 kB   00:00     
(5/5): epel/7/x86_64/primary_db                    | 6.8 MB   00:00     
repo id                            repo name                      status
base                               cd repo                        10,097
epel/7/x86_64                      epel repo                      13,412
repolist: 23,509

2、编译安装http2.4,实现可以正常访问,并将编译步骤和结果提交。

#查看系统的版本,可以看到比较旧,是2.4.6
[root@localhost ~]# yum info httpd
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Available Packages
Name        : httpd
Arch        : x86_64
Version     : 2.4.6
Release     : 90.el7.centos
Size        : 2.7 M
Repo        : base
Summary     : Apache HTTP Server
URL         : http://httpd.apache.org/
License     : ASL 2.0
Description : The Apache HTTP Server is a powerful, efficient, and
            : extensible web server.
#已下载httpd-2.4.25版本到/usr/local/src目录下
[root@localhost ~]# cd /usr/local/src/
[root@localhost src]# ls
httpd-2.4.25.tar.bz2
#解压缩源码包文件
[root@localhost src]# tar xf httpd-2.4.25.tar.bz2 
[root@localhost src]# ls
httpd-2.4.25  httpd-2.4.25.tar.bz2
#必须进入到解压缩的目录中
[root@localhost src]# cd httpd-2.4.25/
[root@localhost httpd-2.4.25]# ls
ABOUT_APACHE     CMakeLists.txt  INSTALL         NWGNUmakefile
acinclude.m4     config.layout   InstallBin.dsp  os
Apache-apr2.dsw  configure       LAYOUT          README
Apache.dsw       configure.in    libhttpd.dep    README.cmake
apache_probes.d  docs            libhttpd.dsp    README.platforms
ap.d             emacs-style     libhttpd.mak    ROADMAP
build            httpd.dep       LICENSE         server
BuildAll.dsp     httpd.dsp       Makefile.in     srclib
BuildBin.dsp     httpd.mak       Makefile.win    support
buildconf        httpd.spec      modules         test
CHANGES          include         NOTICE          VERSIONING
#一般源码包的解压缩目录内会有README和INSTALL说明文件,可以先浏览一下了解软件的功能及安装说明
[root@localhost httpd-2.4.25]# cat README
...(省略)...
  Installation
  ------------
  Please see the file called INSTALL.  Platform specific notes can be
  found in README.platforms.
...(省略)...
#没有更多有关安装的内容,再查看INSATLL文件
[root@localhost httpd-2.4.25]# cat INSTALL 
  APACHE INSTALLATION OVERVIEW
  Quick Start - Unix
  ------------------
  For complete installation documentation, see [ht]docs/manual/install.html or
  http://httpd.apache.org/docs/2.4/install.html
#说明了安装和启动方法
     $ ./configure --prefix=PREFIX
     $ make
     $ make install
     $ PREFIX/bin/apachectl start
...(省略)...

#查看http-2.4.25中configure支持的选项及功能特性
[root@localhost httpd-2.4.25]# ./configure --help
`configure' configures this package to adapt to many kinds of systems.

Usage: ./configure [OPTION]... [VAR=VALUE]...

To assign environment variables (e.g., CC, CFLAGS...), specify them as
VAR=VALUE.  See below for descriptions of some of the useful variables.

Defaults for the options are specified in brackets.

Configuration:
  -h, --help              display this help and exit
      --help=short        display options specific to this package
      --help=recursive    display the short help of all the included packages
  -V, --version           display version information and exit
  -q, --quiet, --silent   do not print `checking ...' messages
      --cache-file=FILE   cache test results in FILE [disabled]
  -C, --config-cache      alias for `--cache-file=config.cache'
  -n, --no-create         do not create output files
      --srcdir=DIR        find the sources in DIR [configure dir or `..']
......(省略)......
#执行第一步,指定安装路径为/apps/httpd,配置文件安装在/etc/httpd目录下,启用ssl加密功能
[root@localhost httpd-2.4.25]# ./configure --prefix=/apps/httpd --sysconfdir=/etc/httpd/ --enable-ssl
checking for chosen layout... Apache
checking for working mkdir -p... yes
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking target system type... x86_64-unknown-linux-gnu
configure: 
configure: Configuring Apache Portable Runtime library...
configure: 
checking for APR... no
configure: error: APR not found.  Please read the documentation.
#提示缺少APR
#当提示缺少某个包时,只要安装提示缺少的包名后加上devel组成的包即可
[root@localhost httpd-2.4.25]# yum -y -q install apr-devel
#再次执行前面的./configure脚本
[root@localhost httpd-2.4.25]# yum -y -q install apr-devel
Package apr-devel-1.4.8-5.el7.x86_64 already installed and latest version
[root@localhost httpd-2.4.25]# ./configure --prefix=/apps/httpd --sysconfdir=/etc/httpd/ --enable-ssl
......(省略)......
configure: 
checking for APR-util... no
configure: error: APR-util not found.  Please read the documentation.
提示缺少APR-util包
#根据提示安装缺少的包apr-util-devel
[root@localhost httpd-2.4.25]# yum -y -q install apr-util-devel
#再次执行前面的./configure脚本
[root@localhost httpd-2.4.25]# ./configure --prefix=/apps/httpd --sysconfdir=/etc/httpd/ --enable-ssl
......(省略)......
configure: 
checking for APR-util... yes
checking for gcc... gcc
checking whether the C compiler works... no
configure: error: in `/usr/local/src/httpd-2.4.25':
configure: error: C compiler cannot create executables
#提示C编译器错误
See `config.log' for more details
#提示查看config.log中的详细说明
#查看日志
[root@localhost httpd-2.4.25]# cat config.log
......(省略)......
configure:5266: checking for C compiler version
configure:5275: gcc --version >&5
#提示gcc命令无法找到
./configure: line 5277: gcc: command not found
configure:5286: $? = 127
configure:5275: gcc -v >&5
./configure: line 5277: gcc: command not found
configure:5286: $? = 127
configure:5275: gcc -V >&5
./configure: line 5277: gcc: command not found
configure:5286: $? = 127
configure:5275: gcc -qversion >&5
./configure: line 5277: gcc: command not found
......(省略)......
#安装gcc编译器工具包,是C源码编译不可缺少的工具必须安装
[root@localhost httpd-2.4.25]# yum -y -q install gcc
#再次执行前面的./configure脚本
[root@localhost httpd-2.4.25]# ./configure --prefix=/apps/httpd --sysconfdir=/etc/httpd/ --enable-ssl
......(省略)......
checking for pcre-config... false
configure: error: pcre-config for libpcre not found. PCRE is required and available from http://pcre.org/
#根据提示安装缺少的包pcre-devel
[root@localhost httpd-2.4.25]# yum -y -q install pcre-devel
#再次执行前面的./configure脚本
[root@localhost httpd-2.4.25]# ./configure --prefix=/apps/httpd --sysconfdir=/etc/httpd/ --enable-ssl
......(省略)......
checking for OpenSSL version >= 0.9.8a... FAILED
configure: WARNING: OpenSSL version is too old
no
checking whether to enable mod_ssl... configure: error: mod_ssl has been requested but can not be built due to prerequisite failures
#根据提示安装缺少的包openssl-devel
[root@localhost httpd-2.4.25]# yum -y -q install openssl-devel
[root@localhost httpd-2.4.25]# yum -y -q install pcre-devel
#再次执行前面的./configure脚本
[root@localhost httpd-2.4.25]# ./configure --prefix=/apps/httpd --sysconfdir=/etc/httpd/ --enable-ssl
......(省略)......
config.status: creating build/rules.mk
config.status: creating build/pkg/pkginfo
config.status: creating build/config_vars.sh
config.status: creating include/ap_config_auto.h
config.status: executing default commands
configure: summary of build options:

    Server Version: 2.4.25
    Install prefix: /apps/httpd
    C compiler:     gcc -std=gnu99
    CFLAGS:           -pthread
    LDFLAGS:         
    LIBS:           
    CPPFLAGS:        -DLINUX -D_REENTRANT -D_GNU_SOURCE
    C preprocessor: gcc -E

#观察上面显示无错误提示,通过$?的值为0来确认成功
[root@localhost httpd-2.4.25]# echo $?
0

#为了下面编译更快,可以先查一下CPU的核数
[root@localhost httpd-2.4.25]# lscpu | grep CPU
CPU op-mode(s):        32-bit, 64-bit
CPU(s):                2
On-line CPU(s) list:   0,1
CPU family:            6
Model name:            Intel(R) Core(TM) i5-6200U CPU @ 2.30GHz
CPU MHz:               2400.001
NUMA node0 CPU(s):     0,1
#利用 -j 选项可以指定多任务进行编译,可以加快编译过程,一般这一步是最耗费时间的
[root@localhost httpd-2.4.25]# make -j 2
......(省略)......
make[4]: Leaving directory `/usr/local/src/httpd-2.4.25/modules/mappers'
make[3]: Leaving directory `/usr/local/src/httpd-2.4.25/modules/mappers'
make[2]: Leaving directory `/usr/local/src/httpd-2.4.25/modules'
make[2]: Entering directory `/usr/local/src/httpd-2.4.25/support'
make[2]: Leaving directory `/usr/local/src/httpd-2.4.25/support'

make[1]: Leaving directory `/usr/local/src/httpd-2.4.25'
#执行安装
[root@localhost httpd-2.4.25]# make install
......(省略)......
Installing configuration files
mkdir /etc/httpd
mkdir /etc/httpd/extra
mkdir /etc/httpd/original
mkdir /etc/httpd/original/extra
Installing HTML documents
mkdir /apps/httpd/htdocs
Installing error documents
mkdir /apps/httpd/error
Installing icons
mkdir /apps/httpd/icons
mkdir /apps/httpd/logs
Installing CGIs
mkdir /apps/httpd/cgi-bin
Installing header files
mkdir /apps/httpd/include
Installing build system files
mkdir /apps/httpd/build
Installing man pages and online manual
mkdir /apps/httpd/man
mkdir /apps/httpd/man/man1
mkdir /apps/httpd/man/man8
mkdir /apps/httpd/manual
make[1]: Leaving directory `/usr/local/src/httpd-2.4.25'
#查看安装后生成的文件,可以看到在/apps/httpd和/etc/httpd目录下生成相关文件
[root@localhost httpd-2.4.25]# ls /apps/httpd
bin    cgi-bin  htdocs  include  man     modules
build  error    icons   logs     manual
[root@localhost httpd-2.4.25]# ls /etc/httpd
extra  httpd.conf  magic  mime.types  original
#根据INSTALL文件中的说明,启动此服务软件
[root@localhost httpd-2.4.25]# /apps/httpd/bin/apachectl start
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain. Set the 'ServerName' directive globally to suppress this message
#用curl命令测试httpd命令已经正常启动
[root@localhost httpd-2.4.25]# curl 127.0.0.1

It works!

#为了以后启动服务更方便,可以将启动程序的路径加入到PATH [root@localhost httpd-2.4.25]# echo $PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin [root@localhost httpd-2.4.25]# echo 'PATH=/apps/httpd/bin:$PATH' > /etc/profile.d/httpd.sh [root@localhost httpd-2.4.25]# . /etc/profile.d/httpd.sh #确定PATH变量已添加了httpd启动程序的路径 [root@localhost httpd-2.4.25]# echo $PATH /apps/httpd/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin #在任意目录下都可以启动服务程序,而不用再加绝对路径 [root@localhost ~]# apachectl stop AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain. Set the 'ServerName' directive globally to suppress this message [root@localhost ~]# curl 127.0.0.1 curl: (7) Failed connect to 127.0.0.1:80; Connection refused [root@localhost ~]# apachectl AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain. Set the 'ServerName' directive globally to suppress this message [root@localhost ~]# curl 127.0.0.1

It works!

3、创建一个2G的文件系统,块大小为2048byte,预留1%可用空间,文件系统 ext4,卷标为TEST,要求此分区开机后自动挂载至/test目录,且默认有acl挂载选项

#查看当前磁盘有没有剩余空间
[root@localhost ~]# lsblk
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda      8:0    0  200G  0 disk 
├─sda1   8:1    0    1G  0 part /boot
├─sda2   8:2    0  100G  0 part /
├─sda3   8:3    0   50G  0 part /data
├─sda4   8:4    0    1K  0 part 
└─sda5   8:5    0    4G  0 part [SWAP]
sr0     11:0    1 10.3G  0 rom  /run/media/yezz/CentOS 7 x86_64
#划分出一个2G的分区
[root@localhost ~]# fdisk /dev/sda
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.


Command (m for help): n
All primary partitions are in use
Adding logical partition 6
First sector (325064704-419430399, default 325064704): 
Using default value 325064704
Last sector, +sectors or +size{K,M,G} (325064704-419430399, default 419430399): +2G
Partition 6 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.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
#读取更新的分区表
[root@localhost ~]# partprobe /dev/sda
#查看分区表是否更新
[root@localhost ~]# cat /proc/partitions 
major minor  #blocks  name

   8        0  209715200 sda
   8        1    1048576 sda1
   8        2  104857600 sda2
   8        3   52428800 sda3
   8        4          1 sda4
   8        5    4194304 sda5
   8        6    2097152 sda6
  11        0   10768384 sr0
[root@localhost ~]# lsblk /dev/sda
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda      8:0    0  200G  0 disk 
├─sda1   8:1    0    1G  0 part /boot
├─sda2   8:2    0  100G  0 part /
├─sda3   8:3    0   50G  0 part /data
├─sda4   8:4    0    1K  0 part 
├─sda5   8:5    0    4G  0 part [SWAP]
└─sda6   8:6    0    2G  0 part 
#有/dev/sda6为2G
#mke2fs命令创建文件系统, -t ext4指定文件系统为ext4类型;-b指定数据块大小;-L指定卷标;-m预留空间,默认为5%
[root@localhost ~]# mke2fs -t ext4 -L TEST -b 2048 -m 2 /dev/sda6
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, 1048576 blocks
20971 blocks (2.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 (32768 blocks): done
Writing superblocks and filesystem accounting information: done 
#查看超级块信息
[root@localhost ~]# tune2fs -l /dev/sda6
tune2fs 1.42.9 (28-Dec-2013)
Filesystem volume name:   TEST
Last mounted on:          
Filesystem UUID:          997d62f5-f4d8-4b7c-a5f3-a7534ce71368
Filesystem magic number:  0xEF53
Filesystem revision #:    1 (dynamic)
Filesystem features:      has_journal ext_attr resize_inode dir_index filetype extent 64bit flex_bg sparse_super huge_file uninit_bg dir_nlink extra_isize
Filesystem flags:         signed_directory_hash 
Default mount options:    user_xattr acl
Filesystem state:         clean
Errors behavior:          Continue
Filesystem OS type:       Linux
Inode count:              131072
Block count:              1048576
Reserved block count:     20971
Free blocks:              994651
Free inodes:              131061
First block:              0
Block size:               2048
Fragment size:            2048
Group descriptor size:    64
Reserved GDT blocks:      512
Blocks per group:         16384
Fragments per group:      16384
Inodes per group:         2048
Inode blocks per group:   256
Flex block group size:    16
Filesystem created:       Sun Jul 19 22:28:13 2020
Last mount time:          n/a
Last write time:          Sun Jul 19 22:28:14 2020
Mount count:              0
Maximum mount count:      -1
Last checked:             Sun Jul 19 22:28:13 2020
Check interval:           0 ()
Lifetime writes:          65 MB
Reserved blocks uid:      0 (user root)
Reserved blocks gid:      0 (group root)
First inode:              11
Inode size:           256
Required extra isize:     28
Desired extra isize:      28
Journal inode:            8
Default directory hash:   half_md4
Directory Hash Seed:      5a1a340d-297f-4b2e-a5bb-097f74ae64ec
Journal backup:           inode blocks
#将挂载选项写入到/etc/fstab中,实现开机自动挂载
[root@localhost ~]# blkid /dev/sda6
/dev/sda6:UUID="997d62f5-f4d8-4b7c-a5f3-a7534ce71368" type="ext4"
[root@localhost ~]# vim /etc/fstab
#内容如下
#
# /etc/fstab
# Created by anaconda on Fri May 15 16:26:08 2020
#
# 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
#
UUID=5323ffc1-3434-41b0-b8ec-909403493a60 /                       xfs     defaults        0 0
UUID=edd1490f-a15a-4a21-82dc-928bc1c04b38 /boot                   xfs     defaults        0 0
UUID=5d56a0d4-150b-4827-8f82-763868b561c7 /data                   xfs     defaults        0 0
UUID=ed5d5d57-d87f-48e8-90df-c962f78230d9 swap                    swap    defaults        0 0
UUID=997d62f5-f4d8-4b7c-a5f3-a7534ce71368 /test                   ext4    defaults,acl    0 0
#挂载所有设备
[root@localhost ~]# mount -a
#验证结果
[root@localhost test]# tune2fs -l /dev/sda6
tune2fs 1.42.9 (28-Dec-2013)
Filesystem volume name:   TEST
Last mounted on:          /test
Filesystem UUID:          997d62f5-f4d8-4b7c-a5f3-a7534ce71368
Filesystem magic number:  0xEF53
Filesystem revision #:    1 (dynamic)
Filesystem features:      has_journal ext_attr resize_inode dir_index filetype needs_recovery extent 64bit flex_bg sparse_super huge_file uninit_bg dir_nlink extra_isize
Filesystem flags:         signed_directory_hash 
Default mount options:    user_xattr acl
Filesystem state:         clean
Errors behavior:          Continue
......(省略)......
[root@localhost test]# df /dev/sda6
Filesystem     1K-blocks  Used Available Use% Mounted on
/dev/sda6        1998538  9238   1939166   1% /test

4、创建一个至少有两个PV组成的大小为20G的名为testvg的VG;要求PE大小 为16MB, 而后在卷组中创建大小为5G的逻辑卷testlv;挂载至/users目录

#已经划分了/dev/sda6和/dev/sda7两块10G的硬盘备用
[root@localhost ~]# lsblk /dev/sda
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda      8:0    0  200G  0 disk 
├─sda1   8:1    0    1G  0 part /boot
├─sda2   8:2    0  100G  0 part /
├─sda3   8:3    0   50G  0 part /data
├─sda4   8:4    0    1K  0 part 
├─sda5   8:5    0    4G  0 part [SWAP]
├─sda6   8:6    0   10G  0 part 
└─sda7   8:7    0   10G  0 part 
#指定/dev/sda6和/dev/sda7的ID号为Linux LVM类型
[root@localhost ~]# fdisk /dev/sda
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.


Command (m for help): t
Partition number (1-7, default 7): 6
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'
Command (m for help): t   
Partition number (1-7, default 7): 7
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
[root@localhost ~]# partprobe /dev/sda

第一步:创建PV

[root@localhost ~]# pvcreate /dev/sda6
  Physical volume "/dev/sda6" successfully created.
[root@localhost ~]# pvcreate /dev/sda7
  Physical volume "/dev/sda7" successfully created.
#验证结果
[root@localhost ~]# pvs
  PV         VG Fmt  Attr PSize  PFree 
  /dev/sda6     lvm2 ---  10.00g 10.00g
  /dev/sda7     lvm2 ---  10.00g 10.00g
[root@localhost ~]# pvdisplay
  "/dev/sda7" is a new physical volume of "10.00 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/sda7
  VG Name               
  PV Size               10.00 GiB
  Allocatable           NO
  PE Size               0   
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               rVVgdf-Y1Ah-R49p-0BM3-F0WT-53Wo-G9KlT0
   
  "/dev/sda6" is a new physical volume of "10.00 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/sda6
  VG Name               
  PV Size               10.00 GiB
  Allocatable           NO
  PE Size               0   
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               jPz7zt-LNiK-3iV8-Cf5m-CanF-Z8QH-Q2eseH

第二步:创建VG

#创建VG名称为testvg;设定PE为16M;把/dev/sda6和/dev/sda7两分区加入到VG中
[root@localhost ~]# vgcreate -s 16M testvg /dev/sda{6,7}
  Volume group "testvg" successfully created
#验证结果
[root@localhost ~]# vgs
  VG     #PV #LV #SN Attr   VSize   VFree  
  testvg   2   0   0 wz--n- <19.97g <19.97g
[root@localhost ~]# 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               4exCF4-D9Qk-WHFM-AD0n-DDgv-2yrB-xp4FwA

第三步:创建LV

#从名称为testvg的VG中划分LV且设置其名称为testlv,大小为5G
[root@localhost ~]# lvcreate -n testlv -L 2G testvg
  Logical volume "testlv" created.
#验证结果
[root@localhost ~]# lvs
  LV     VG     Attr       LSize Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  testlv testvg -wi-a----- 2.00g                                                    
[root@localhost ~]# lvdisplay 
  --- Logical volume ---
  LV Path                /dev/testvg/testlv
  LV Name                testlv
  VG Name                testvg
  LV UUID                J7A7cx-m8gA-MjCY-K3Xn-3mh3-n6Vz-VNQYAB
  LV Write Access        read/write
  LV Creation host, time localhost.localdomain, 2020-07-19 23:32:34 +0800
  LV Status              available
  # open                 0
  LV Size                2.00 GiB
  Current LE             128
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:0
   
[root@localhost ~]# vgs
  VG     #PV #LV #SN Attr   VSize   VFree  
  testvg   2   1   0 wz--n- <19.97g <17.97g

第四步:创建ext4系统

[root@localhost ~]# mkfs.ext4 /dev/testvg/testlv 
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
131072 inodes, 524288 blocks
26214 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=536870912
16 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks: 
    32768, 98304, 163840, 229376, 294912

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information: done 
#验证UUID
/dev/sda1: UUID="edd1490f-a15a-4a21-82dc-928bc1c04b38" TYPE="xfs" 
/dev/sda2: UUID="5323ffc1-3434-41b0-b8ec-909403493a60" TYPE="xfs" 
/dev/sda3: UUID="5d56a0d4-150b-4827-8f82-763868b561c7" TYPE="xfs" 
/dev/sda5: UUID="ed5d5d57-d87f-48e8-90df-c962f78230d9" TYPE="swap" 
/dev/sda6: UUID="jPz7zt-LNiK-3iV8-Cf5m-CanF-Z8QH-Q2eseH" TYPE="LVM2_member" 
/dev/sda7: UUID="rVVgdf-Y1Ah-R49p-0BM3-F0WT-53Wo-G9KlT0" TYPE="LVM2_member" 
/dev/sr0: UUID="2019-09-09-19-08-41-00" LABEL="CentOS 7 x86_64" TYPE="iso9660" PTTYPE="dos" 
/dev/mapper/testvg-testlv: UUID="aefe8103-c6dd-4b4a-b962-30aae5a474ad" TYPE="ext4" 

第五步:开机自动挂载文件系统

#创建挂载点
[root@localhost ~]# mkdir /users
[root@localhost ~]# vim /etc/fstab
#最后一行添加
UUID=aefe8103-c6dd-4b4a-b962-30aae5a474ad /users                  ext4    defaults        0 0
#挂载该文件系统
[root@localhost ~]# mount -a
#验证结果
[root@localhost ~]# df | grep /dev/
tmpfs                       1013984        0   1013984   0% /dev/shm
/dev/sda2                 104806400  4721972 100084428   5% /
/dev/sda3                  52403200    32992  52370208   1% /data
/dev/sda1                   1038336   171708    866628  17% /boot
/dev/sr0                   10767514 10767514         0 100% /run/media/yezz/CentOS 7 x86_64
/dev/mapper/testvg-testlv   1998672     6144   1871288   1% /users

你可能感兴趣的:(第六周作业(7.13-7.19))