第六周学习

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

[root@centos7 ~]# mkdir /etc/yum.repos.d/backup
[root@centos7 ~]# mkdir -p /var/www/centos/7/os
[root@centos7 ~]# cp -r /misc/cd/Packages /var/www/centos/7/os/
[root@centos7 ~]# cp -r /misc/cd/repodata /var/www/centos/7/os/
[root@centos7 ~]# cp  /misc/cd/RPM-GPG-KEY-CentOS-7 /var/www/centos/7/
[root@centos7 ~]# mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/backup
[root@centos7 ~]# vim /etc/yum.repos.d/centos7.repo
[base]  优先本地源
name=centos-$releasever-Base
baseurl=file:///var/www/centos/$releasever/os/  
baseurl=https://mirrors.aliyun.com/centos/$releasever/os/$basearch/
gpgcheck=1
enable=1
gpgkey=file:///var/www/centos/$releasever/
gpgkey=https://mirrors.aliyun.com/centos/$releasever/os/$basearch/RPM-GPG-KEY-CentOS-$releasever

[extras]  网络源
name=centos-$releasever-Extras
baseurl=https://mirrors.aliyun.com/centos/$releasever/extras/$basearch/
gpgcheck=1
enable=1
gpgkey=file:///var/www/centos/$releasever/
gpgkey=https://mirrors.aliyun.com/centos/$releasever/os/$basearch/RPM-GPG-KEY-CentOS-$releasever

[updates] 网络源
name=centos-$releasever-Updates
baseurl=https://mirrors.aliyun.com/centos/$releasever/updates/$basearch/
gpgcheck=1
enable=1
gpgkey=file:///var/www/centos/$releasever/
gpgkey=https://mirrors.aliyun.com/centos/$releasever/os/$basearch/RPM-GPG-KEY-CentOS-$releasever

[epel] 网络源
name=centos-$releasever-Epel
baseurl=https://mirrors.aliyun.com/epel/$releasever/x86_64
gpgcheck=1
enable=1
gpgkey=https://mirrors.aliyun.com/epel/RPM-GPG-KEY-EPEL-7
[root@centos7 ~]# yum clean all
[root@centos7 yum.repos.d]# yum repolist
Loaded plugins: fastestmirror
Determining fastest mirrors
base                                                                                                                | 3.6 kB  00:00:00     
epel                                                                                                                | 4.7 kB  00:00:00     
extras                                                                                                              | 2.9 kB  00:00:00     
updates                                                                                                             | 2.9 kB  00:00:00     
(1/7): base/7/x86_64/group_gz                                                                                       | 153 kB  00:00:00     
(2/7): epel/7/group_gz                                                                                              |  96 kB  00:00:00     
(3/7): epel/7/updateinfo                                                                                            | 1.0 MB  00:00:00     
(4/7): base/7/x86_64/primary_db                                                                                     | 6.1 MB  00:00:01     
(5/7): extras/7/x86_64/primary_db                                                                                   | 227 kB  00:00:00     
(6/7): updates/7/x86_64/primary_db                                                                                  | 6.5 MB  00:00:01     
(7/7): epel/7/primary_db                                                                                            | 6.9 MB  00:00:01     
repo id                                                           repo name                                                          status
base/7/x86_64                                                     centos-7-Base                                                      10,072
epel/7                                                            centos-7-Epel                                                      13,564
extras/7/x86_64                                                   centos-7-Extras                                                       460
updates/7/x86_64                                                  centos-7-Updates                                                    1,898
repolist: 25,994
二、编译安装http2.4,实现可以正常访问,并将编译步骤和结果提交。
#关闭防火墙和SELinux
[root@centos7 ~]# systemctl stop firewalld.service
[root@centos7 ~]# systemctl disable firewalld.service
[root@centos7 ~]# vim /etc/sysconfig/selinux
SELINUX=disabled
#下载安装包
[root@centos7 ~]# wget http://archive.apache.org/dist/httpd/httpd-2.4.41.tar.gz
#安装其他相关包
[root@centos7 ~]# yum install gcc make apr-devel apr-util-devel pcre-devel openssl-devel redhat-rpm-config
#解压安装包
[root@centos7 ~]# tar xvf httpd-2.4.41.tar.gz -C /usr/local/src
#配置编译的相关参数
[root@centos7 ~]# cd /usr/local/src/-2.4.41
[root@centos7 httpd-2.4.41]# ./configure --prefix=/apps/httpd24 --
sysconfdir=/etc/httpd24 --enable-ssl
#编译并安装
[root@centos7 httpd-2.4.41]# make -j 2 && make install
#配置环境
[root@centos7 ~]# echo 'PATH=/apps/httpd24/bin:$PATH' > /etc/profile.d/httpd24.sh
[root@centos7 ~]# . /etc/profile.d/httpd24.sh
#指定用apache运行
[root@centos7 ~]# useradd -r -s /sbin/nologin -d /var/www -c Apache -u 48 apache
[root@centos7 ~]# vim /etc/httpd24/httpd.conf
user apache
group apache
#生效与验证
[root@centos7 ~]# apachectl
[root@centos7 ~]# ps aux | grep httpd
root      22295  0.0  0.3  79196  3104 ?        Ss   20:35   0:00 /apps/httpd24/bin/httpd
apache    22442  0.0  0.4 433696  4716 ?        Sl   20:43   0:00 /apps/httpd24/bin/httpd
apache    22443  0.0  0.4 433696  4836 ?        Sl   20:43   0:00 /apps/httpd24/bin/httpd
apache    22444  0.0  0.4 433696  4436 ?        Sl   20:43   0:00 /apps/httpd24/bin/httpd
apache    22605  0.0  0.4 433696  4184 ?        Sl   20:46   0:00 /apps/httpd24/bin/httpd
root      22755  0.0  0.0 112808   980 pts/0    S+   21:15   0:00 grep --color=auto httpd
[root@centos7 cd]# curl 192.168.88.132
<html><body><h1>It works!</h1></body></html>
三、利用sed 取出ifconfig命令中本机的IPv4地址
[root@centos7 ~]# ifconfig eth0 | sed -rn '2s/^[^0-9]+([0-9.]+) .*$/\1/p'
192.168.88.132
四、删除/etc/fstab文件中所有以#开头,后面至少跟一个空白字符的行的行首的#和空白字符
[root@centos7 ~]# sed -ri.bak '/^#\s+/s/^#\s+//' /etc/fstab
[root@centos7 ~]# cat /etc/fstab

#
/etc/fstab
Created by anaconda on Sun Jan 24 22:52:28 2021
#
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
#
UUID=c31c6985-a421-4b8f-b8fb-fab3d853cc07 /                       xfs     defaults        0 0
UUID=4c97516a-8359-489d-a481-e6fa6b286648 /boot                   xfs     defaults        0 0
UUID=759b3298-d487-4864-9d35-40935cf473e1 /data                   xfs     defaults        0 0
UUID=56ab2fcf-4754-46fe-8a19-cc30bea9661b swap                    swap    defaults        0 0
五、处理/etc/fstab路径,使用sed命令取出其目录名和基名
#取目录名
[root@centos7 ~]# echo /etc/fstab | sed -rn 's#(.*)/([^/]+)/?#\1#p'
/etc
#取基名
[root@centos7 ~]# echo /etc/fstab | sed -rn 's#(.*)/([^/]+)/?#\2#p'
fstab
posted @ 2021-03-23 13:22  jy03017317  阅读(58)  评论(0)    收藏  举报