软件包管理及磁盘存储和文件系统相关经典问题

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

# 两种其实内容都是一样的内容,不过区别就是:如果当前主机连接了互联网,yum可以直接通过互联网下载软件包,如果是内网的话,那就需要自己配置了,需要配置的文件和仓库。在/etc/yum.repos.d/目录下已经存放好了yum库和配置文件,可以直接利用他进行软件管理,但最好改成国内的源,因为速度更快

# 先配置本地源吧,就用centos盘作为本地源
# 把光盘挂载到/mnt目录下
[root@localhost yum.repos.d]#mount /dev/cdrom /mnt
mount: /dev/sr0 is write-protected, mounting read-only

[root@localhost yum.repos.d]#lsblk
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
...
sr0              11:0    1 10.3G  0 rom  /mnt

# 在当前目录下,创建一个.repo文件
# 写入如下信息
[root@localhost yum.repos.d]#cat base.repo 
[base]
name=CentOS-$releasever - Base # 源的名字
baseurl=file:///mnt		# 用文件路径的方式写出挂载点为源路径
gpgcheck=1		# 安装包时启用gpg检查
gpgkey=file:///mnt/RPM-GPG-KEY-CentOS-7		# gpg检查时候需要的公钥


# 用如下命令检查一下是否添加成功
[root@localhost mnt]#yum repolist 
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
http://192.168.1.4/dnf/repodata/repomd.xml: [Errno 14] HTTP Error 404 - Not Found
Trying other mirror.
To address this issue please refer to the below wiki article 

https://wiki.centos.org/yum-errors

If above article doesn't help to resolve this issue please use https://bugs.centos.org/.

repo id                                         repo name                                          status
base                                            CentOS-7 - Base                                    10,097



# 网络源的添加和本地差不多,以阿里云的EPEL源为例
[root@localhost yum.repos.d]#cat epel.repo 
[epel]
name=aliyun epel
baseurl=https://mirrors.aliyun.com/epel/$releasever/$basearch/
# 用变量的方式显示版本号和架构
gpgcheck=0
enable=1
# 检查一下
[root@localhost mnt]#yum repolist 
[root@localhost mnt]#yum repolist 
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
http://192.168.1.4/dnf/repodata/repomd.xml: [Errno 14] HTTP Error 404 - Not Found
Trying other mirror.
To address this issue please refer to the below wiki article 

https://wiki.centos.org/yum-errors

If above article doesn't help to resolve this issue please use https://bugs.centos.org/.

repo id                                         repo name                                          status
base                                            CentOS-7 - Base                                    10,097

epel/7/x86_64                                   aliyun epel                                        13,22

# 成功

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

http-2.4.39

# 编译安装 http2.4

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

# 提一嘴:一些编译工具
# gcc
# 项目管理工具 :C C++ : make 项目管理器
# jave: maven 项目管理器
# makefile需要生成
# 通过configure脚本生成Makefile.in——>Makefile
# configure脚本中需要添加功能和路径

# 所以
# c语言源代码编译安装三步骤:
# 1、通过选项传递参数,指定启用特性,安装路径等;执行时会参考用户的指定以及Makefile.in文件生成Makefile	之后检查依赖到的外部环境,如依赖的软件包
# 2、make 根据Makefile文件,构建应用程序
# 3、 make install 复制文件到相应路径


# 拿到http2.4文件解压
[root@localhost data]#tar -xvf httpd-2.4.39.tar.gz
[root@localhost data]#ls
httpd-2.4.39  httpd-2.4.39.tar.gz

# 第一步:通过选项传递参数,指定启用特性,安装路径等;执行时会参考用户的指定以及Makefile.in文件生成Makefile	之后检查依赖到的外部环境,如依赖的软件包

# 接上面
[root@localhost data]#ls
httpd-2.4.39  httpd-2.4.39.tar.gz
[root@localhost data]#cd httpd-2.4.39/
[root@localhost httpd-2.4.39]#ls
ABOUT_APACHE     BuildBin.dsp    emacs-style     LAYOUT        NOTICE            srclib
acinclude.m4     buildconf       httpd.dep       libhttpd.dep  NWGNUmakefile     support
Apache-apr2.dsw  CHANGES         httpd.dsp       libhttpd.dsp  os                test
Apache.dsw       CMakeLists.txt  httpd.mak       libhttpd.mak  README            VERSIONING
apache_probes.d  config.layout   httpd.spec      LICENSE       README.cmake
ap.d             configure       include         Makefile.in   README.platforms
build            configure.in    INSTALL         Makefile.win  ROADMAP
BuildAll.dsp     docs            InstallBin.dsp  modules       server

# 一般源码包的解压缩目录内会有README和INSTALL说明,有必要浏览一下,看看说了些什么

[root@localhost httpd-2.4.39]#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

   ...
  ----------

  To obtain help with installation problems, please see the resources at
  <http://httpd.apache.org/support.html>

  Thanks for using the Apache HTTP Server, version 2.4.

                                     The Apache Software Foundation
                                     http://www.apache.org/
# 四步嗷
[root@localhost httpd-2.4.39]#./configure --help
# 这个是看./configure 支持的选项及功能的

# 我想指定安装目录在/apps/http24下,配置文件安装在/etc/httpd24目录下,启用ssl加密功能
[root@localhost httpd-2.4.39]#./configure --prefix=/apps/httpd24 \
> --sysconfdir=/etc/httpd24 \
> --enable-ssl
checking for chosen layout... Apache
checking for working mkdir -p... yes
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking target system type... x86_64-pc-linux-gnu
configure: 
configure: Configuring Apache Portable Runtime library...
configure: 
checking for APR... no
configure: error: APR not found.  Please read the documentation.
# 注意:提示说错误,缺少某个包,我们只需要在缺少包名后增加devel即可
[root@localhost httpd-2.4.39]#yum install apr-devel
...
# 安装好了继续再来
[root@localhost httpd-2.4.39]#./configure --prefix=/apps/httpd24 \
> --sysconfdir=/etc/httpd24 \
> --enable-ssl
...
checking for APR-util... no
configure: error: APR-util not found.  Please read the documentation.
# 继续装
[root@localhost httpd-2.4.39]#yum install  apr-util-devel
# 再来
[root@localhost httpd-2.4.39]#./configure --prefix=/apps/httpd24 \
> --sysconfdir=/etc/httpd24 \
> --enable-ssl
...
checking for pcre-config... false
configure: error: pcre-config for libpcre not found. PCRE is required and available from http://pcre.org/
# 在装包
[root@localhost httpd-2.4.39]#yum install pcre-devel
# 再来
[root@localhost httpd-2.4.39]#./configure --prefix=/apps/httpd24 --sysconfdir=/etc/httpd24 --enable-ssl
...
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
# 这下好了,还少包
[root@localhost httpd-2.4.39]#yum install openssl-devel
# 再来
[root@localhost httpd-2.4.39]#./configure --prefix=/apps/httpd24 --sysconfdir=/etc/httpd24 --enable-ssl
checking for chosen layout... Apache
checking for working mkdir -p... yes
...
configure: summary of build options:

    Server Version: 2.4.39
    Install prefix: /apps/httpd24
    C compiler:     gcc -std=gnu99
    CFLAGS:           -pthread  
    CPPFLAGS:        -DLINUX -D_REENTRANT -D_GNU_SOURCE  
    LDFLAGS:           
    LIBS:             
    C preprocessor: gcc -E
# 这下好了,看看是否成功
[root@localhost httpd-2.4.39]#echo $?
0


# 第二步:执行安装
[root@localhost httpd-2.4.39]#make install
# 稀里哗啦一阵等待
...
Installing man pages and online manual
mkdir /apps/httpd24/man
mkdir /apps/httpd24/man/man1
mkdir /apps/httpd24/man/man8
mkdir /apps/httpd24/manual
make[1]: Leaving directory `/data/httpd-2.4.39'

# 可以看到,安装后生成的一些文件
[root@localhost httpd-2.4.39]#ls /apps/httpd24/
bin  build  cgi-bin  error  htdocs  icons  include  logs  man  manual  modules
##################
[root@localhost httpd-2.4.39]#ls /etc/httpd24
extra  httpd.conf  magic  mime.types  original
# 接下来该开启来了吧,我们再回头看看INSTALL说了啥
 	$ ./configure --prefix=PREFIX
     $ make
     $ make install
     $ PREFIX/bin/apachectl start
# 最后一行就是启动了
[root@localhost httpd-2.4.39]#/apps/httpd24/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测试一下我的IP
[root@localhost httpd-2.4.39]#curl 192.168.1.4
<html><body><h1>It works!</h1></body></html>

# 成功了,显示了html网页的内容

# 以后为了启动方便,我们将该路径写入PATH变量中
[root@localhost httpd-2.4.39]#echo $PATH
/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
[root@localhost httpd-2.4.39]#echo 'PATH=/apps/httpd24/bin:$PATH' > /etc/profile.d/httpd.sh
[root@localhost httpd-2.4.39]#. /etc/profile.d/httpd.sh

[root@localhost httpd-2.4.39]#echo $PATH
/apps/httpd24/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
# 已经添加成功
# 试试关闭
[root@localhost httpd-2.4.39]#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 httpd-2.4.39]#curl 192.168.1.4
curl: (7) Failed connect to 192.168.1.4:80; Connection refused
# 已经关了
# 再打开
[root@localhost httpd-2.4.39]#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
[root@localhost httpd-2.4.39]#curl 192.168.1.4
<html><body><h1>It works!</h1></body></html>

# ok了

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

# 知识点:MBR分区、mkfs,开机自动挂载

# 看看哪个盘有空间
[root@centos-linux /]# lsblk
NAME               MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda                  8:0    0    64G  0 disk 
├─sda1               8:1    0   500M  0 part /boot
└─sda2               8:2    0  63.5G  0 part 
  ├─VolGroup-lv_root
                   253:0    0    50G  0 lvm  /
  ├─VolGroup-lv_swap
                   253:1    0     2G  0 lvm  [SWAP]
  └─VolGroup-lv_home
                   253:2    0  11.6G  0 lvm  /home
sdb                  8:16   0    10G  0 disk 
└─testvg-testlv    253:3    0     5G  0 lvm  /users
sdc                  8:32   0    10G  0 disk 
sr0                 11:0    1 117.8M  0 rom  /run/media/flamenca/CDROM

# 选sdc

# fdisk打开磁盘设备文件,并创建MBR类型的分区

[root@centos-linux /]# 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 0x6dced5bf.

The device presents a logical sector size that is smaller than
the physical sector size. Aligning to a physical sector (or optimal
I/O) size boundary is recommended, or performance may be impacted.

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-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/sdc: 10.7 GB, 10737418240 bytes, 20971520 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk label type: dos
Disk identifier: 0x6dced5bf

   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.

# 检查 lsblk
[root@centos-linux /]# lsblk
NAME               MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
...
sdc                  8:32   0    10G  0 disk 
└─sdc1               8:33   0     2G  0 part 

# mkfs创建文件系统
# 块大小为2048byte,预留1%可用空间,文件系统 ext4,卷标为TEST
[root@centos-linux /]# mkfs.ext4 -b 2048 -m 1 -L TEST /dev/sdc1
mke2fs 1.42.9 (28-Dec-2013)
Warning: specified blocksize 2048 is less than device physical sectorsize 4096
Discarding device blocks: done                            
Filesystem label=TEST
OS type: Linux
Block size=2048 (log=1)
Fragment size=2048 (log=1)
Stride=2 blocks, Stripe width=2 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@centos-linux /]# partprobe /dev/sdc1
[root@centos-linux /]# cat /proc/partitions 
major minor  #blocks  name

 ...
   8       32   10485760 sdc
   8       33    2097152 sdc1
 ...
 
 # blkid 检查
 [root@centos-linux /]# blkid /dev/sdc1
/dev/sdc1: LABEL="TEST" UUID="19839a72-e350-42b9-9630-9fb16145a68d" TYPE="ext4" 

# 要求此分区开机后自动挂载至/test目录,且默认有acl挂载选项
# 创建挂载点 /test
[root@centos-linux /]# mkdir /test

# 挂载,并启用acl功能
[root@centos-linux /]# mount -o acl /dev/sdc1 /test/

# 检查
[root@centos-linux /]# lsblk
NAME               MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
...
sdc                  8:32   0    10G  0 disk 
└─sdc1               8:33   0     2G  0 part /test

# 实现开机自启
# 打开文件/etc/fstab
# 将下列语句写入其中 
UUID=19839a72-e350-42b9-9630-9fb16145a68d /test                   ext4    defaults        0 0
# 保存退出

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

# 知识点:LVM

# 步骤1:创建两个PV 
# sdb 和 sdc 大小都为10G
[root@centos-linux ~]# lsblk
NAME               MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda                  8:0    0    64G  0 disk 
├─sda1               8:1    0   500M  0 part /boot
└─sda2               8:2    0  63.5G  0 part 
  ├─VolGroup-lv_root
                   253:0    0    50G  0 lvm  /
  ├─VolGroup-lv_swap
                   253:1    0     2G  0 lvm  [SWAP]
  └─VolGroup-lv_home
                   253:2    0  11.6G  0 lvm  /home
sdb                  8:16   0    10G  0 disk 
sdc                  8:32   0    10G  0 disk 
sr0                 11:0    1 117.8M  0 rom  /run/media/flamenca/CDROM
sr1                 11:1    1   8.1G  0 rom  /run/media/flamenca/CentOS 7 x86_64


# 创建PV
[root@centos-linux ~]# pvcreate /dev/sdb
  Physical volume "/dev/sdb" successfully created.
[root@centos-linux ~]# pvcreate /dev/sdc
  Physical volume "/dev/sdc" successfully created.


# 查看一下内容
[root@centos-linux ~]# pvdisplay
  --- Physical volume ---
  PV Name               /dev/sda2
  VG Name               VolGroup
  PV Size               63.51 GiB / not usable 3.00 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              16258
  Free PE               0
  Allocated PE          16258
  PV UUID               mhhGXl-37B4-YCd4-nRmw-1kcC-wBmP-bNf3Rt
   
  "/dev/sdb" is a new physical volume of "10.00 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/sdb
  VG Name               
  PV Size               10.00 GiB
  Allocatable           NO
  PE Size               0   
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               AT1lQB-mNHy-jvgm-wxHp-PxLI-Wz02-xiw30G
   
  "/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               TcF9G1-wSW0-dGD4-dUse-D7rK-DGLt-PJfch7


# 创建成功后来第二步:创建VG
# 要求:20G大小,名为testvg,PE大小为16MB
[root@centos-linux ~]# vgcreate -s 16M testvg /dev/sd{b,c}
  Volume group "testvg" successfully created

# 查看是否成功
[root@centos-linux ~]# vgs
  VG       #PV #LV #SN Attr   VSize   VFree  
  VolGroup   1   3   0 wz--n- <63.51g      0 
  testvg     2   0   0 wz--n- <19.97g <19.97g
  
# vgdisplay
[root@centos-linux ~]# 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               vFlceA-WsQP-YTQR-lNe3-Wd6G-0MwE-BTDxGE

# 创建5G的逻辑卷testlv,挂载到/users目录
# 挂载的命令为mount

# 在testvg中划分testlv
# 大小为5G
[root@centos-linux ~]# lvcreate -n testlv -L 5G testvg
  Logical volume "testlv" created.
  
# 查看一下lvdisplay
[root@centos-linux ~]# lvdisplay
  --- Logical volume ---
  LV Path                /dev/testvg/testlv
  LV Name                testlv
  VG Name                testvg
  LV UUID                sbqDST-WC2P-RAtK-sXzT-LVxh-t4co-RlqBiO
  LV Write Access        read/write
  LV Creation host, time centos-linux.shared, 2020-04-03 03:01:26 +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:3

# 注意:testlv 路径/dev/testvg/testlv事实上是一个软连接,其实际路径在/dev/mapper/testvg-testlv 
# 创建ext4文件系统后再挂载
[root@centos-linux ~]# mkfs.ext4 /dev/testvg/testlv 
mke2fs 1.42.9 (28-Dec-2013)
Discarding device blocks: done                            
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 


# blkid命令检查一下
[root@centos-linux ~]# blkid
/dev/sda1: UUID="3ed13ed8-0019-45e1-bb33-9e92d92fc760" TYPE="ext4" 
/dev/sda2: UUID="mhhGXl-37B4-YCd4-nRmw-1kcC-wBmP-bNf3Rt" TYPE="LVM2_member" 
/dev/sdc: UUID="TcF9G1-wSW0-dGD4-dUse-D7rK-DGLt-PJfch7" TYPE="LVM2_member" 
/dev/sr0: UUID="2020-03-03-23-22-30-00" LABEL="CDROM" TYPE="iso9660" 
/dev/sdb: UUID="AT1lQB-mNHy-jvgm-wxHp-PxLI-Wz02-xiw30G" TYPE="LVM2_member" 
/dev/sr1: UUID="2017-09-06-10-53-42-00" LABEL="CentOS 7 x86_64" TYPE="iso9660" PTTYPE="dos" 
...
/dev/mapper/testvg-testlv: UUID="e9aedf27-fc4e-472e-9865-27b7cf2eab0f" TYPE="ext4" 


# 挂载到 /users 目录下
# 创建挂载点
[root@centos-linux ~]# mkdir /users
# 挂载到/users
[root@centos-linux ~]# mount /dev/testvg/testlv /users
# 检查
[root@centos-linux ~]# df -h
Filesystem                    Size  Used Avail Use% Mounted on
...
/dev/mapper/testvg-testlv     4.8G   20M  4.6G   1% /users


猜你喜欢

转载自blog.csdn.net/FlamencaH/article/details/105305461