第六週作業

1、自建yum倉庫,分別爲網絡源和本地源

出於安全起見,有些企業內部服務器使用本地局域網而不連接外網,爲了安裝一些服務,就需要搭建本地的yum倉庫;
在系統安裝盤內,已經自帶了大量必要的安裝包,可以用做本地yum倉庫的源;

作爲yum倉庫服務器的主機配置
先把原來系統相關的配置文件歸置存放

[root@mini71 ~]#mkdir /etc/yum.repos.d/bak
[root@mini71 ~]#mv /etc/yum.repos.d/* /etc/yum.repos.d/bak/

然後編輯以光盤路徑爲yum源的配置文件

[root@mini71 ~]#cat /etc/yum.repos.d/base.repo 
[base]
name=cdrom
baseurl=file:///mnt/cdrom/
gpgcheck=0

配置epel源(作爲擴展,可以不配置)

[root@mini71 ~]#cat /etc/yum.repos.d/epel.repo 
[aliyun.epel]
name=aliyun epel
baseurl=https://mirrors.aliyun.com/epel/7/x86_64/(這裏選擇裏阿里雲的epel源,也可以選擇其他的)
gpgcheck=0
enabled=1(通過修改此項爲0,即可關閉epel源)

安裝http服務,啓動,並開機啓動

[root@mini71 ~]#yum install httpd
[root@mini71 ~]#systemctl start httpd
[root@mini71 ~]#systemctl enable httpd
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.

將光盤掛載至httpd路徑下

[root@mini71 ~]#mkdir -p /var/www/html/centos/7/os/x86_64
[root@mini71 ~]#mount /dev/sr0 /var/www/html/centos/7/os/x86_64/
mount: /dev/sr0 is write-protected, mounting read-only
[root@mini71 ~]#ls /var/www/html/centos/7/os/x86_64/
CentOS_BuildTag  EULA  images    LiveOS    repodata              RPM-GPG-KEY-CentOS-Testing-7
EFI              GPL   isolinux  Packages  RPM-GPG-KEY-CentOS-7  TRANS.TBL

清理yum緩存,再查看yum源列表,出現本地源列表和epel源列表

[root@mini71 ~]#yum clean all
Loaded plugins: fastestmirror
Cleaning repos: aliyun.epel base
Cleaning up list of fastest mirrors
Other repos take up 48 M of disk space (use --verbose for details)
[root@mini71 ~]#yum repolist
Loaded plugins: fastestmirror
Determining fastest mirrors
aliyun.epel                                                                                                   | 4.7 kB  00:00:00     
base                                                                                                          | 3.6 kB  00:00:00     
(1/5): aliyun.epel/group_gz                                                                                   |  95 kB  00:00:01     
(2/5): base/group_gz                                                                                          | 166 kB  00:00:00     
(3/5): aliyun.epel/updateinfo                                                                                 | 1.0 MB  00:00:01     
(4/5): base/primary_db                                                                                        | 3.1 MB  00:00:00     
(5/5): aliyun.epel/primary_db                                                                                 | 6.7 MB  00:00:03     
repo id                                                        repo name                                                       status
aliyun.epel                                                    aliyun epel                                                     13,217
base                                                           cdrom                                                            4,021
repolist: 17,238

在瀏覽器輸入網址,看到光盤內容即表示可以訪問
第六週作業

配置其他主機
開啓另外一臺虛擬機,配置LAN區段內網,不啓動外網和光盤
第六週作業

此時查看yum源列表沒有任何可供安裝的包

[root@mini73 ~]#yum repolist
Loaded plugins: fastestmirror
Determining fastest mirrors
file:///mnt/cdrom/repodata/repomd.xml: [Errno 14] curl#37 - "Couldn't open file /mnt/cdrom/repodata/repomd.xml"
Trying other mirror.
file:///mnt/cdrom/repodata/repomd.xml: [Errno 14] curl#37 - "Couldn't open file /mnt/cdrom/repodata/repomd.xml"
Trying other mirror.
repo id                                                         repo name                                                      status
base                                                            cdrom                                                          0
repolist: 0

配置以yum倉庫路徑的源

[root@mini73 ~]#cat /etc/yum.repos.d/base.repo
[base]
name=cdrom
baseurl=http://192.168.36.71/centos/7/os/x86_64/
gpgcheck=0

刷新yum源,出現可供安裝的包列表

[root@mini73 ~]#yum repolist
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
base                                                                                                          | 3.6 kB  00:00:00     
(1/2): base/group_gz                                                                                          | 166 kB  00:00:00     
(2/2): base/primary_db                                                                                        | 3.1 MB  00:00:00     
repo id                                                         repo name                                                      status
base                                                            cdrom                                                          4,021
repolist: 4,021

測試安裝服務,表示安裝正常

[root@mini73 ~]#yum install httpd -y
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package httpd.x86_64 0:2.4.6-88.el7.centos will be installed
.
.
.
Installed:
  httpd.x86_64 0:2.4.6-88.el7.centos                                                                                                 

Dependency Installed:
  apr.x86_64 0:1.4.8-3.el7_4.1 apr-util.x86_64 0:1.5.2-6.el7 httpd-tools.x86_64 0:2.4.6-88.el7.centos mailcap.noarch 0:2.1.41-2.el7

Complete!

2、編譯安裝http2.4,實現可以正常訪問,並將編譯步驟和結果提交。

安裝包已經下載了,沒有下載最新的,因爲可能會有一些未知bug(如果沒下載,就去官方站點或者阿里雲下載,這裏就不敘述了)
下載一般建議源碼編譯安裝的包放在此目錄下,只是建議,儘量規範

[root@mini72 ~]#rpm -qi httpd
package httpd is not installed
[root@mini72 ~]#rpm -qa httpd
[root@mini72 ~]#cd /usr/local/src/
[root@mini72 src]#ls
[root@mini72 src]#rz -E
rz waiting to receive.
[root@mini72 src]#ls
httpd-2.4.25.tar.bz2

httpd服務安裝運行需要依賴一些其他的服務,所以先把這些包裝上,一般不需要全部安裝,裝devel也就是開發包即可,gcc是關於c語言的,pcre是關於正則表達式的
[root@mini72 src]#yum install gcc apr-devel apr-util-devel pcre-devel openssl-devel -y

解壓

[root@mini72 src]#tar xvf httpd-2.4.26.tar.bz2 -C /usr/local/src
[root@mini72 src]#ls
httpd-2.4.25  httpd-2.4.25.tar.bz2
[root@mini72 src]#cd /usr/local/src/httpd-2.4.25
[root@mini72 httpd-2.4.25]#ls
ABOUT_APACHE     buildconf       httpd.dsp       libhttpd.mak   README.cmake
acinclude.m4     CHANGES         httpd.mak       LICENSE        README.platforms
Apache-apr2.dsw  CMakeLists.txt  httpd.spec      Makefile.in    ROADMAP
Apache.dsw       config.layout   include         Makefile.win   server
apache_probes.d  configure       INSTALL         modules        srclib
ap.d             configure.in    InstallBin.dsp  NOTICE         support
build            docs            LAYOUT          NWGNUmakefile  test
BuildAll.dsp     emacs-style     libhttpd.dep    os             VERSIONING
BuildBin.dsp     httpd.dep       libhttpd.dsp    README

運行腳本一定要在解壓之後生成的軟件所在目錄裏運行安裝腳本,指定服務主程序路徑,配置文件路徑,啓用ssl,禁用基本的身份驗證(選項可以根據自己要求,./configure --help可以查看幫助)
[root@mini72 httpd-2.4.25]#./configure --prefix=/apps/httpd24 --sysconfdir=/etc/httpd24/ --enable-ssl --disable-auth-basic

出現這些提示,說明安裝成功,如果出現警告或者錯誤,可能是依賴包沒有安裝或者防火牆阻止

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

製作安裝,過程可能比較慢,再去查看相應的目錄下已經出現相關文件

[root@mini72 httpd-2.4.25]#make && make install
.
.
.
make[1]: Leaving directory `/usr/local/src/httpd-2.4.25'
.
.
.
make[1]: Leaving directory `/usr/local/src/httpd-2.4.25'
[root@mini72 httpd-2.4.25]#ls /usr/local/src/httpd-2.4.25
ABOUT_APACHE     BuildAll.dsp    config.log     httpd       InstallBin.dsp  Makefile.in   NWGNUmakefile     srclib
acinclude.m4     BuildBin.dsp    config.nice    httpd.dep   LAYOUT          Makefile.win  os                support
Apache-apr2.dsw  buildconf       config.status  httpd.dsp   libhttpd.dep    modules       README            test
Apache.dsw       buildmark.o     configure      httpd.mak   libhttpd.dsp    modules.c     README.cmake      VERSIONING
apache_probes.d  CHANGES         configure.in   httpd.spec  libhttpd.mak    modules.lo    README.platforms
ap.d             CMakeLists.txt  docs           include     LICENSE         modules.o     ROADMAP
build            config.layout   emacs-style    INSTALL     Makefile        NOTICE        server
[root@mini72 httpd-2.4.25]#ls /apps/httpd24/
bin  build  cgi-bin  error  htdocs  icons  include  logs  man  manual  modules
[root@mini72 httpd-2.4.25]#ls /etc/httpd24/
extra  httpd.conf  magic  mime.types  origina

接下來把服務的執行程序寫進變量裏並執行,這樣每次就不用敲那麼長的路徑了

[root@mini72 ~]#cat /etc/profile.d/env.sh
PATH=/apps/httpd24/bin:$PATH
[root@mini72 ~]#source /etc/profile.d/env.sh
[root@mini72 ~]#echo $PATH
/apps/httpd24/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
[root@mini72 ~]#apachectl start

最後啓動apachectl,登陸本地瀏覽器,出現默認頁,說明搭建成功
第六週作業

3、創建一個2G的文件系統,塊大小爲2048byte,預留1%可用空間,文件系統 ext4,卷標爲TEST,要求此分區開機後自動掛載至/test目錄,且默認有acl掛載選項

先裝上一塊10G的硬盤,掃描一下,此時磁盤上面沒有任何信息

[root@centos7 ~]#echo '- - -' >/sys/class/scsi_host/host2/scan
[root@centos7 ~]#lsblk
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda      8:0    0   10G  0 disk 
├─sda1   8:1    0  200M  0 part /boot
├─sda2   8:2    0    4G  0 part [SWAP]
├─sda3   8:3    0    2G  0 part /
├─sda4   8:4    0    1K  0 part 
└─sda5   8:5    0    2G  0 part /data
sdb      8:16   0    10G  0 disk 
sr0     11:0    1  4.3G  0 rom  
[root@centos7 ~]#lsblk -f
NAME   FSTYPE  LABEL           UUID                                 MOUNTPOINT
sda                                                                 
├─sda1 xfs                     de1c872e-abea-498c-a07a-38750913e570 /boot
├─sda2 swap                    d133fd09-7e88-4e2c-b9bb-b9c86638cf5a [SWAP]
├─sda3 xfs                     e7dace1d-16b2-4400-bf0a-d7c1027c6f8c /
├─sda4                                                              
└─sda5 xfs                     89bc32ab-6c2d-481f-ab50-be09a5b73192 /data
sdb                                                                 
sr0    iso9660 CentOS 7 x86_64 2018-11-25-23-54-16-00 

在/dev/sdb上創建分區,大小爲2G

[root@centos7 ~]#lsblk
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda      8:0    0   10G  0 disk 
├─sda1   8:1    0  200M  0 part /boot
├─sda2   8:2    0    4G  0 part [SWAP]
├─sda3   8:3    0    2G  0 part /
├─sda4   8:4    0    1K  0 part 
└─sda5   8:5    0    2G  0 part /data
sdb      8:16   0   10G  0 disk 
sr0     11:0    1  4.3G  0 rom  
[root@centos7 ~]#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 0x8be52446.

Command (m for help): p

Disk /dev/sdb: 10.7 GB, 10737418240 bytes, 20971520 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: 0x8be52446

   Device Boot      Start         End      Blocks   Id  System

Command (m for help): m  
Command action
   a   toggle a bootable flag
   b   edit bsd disklabel
   c   toggle the dos compatibility flag
   d   delete a partition
   g   create a new empty GPT partition table
   G   create an IRIX (SGI) partition table
   l   list known partition types
   m   print this menu
   n   add a new partition
   o   create a new empty DOS partition table
   p   print the partition table
   q   quit without saving changes
   s   create a new empty Sun disklabel
   t   change a partition's system id
   u   change display/entry units
   v   verify the partition table
   w   write table to disk and exit
   x   extra functionality (experts only)

Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-20971519, default 2048): 
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519): +2G
Partition 1 of type Linux and of size 2 GiB is set

Command (m for help): p

Disk /dev/sdb: 10.7 GB, 10737418240 bytes, 20971520 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: 0x8be52446

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048     4196351     2097152   83  Linux

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

Calling ioctl() to re-read partition table.
Syncing disks.
[root@centos7 ~]#fdisk -l

Disk /dev/sda: 10.7 GB, 10737418240 bytes, 20971520 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: 0x0001658e

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048      411647      204800   83  Linux
/dev/sda2          411648     8800255     4194304   82  Linux swap / Solaris
/dev/sda3         8800256    12994559     2097152   83  Linux
/dev/sda4        12994560    20971519     3988480    5  Extended
/dev/sda5        12996608    17190911     2097152   83  Linux

Disk /dev/sdb: 10.7 GB, 10737418240 bytes, 20971520 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: 0x8be52446

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048     4196351     2097152   83  Linux
[root@centos7 ~]#lsblk
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda      8:0    0   10G  0 disk 
├─sda1   8:1    0  200M  0 part /boot
├─sda2   8:2    0    4G  0 part [SWAP]
├─sda3   8:3    0    2G  0 part /
├─sda4   8:4    0    1K  0 part 
└─sda5   8:5    0    2G  0 part /data
sdb      8:16   0   10G  0 disk 
└─sdb1   8:17   0    2G  0 part 
sr0     11:0    1  4.3G  0 rom

創建文件系統,-b指定塊大小爲2048,-m指定預留空間,-L指定卷名

[root@centos7 ~]#mkfs.ext4 -b 2048 -m 1 -L TEST /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, 1048576 blocks
10485 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 (32768 blocks): done
Writing superblocks and filesystem accounting information: done 

[root@centos7 ~]#lsblk -f
NAME   FSTYPE  LABEL           UUID                                 MOUNTPOINT
sda                                                                 
├─sda1 xfs                     de1c872e-abea-498c-a07a-38750913e570 /boot
├─sda2 swap                    d133fd09-7e88-4e2c-b9bb-b9c86638cf5a [SWAP]
├─sda3 xfs                     e7dace1d-16b2-4400-bf0a-d7c1027c6f8c /
├─sda4                                                              
└─sda5 xfs                     89bc32ab-6c2d-481f-ab50-be09a5b73192 /data
sdb                                                                 
└─sdb1 ext4    TEST           38615919-cf0f-4eb7-ae22-ace6223dca1e 
sr0    iso9660 CentOS 7 x86_64 2018-11-25-23-54-16-00

查看磁盤的UUID,寫進/etc/fstab,

[root@centos7 ~]#blkid /dev/sdb1
/dev/sdb1: LABEL="test" UUID="38615919-cf0f-4eb7-ae22-ace6223dca1e" TYPE="ext4"
[root@centos7 ~]#tail -1 /etc/fstab
UUID=38615919-cf0f-4eb7-ae22-ace6223dca1e /test           ext4    defaults        0 0

創建目錄,掛載所有fstab文件指定的文件系統

[root@centos7 ~]#mkdir /test
[root@centos7 ~]#mount -a
[root@centos7 ~]#lsblk
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda      8:0    0   10G  0 disk 
├─sda1   8:1    0  200M  0 part /boot
├─sda2   8:2    0    4G  0 part [SWAP]
├─sda3   8:3    0    2G  0 part /
├─sda4   8:4    0    1K  0 part 
└─sda5   8:5    0    2G  0 part /data
sdb      8:16   0   10G  0 disk 
└─sdb1   8:17   0    2G  0 part /test
sr0     11:0    1  4.3G  0 rom

查看分區是否有facl權限

[root@centos7 ~]#tune2fs -l /dev/sdb1
tune2fs 1.42.9 (28-Dec-2013)
Filesystem volume name:   test
Last mounted on:          <not available>
Filesystem UUID:          38615919-cf0f-4eb7-ae22-ace6223dca1e
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
Filesystem OS type:       Linux
Inode count:              131072
Block count:              1048576
Reserved block count:     10485
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:       Wed Mar 25 13:35:35 2020
Last mount time:          Wed Mar 25 13:46:06 2020
Last write time:          Wed Mar 25 13:46:06 2020
Mount count:              1
Maximum mount count:      -1
Last checked:             Wed Mar 25 13:35:35 2020
Check interval:           0 (<none>)
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:      3054c428-09e3-4262-abdd-b3ef0741a97a
Journal backup:           inode blocks

4、創建一個至少有兩個PV組成的大小爲20G的名爲testvg的VG;要求PE大小 爲16MB, 而後在卷組中創建大小爲5G的邏輯卷testlv;掛載至/users目錄

環境:/dev/sdb盤還有不到8G空間(暫按8G計算),再從/dev/sdc盤中劃分出12G,合計20G空間製作物理卷

[root@centos7 ~]#echo '- - -' >/sys/class/scsi_host/host2/scan 
[root@centos7 ~]#lsblk
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda      8:0    0   10G  0 disk 
├─sda1   8:1    0  200M  0 part /boot
├─sda2   8:2    0    4G  0 part [SWAP]
├─sda3   8:3    0    2G  0 part /
├─sda4   8:4    0    1K  0 part 
└─sda5   8:5    0    2G  0 part /data
sdb      8:16   0   10G  0 disk 
└─sdb1   8:17   0    2G  0 part /test
sdc      8:32   0   16G  0 disk 
sr0     11:0    1  4.3G  0 rom 

分區

[root@centos7 ~]#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.

Command (m for help): n
Partition type:
   p   primary (1 primary, 0 extended, 3 free)
   e   extended
Select (default p): p
Partition number (2-4, default 2): 2
First sector (4196352-20971519, default 4196352): 
Using default value 4196352
Last sector, +sectors or +size{K,M,G} (4196352-20971519, default 20971519): 
Using default value 20971519
Partition 2 of type Linux and of size 8 GiB is set

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

Command (m for help): p

Disk /dev/sdb: 10.7 GB, 10737418240 bytes, 20971520 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: 0x8be52446

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048     4196351     2097152   83  Linux
/dev/sdb2         4196352    20971519     8387584   8e  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@centos7 ~]#fdisk /dev/sdc
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 0x81bb6c08.

Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-33554431, default 2048): 
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-33554431, default 33554431): +12G
Partition 1 of type Linux and of size 12 GiB is set

Command (m for help): t
Selected partition 1
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'

Command (m for help): p

Disk /dev/sdc: 17.2 GB, 17179869184 bytes, 33554432 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: 0x81bb6c08

   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1            2048    25167871    12582912   8e  Linux LVM

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

Calling ioctl() to re-read partition table.
Syncing disks.
[root@centos7 ~]#partprobe
Warning: Unable to open /dev/sr0 read-write (Read-only file system).  /dev/sr0 has been opened read-only.
[root@centos7 ~]#lsblk
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda      8:0    0   10G  0 disk 
├─sda1   8:1    0  200M  0 part /boot
├─sda2   8:2    0    4G  0 part [SWAP]
├─sda3   8:3    0    2G  0 part /
├─sda4   8:4    0    1K  0 part 
└─sda5   8:5    0    2G  0 part /data
sdb      8:16   0   10G  0 disk 
├─sdb1   8:17   0    2G  0 part /test
└─sdb2   8:18   0    8G  0 part 
sdc      8:32   0   16G  0 disk 
└─sdc1   8:33   0   12G  0 part 
sr0     11:0    1  4.3G  0 rom

創建物理卷

[root@centos7 ~]#pvcreate /dev/sdb2
  Physical volume "/dev/sdb2" successfully created.
[root@centos7 ~]#pvs
  PV         VG Fmt  Attr PSize  PFree 
  /dev/sdb2     lvm2 ---  <8.00g <8.00g
[root@centos7 ~]#pvcreate /dev/sdc1
  Physical volume "/dev/sdc1" successfully created.
[root@centos7 ~]#pvs
  PV         VG Fmt  Attr PSize  PFree 
  /dev/sdb2     lvm2 ---  <8.00g <8.00g
  /dev/sdc1     lvm2 ---  12.00g 12.00g
[root@centos7 ~]#pvdisplay
  "/dev/sdb2" is a new physical volume of "<8.00 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/sdb2
  VG Name               
  PV Size               <8.00 GiB
  Allocatable           NO
  PE Size               0   
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               vjsQVU-6ihn-v5kD-82nY-O68O-42Iv-7lvEyA

  "/dev/sdc1" is a new physical volume of "12.00 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/sdc1
  VG Name               
  PV Size               12.00 GiB
  Allocatable           NO
  PE Size               0   
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               TAYOcw-uI9D-OmBI-kl2P-gBfD-GNXA-nor1vD

創建物理卷組,-s指定塊大小爲16M

[root@centos7 ~]#vgcreate -s 16M testvg /dev/sdb2 /dev/sdc1
  Volume group "testvg" successfully created
[root@centos7 ~]#vgs
  VG     #PV #LV #SN Attr   VSize   VFree  
  testvg   2   0   0 wz--n- <19.97g <19.97g
[root@centos7 ~]#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               vrXxL9-gewG-0Bo9-VNii-1vrJ-8AFs-xL5r0O

創建邏輯卷,大小爲5G

[root@centos7 ~]#lvcreate -n testvg -L 5G testvg
  Logical volume "testvg" created.
[root@centos7 ~]#lvs
  LV     VG     Attr       LSize Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  testvg testvg -wi-a----- 5.00g                                                    
[root@centos7 ~]#lvdisplay 
  --- Logical volume ---
  LV Path                /dev/testvg/testvg
  LV Name                testvg
  VG Name                testvg
  LV UUID                cfkOjV-PcjM-uc9C-vrdZ-U6vZ-JGRW-9LYj0q
  LV Write Access        read/write
  LV Creation host, time centos7, 2020-03-25 15:33:25 +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     8192
  Block device           253:0

寫入/etc/fstab

[root@centos7 ~]#blkid /dev/testvg/testvg
/dev/testvg/testvg: UUID="c048c0e0-378f-4659-a622-b7b4b78c0a30" TYPE="xfs" 
[root@centos7 ~]#echo "UUID=c048c0e0-378f-4659-a622-b7b4b78c0a30 /users  xfs defaults 0 0" >> /etc/fstab
[root@centos7 ~]#tail -1 /etc/fstab
UUID=c048c0e0-378f-4659-a622-b7b4b78c0a30 /users  xfs defaults 0 0

掛載

[root@centos7 ~]#mkdir /users
[root@centos7 ~]#mount -a
[root@centos7 ~]#lsblk
NAME              MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda                 8:0    0   10G  0 disk 
├─sda1              8:1    0  200M  0 part /boot
├─sda2              8:2    0    4G  0 part [SWAP]
├─sda3              8:3    0    2G  0 part /
├─sda4              8:4    0    1K  0 part 
└─sda5              8:5    0    2G  0 part /data
sdb                 8:16   0   10G  0 disk 
├─sdb1              8:17   0    2G  0 part /test
└─sdb2              8:18   0    8G  0 part 
  └─testvg-testvg 253:0    0    5G  0 lvm  /users
sdc                 8:32   0   16G  0 disk 
└─sdc1              8:33   0   12G  0 part 
sr0                11:0    1  4.3G  0 rom  /mnt/cdrom

架構班小夥伴看這裏:
1、實現openstack控制端的高可用
2、結合lvs實現openstack的負載均衡

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章