第六周作业

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

 

一:本地源配置:

  (1)将镜像挂载至系统,并查看系统中挂载ISO的设备所在位置,一般是sr#  

  [root@db01 ~]# ls /dev/sr0
  /dev/sr0

  (2)将设备挂载至指定目录
  [root@db01 ~]# mount /dev/sr0 /media/
  mount: /dev/sr0 is write-protected, mounting read-only

  (3)备份系统自带的yum源

  [root@db01 ~]# cd /etc/yum.repos.d/

  [root@db01 yum.repos.d]# mkdir REPOBAK

  [root@db01 yum.repos.d]# mv CentOS* REPOBAK

  (4)配置本地YUM仓库

  [root@db01 yum.repos.d]# vim base7.repo

  [base7]
  name=CentOS7
  baseurl=file:///media
  gpgcheck=0
  enabled=1

  (5)查看YUM源 

  [root@db01 yum.repos.d]# yum list
  Loaded plugins: fastestmirror, langpacks
  base7 | 3.6 kB 00:00
  (1/2): base7/group_gz | 156 kB 00:00
  (2/2): base7/primary_db | 3.1 MB 00:00
  Loading mirror speeds from cached hostfile

  ...

  (6)安装httpd

  [root@db01 yum.repos.d]# yum install httpd -y

  ...  

  Installed:
  httpd.x86_64 0:2.4.6-67.el7.centos

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

  Complete!


  

二:网络源配置,通过httpd服务实现:

  服务器端配置:

  (1)关闭并永久关闭selinux,iptables

  (2)上面已安装好httpd服务,创建新的挂载目录: 

  [root@db01 yum.repos.d]# cd /var/www/html/
  [root@db01 html]# mkdir mkdir centos/7/os/x86_64/ -p
  (3)卸载之前的本地挂载目录,并重新挂载至新的目录 

  [root@db01 html]# umount /media/

  [root@db01 html]# mount /dev/sr0 /var/www/html/centos/7/os/x86_64/
  mount: /dev/sr0 is write-protected, mounting read-only

  (4)启动httpd服务

  [root@db01 html]# systemctl start httpd

  客户端上配置:

  (1)备份系统自带的YUM源

  [root@db02 ~]# cd /etc/yum.repos.d/

  [root@db02 yum.repos.d]# mkdir REPOBAK

  [root@db02 yum.repos.d]# mv CentOS* REPOBAK

  (2)配置YUM仓库:  

  [root@db02 yum.repos.d]# vim base7.repo

  [base7]
  name=CentOS7
  baseurl=http://192.168.0.199/centos/7/os/x86_64/
  gpgcheck=0
  enabled=1

  (3)测试安装tomcat  

  [root@db02 yum.repos.d]# yum install tomcat
  Loaded plugins: fastestmirror, langpacks
  base7 | 3.6 kB 00:00:00
  Loading mirror speeds from cached hostfile
  Resolving Dependencies
  --> Running transaction check

 

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

  (1)安装开发程序依赖包:

  [root@db01 data]# yum groupinstall "Development Tools" -y

    或者:

  [root@db01 data]# yum install gcc openssl-devel pcre-devel apr-devel apr-util-devel -y

  (2)上传源码包至服务器中并解压: 

  [root@db01 data]# ls
  httpd-2.4.39.tar.bz2
  [root@db01 data]# bunzip2 httpd-2.4.39.tar.bz2
  [root@db01 data]# ls
  httpd-2.4.39.tar
  [root@db01 data]# tar xf httpd-2.4.39.tar

  [root@db01 data]# ls
  httpd-2.4.39 httpd-2.4.39.tar

  (3)默认编译安装: 

  [root@db01 data]# cd httpd-2.4.39/
  [root@db01 httpd-2.4.39]# ./config

  [root@db01 httpd-2.4.39]# make && make install

  (4)安装后配置:

  配置环境变量:  

  [root@db01 ~]# echo 'export PATH=/usr/local/apache2/bin:$PATH' > /etc/profile.d/apache2.sh
  [root@db01 ~]# cat /etc/profile.d/apache2.sh
  export PATH=/usr/local/apache2/bin:$PATH
  [root@db01 ~]# source /etc/profile.d/apache2.sh

  导出帮助手册,添加黄色部分:

  [root@db01 ~]# vim /etc/man_db.conf

  ...  

  #
  MANDATORY_MANPATH /usr/man
  MANDATORY_MANPATH /usr/share/man
  MANDATORY_MANPATH /usr/local/share/man
  MANDATORY_MANPATH /usr/local/apache2/man

  启动httpd服务,查看80端口是否监听:

  [root@db01 ~]# apachectl start
  AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using   fe80::20c:29ff:fe1f:38ca. Set the 'ServerName' directive globally to suppress this message
  [root@db01 ~]# ss -tnl
  State Recv-Q Send-Q Local Address:Port Peer Address:Port
  LISTEN 0 128 *:111 *:*
  LISTEN 0 5 192.168.122.1:53 *:*
  LISTEN 0 128 *:22 *:*
  LISTEN 0 128 127.0.0.1:631 *:*
  LISTEN 0 100 127.0.0.1:25 *:*
  LISTEN 0 128 127.0.0.1:6010 *:*
  LISTEN 0 128 :::111 :::*
  LISTEN 0 128 :::80 :::*
  LISTEN 0 128 :::22 :::*
  LISTEN 0 128 ::1:631 :::*
  LISTEN 0 100 ::1:25 :::*
  LISTEN 0 128 ::1:6010 :::*
  LISTEN 0 80 :::3306 :::*

  通过浏览器访问:

   

 

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

   (1)在虚拟机上添加一块新的硬盘,并在系统上扫描,发现一块sdb的10G盘: 

  [root@db01 ~]# echo "- - -" > /sys/class/scsi_host/host0/scan
  [root@db01 ~]# echo "- - -" > /sys/class/scsi_host/host1/scan
  [root@db01 ~]# lsblk
  NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
  fd0 2:0 1 4K 0 disk
  sda 8:0 0 50G 0 disk
  ├─sda1 8:1 0 1G 0 part /boot
  └─sda2 8:2 0 49G 0 part
  ├─centos-root 253:0 0 45G 0 lvm /
  └─centos-swap 253:1 0 4G 0 lvm [SWAP]
  sdb 8:16 0 10G 0 disk
  sr0 11:0 1 4.2G 0 rom /media

   (2)按要求创建文件系统
  创建一块2G的分区:

  [root@db01 ~]# 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 0x4383546f.

  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): 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): w
  The partition table has been altered!

  Calling ioctl() to re-read partition table.
  Syncing disks.

  查看分区信息:
  [root@db01 ~]# fdisk -l
  ...  

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

   

  查看分区表信息:

  [root@db01 ~]# cat /proc/partitions
  major minor #blocks name

  2 0 4 fd0
  8 0 52428800 sda
  8 1 1048576 sda1
  8 2 51379200 sda2
  11 0 4415488 sr0
  253 0 47181824 dm-0
  253 1 4194304 dm-1
  8 16 10485760 sdb
  8 17 2097152 sdb1

   如果看不到分区,使用以下命令让内核重读分区表:

  [root@db01 ~]# partprobe /dev/sdb

  

  (3)开始格式化:

  

  [root@db01 ~]# mke2fs -t ext4 -L TEST -b 2048 -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, 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

  (4)调整默认挂载选项:

  [root@db01 ~]# tune2fs -o acl /dev/sdb1
  tune2fs 1.42.9 (28-Dec-2013)

  (5) 查看文件系统属性:

  [root@db01 ~]# tune2fs -l /dev/sdb1
  tune2fs 1.42.9 (28-Dec-2013)
  Filesystem volume name: TEST
  Last mounted on: <not available>
  Filesystem UUID: b2a72bff-c449-43dc-98f2-8a4a1da3b4fb
  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: Mon Jan 6 12:04:04 2020
  Last mount time: n/a
  Last write time: Mon Jan 6 12:14:45 2020
  Mount count: 0
  Maximum mount count: -1
  Last checked: Mon Jan 6 12:04:04 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: eab2d0e7-3e3e-456c-b9b7-8e1ab820fd67
  Journal backup: inode blocks

   (6)设置开机自动挂载:

  [root@db01 ~]# mkdir /test
  [root@db01 ~]# vim /etc/fstab
  [root@db01 ~]# cat /etc/fstab 

  #
  # /etc/fstab
  # Created by anaconda on Thu Nov 7 13:07:01 2019
  #
  # 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
  #
  /dev/mapper/centos-root / xfs defaults 0 0
  UUID=0a4a57b3-645c-4c03-beba-a6a9a4242549 /boot xfs defaults 0 0
  /dev/mapper/centos-swap swap swap defaults 0 0
  /dev/sdb1 /test ext4 defaults 0 0
  [root@db01 ~]# mount -a

  

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

(1)添加磁盘,创建分区类型为LVM  

  [root@db01 ~]# echo "- - -" > /sys/class/scsi_host/host0/scan
  [root@db01 ~]# lsblk
  NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
  fd0 2:0 1 4K 0 disk
  sda 8:0 0 50G 0 disk
  ├─sda1 8:1 0 1G 0 part /boot
  └─sda2 8:2 0 49G 0 part
  ├─centos-root 253:0 0 45G 0 lvm /
  └─centos-swap 253:1 0 4G 0 lvm [SWAP]
  sdb 8:16 0 10G 0 disk
  └─sdb1 8:17 0 2G 0 part /test
  sdc 8:32 0 40G 0 disk
  sr0 11:0 1 4.2G 0 rom /media

  [root@db01 ~]# 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): 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-83886079, default 2048):
  Using default value 2048
  Last sector, +sectors or +size{K,M,G} (2048-83886079, default 83886079): +10G
  Partition 1 of type Linux and of size 10 GiB is set

  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 (20973568-83886079, default 20973568):
  Using default value 20973568
  Last sector, +sectors or +size{K,M,G} (20973568-83886079, default 83886079): +10G
  Partition 2 of type Linux and of size 10 GiB is set

  Command (m for help): t
  Partition number (1,2, default 2): 1
  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,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): w
  The partition table has been altered!

  Calling ioctl() to re-read partition table.
  Syncing disks.
  [root@db01 ~]# cat /proc/partitions
  major minor #blocks name

  2 0 4 fd0
  8 16 10485760 sdb
  8 17 2097152 sdb1
  8 0 52428800 sda
  8 1 1048576 sda1
  8 2 51379200 sda2
  11 0 4415488 sr0
  253 0 47181824 dm-0
  253 1 4194304 dm-1
  8 32 41943040 sdc
  8 33 10485760 sdc1
  8 34 10485760 sdc2

  [root@db01 ~]# partprobe /dev/sdc

(2)创建PV,VG

  [root@db01 ~]# pvcreate /dev/sdc1
  Physical volume "/dev/sdc1" successfully created.
  [root@db01 ~]# pvcreate /dev/sdc2
  Physical volume "/dev/sdc2" successfully created.
  [root@db01 ~]# vgcreate -s 16M testvg /dev/sdc1
  Volume group "testvg" successfully created
  [root@db01 ~]# vgs testvg
  VG #PV #LV #SN Attr VSize VFree
  testvg 1 0 0 wz--n- 9.98g 9.98g
  [root@db01 ~]# pvs /dev/sdc1
  PV VG Fmt Attr PSize PFree
  /dev/sdc1 testvg lvm2 a-- 9.98g 9.98g
  [root@db01 ~]# vgdisplay testvg
  --- Volume group ---
  VG Name testvg
  System ID
  Format lvm2
  Metadata Areas 1
  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 1
  Act PV 1
  VG Size 9.98 GiB
  PE Size 16.00 MiB
  Total PE 639
  Alloc PE / Size 0 / 0
  Free PE / Size 639 / 9.98 GiB
  VG UUID dvu6f0-5l57-VDtM-7kKy-g3q5-umUc-hBg7E9

  [root@db01 ~]# vgextend testvg /dev/sdc2
  Volume group "testvg" successfully extended
  [root@db01 ~]# vgdisplay testvg
  --- Volume group ---
  VG Name testvg
  System ID
  Format lvm2
  Metadata Areas 2
  Metadata Sequence No 2
  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 dvu6f0-5l57-VDtM-7kKy-g3q5-umUc-hBg7E9

 (3)创建LV并挂载

  [root@db01 ~]# lvcreate -L 5G -n testlv testvg
  Logical volume "testlv" created.
  [root@db01 ~]# mkdir /users
  [root@db01 ~]# ls /dev/mapper/
  centos-root centos-swap control testvg-testlv
  [root@db01 ~]# mke2fs -t ext4 -b 1024 -L TESTLV /dev/testvg/testlv
  mke2fs 1.42.9 (28-Dec-2013)
  Filesystem label=TESTLV
  OS type: Linux
  Block size=1024 (log=0)
  Fragment size=1024 (log=0)
  Stride=0 blocks, Stripe width=0 blocks
  327680 inodes, 5242880 blocks
  262144 blocks (5.00%) reserved for the super user
  First data block=1
  Maximum filesystem blocks=38797312
  640 block groups
  8192 blocks per group, 8192 fragments per group
  512 inodes per group
  Superblock backups stored on blocks:
  8193, 24577, 40961, 57345, 73729, 204801, 221185, 401409, 663553,
  1024001, 1990657, 2809857, 5120001

  Allocating group tables: done
  Writing inode tables: done
  Creating journal (32768 blocks): done
  Writing superblocks and filesystem accounting information: done

  [root@db01 ~]# mount /dev/testvg/testlv /users/

原文地址:https://www.cnblogs.com/mark-dq/p/12009402.html