linux自建yum仓库、编译安装httpd、硬盘管理

有些话、适合烂在心里 提交于 2020-12-05 17:58:53

一、自建yum仓库,分别为网络源和本地源
(一)本地源
1、挂载安装光盘,复制光盘上所有文件到/repo/下。
2、备份 /etc/yum.repos.d/CentOS-Base.repo。
3、修改/etc/yum.repos.d/CentOS-Base.repo文件为以下内容即可本地安装各种软件。



[BaseOS]
name=BaseOS
baseurl=file:///repo/BaseOS
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
[AppStream]
name=Appstream
baseurl=file:///repo/AppStream/
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial

(二)网络源

1、安装httpd,提供网络服务。

[root@centos8 ~]#yum -y install httpd
[root@cengos8 ~]#systemctl enable --now httpd
Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.

2、创建文件夹,存放下载的软件包。

[root@centos8 ~]#mkdir /var/www/html/centos -pv
mkdir: 已创建目录 '/var/www/html/centos'

3、下载阿里云extras源的全部软件。

[root@centos8 ~]#dnf reposync --repoid=extras --download-metadata -p /var/www/html/centos
CentOS-8 - Extras - mirrors.aliyun.com                                                                                                              21 kB/s | 1.5 kB     00:00    
CentOS-8 - Extras - mirrors.aliyun.com                                                                                                              46 kB/s |  13 kB     00:00    
(1/30): centos-release-ansible-29-1-2.el8.noarch.rpm                                                                                                62 kB/s | 8.4 kB     00:00    
(2/30): centos-release-advanced-virtualization-1.0-2.el8.noarch.rpm                                                                                 95 kB/s |  15 kB     00:00    
(3/30): centos-release-ceph-nautilus-1.2-2.el8.noarch.rpm                                                                                           48 kB/s | 8.8 kB     00:00    
(4/30): centos-release-ceph-octopus-1.0-1.el8.noarch.rpm                                                                                           150 kB/s | 8.8 kB     00:00    
(5/30): centos-release-configmanagement-1-1.el8.noarch.rpm                                                                                         144 kB/s | 8.7 kB     00:00    
(6/30): centos-release-gluster7-1.0-2.el8.noarch.rpm                                                                                               159 kB/s | 9.5 kB     00:00    
(7/30): centos-release-gluster6-1.0-1.el8.noarch.rpm                                                                                               137 kB/s | 9.3 kB     00:00    
(8/30): centos-release-gluster8-1.0-1.el8.noarch.rpm                                                                                               113 kB/s | 9.3 kB     00:00    
(9/30): centos-release-nfs-ganesha28-1.0-3.el8.noarch.rpm                                                                                          169 kB/s | 8.7 kB     00:00    
(10/30): centos-release-messaging-1-2.el8.noarch.rpm                                                                                                72 kB/s | 9.4 kB     00:00    
(11/30): centos-release-nfs-ganesha30-1.0-2.el8.noarch.rpm                                                                                          95 kB/s | 8.6 kB     00:00    
(12/30): centos-release-nfv-common-1-2.el8.noarch.rpm                                                                                               64 kB/s | 8.7 kB     00:00    
(13/30): centos-release-nfv-extras-1-2.el8.noarch.rpm                                                                                              110 kB/s | 8.4 kB     00:00    
(14/30): centos-release-openstack-train-2-1.el8.noarch.rpm                                                                                         189 kB/s |  11 kB     00:00    
(15/30): centos-release-nfv-openvswitch-1-2.el8.noarch.rpm                                                                                          63 kB/s | 8.4 kB     00:00    
(16/30): centos-release-openstack-ussuri-1-4.el8.noarch.rpm                                                                                        134 kB/s |  11 kB     00:00    
(17/30): centos-release-openstack-victoria-1-1.el8.noarch.rpm                                                                                      191 kB/s | 9.9 kB     00:00    
(18/30): centos-release-opstools-1-10.el8.noarch.rpm                                                                                               187 kB/s | 9.9 kB     00:00    
(19/30): centos-release-qpid-proton-1-2.el8.noarch.rpm                                                                                             124 kB/s | 8.3 kB     00:00    
(20/30): centos-release-rabbitmq-38-1-2.el8.noarch.rpm                                                                                             106 kB/s | 8.3 kB     00:00    
(21/30): centos-release-ovirt44-1.0-1.el8.noarch.rpm                                                                                                93 kB/s |  15 kB     00:00    
(22/30): centos-release-samba412-1.0-1.el8.noarch.rpm                                                                                              126 kB/s | 8.8 kB     00:00    
(23/30): centos-release-samba411-1.0-1.el8.noarch.rpm                                                                                               74 kB/s | 8.8 kB     00:00    
(24/30): centos-release-samba413-1.0-1.el8.noarch.rpm                                                                                              121 kB/s | 8.8 kB     00:00    
(25/30): centos-release-storage-common-2-2.el8.noarch.rpm                                                                                          153 kB/s | 9.4 kB     00:00    
(26/30): centos-release-stream-8.1-1.1911.0.7.el8.x86_64.rpm                                                                                       201 kB/s |  11 kB     00:00    
(27/30): centos-release-virt-common-1-2.el8.noarch.rpm                                                                                             157 kB/s | 8.9 kB     00:00    
(28/30): elrepo-release-8.1-1.el8.elrepo.noarch.rpm                                                                                                257 kB/s |  14 kB     00:00    
(29/30): cpaste-1.0.0-3.el8.x86_64.rpm                                                                                                             487 kB/s |  42 kB     00:00    
(30/30): epel-release-8-8.el8.noarch.rpm                                                                                                           559 kB/s |  23 kB     00:00 

4、浏览器输入源地址http://10.0.0.8/centos/extras/查看,可以正常访问即可。

linux自建yum仓库、编译安装httpd、硬盘管理

5、局域网上其他需要使用此源的用户将相应.repo文件地址进行修改,即可不通过互联网安装软件,如需其他源的软件,只要将其他源下载即可。

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

1、安装前先关闭系统防火墙和SELinux 。

2、安装编译过程需要的包,如编译过程报错需要查看错误信息查找所需的包。

[root@centos8 ~]#dnf install tar gcc make apr-devel apr-util-devel pcre-devel openssl-devel redhat-rpm-config

3、下载安装包。

[root@centos8 ~]#wget https://mirrors.aliyun.com/apache/httpd/httpd-2.4.46.tar.gz

4、解压缩安装包。

[root@centos8 ~]#tar xvf httpd-2.4.46.tar.gz -C /usr/local/src

5、配置安装,必须在软件包所在目录进行操作。

[root@centos8 ~]#cd /usr/local/src/httpd-2.4.46/
[root@centos8 ~]#./configure --prefix=/apps/httpd24 --sysconfdir=/etc/httpd24 --enable-ssl

6、开始编译和安装。

[root@centos8 ~]#make -j 4 && make install

7、配置环境变量。

[root@centos8 ~]#echo 'PATH=/apps/httpd24/bin:$PATH' > /etc/profile.d/httpd24.sh
[root@centos8 ~]#. /etc/profile.d/httpd24.sh

8、启动服务。

[root@centos8 ~]#apachectl

9、检测是否正常运行。

[root@centos8 ~]#ps aux | grep httpd
root       23702  0.0  0.2 117572  5440 ?        Ss   10:52   0:00 /apps/httpd24/bin/httpd
daemon     23703  0.0  0.6 2057948 14024 ?       Sl   10:52   0:00 /apps/httpd24/bin/httpd
daemon     23704  0.0  0.6 2123484 13720 ?       Sl   10:52   0:00 /apps/httpd24/bin/httpd
daemon     23705  0.0  0.6 2057948 13720 ?       Sl   10:52   0:00 /apps/httpd24/bin/httpd

​ 服务已正常运行,浏览器输入地址检查是否能够正常显示。

linux自建yum仓库、编译安装httpd、硬盘管理

如无法打开请检查防火墙和SElinux是否关闭。

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

1、给系统添加一块20G的硬盘,并让系统识别。

[root@centos8 ~]#echo "- - -" > /sys/class/scsi_host/host2/scan
[root@centos8 ~]#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   49G  0 part [SWAP]
sdb      8:16   0   20G  0 disk 
sr0     11:0    1  1.6G  0 rom 

2、划分一个2G的分区。

[root@centos8 ~]#fdisk /dev/sdb

Welcome to fdisk (util-linux 2.32.1).
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.
Created a new DOS disklabel with disk identifier 0x294c9482.

Command (m for help): n
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p): 

Using default response p.
Partition number (1-4, default 1): 
First sector (2048-41943039, default 2048): 
Last sector, +sectors or +size{K,M,G,T,P} (2048-41943039, default 41943039): +2G

Created a new partition 1 of type 'Linux' and of size 2 GiB.

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

[root@centos8 ~]#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   49G  0 part [SWAP]
sdb      8:16   0   20G  0 disk 
└─sdb1   8:17   0    2G  0 part 
sr0     11:0    1  1.6G  0 rom  

3、格式化分区,创建文件系统。

[root@centos88 ~]#mkfs.ext4  -b 2048 -m 1 -L TEST /dev/sdb1
mke2fs 1.45.4 (23-Sep-2019)
Creating filesystem with 1048576 2k blocks and 131072 inodes
Filesystem UUID: cdc6525f-4817-4903-a0ba-00bd1bd4d98f
Superblock backups stored on blocks: 
    16384, 49152, 81920, 114688, 147456, 409600, 442368, 802816

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

4、创建/test目录。

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

5、将配置写入/etv/fatab。

[root@centos8 ~]#vim /etc/fstab
# 
# /etc/fstab
# Created by anaconda on Wed Dec  2 17:57: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.
#
# After editing this file, run 'systemctl daemon-reload' to update systemd
# units generated from this file.
#
UUID=daf7d458-735f-4397-99ef-1a85a0858b88 /                xfs     defaults        0 0
UUID=f1956afd-9e82-4940-803e-ec09d067de8e /boot            ext4    defaults        1 2
UUID=92bd3322-5a96-4f66-bdb2-477868d22851 /data            xfs     defaults        0 0
UUID=6874faf8-8828-4451-bf18-c0c486bc9791 swap             swap    defaults        0 0
UUID=cdc6525f-4817-4903-a0ba-00bd1bd4d98f /test            ext4    acl             0 0

6、重启,查看是否成功。

[root@centos8 ~]#reboot

[root@centos8 ~]#df -h
Filesystem      Size  Used Avail Use% Mounted on
devtmpfs        964M     0  964M   0% /dev
tmpfs           981M     0  981M   0% /dev/shm
tmpfs           981M  8.7M  972M   1% /run
tmpfs           981M     0  981M   0% /sys/fs/cgroup
/dev/sda2       100G  2.5G   98G   3% /
/dev/sda3        50G  390M   50G   1% /data
/dev/sdb1       2.0G  9.1M  2.0G   1% /test
/dev/sda1       976M  104M  806M  12% /boot
tmpfs           197M     0  197M   0% /run/user/1000

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

1、增加两块硬盘,并让系统识别。

[root@centos8 ~]#echo "- - -" > /sys/class/scsi_host/host2/scan
[root@centos8 ~]#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   49G  0 part [SWAP]
sdb      8:16   0   20G  0 disk 
└─sdb1   8:17   0    2G  0 part /test
sdc      8:32   0   20G  0 disk 
sdd      8:48   0   20G  0 disk 
sr0     11:0    1  1.6G  0 rom

2、新增的两块硬盘分别划分10G分区。

[root@centos8 ~]#echo -e 'n\np\n\n\n+10G\nw\n' | fdisk /dev/sdc

Welcome to fdisk (util-linux 2.32.1).
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.
Created a new DOS disklabel with disk identifier 0xbe801379.

Command (m for help): Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p): Partition number (1-4, default 1): First sector (2048-41943039, default 2048): Last sector, +sectors or +size{K,M,G,T,P} (2048-41943039, default 41943039): 
Created a new partition 1 of type 'Linux' and of size 10 GiB.

Command (m for help): The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

[root@centos8 ~]#echo -e 'n\np\n\n\n+10G\nw\n' | fdisk /dev/sdd

Welcome to fdisk (util-linux 2.32.1).
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.
Created a new DOS disklabel with disk identifier 0x3bbfea2f.

Command (m for help): Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p): Partition number (1-4, default 1): First sector (2048-41943039, default 2048): Last sector, +sectors or +size{K,M,G,T,P} (2048-41943039, default 41943039): 
Created a new partition 1 of type 'Linux' and of size 10 GiB.

Command (m for help): The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

[root@centos8 ~]#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   49G  0 part [SWAP]
sdb      8:16   0   20G  0 disk 
└─sdb1   8:17   0    2G  0 part /test
sdc      8:32   0   20G  0 disk 
└─sdc1   8:33   0   10G  0 part 
sdd      8:48   0   20G  0 disk 
└─sdd1   8:49   0   10G  0 part 
sr0     11:0    1  1.6G  0 rom  

3、安装lvm2。

[root@centos8 ~]#yum install -y lvm2

4、新加的硬盘创建物理卷。

[root@centos8 ~]#pvcreate /dev/sdc1
  Physical volume "/dev/sdc1" successfully created.
[root@centos8 ~]#pvcreate /dev/sdd1
  Physical volume "/dev/sdd1" successfully created.

5、创建卷组。

[root@centos8 ~]#vgcreate  testvg -s 16M /dev/sdc1 /dev/sdd1
  Volume group "testvg" successfully created

[root@centos8 ~]#vgs
  VG     #PV #LV #SN Attr   VSize   VFree  
  testvg   2   0   0 wz--n- <19.97g <19.97g

[root@centos8 ~]#vgdisplay testvg
  --- 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               vjeH0o-YVjO-0MRg-muoK-pXdI-gK3k-STd6G4

6、创建逻辑卷。

[root@centos8 ~]#lvcreate -L 5G -n testlv testvg
  Logical volume "testlv" created.

[root@centos88 ~]#lvs
  LV     VG     Attr       LSize Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  testlv testvg -wi-a----- 5.00g               

[root@centos8 ~]#lvdisplay /dev/testvg/testlv
  --- Logical volume ---
  LV Path                /dev/testvg/testlv
  LV Name                testlv
  VG Name                testvg
  LV UUID                XRGF2B-bscm-SS6Y-sPu0-icp7-Ig9g-1kex1v
  LV Write Access        read/write
  LV Creation host, time centos88.wj3721.top, 2020-12-03 16:23:55 +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:0

7、格式化逻辑卷。

[root@centos8 ~]#mkfs.ext4 /dev/testvg/testlv
mke2fs 1.45.4 (23-Sep-2019)
Creating filesystem with 1310720 4k blocks and 327680 inodes
Filesystem UUID: 0c069581-ca1a-4060-811a-94bff8a0c872
Superblock backups stored on blocks: 
    32768, 98304, 163840, 229376, 294912, 819200, 884736

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

8、挂载。

[root@centos8 ~]#mkdir /users
[root@centos8 ~]#mount /dev/testvg/testlv /users
[root@centos8 ~]#df -h
Filesystem                 Size  Used Avail Use% Mounted on
devtmpfs                   964M     0  964M   0% /dev
tmpfs                      981M     0  981M   0% /dev/shm
tmpfs                      981M  8.7M  972M   1% /run
tmpfs                      981M     0  981M   0% /sys/fs/cgroup
/dev/sda2                  100G  2.5G   98G   3% /
/dev/sda3                   50G  390M   50G   1% /data
/dev/sdb1                  2.0G  9.1M  2.0G   1% /test
/dev/sda1                  976M  104M  806M  12% /boot
tmpfs                      197M     0  197M   0% /run/user/1000
/dev/mapper/testvg-testlv  4.9G   20M  4.6G   1% /users
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!