第6周

  1. 自建yum仓库,分别为网络源和本地源
    1.1 Yum介绍:
    Yum是一个在Fedora和Redhat以及CentOS中的基于python实现的前端软件包管理器。Yum的实现是基于C/S架构,即要想利用yum,需要在一台主机上建立yum服务器,并在想利用yum安装软件包的主机上配置为yum客户端后,才可以利用yum安装软件包。所谓yum服务器,就是一台部署有相关的rpm包以及对应的yum元数据(包括rpm包的列表清单,包依赖,包说明等信息)的主机。我们将rpm包和yum元数据的集合称为repository(仓库)。当用户用yum安装软件包时,会主动下载仓库的元数据至本地的缓存中,并从中查询对应的软件包是否存在以及软件的依赖关系,将相关的软件包都下载至本地进行安装,安装后默认会删除软件包,单元数据仍保留在缓存中。

    1.2 配置文件介绍:
    所有Yum仓库的配置文件均以.repo结尾并存放在/etc/yum.repos.d/目录中的
    [base]:yum仓库的唯一标识符,一定要避免与其他仓库冲突
    name=:yum仓库的名称描述,用于描述仓库的信息
    baseurl=:提供的方式包括FTP(ftp://...)、HTTP(http://...)、本地(file:///...)
    enabled=:设置此源是否可用,1为可用,0为不可用
    gpgcheck=:1表示安装包时做gpg的检查,0表示不检查
    gpgkey=:如果gpgcheck为校验,则需要指定公钥文件地址

    1.3 配置本地源
    a. 准备神奇目录/misc/cd/,先启动autofs服务:

    systemctl start autofs; 
    systemctl enable autofs;
    systemctl status autofs    --显示active(running)就可以了,显示为亮绿色;
    ls /misc/;
    ls /misc/cd/             --这一步就可以将/dev/sr0挂载至/misc/cd;
    df                            --通过df查看是否成功; 
    

    b.写配置文件

    [root@centos7 yum.repos.d]# vim base.repo
        [base1]
        name=cdrom base
        baseurl=file:///misc/cd
        gpgcheck=0
    [root@centos7 yum.repos.d]# yum clean all
    [root@centos7 yum.repos.d]# yum repolist
        repo id            repo name              status
        base1              cdrom base             4,067
    

    1.4 配置网络源
    a.查看网络源配置文件:

    [root@centos7 ~]# cd /etc/yum.repos.d/
    [root@centos7 yum.repos.d]# ls
        base.repo         CentOS-CR.repo         CentOS-fasttrack.repo       
        CentOS-Sources.repo   CentOS-Base.repo  
        CentOS-Debuginfo.repo  CentOS-Media.repo      
        CentOS-Vault.repo
    

    b.将需要启用的配置文件中的enabled项设置为1

    [root@centos7 yum.repos.d]# vim CentOS-Base.repo         
    [root@centos7 yum.repos.d]# yum repolist
        Loaded plugins: fastestmirror, langpacks
        Loading mirror speeds from cached hostfile
           * base: mirrors.njupt.edu.cn
           * extras: mirrors.163.com
           * updates: mirrors.163.com
        repo id              repo name                status
        base/7/x86_64        CentOS-7 - Base          10,097                                        
        base1                cdrom base               4,067
        extras/7/x86_64      CentOS-7 - Extras        323                            
        updates/7/x86_64     CentOS-7 - Updates       1,446
        repolist: 15,933
    

    1.5配置过程中易错点:

       a. 启动autofs服务
       b. 对于目录/misc/cd/一定要利用cd命令进入,才能完成自动挂载
       c. 对于本地源的配置文件,baseurl一行,共有3个'/',其中第三个表示根目录
    
  2. 编译安装httpd2.4.41,实现可以正常访问,并将编译步骤和结果提交
    2.1 下载httpd2.4.41压缩包,并放置/usr/local/src目录下并解压

    [root@centos7 ~]#cd /usr/local/src
    [root@centos7 src]#ls
        httpd-2.4.41.tar.gz
    [root@centos7 src]#tar xf httpd-2.4.41.tar.gz
    [root@centos7 src]#ls
        httpd-2.4.41  httpd-2.4.41.tar.gz
    

    2.2 安装编译工具及相关的依赖包

    [root@centos7 src]#yum -y install gcc apr-devel apr-util-devel openssl-devel
    

    2.3 进入源码包解压的目录,并执行configure脚本,指定安装路径和功能特性

    [root@centos7 src]#cd httpd-2.4.41/
    [root@centos7 httpd-2.4.41]#./configure --prefix=/app/httpd/ --sysconfdir=/etc/httpd/ --enable-ssl
    

    2.4 执行编译和安装

    [root@centos7 httpd-2.4.41]#make && make install
    

    2.5 设置PATH变量

    [root@centos7 httpd-2.4.41]#cd
    [root@centos7 ~]#echo 'PATH=/app/httpd/bin:$PATH' > /etc/profile.d/httpd.sh
    [root@centos7 ~]#. /etc/profile.d/httpd.sh
    

    2.6 启动服务&&本机查看

    [root@centos7 ~]#apachectl
    [root@centos7 ~]#curl 127.0.0.1
       <html><body><h1>It works!</h1></body></html>
    

    2.7 清空本机的iptables规则,便于其他主机查看

    [root@centos6 ~]#curl 192.168.43.134
       curl: (7) couldn't connect to host
    [root@centos7 ~]#iptables -F
    [root@centos6 ~]#curl 192.168.43.134
      <html><body><h1>It works!</h1></body></html>
    
  3. 创建一个2G的文件系统,块大小为2048byte,预留1%可用空间,文件系统 ext4,卷标为TEST,要求此分区开机后自动挂载至/test目录,且默认有acl挂载选项
    3.1 查看块设备信息,以sdb磁盘作为操作目标

    [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]
    sdb      8:16   0  200G  0 disk 
    sr0     11:0    1  4.4G  0 rom
    

    3.2 在sdb磁盘上创建2G大小的分区

    [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 0x72680aed.
    
    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-419430399, default 2048): 
    Using default value 2048
    Last sector, +sectors or +size{K,M,G} (2048-419430399, default 419430399): +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.
    

    3.3 按照题目要求在sdb1分区上创建文件系统

    [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
    

    3.4 查看结果

    [root@centos7 ~]# blkid
    /dev/sr0: UUID="2019-09-11-18-50-31-00" LABEL="CentOS 7 x86_64" TYPE="iso9660" PTTYPE="dos" 
    /dev/sda1: UUID="a089259d-63ba-4099-966f-d0e753e08650" TYPE="xfs" 
    /dev/sda2: UUID="78e8f470-86be-4e06-9d7a-7f0cc1862827" TYPE="xfs" 
    /dev/sda3: UUID="95ef2603-1f60-459d-b931-16bc81a213f6" TYPE="xfs" 
    /dev/sda5: UUID="36751366-63ee-42ff-bad6-7517bffe6747" TYPE="swap" 
    /dev/sdb1: LABEL="TEST" UUID="e18bb5ef-4ce9-4842-8e5c-3b82f6f7eaae" TYPE="ext4"
    

    3.5 挂载操作

    [root@centos7 ~]# mkdir /test
    [root@centos7 ~]# vim /etc/fstab 
    [root@centos7 ~]# tail -1 /etc/fstab 
    UUID=e18bb5ef-4ce9-4842-8e5c-3b82f6f7eaae /test         ext4    acl     0 0 
    [root@centos7 ~]# mount -a
    [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]
    sdb      8:16   0  200G  0 disk 
    └─sdb1   8:17   0    2G  0 part /test
    sr0     11:0    1  4.4G  0 rom  
    
  4. 创建一个至少有两个PV组成的大小为20G的名为testvg的VG;要求PE大小 为16MB, 而后在卷组中创建大小为5G的逻辑卷testlv;挂载至/users目录
    4.1 在sdb磁盘中新创建两个10G大小分区sdb2,sdb3用于实验,创建过程省略

    [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]
    sdb      8:16   0  200G  0 disk 
    ├─sdb1   8:17   0    2G  0 part /test
    ├─sdb2   8:18   0   10G  0 part 
    └─sdb3   8:19   0   10G  0 part 
    sr0     11:0    1  4.4G  0 rom 
    

    4.2 创建物理卷

    [root@centos7 ~]# pvcreate /dev/sdb2
       Physical volume "/dev/sdb2" successfully created.
    [root@centos7 ~]# pvcreate /dev/sdb3
       Physical volume "/dev/sdb3" successfully created.
    [root@centos7 ~]# pvs
       PV         VG Fmt  Attr PSize  PFree 
       /dev/sdb2     lvm2 ---  10.00g 10.00g
       /dev/sdb3     lvm2 ---  10.00g 10.00g
    

    4.3 创建卷组

    [root@centos7 ~]# vgcreate -s 16M testvg /dev/sdb2 /dev/sdb3
       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
    

    4.4 创建逻辑卷

    [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
    

    4.5 创建文件系统

    [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 
    
    [root@centos7 ~]# blkid
    /dev/sr0: UUID="2019-09-11-18-50-31-00" LABEL="CentOS 7 x86_64" TYPE="iso9660" PTTYPE="dos" 
    /dev/sda1: UUID="a089259d-63ba-4099-966f-d0e753e08650" TYPE="xfs" 
    /dev/sda2: UUID="78e8f470-86be-4e06-9d7a-7f0cc1862827" TYPE="xfs" 
    /dev/sda3: UUID="95ef2603-1f60-459d-b931-16bc81a213f6" TYPE="xfs" 
    /dev/sda5: UUID="36751366-63ee-42ff-bad6-7517bffe6747" TYPE="swap" 
    /dev/sdb1: LABEL="TEST" UUID="e18bb5ef-4ce9-4842-8e5c-3b82f6f7eaae" TYPE="ext4" 
    /dev/sdb2: UUID="ajLYLm-C73p-UHGE-IAqf-3unH-Mt2i-CgrT7m" TYPE="LVM2_member" 
    /dev/sdb3: UUID="d8pWxi-vPBV-p5Bq-9gfR-r6pu-iURt-6FAwEH" TYPE="LVM2_member" 
    /dev/mapper/testvg-testlv: UUID="0a89689f-d794-48d6-be68-a81eb4286fab" TYPE="ext4"
    

    4.6 挂载逻辑卷

    [root@centos7 ~]# mkdir /users
    [root@centos7 ~]# vim /etc/fstab 
    [root@centos7 ~]# tail -1 /etc/fstab 
    UUID=0a89689f-d794-48d6-be68-a81eb4286fab /users          ext4    defaults       0 0
    [root@centos7 ~]# mount -a
    [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]
    sdb                 8:16   0  200G  0 disk 
    ├─sdb1              8:17   0    2G  0 part /test
    ├─sdb2              8:18   0   10G  0 part 
    │ └─testvg-testlv 253:0    0    5G  0 lvm  /users
    └─sdb3              8:19   0   10G  0 part 
    sr0                11:0    1  4.4G  0 rom
    
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 220,492评论 6 513
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 94,048评论 3 396
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 166,927评论 0 358
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 59,293评论 1 295
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 68,309评论 6 397
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 52,024评论 1 308
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 40,638评论 3 420
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 39,546评论 0 276
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 46,073评论 1 319
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 38,188评论 3 340
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 40,321评论 1 352
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,998评论 5 347
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 41,678评论 3 331
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 32,186评论 0 23
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 33,303评论 1 272
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 48,663评论 3 375
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 45,330评论 2 358

推荐阅读更多精彩内容