六、Linux 系統yum倉庫與硬碟掛載
阿新 • • 發佈:2020-09-14
1.自建yum倉庫,分別為網路源和本地源。
備份yum源配置
[root@centos6 ~]#ll /etc/yum.repos.d/ total 28 -rw-r--r--. 1 root root 1991 Jun 26 2018 CentOS-Base.repo -rw-r--r--. 1 root root 647 Jun 26 2018 CentOS-Debuginfo.repo -rw-r--r--. 1 root root 289 Jun 26 2018 CentOS-fasttrack.repo -rw-r--r--. 1 root root 630 Jun 26 2018 CentOS-Media.repo -rw-r--r--. 1 root root 8854 Jun 26 2018 CentOS-Vault.repo [root@centos6 ~]#cd !* cd /etc/yum.repos.d/ [root@centos6 yum.repos.d]#mkdir backup [root@centos6 yum.repos.d]#ll total 32 drwxr-xr-x 2 root root 4096 Sep 1 02:20 backup -rw-r--r--. 1 root root 1991 Jun 26 2018 CentOS-Base.repo -rw-r--r--. 1 root root 647 Jun 26 2018 CentOS-Debuginfo.repo -rw-r--r--. 1 root root 289 Jun 26 2018 CentOS-fasttrack.repo -rw-r--r--. 1 root root 630 Jun 26 2018 CentOS-Media.repo -rw-r--r--. 1 root root 8854 Jun 26 2018 CentOS-Vault.repo [root@centos6 yum.repos.d]#mv ./*.repo backup/ [root@centos6 yum.repos.d]#ll total 4 drwxr-xr-x 2 root root 4096 Sep 1 02:21 backup
掛載光碟
[root@centos6 yum.repos.d]#mkdir /mnt/cdrom [root@centos6 yum.repos.d]#mount /dev/sr0 /mnt/cdrom/ mount: block device /dev/sr0 is write-protected, mounting read-only [root@centos6 yum.repos.d]#df -h Filesystem Size Used Avail Use% Mounted on /dev/sda2 99G 4.3G 90G 5% / tmpfs 931M 84K 931M 1% /dev/shm /dev/sda1 976M 39M 887M 5% /boot /dev/sda3 50G 52M 47G 1% /data /dev/sr0 3.8G 3.8G 0 100% /mnt/cdrom
配置本地光碟為yum本地源
在/etc/yum.repos.d/路徑下建立檔案base.repo寫入以下內容:
[root@centos6 yum.repos.d]#cat base.repo
[base]
name=cdrom
baseurl=file:///misc/cd/
gpgcheck=0
gpgkey=file:///misc/cd/RPM-GPG-KEY-CentOS-6
配置阿里雲epel作為網路源,在上述檔案中再新增以下內容:
[epel] name=aliyun epel baseurl=https://mirrors.aliyun.com/epel/$releasever/x86_64 gpgcheck=0 enabled=1 注意##enabled=1時啟動網路源,enabled=0時關閉網路源
檢視yum源配置結果
[root@centos6 yum.repos.d]#yum repolist
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
base | 4.0 kB 00:00 ...
epel | 4.7 kB 00:00
epel/primary_db | 6.1 MB 00:01
repo id repo name status
base cdrom 6,713
epel aliyun epel 12,582
repolist: 19,295
2.編譯安裝http2.4,實現可以正常訪問,並將編譯步驟和結果提交。
[16:07:55 root@centos7 ~]#tar xvf httpd-2.4.25.tar.gz
[16:08:47 root@centos7 httpd-2.4.25]#yum -y install gcc apr-devel apr-util-devel pcre-devel openssl-devel
[16:08:47 root@centos7 httpd-2.4.25]#./configure \
--prefix=/app/http24 \
--sysconfdir=/etc/httpd \
--enable-ssl \
--enable-so
[16:08:47 root@centos7 httpd-2.4.25]#make -j 4
[16:08:47 root@centos7 httpd-2.4.25]#make install
[16:08:47 root@centos7 httpd-2.4.25]#vim /etc/profile.d/env.sh
#export PATH=/app/http24/bin:/usr/local/apache/bin:$PATH
[16:08:47 root@centos7 httpd-2.4.25]#source /etc/profile.d/env.sh
[16:08:47 root@centos7 httpd-2.4.25]#echo $PATH
/app/httpd24/bin:/usr/local/apache/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/usr/local/apache/bin:/root/bin
[16:08:47 root@centos7 httpd-2.4.25]#cd
[root@localhost ~]#apachectl star
3.建立一個2G的檔案系統,塊大小為2048byte,預留1%可用空間,檔案系統 ext4,卷標為TEST,要求此分割槽開機後自動掛載至/test目錄,且預設有acl掛載選項。
虛擬機器線上新增一個20G硬碟,識別使用以下命令
echo '- - -' > /sys/class/scsi_host/host0/scan
echo '- - -' > /sys/class/scsi_host/host2/scan
[14:41:46 root@centos7 ~]#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]
├─sda6 8:6 0 2G 0 part /mnt/sda6
└─sda7 8:7 0 3G 0 part
sdb 8:16 0 200G 0 disk
├─sdb1 8:17 0 4G 0 part
└─sdb2 8:18 0 2G 0 part /home
sdc 8:32 0 20G 0 disk
sdd 8:48 0 10G 0 disk
└─vg0-mysql 253:0 0 8G 0 lvm /mnt/mysql
sr0 11:0 1 4.5G 0 rom /mnt/cdrom
建立一個2G分割槽,儲存後不生效,請執行partprobe進行同步
[14:44:57 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 0xe87cdb45.
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):
First sector (2048-41943039, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039): +2G
Partition 1 of type Linux and of size 2 GiB is set
Command (m for help): p
Disk /dev/sdc: 21.5 GB, 21474836480 bytes, 41943040 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: 0xe87cdb45
Device Boot Start End Blocks Id System
/dev/sdc1 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.
[14:50:10 root@centos7 ~]#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]
├─sda6 8:6 0 2G 0 part /mnt/sda6
└─sda7 8:7 0 3G 0 part
sdb 8:16 0 200G 0 disk
├─sdb1 8:17 0 4G 0 part
└─sdb2 8:18 0 2G 0 part /home
sdc 8:32 0 20G 0 disk
└─sdc1 8:33 0 2G 0 part
sdd 8:48 0 10G 0 disk
└─vg0-mysql 253:0 0 8G 0 lvm /mnt/mysql
sr0 11:0 1 4.5G 0 rom /mnt/cdrom
將2G空間的分割槽格式化為塊大小為2048byte,預留1%可用空間,檔案系統 ext4,卷標為TEST
[14:54:18 root@centos7 ~]#mkfs.ext4 -t ext4 -b 2048 -m 1 -L TEST /dev/sdc1
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
[14:54:45 root@centos7 ~]#blkid /dev/sdc1
/dev/sdc1: LABEL="TEST" UUID="06573fa3-f4a7-4961-a69e-038dea237ee3" TYPE="ext4"
[14:54:58 root@centos7 ~]#tune2fs -l /dev/sdc1
tune2fs 1.42.9 (28-Dec-2013)
Filesystem volume name: TEST
Last mounted on: <not available>
Filesystem UUID: 06573fa3-f4a7-4961-a69e-038dea237ee3
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: 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: Sun Sep 13 14:54:44 2020
Last mount time: n/a
Last write time: Sun Sep 13 14:54:45 2020
Mount count: 0
Maximum mount count: -1
Last checked: Sun Sep 13 14:54:44 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: 9eefdff2-eff9-4cec-b611-6b0df42b5a55
Journal backup: inode blocks
將配置寫入/etc/fstab
[14:57:51 root@centos7 ~]#mkdir /mnt/test
[14:57:58 root@centos7 ~]#cat /etc/fstab
#
# /etc/fstab
# Created by anaconda on Sat Jun 27 23:00:26 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=7fe60235-39b2-4c21-9b41-c5f5dd46abed / xfs defaults 0 0
UUID=6df336dd-758b-48c3-abf0-ddb9745ebaef /boot xfs defaults 0 0
UUID=48940412-0f85-4525-a992-5000f210c847 /data xfs defaults 0 0
UUID=ff40c635-1eed-4078-94ac-adcd74b3b844 swap swap defaults 0 0
UUID=7c1968a3-f395-48ac-a25f-1161cbb83313 /mnt/sda6 xfs defaults 0 0
UUID=77d71eda-6592-4357-ae8f-7b35c2333a85 /home xfs defaults 0 0
UUID=06573fa3-f4a7-4961-a69e-038dea237ee3 /test ext4 acl 0 0
[14:58:30 root@centos7 ~]#tune2fs -l /dev/sdc1
tune2fs 1.42.9 (28-Dec-2013)
Filesystem volume name: TEST
Last mounted on: <not available>
Filesystem UUID: 06573fa3-f4a7-4961-a69e-038dea237ee3
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
4.建立一個至少有兩個PV組成的大小為20G的名為testvg的VG;要求PE大小 為16MB, 而後在卷組中建立大小為5G的邏輯卷testlv;掛載至/users目錄。
檢視硬碟資訊,用sdc和sdd中的10G空間共同建立物理卷組
[16:10:52 root@centos7 ~]#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]
├─sda6 8:6 0 2G 0 part /mnt/sda6
└─sda7 8:7 0 3G 0 part
sdb 8:16 0 200G 0 disk
├─sdb1 8:17 0 4G 0 part
└─sdb2 8:18 0 2G 0 part /home
sdc 8:32 0 20G 0 disk
└─sdc1 8:33 0 2G 0 part
sdd 8:48 0 10G 0 disk
sr0 11:0 1 4.5G 0 rom /mnt/cdrom
在sdc硬碟上建立10G的分割槽
[16:10:54 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.
Command (m for help): p
Disk /dev/sdc: 21.5 GB, 21474836480 bytes, 41943040 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: 0xe87cdb45
Device Boot Start End Blocks Id System
/dev/sdc1 2048 4196351 2097152 83 Linux
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):
First sector (4196352-41943039, default 4196352):
Using default value 4196352
Last sector, +sectors or +size{K,M,G} (4196352-41943039, default 41943039): +10G
Partition 2 of type Linux and of size 10 GiB is set
Command (m for help): p
Disk /dev/sdc: 21.5 GB, 21474836480 bytes, 41943040 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: 0xe87cdb45
Device Boot Start End Blocks Id System
/dev/sdc1 2048 4196351 2097152 83 Linux
/dev/sdc2 4196352 25167871 10485760 83 Linux
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/sdc: 21.5 GB, 21474836480 bytes, 41943040 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: 0xe87cdb45
Device Boot Start End Blocks Id System
/dev/sdc1 2048 4196351 2097152 83 Linux
/dev/sdc2 4196352 25167871 10485760 8e Linux LVM
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
在sdc2分割槽和sdd上分別建立物理卷(pv)
[16:15:17 root@centos7 ~]#pvcreate /dev/sd{c2,d}
Physical volume "/dev/sdc2" successfully created.
Physical volume "/dev/sdd" successfully created.
[16:16:28 root@centos7 ~]#pvs
PV VG Fmt Attr PSize PFree
/dev/sdc2 lvm2 --- 10.00g 10.00g
/dev/sdd lvm2 --- 10.00g 10.00g
建立物理卷組(vg),並將以上的pv加入其中
[16:16:31 root@centos7 ~]#vgcreate -s 16M testvg /dev/sdd /dev/sdc2
Volume group "testvg" successfully created
[16:18:31 root@centos7 ~]#vgs
VG #PV #LV #SN Attr VSize VFree
testvg 2 0 0 wz--n- <19.97g <19.97g
[16:18:35 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 b3C8BL-3SAl-gXxD-0Joc-fw3B-gtrN-1QjLPD
在testvgz中建立大小為5G的邏輯卷(lv)
[16:19:35 root@centos7 ~]#lvcreate -n testlv -L 5G testvg
WARNING: xfs signature detected on /dev/testvg/testlv at offset 0. Wipe it? [y/n]: y
Wiping xfs signature on /dev/testvg/testlv.
Logical volume "testlv" created.
[16:20:15 root@centos7 ~]#lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
testlv testvg -wi-a----- 5.00g
建立檔案系統
[16:20:20 root@centos7 ~]#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
327680 inodes, 1310720 blocks
65536 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=1342177280
40 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736
Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
[16:21:41 root@centos7 ~]#blkid
/dev/sda1: UUID="6df336dd-758b-48c3-abf0-ddb9745ebaef" TYPE="xfs"
/dev/sda2: UUID="7fe60235-39b2-4c21-9b41-c5f5dd46abed" TYPE="xfs"
/dev/sda3: UUID="48940412-0f85-4525-a992-5000f210c847" TYPE="xfs"
/dev/sda5: UUID="ff40c635-1eed-4078-94ac-adcd74b3b844" TYPE="swap"
/dev/sda6: UUID="7c1968a3-f395-48ac-a25f-1161cbb83313" TYPE="xfs"
/dev/sr0: UUID="2020-04-22-00-54-00-00" LABEL="CentOS 7 x86_64" TYPE="iso9660" PTTYPE="dos"
/dev/sdb2: UUID="77d71eda-6592-4357-ae8f-7b35c2333a85" TYPE="xfs"
/dev/sdd: UUID="emilQ9-sk2h-ry6t-hyu8-p69l-yUz0-aAhcQ3" TYPE="LVM2_member"
/dev/sdc1: LABEL="TEST" UUID="06573fa3-f4a7-4961-a69e-038dea237ee3" TYPE="ext4"
/dev/sdc2: UUID="KLIwlU-Ohbs-l1Lu-MUVY-EVbO-zKJd-VkjrJz" TYPE="LVM2_member"
/dev/mapper/testvg-testlv: UUID="8a76d6b3-e95b-4192-ad9f-f88d068e64df" TYPE="ext4"
在/etc/fstab配置檔案中新增以下內容:
UUID=8a76d6b3-e95b-4192-ad9f-f88d068e64df /users ext4 defaults 0 0
建立目標資料夾,並手動使配置檔案生效
[16:26:04 root@centos7 ~]#mount /dev/mapper/testvg-testlv /mnt/users/
[16:26:26 root@centos7 ~]#df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 975M 0 975M 0% /dev
tmpfs 991M 0 991M 0% /dev/shm
tmpfs 991M 11M 980M 2% /run
tmpfs 991M 0 991M 0% /sys/fs/cgroup
/dev/sda2 100G 5.0G 95G 5% /
/dev/sda3 50G 105M 50G 1% /data
/dev/sda6 2.0G 33M 2.0G 2% /mnt/sda6
/dev/sda1 1014M 169M 846M 17% /boot
tmpfs 199M 12K 199M 1% /run/user/42
/dev/sr0 4.5G 4.5G 0 100% /mnt/cdrom
/dev/sdb2 2.0G 40M 2.0G 2% /home
tmpfs 199M 0 199M 0% /run/user/0
/dev/mapper/testvg-testlv 4.8G 20M 4.6G 1% /mnt/users