一、自建yum仓库,分别为网络源和本地源;
配置本地源
- 建立本地源目录;
[root@localhost ~]#mkdir /mnt/cdrom
[root@localhost ~]#mkdir /yum
- 挂载Centos光盘;
[root@localhost ~]#mount /dev/cdrom /mnt/cdrom
[root@localhost ~]cp -r /mnt/cdrom/* /yum
- 备份repo;
[root@localhost ~]#cd /etc/yum.repo.d/
[root@localhost yum.repos.d]#mkdir backup
[root@localhost yum.repos.d]#mv CentOS-Base.repo CentOS-CR.repo CentOS-Vault.repo CentOS-Vault.repo ./backup
- 编辑Centos-Media.repo;
[root@localhost yum.repos.d]#cat Centos-Media.repo
[base]
name=Centos
baseurl=file:///yum
enable=1
gpgckeck=0
gpgkey=file:///mnt/cdrom/RPM-GPG-KEY-CentOS-7
- 清除yum缓存;
[root@localhost yum.repos.d]#yum clean all
配置网络源
- 备份源镜像文件;
[root@localhost yum.repos.d]# mv centos* ./backup
- 下载阿里云的镜像到/etc/yum.repos.d/;
[root@localhost yum.repos.d]# wget -O /etc/yum.repos.d/CentOS-Base.repo
(地址:http://mirrors.aliyun.com/repo/Centos-7.repo)
- 清除yum缓存;
[root@localhost yum.repos.d]# yum clean all
[root@localhost yum.repos.d]# yum makecache
二、编译安装http2.4,实现可以正常访问;
关闭防火墙和selinux:https://www.jianshu.com/p/97c3c4012c4c
1、在 Apache 官网下载最新版的http2.4
2、服务器端下载;
[root@localhost yum.repos.d]# cd /usr/local/src
[root@localhost src]# wget https://mirrors.tuna.tsinghua.edu.cn/apache//httpd/httpd-2.4.43.tar.gz
--2020-07-14 14:43:05-- https://mirrors.tuna.tsinghua.edu.cn/apache//httpd/httpd-2.4.43.tar.gz
正在解析主机 mirrors.tuna.tsinghua.edu.cn (mirrors.tuna.tsinghua.edu.cn)... 101.6.8.193, 2402:f000:1:408:8100::1
正在连接 mirrors.tuna.tsinghua.edu.cn (mirrors.tuna.tsinghua.edu.cn)|101.6.8.193|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:9348230 (8.9M) [application/x-gzip]
正在保存至: “httpd-2.4.43.tar.gz”
100%[==============================================================================================>] 9,348,230 1.96MB/s 用时 4.5s
2020-07-14 14:43:10 (1.96 MB/s) - 已保存 “httpd-2.4.43.tar.gz” [9348230/9348230])
[root@localhost src]# ls
httpd-2.4.43.tar.gz nginx-1.14.2 nginx-1.14.2.tar.gz
3、解包;
[root@localhost src]# tar xzvf httpd-2.4.43.tar.gz
[root@localhost src]# ll
总用量 10128
drwxr-sr-x 11 root 40 4096 3月 26 22:46 httpd-2.4.43
-rw-r--r-- 1 root root 9348230 3月 30 22:21 httpd-2.4.43.tar.gz
drwxr-xr-x 9 1001 1001 186 6月 13 14:45 nginx-1.14.2
-rw-r--r-- 1 root root 1015384 12月 4 2018 nginx-1.14.2.tar.gz
[root@localhost src]# cd httpd-2.4.43/
[root@localhost httpd-2.4.43]# ls
ABOUT_APACHE ap.d CHANGES docs httpd.spec libhttpd.dep Makefile.win README srclib
acinclude.m4 build CMakeLists.txt emacs-style include libhttpd.dsp modules README.cmake support
Apache-apr2.dsw BuildAll.dsp config.layout httpd.dep INSTALL libhttpd.mak NOTICE README.platforms test
Apache.dsw BuildBin.dsp configure httpd.dsp InstallBin.dsp LICENSE NWGNUmakefile ROADMAP VERSIONING
apache_probes.d buildconf configure.in httpd.mak LAYOUT Makefile.in os server
4、查看 README 和 INSTALL;
执行./configure --prefix=/apps/httpd24 --sysconfdir=/etc/httpd --enable-ssl --enable-so
5、可能会有依赖的包未安装,根据其提示安装即可(一般为缺啥,安装啥-devel);
[root@localhost httpd-2.4.43]# ./configure --prefix=/apps/httpd24 --sysconfdir=/etc/httpd --enable-ssl --enable-so
checking for chosen layout... Apache
checking for working mkdir -p... yes
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/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.
[root@localhost httpd-2.4.43]# yum install apr-devel -y
重复第4,5步 直到成功安装生成 Makefile 文件
[root@localhost httpd-2.4.43]# make -j4
[root@localhost httpd-2.4.43]# make install
6、启动访问;
[root@localhost httpd-2.4.43]# cd /apps/
httpd24/ nginx/
[root@localhost httpd-2.4.43]# cd /apps/httpd24/
[root@localhost httpd24]# ls
bin build cgi-bin error htdocs icons include logs man manual modules
[root@localhost httpd24]# cd bin
[root@localhost bin]# ls
ab apxs dbmmanage envvars-std htcacheclean htdigest httpd logresolve
apachectl checkgid envvars fcgistarter htdbm htpasswd httxt2dbm rotatelogs
[root@localhost bin]# ./apachectl
[root@localhost bin]# ps aux|grep http
root 22644 0.0 0.1 74932 2388 ? Ss 14:57 0:00 /apps/httpd24/bin/httpd -k start
daemon 22645 0.0 0.2 429432 4216 ? Sl 14:57 0:00 /apps/httpd24/bin/httpd -k start
daemon 22646 0.0 0.2 429432 4216 ? Sl 14:57 0:00 /apps/httpd24/bin/httpd -k start
daemon 22647 0.0 0.2 429432 4216 ? Sl 14:57 0:00 /apps/httpd24/bin/httpd -k start
root 22739 0.0 0.0 112824 980 pts/0 S+ 14:58 0:00 grep --color=auto http
[root@localhost bin]# lsof -i:80
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
httpd 22644 root 4u IPv6 39358 0t0 TCP *:http (LISTEN)
httpd 22645 daemon 4u IPv6 39358 0t0 TCP *:http (LISTEN)
httpd 22646 daemon 4u IPv6 39358 0t0 TCP *:http (LISTEN)
httpd 22647 daemon 4u IPv6 39358 0t0 TCP *:http (LISTEN)
[root@localhost bin]# curl 192.168.1.111
<html><body><h1>It works!</h1></body></html>
访问
三、创建一个2G的文件系统,块大小为2048byte,预留1%可用空间,文件系统 ext4,卷标为TEST,要求此分区开机后自动挂载至/test目录,且默认有acl挂载选项;
1、查看块设备信息;
[root@localhost ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 20G 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 19G 0 part
├─centos-root 253:0 0 17G 0 lvm /
└─centos-swap 253:1 0 2G 0 lvm [SWAP]
sdb 8:16 0 10G 0 disk
sr0 11:0 1 918M 0 rom
以下将在sdb磁盘作为操作目标
2、在sdb磁盘上创建大小为2G的分区;
[root@localhost ~]# 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 0xb6901c7c.
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 #大小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@localhost ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 20G 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 19G 0 part
├─centos-root 253:0 0 17G 0 lvm /
└─centos-swap 253:1 0 2G 0 lvm [SWAP]
sdb 8:16 0 10G 0 disk
└─sdb1 8:17 0 2G 0 part ############创建的2G分区
sr0 11:0 1 918M 0 rom
3、在sdb1分区上创建文件系统;
[root@localhost ~]# 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
[root@localhost ~]# blkid
/dev/sda1: UUID="61bfe580-8947-41c1-91c0-0e3422e7d468" TYPE="xfs"
/dev/sda2: UUID="e2U6Yk-baaU-nYV4-UZxe-Uewf-etbD-yBNpQX" TYPE="LVM2_member"
/dev/sdb1: LABEL="TEST" UUID="e598b458-c2ba-4bbe-a2b7-7791be1278fb" TYPE="ext4"
/dev/sr0: UUID="2018-11-25-21-21-31-00" LABEL="CentOS 7 x86_64" TYPE="iso9660" PTTYPE="dos"
/dev/mapper/centos-root: UUID="a5cdc275-8211-41ab-b6b3-3dec286dd8b9" TYPE="xfs"
/dev/mapper/centos-swap: UUID="46e70da6-8858-46a4-a187-71b59a52b95b" TYPE="swap"
4、将分区挂载到指定文件夹;
[root@localhost ~]# vim /etc/fstab
----最后一行在命令行模式执行 :r!blkid /dev/sdb1 然后回车
将粘贴的一行修改为:
UUID=e598b458-c2ba-4bbe-a2b7-7791be1278fb /test ext4 acl 0 0
5、创建目标文件夹,并手动使配置文件生效;
[root@localhost ~]# mkdir /test
[root@localhost ~]# mount -a
[root@localhost ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 20G 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 19G 0 part
├─centos-root 253:0 0 17G 0 lvm /
└─centos-swap 253:1 0 2G 0 lvm [SWAP]
sdb 8:16 0 10G 0 disk
└─sdb1 8:17 0 2G 0 part /test
sr0 11:0 1 918M 0 rom
[root@localhost ~]# df -h /test
Filesystem Size Used Avail Use% Mounted on
/dev/sdb1 2.0G 9.1M 1.9G 1% /test
四、创建一个至少有两个PV组成的大小为20G的名为testvg的VG;要求PE大小 为16MB, 而后在卷组中创建大小为5G的逻辑卷testlv;挂载至/users目录;
1、查看硬盘信息;
[root@localhost ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 20G 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 19G 0 part
├─centos-root 253:0 0 17G 0 lvm /
└─centos-swap 253:1 0 2G 0 lvm [SWAP]
sdb 8:16 0 10G 0 disk
└─sdb1 8:17 0 2G 0 part /test
sdc 8:32 0 15G 0 disk
sdd 8:48 0 15G 0 disk
sr0 11:0 1 918M 0 rom
以下将使用整块sdc和sdd各10G空间共同创建物理卷组
2、在sdc和sdd硬盘上各创建10G的分区;
------sdc
[root@localhost ~]# 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 0xddedf037.
Command (m for help): p
Disk /dev/sdc: 16.1 GB, 16106127360 bytes, 31457280 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0xddedf037
Device Boot Start End Blocks Id System
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-31457279, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-31457279, default 31457279): +10G
Partition 1 of type Linux and of size 10 GiB is set
Command (m for help): P
Disk /dev/sdc: 16.1 GB, 16106127360 bytes, 31457280 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0xddedf037
Device Boot Start End Blocks Id System
/dev/sdc1 2048 20973567 10485760 83 Linux
Command (m for help): t
Selected partition 1
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'
Command (m for help): p
Disk /dev/sdc: 16.1 GB, 16106127360 bytes, 31457280 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0xddedf037
Device Boot Start End Blocks Id System
/dev/sdc1 2048 20973567 10485760 8e Linux LVM
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
------sdd
[root@localhost ~]# fdisk /dev/sdd
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 0xcf6c8040.
Command (m for help): p
Disk /dev/sdd: 16.1 GB, 16106127360 bytes, 31457280 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0xcf6c8040
Device Boot Start End Blocks Id System
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-31457279, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-31457279, default 31457279): +10G
Partition 1 of type Linux and of size 10 GiB is set
Command (m for help): T
Selected partition 1
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'
Command (m for help): p
Disk /dev/sdd: 16.1 GB, 16106127360 bytes, 31457280 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0xcf6c8040
Device Boot Start End Blocks Id System
/dev/sdd1 2048 20973567 10485760 8e Linux LVM
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
查询硬盘信息:
[root@localhost ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 20G 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 19G 0 part
├─centos-root 253:0 0 17G 0 lvm /
└─centos-swap 253:1 0 2G 0 lvm [SWAP]
sdb 8:16 0 10G 0 disk
└─sdb1 8:17 0 2G 0 part /test
sdc 8:32 0 15G 0 disk
└─sdc1 8:33 0 10G 0 part
sdd 8:48 0 15G 0 disk
└─sdd1 8:49 0 10G 0 part
sr0 11:0 1 918M 0 rom
3、在sdc1和sdd1分区上分别创建物理卷(pv);
[root@localhost ~]# pvcreate /dev/sdc1
Physical volume "/dev/sdc1" successfully created.
[root@localhost ~]# pvcreate /dev/sdd1
Physical volume "/dev/sdd1" successfully created.
[root@localhost ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/sda2 centos lvm2 a-- <19.00g 0
/dev/sdc1 lvm2 --- 10.00g 10.00g
/dev/sdd1 lvm2 --- 10.00g 10.00g
4、创建物理卷组(vg)为testvg,并将以上的pv加入其中;
[root@localhost ~]# vgcreate -s 16M testvg /dev/sdc1 /dev/sdd1
Volume group "testvg" successfully created
[root@localhost ~]# vgs
VG #PV #LV #SN Attr VSize VFree
centos 1 2 0 wz--n- <19.00g 0
testvg 2 0 0 wz--n- <19.97g <19.97g
5、在testvgz中创建大小为5G的逻辑卷(lv)卷名testlv;
[root@localhost ~]# lvcreate -n testlv -L 5G testvg
Logical volume "testlv" created.
[root@localhost ~]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
root centos -wi-ao---- <17.00g
swap centos -wi-ao---- 2.00g
testlv testvg -wi-a----- 5.00g
[root@localhost ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 20G 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 19G 0 part
├─centos-root 253:0 0 17G 0 lvm /
└─centos-swap 253:1 0 2G 0 lvm [SWAP]
sdb 8:16 0 10G 0 disk
└─sdb1 8:17 0 2G 0 part /test
sdc 8:32 0 15G 0 disk
└─sdc1 8:33 0 10G 0 part
└─testvg-testlv 253:2 0 5G 0 lvm
sdd 8:48 0 15G 0 disk
└─sdd1 8:49 0 10G 0 part
sr0 11:0 1 918M 0 rom
6、创建文件系统;
[root@localhost ~]# 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@localhost ~]# blkid
/dev/sda1: UUID="61bfe580-8947-41c1-91c0-0e3422e7d468" TYPE="xfs"
/dev/sda2: UUID="e2U6Yk-baaU-nYV4-UZxe-Uewf-etbD-yBNpQX" TYPE="LVM2_member"
/dev/sdb1: LABEL="TEST" UUID="e598b458-c2ba-4bbe-a2b7-7791be1278fb" TYPE="ext4"
/dev/sdc1: UUID="pPMjyj-x14w-wfFk-Sfao-XslB-BJve-yXGBrU" TYPE="LVM2_member"
/dev/sdd1: UUID="e8Kn4u-wfah-2zF1-nIdL-izYf-lIWh-KvGjje" TYPE="LVM2_member"
/dev/sr0: UUID="2018-11-25-21-21-31-00" LABEL="CentOS 7 x86_64" TYPE="iso9660" PTTYPE="dos"
/dev/mapper/centos-root: UUID="a5cdc275-8211-41ab-b6b3-3dec286dd8b9" TYPE="xfs"
/dev/mapper/centos-swap: UUID="46e70da6-8858-46a4-a187-71b59a52b95b" TYPE="swap"
/dev/mapper/testvg-testlv: UUID="94464a8b-758d-474c-bf56-55b76c425b19" TYPE="ext4"
7、在/etc/fstab配置文件中添加以下内容;
UUID=94464a8b-758d-474c-bf56-55b76c425b19 /users ext4 defaults 0 0
8、创建目标文件夹,并手动使配置文件生效;
[root@localhost ~]# mkdir /users
[root@localhost ~]# mount -a
[root@localhost ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 20G 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 19G 0 part
├─centos-root 253:0 0 17G 0 lvm /
└─centos-swap 253:1 0 2G 0 lvm [SWAP]
sdb 8:16 0 10G 0 disk
└─sdb1 8:17 0 2G 0 part /test
sdc 8:32 0 15G 0 disk
└─sdc1 8:33 0 10G 0 part
└─testvg-testlv 253:2 0 5G 0 lvm /users
sdd 8:48 0 15G 0 disk
└─sdd1 8:49 0 10G 0 part
sr0 11:0 1 918M 0 rom
[root@localhost ~]# df -h /users
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/testvg-testlv 4.8G 20M 4.6G 1% /users
至此,逻辑卷testlv已经可以正常使用了
[root@localhost ~]# cd /users
[root@localhost users]# echo "life is shit" >a.txt
[root@localhost users]# ll
total 20
-rw-r--r-- 1 root root 13 Jul 15 14:48 a.txt
drwx------ 2 root root 16384 Jul 15 14:35 lost+found
[root@localhost users]# cat a.txt
life is shit
测试:
生成一个1G的文件在/user目录
[root@localhost users]# dd if=/dev/zero of=/users bs=1G count=1
dd: failed to open ‘/users’: Is a directory
[root@localhost users]# dd if=/dev/zero of=/users/b.txt bs=1G count=1
1+0 records in
1+0 records out
1073741824 bytes (1.1 GB) copied, 21.8943 s, 49.0 MB/s
[root@localhost users]# ll -h b.txt
-rw-r--r-- 1 root root 1.0G Jul 15 14:53 b.txt
[root@localhost users]# df -h /users
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/testvg-testlv 4.8G 1.1G 3.6G 23% /users