第六周作业

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

[root@centos7-02 ~]# cd /etc/yum.repos.d/
[root@centos7-02 yum.repos.d]# ls
CentOS-Base.repo  CentOS-Debuginfo.repo  CentOS-Media.repo    CentOS-Vault.repo
CentOS-CR.repo    CentOS-fasttrack.repo  CentOS-Sources.repo
[root@centos7-02 yum.repos.d]# mkdir repo.bak
[root@centos7-02 yum.repos.d]# mv *.repo repo.bak/
[root@centos7-02 yum.repos.d]# vim Centos7.repo
[root@centos7-02 yum.repos.d]# cat Centos7.repo 
[Base]
name=Base
baseurl=file:///media/
enable=1
gpgcheck=0
[root@centos7-02 yum.repos.d]# yum repolist
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Base                                                       | 3.6 kB  00:00:00     
(1/2): Base/group_gz                                       | 166 kB  00:00:00     
(2/2): Base/primary_db                                     | 6.0 MB  00:00:00     
repo id                                repo name                            status
Base                                   Base                                 10,019
repolist: 10,019

配置网络源

[root@centos7-02 yum.repos.d]# cat Centos7_network.repo 
[network_base_repo]
name=centos7_network_base_repo
baseurl=https://mirrors.aliyun.com/centos/7/os/x86_64/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

[network_epel_repo]
name=centos7_network_epel_repo
baseurl=https://mirrors.aliyun.com/epel/7/x86_64/
gpgcheck=0

[network_updates_repo]
name=centos7_network_updates_repo
baseurl=https://mirrors.aliyun.com/centos/7/updates/x86_64/
gpgcheck=0

[root@centos7-02 yum.repos.d]# yum repolist
Loaded plugins: fastestmirror
Determining fastest mirrors
Base                                                       | 3.6 kB  00:00:00     
network_base_repo                                          | 3.6 kB  00:00:00     
network_epel_repo                                          | 4.7 kB  00:00:00     
network_updates_repo                                       | 2.9 kB  00:00:00     
(1/8): Base/group_gz                                       | 166 kB  00:00:00     
(2/8): Base/primary_db                                     | 6.0 MB  00:00:00     
(3/8): network_base_repo/group_gz                          | 153 kB  00:00:00     
(4/8): network_epel_repo/group_gz                          |  95 kB  00:00:00     
(5/8): network_epel_repo/updateinfo                        | 1.0 MB  00:00:01     
(6/8): network_base_repo/primary_db                        | 6.1 MB  00:00:04     
(7/8): network_epel_repo/primary_db                        | 6.9 MB  00:00:05     
(8/8): network_updates_repo/primary_db                     | 4.7 MB  00:00:06     
repo id                           repo name                                 status
Base                              Base                                      10,019
network_base_repo                 centos7_network_base_repo                 10,072
network_epel_repo                 centos7_network_epel_repo                 13,501
network_updates_repo              centos7_network_updates_repo               1,155
repolist: 34,747

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

#安装依赖包
[root@centos7-02 src]#yum install -y gcc make apr-devel apr-util-devel pcre-devel openssl-devel redhat-rpm-config
[root@centos7-02 src]# pwd
/usr/local/src
[root@centos7-02 src]# ll
total 9148
drwxr-sr-x 11 root   40    4096 Aug  1 10:11 httpd-2.4.46
#上传解压安装包
[root@centos7-02 src]# tar -zxvf httpd-2.4.46.tar.gz 
[root@centos7-02 src]# ll
total 9148
drwxr-sr-x 11 root   40    4096 Aug  1 10:11 httpd-2.4.46
-rw-r--r--  1 root root 9363314 Dec 30 02:32 httpd-2.4.46.tar.gz
#配置
[root@centos7-02 src]#cf httpd-2.4.46/
[root@centos7-02 httpd-2.4.46]# ./configure --prefix=/usr/local/http24 --sysconfdir=/etc/http24 --enable-ssl
#编译安装
[root@centos7-02 httpd-2.4.46]# make -j 4 && make install
#修改环境变量
[root@centos7-02 httpd-2.4.46]# echo 'PATH=/usr/local/http24/bin:$PATH' > /etc/profile.d/httpd24.sh
[root@centos7-02 httpd-2.4.46]# source /etc/profile.d/httpd24.sh
[root@centos7-02 httpd-2.4.46]# echo $PATH
/usr/local/http24/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
#指定运行用户
[root@centos7-02 httpd-2.4.46]# useradd -r -s /sbin/nologin -d /var/www -c Apache -u 48 apache
[root@centos7-02 httpd-2.4.46]# vim /etc/http24/httpd.conf 
User apache
Group apache
#启动HTTP
[root@centos7-02 httpd-2.4.46]# apachectl start
#查看状态
[root@centos7-02 httpd-2.4.46]# netstat -ntlp | grep :80
tcp6       0      0 :::80                   :::*                    LISTEN      24950/httpd 
[root@centos7-02 httpd-2.4.46]# ps -ef | grep httpd
apache    25043  24950  0 02:53 ?        00:00:00 /usr/local/http24/bin/httpd
[root@centos7-02 httpd-2.4.46]# curl http://192.168.246.21
<html><body><h1>It works!</h1></body></html>

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

[root@centos7-02 httpd-2.4.46]#ifconfig | grep "inet\>" | sed -n 's/.*inet[[:space:]]\+\(.*\)[[:space:]]\+netmask.*/\1/pg'
192.168.246.21
127.0.0.1 
[root@centos7-02 httpd-2.4.46]#ifconfig eth0 | sed -n '2s/^.*inet[[:space:]]//;s/[[:space:]]\+netmask.*//p'
192.168.246.21

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

[16:40:01 root@centos8-01 data]#sed -i '/^#/s/^# //' /etc/fstab
[16:40:01 root@centos8-01 data]#cat /etc/fstab

#
/etc/fstab
Created by anaconda on Fri Oct 30 10:56:09 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.
#
/dev/mapper/cl-root                          /                       xfs     defaults        0 0
UUID=f83057d7-0945-484b-bf18-366d8e9f43df    /boot                   ext4    defaults        1 2
/dev/mapper/cl-swap                          swap                    swap    defaults        0 0
UUID=643d9286-72e1-42b4-b8cf-59aaf93a5381    /mysql/data            ext4    defaults         0 0    

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

#取目录名
[root@centos7-02 httpd-2.4.46]# echo /etc/fstab | sed -nr 's#(.*)/([^/]+)/?#\1#p'
/etc
#取基名
[root@centos7-02 httpd-2.4.46]# echo /etc/fstab | sed -nr 's#(.*)/([^/]+)/?#\2#p'
fstab
posted @ 2020-12-30 16:44  gody2019  阅读(104)  评论(1)    收藏  举报