2021-01-02第六周

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

1)基于本地光盘创建yum源

#将本地光盘挂载到/misc/cd目录
[04:55:18  root@base ~]#yum -y install autofs
[04:56:26  root@base ~]#systemctl start autofs
[04:56:33  root@base ~]#systemctl enable autofs
[04:57:02  root@base ~]#cd /misc/cd
[04:57:43  root@base cd]#ls
CentOS_BuildTag  EULA  images    LiveOS    repodata              RPM-GPG-KEY-CentOS-Testing-7
EFI              GPL   isolinux  Packages  RPM-GPG-KEY-CentOS-7  TRANS.TBL
[04:58:11  root@base cd]#df -h 
Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/centos-root   17G  1.4G   16G   9% /
devtmpfs                 476M     0  476M   0% /dev
tmpfs                    488M     0  488M   0% /dev/shm
tmpfs                    488M  7.6M  480M   2% /run
tmpfs                    488M     0  488M   0% /sys/fs/cgroup
/dev/sda1               1014M  130M  885M  13% /boot
tmpfs                     98M     0   98M   0% /run/user/0
/dev/sr0                 8.8G  8.8G     0 100% /misc/cd
#创建本地光盘源的repo文件
[05:23:46  root@base cd]#cat /etc/yum.repos.d/loacl.repo 
[local_base]
name=local_base
baseurl=file:///misc/cd
enable=1
gpgcheck=0
#查看yum源的仓库列表,可以看到手动创建的本地光盘源生效
[05:23:34  root@base cd]#yum repolist
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
local_base                                                                                    | 3.6 kB  00:00:00     
(1/2): local_base/group_gz                                                                    | 166 kB  00:00:00     
(2/2): local_base/primary_db                                                                  | 5.9 MB  00:00:00     
repo id                                 repo name                                                              status
base/7/x86_64                           CentOS-7 - Base - mirrors.aliyun.com                                   10,072
epel/x86_64                             Extra Packages for Enterprise Linux 7 - x86_64                         13,504
extras/7/x86_64                         CentOS-7 - Extras - mirrors.aliyun.com                                    448
local_base                              local_base                                                              9,911
updates/7/x86_64                        CentOS-7 - Updates - mirrors.aliyun.com                                 1,155
repolist: 35,090

2)基于本地的网络yum源(web服务httpd)

注:centos8充当服务端,base充当客户端

服务器端配置:
[03:39:07  root@centos8 ~]#yum -y install  httpd
[03:39:07  root@centos8 ~]# systemctl start httpd
[03:39:07  root@centos8 ~]#ss -nultp | grep :80
[03:39:07  root@centos8 ~]#cp -av /misc/cd/AppStream/ /misc/cd/BaseOS/ /var/www/html/data/
[03:39:07  root@centos8 ~]#cd /var/www/html/data/
[03:39:07  root@centos8 data]#createrepo  .
[03:43:15  root@centos8 data]#ls
AppStream  BaseOS  repodata

客户端配置:
[06:37:41  root@base ~]#cat /etc/yum.repos.d/http.repo
[http_base]
name=http_base
baseurl=http://192.168.10.30/data
enable=1
gpgcheck=0
[06:44:34  root@base ~]#yum repolist
\Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
repo id                                 repo name                                                             status
base/7/x86_64                           CentOS-7 - Base - mirrors.aliyun.com                                  10,072
epel/x86_64                             Extra Packages for Enterprise Linux 7 - x86_64                        13,504
extras/7/x86_64                         CentOS-7 - Extras - mirrors.aliyun.com                                   448
http_base                               http_base                                                              6,774
updates/7/x86_64                        CentOS-7 - Updates - mirrors.aliyun.com                                1,155
repolist: 31,953

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

#编译安装httpd软件
[10:38:53  root@base ]#mv /root/httpd-2.4.46.tar.gz  /usr/local/src
[10:38:53  root@base src]#tar -xf httpd-2.4.46.tar.gz
[10:38:53  root@base httpd-2.4.46]#yum -y install gcc make
#执行 ./configure生成makefile文件时报错,缺少以下包安装即可
[10:38:53  root@base httpd-2.4.46]#./configure
[10:38:53  root@base httpd-2.4.46]#yum -y isntall apr-devel.x86_64
[10:38:53  root@base httpd-2.4.46]#yum -y install apr-util-devel.x86_64
[10:38:53  root@base httpd-2.4.46]#yum -y install pcre-devel-8.32-17.el7.x86_64
[10:38:53  root@base httpd-2.4.46]#./configure
[10:38:53  root@base httpd-2.4.46]#make && make install
#启动httpd服务:
[10:49:15  root@base apache2]#./bin/apachectl 
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using fe80::20c:29ff:fe08:cc83. Set the 'ServerName' directive globally to suppress this message
#查看服务端口:
[11:26:35  root@base apache2]#ss -nltp | grep :80 
LISTEN     0      128         :::80                      :::*                   users:(("httpd",pid=20144,fd=4),("httpd",pid=20062,fd=4),("httpd",pid=20061,fd=4),("httpd",pid=20060,fd=4),("httpd",pid=20058,fd=4))

启动Apache服务可以看到下面的初始界面


1609605196(1).jpg

3、利用sed 取出ifconfig命令中本机的IPv4地址

[20:24:10  root@base ~]#ifconfig ens32 | sed -nr '2s/(.*inet )([0-9].*)( netmask.*)/\2/p'
192.168.10.21 
[20:31:44  root@base ~]#ifconfig ens32 | sed -nr '2s/[^0-9]+([0-9.]+).*/\1/p'
192.168.10.21
[20:33:17  root@base ~]#ifconfig ens32 | sed -nr '2s/^[^0-9]+([0-9.]+) .*$/\1/p'
192.168.10.21

4、删除/etc/fstab文件中所有以#开头,后面至少跟一个空白字符的行的行首的#和空白字符

[20:44:12  root@base ~]#cat /data/fstab 

#
# /etc/fstab
# Created by anaconda on Fri Sep 18 09:14:37 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
#
/dev/mapper/centos-root /                       xfs     defaults        0 0
UUID=4a4824a6-7cbd-4f25-9579-b51cce5b937c /boot                   xfs     defaults        0 0
/dev/mapper/centos-swap swap                    swap    defaults        0 0
[20:44:07  root@base ~]#sed -nr 's/^[^#](.*)/\1/p' /data/fstab 
dev/mapper/centos-root /                       xfs     defaults        0 0
UID=4a4824a6-7cbd-4f25-9579-b51cce5b937c /boot                   xfs     defaults        0 0
dev/mapper/centos-swap swap                    swap    defaults        0 0

5、处理/etc/fstab路径,使用sed命令取出其目录名和基名

#取基名:
[20:52:29  root@base ~]#echo /etc/fstab | sed -nr 's/(^\/.*\/)([^/]+\/?)/\2/p'
fstab
#取目录名
[20:52:34  root@base ~]#echo /etc/fstab | sed -nr 's/(^\/.*\/)([^/]+\/?)/\1/p'
/etc/

命令取基名、目录名
[20:53:05  root@base ~]#basename /etc/fstab 
fstab
[20:55:47  root@base ~]#dirname /etc/fstab 
/etc

你可能感兴趣的:(2021-01-02第六周)