2020-06-01

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

# 把原有的yum源配置文件移动到备份文件夹
[root@centos7 cd]# cd /etc/yum.repos.d/
[root@centos7 yum.repos.d]# ls
CentOS-Base.repo       CentOS-fasttrack.repo  CentOS-Vault.repo
CentOS-CR.repo         CentOS-Media.repo      CentOS-x86_64-kernel.repo
CentOS-Debuginfo.repo  CentOS-Sources.repo

[root@centos7 yum.repos.d]# mkdir backup
[root@centos7 yum.repos.d]# mv CentOS-* backup

# 挂载光盘到/misc/cd目录下,也可以是其他目录
[root@centos7 yum.repos.d]# cd /misc/cd
[root@centos7 cd]# ls
CentOS_BuildTag  GPL       LiveOS    RPM-GPG-KEY-CentOS-7
EFI              images    Packages  RPM-GPG-KEY-CentOS-Testing-7
EULA             isolinux  repodata  TRANS.TBL

# 创建指向本地yum源的配置文件,必须是.repo结尾
[root@centos7 yum.repos.d]# cat base.repo
[base]                        # 为yum源起一个名字,也可以是其他名字,但是参考原有的配置文件还是叫base
name=local_iso                # yum源的描述信息,也可以不写
baseurl=file:///misc/cd       # yum源的路径,指向光盘中repodata目录所在的路径
gpgcheck=0                    # 是否开启校验,0是不校验,默认为1

# 清除原有yum源缓存,这一步必须做,否则会出错
[root@centos7 ~]# yum clean all
Loaded plugins: fastestmirror, langpacks
Cleaning repos: base
Cleaning up list of fastest mirrors
Other repos take up 38 M of disk space (use --verbose for details)


# 生成现有yum源的元数据缓存,可以不执行,如果不执行,在安装数据包时,会自动下载缓存
[root@centos7 ~]# yum makecache
Loaded plugins: fastestmirror, langpacks
Determining fastest mirrors
base                                                                    | 4.0 kB  00:00:00     
(1/4): base/group_gz                                                    | 242 kB  00:00:00     
(2/4): base/primary_db                                                  | 4.7 MB  00:00:00     
(3/4): base/other_db                                                    | 2.8 MB  00:00:00     
(4/4): base/filelists_db                                                | 6.3 MB  00:00:00     
Metadata Cache Created

# 列出yum源
[root@centos7 ~]# yum repolist
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
repo id                                    repo name                                     status
base                                       local_iso                                     6,713
repolist: 6,713

1.2 创建网络源

# 先查看httpd包是否安装,如果没有安装通过yum安装,http服务器地址192.168.227.128
[root@centos7 ~]# rpm -q httpd
httpd-2.4.6-90.el7.centos.x86_64

# 启动httpd服务
[root@centos7 ~]# systemctl start httpd
[root@centos7 ~]# systemctl status httpd
● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
   Active: active (running) since Sat 2020-05-30 23:12:58 CST; 110ms ago
     Docs: man:httpd(8)
           man:apachectl(8)
           
# 模仿aliyun的yum源路径,在httpd主目录下创建子目录
[root@centos7 ~]# mkdir -p /var/www/html/centos/{6,7}/os/x86_64
[root@centos7 ~]# tree /var/www/html/centos
/var/www/html/centos
├── 6
│   └── os
│       └── x86_64
└── 7
    └── os
        └── x86_64

# 分别挂载CentOS6和CentOS7的光盘到相应文件夹
[root@centos7 ~]# mount /dev/sr0 /var/www/html/centos/6/os/x86_64/
mount: /dev/sr0 is write-protected, mounting read-only
[root@centos7 ~]# mount /dev/sr1 /var/www/html/centos/7/os/x86_64/
mount: /dev/sr1 is write-protected, mounting read-only

# CentOS6上修改客户端的配置文件
[root@CentOS6 yum.repos.d]#cat base.repo
[base]
name=http_yum
baseurl=http://192.168.227.128/centos/$releasever/os/$basearch/
gpgcheck=0

[root@CentOS6 yum.repos.d]#yum clean all
Loaded plugins: fastestmirror, refresh-packagekit, security
Cleaning repos: base
Cleaning up Everything
Cleaning up list of fastest mirrors

[root@CentOS6 yum.repos.d]#yum makecache
Loaded plugins: fastestmirror, refresh-packagekit, security
Determining fastest mirrors
base                                                                    | 4.0 kB     00:00     
base/group_gz                                                           | 242 kB     00:00     
base/filelists_db                                                       | 6.3 MB     00:00     
base/primary_db                                                         | 4.7 MB     00:00     
base/other_db                                                           | 2.8 MB     00:00     
Metadata Cache Created

[root@CentOS6 yum.repos.d]#yum repolist
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
repo id                                     repo name                                    status
base                                        http_yum                                     6713
repolist: 6713


# 在CentOS7上修改客户端配置文件
[root@centos7 yum.repos.d]#cat base.repo
[base]
name=http_yum
baseurl=http://192.168.227.128/centos/$releasever/os/$basearch/
gpgcheck=0

[root@centos7 yum.repos.d]#yum clean all
Loaded plugins: fastestmirror, langpacks
Repodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fast
Cleaning repos: base
Cleaning up list of fastest mirrors
Other repos take up 56 M of disk space (use --verbose for details)


[root@centos7 yum.repos.d]#yum makecache
Loaded plugins: fastestmirror, langpacks
Determining fastest mirrors
base                                                                    | 3.6 kB  00:00:00     
(1/4): base/7/x86_64/group_gz                                           | 165 kB  00:00:00     
(2/4): base/7/x86_64/filelists_db                                       | 3.3 MB  00:00:00     
(3/4): base/7/x86_64/primary_db                                         | 3.2 MB  00:00:00     
(4/4): base/7/x86_64/other_db                                           | 1.3 MB  00:00:00     
Metadata Cache Created

[root@centos7 yum.repos.d]#yum repolist
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
repo id                                        repo name                                 status
base/7/x86_64                                  http_yum                                  4,067
repolist: 4,067

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

# 解压httpd软件包

[root@centos7 data]# tar xf httpd-2.4.39.tar.bz2

# 进入到目录中,可以先看一下INSTALL和README文件,里面写了安装方法

[root@centos7 data]# cd httpd-2.4.39/# 在安装之前,先把需要的软件包装上,如果没有提前装,在执行configure时会提示,也可以根据提示安装;也可以直接安装“Development Tools”开发包组

[root@centos7 httpd-2.4.39]#yum install gcc apr-devel apr-util-devel pcre-devel openssl-devel -y

# 执行configure开启特性和检测安装环境,可以使用./configure --help来查看选项,这里只指定了安装目录为/app/httpd2.4.39,开启了ssl加密功能,在执行完毕之后可以使用echo $?查看执行结果

[root@centos7 httpd-2.4.39]# ./configure --prefix=/app/httpd2.4.39 --enable-ssl

# 执行make命令编译,可以跟-j选项指定编译的核心个数,个数越多编译越快,我只有单核的处理器,就不指定了,过程可能会比较长,执行完毕之后使用echo $?查看结果

[root@centos7 httpd-2.4.39]# make

# 执行make install安装

[root@centos7 httpd-2.4.39]# make install

# 修改环境变量,我这里是临时修改,要永久修改可以写到配置文件中

[root@centos7 bin]# PATH="/app/httpd2.4.39/bin:$PATH"

[root@centos7 bin]# which apachectl /app/httpd2.4.39/bin/apachectl

# 启动服务,启动时可能会报域名错误,找到配置文件中ServerName一行,去掉前面的#即可

[root@centos7 bin]# apachectl start

# 访问测试,通过CentOS6客户端访问成功

[root@CentOS6 ~]#curl 192.168.227.128

It works!

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

# 先通过fdisk分出来一个2G的分区/dev/sda8
[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    2G  0 part [SWAP]
├─sda6              8:6    0   10G  0 part 
├─sda7              8:7    0   10G  0 part 
│ └─testvg-testlv 253:0    0    4G  0 lvm  
└─sda8              8:8    0    2G  0 part 
sdb                 8:16   0   20G  0 disk 
└─sdb1              8:17   0   10G  0 part 
sr0                11:0    1  3.7G  0 rom  
sr1                11:1    1  4.4G  0 rom 

# 创建文件系统
[root@centos7 ~]# mkfs.ext4 -b 2048 -L 'TEST' -m 1 /dev/sda8
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 

# 把挂载信息写入/etc/fstab文件中,实现开机自动挂载,在CentOS7上默认就支持acl权限,所以权限写defaults即可,这里的/dev/sda8也可以写成UUID,UUID可以通过blkid命令查
[root@centos7 ~]# cat /etc/fstab

#
# /etc/fstab
# Created by anaconda on Thu Apr 16 12:30:24 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=6d9afe5c-50af-4d28-9855-2292ba1ef3c0 /                       xfs     defaults        0 0
UUID=7a87851a-947b-41a6-96e0-a0f6a1a20069 /boot                   xfs     defaults        0 0
UUID=87c89478-a67c-4f92-9d99-3924cce70351 /data                   xfs     defaults        0 0
UUID=131563e5-7253-495b-bb20-c7873c76cdb9 swap                    swap    defaults        0 0
/dev/sda8                                 /test                   ext4    defaults        0 0

# 在CentOS6上默认挂载权限不包括acl,需要指定acl权限挂载
[root@CentOS6 ~]#cat /etc/fstab
#
# /etc/fstab
# Created by anaconda on Sun Dec 11 11:13:37 2016
#
# 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=2bb39d88-9d3d-4675-b842-213ad94b1f30 /                       ext4    defaults        1 1
UUID=347e9532-1408-47a0-bb6a-b4d2bf886e31 /boot                   ext4    defaults        1 2
/dev/sdb3                                 /test                   ext4    acl             1 2
UUID=31bf342f-8f6e-4e13-959c-4ee6e4bd1110 swap                    swap    defaults        0 0
tmpfs                   /dev/shm                tmpfs   defaults        0 0
devpts                  /dev/pts                devpts  gid=5,mode=620  0 0
sysfs                   /sys                    sysfs   defaults        0 0
proc                    /proc                   proc    defaults        0 0

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

# 先划分出来/dev/sda7和/dev/sdb1两个分区,大小都为10G
[root@centos7 ~]# lsblk /dev/sda7
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda7   8:7    0  10G  0 part 
[root@centos7 ~]# lsblk /dev/sdb1
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sdb1   8:17   0  10G  0 part 

# 创建pv
[root@centos7 ~]# pvcreate /dev/sda7 /dev/sdb1
  Physical volume "/dev/sda7" successfully created.
  Physical volume "/dev/sdb1" successfully created.
[root@centos7 ~]# pvs
  PV         VG Fmt  Attr PSize  PFree 
  /dev/sda7     lvm2 ---  10.00g 10.00g
  /dev/sdb1     lvm2 ---  10.00g 10.00g
  
# 创建testvg,指定PE为16M
[root@centos7 ~]# vgcreate -s 16M testvg /dev/sda7 /dev/sdb1
  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
  
# 创建testlv,大小为5G
[root@centos7 ~]# lvcreate -n testlv -L 5G testvg
  Logical volume "testlv" created.
[root@centos7 ~]# lvs
  LV     VG     Attr       LSize Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  testlv testvg -wi-a----- 5.00g
  
# 创建文件系统
[root@centos7 ~]# mkfs.ext4 /dev/testvg/testlv 
[root@centos7 ~]# blkid /dev/testvg/testlv
/dev/testvg/testlv: UUID="847705c0-a8b1-432b-a89e-2d8feec446cd" TYPE="ext4"

# 挂载至/user目录
[root@centos7 ~]# mkdir /users
[root@centos7 ~]# mount /dev/testvg/testlv /users
[root@centos7 ~]# df /users
Filesystem                 Size  Used Avail Use% Mounted on
/dev/mapper/testvg-testlv  4.8G   20M  4.6G   1% /users

你可能感兴趣的:(2020-06-01)