第六周作业
1、自建yum仓库,分别为网络源和本地源
建立本地源目录 [root@ys ~]#mkdir /mnt/cdrom [root@ys ~]#mkdir /yum 挂载Centos光盘 [root@ysd ~]#mount /dev/cdrom /mnt/cdrom [root@ysd ~]#cp -r /mnt/cdrom/* /yum 备份repo [root@ysd ~]#cd /etc/yum.repo.d/ [root@ysd yum.repo.d]#mkdir backup [root@ysd yum.repo.d]#mv CentOS-Base.repo CentOS-CR.repo CentOS-Vault.repo CentOS-Vault.repo ./backup 编辑Centos-Media.repo [root@yum.repo.d]#vim Centos-Media.repo
[base]
name=Centos
baseurl=file:///yum
enable=1
gpgckeck=0(关闭检查)
gpgkey=file:///mnt/cdrom/RPM-GPG-KEY-CentOS-7
2.进行yum clean all清除缓存就可以使用了
建立网络源
备份原始repo文件 [root@ysd yum.repos.d]# ls centos-base.repo CentOS-Debuginfo.repo CentOS-Sources.repo centos-base.repo.bak CentOS-fasttrack.repo CentOS-Vault.repo CentOS-CR.repo CentOS-Media.repo CentOS-x86_64-kernel.repo [root@ysd yum.repos.d]rm -f centos7-base.repo 直接获取阿里云地址下载repo文件到目录下 [root@ysd yum.repos.d]# wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo yum makecache 已加载插件:fastestmirror, langpacks Loading mirror speeds from cached hostfile * base: mirrors.aliyun.com * extras: mirrors.aliyun.com * updates: mirrors.aliyun.com base | 3.6 kB 00:00:00 extras | 2.9 kB 00:00:00 updates | 2.9 kB 00:00:00 (1/4): extras/7/x86_64/filelists_db | 224 kB 00:00:00 (2/4): base/7/x86_64/filelists_db | 7.2 MB 00:00:00 extras/7/x86_64/other_db FAILED http://mirrors.aliyuncs.com/centos/7/extras/x86_64/repodata/2e9fd48ed164af0d6a80c2a07dc67c09d733ea94fbde75f81cc7076405c90124-other.sqlite.bz2: [Errno 14] curl#7 - "Failed connect to mirrors.aliyuncs.com:80; Connection refused" 正在尝试其它镜像。 base/7/x86_64/other_db FAILED http://mirrors.aliyuncs.com/centos/7/os/x86_64/repodata/ecaab5cc3b9c10fefe6be2ecbf6f9fcb437231dac3e82cab8d9d2cf70e99644d-other.sqlite.bz2: [Errno 14] curl#7 - "Failed connect to mirrors.aliyuncs.com:80; Connection refused" 正在尝试其它镜像。 (3/4): extras/7/x86_64/other_db | 134 kB 00:00:00 (4/4): base/7/x86_64/other_db | 2.6 MB 00:00:00 元数据缓存已建立
2、编译安装http2.4,实现可以正常访问,并将编译步骤和结果提交。
最小化安装系统的,需要安装以下依赖包
yum install gcc make autoconf gcc-c++ glibc glibc-devel pcre pcre-devel openssl openssl-devel systemd-devel zlib-devel vim lrzsz tree tmux lsof tcpdump wget net-tools iotop bc bzip2 zip unzip nfs-utils man-pages
#安装相关包:[root@centos7 ~]#yum -y install gcc make pcre-devel openssl-devel expat-devel
#下载源代码并解压缩:
[root@centos7 ~]wget https://downloads.apache.org//apr/apr-1.7.0.tar.bz2
[root@centos7 ~]wget https://downloads.apache.org//apr/apr-util-1.6.1.tar.bz2
[root@centos7 ~]wget https://downloads.apache.org//httpd/httpd-2.4.43.tar.bz2
[root@centos7 ~]ls
httpd-2.4.43.tar.bz2,apr-1.7.0.tar.bz2,apr-util-1.6.1.tar.bz2
[root@centos7 ~]tar xvf apr-1.7.0.tar.bz2
[root@centos7 ~]tar xvf apr-util-1.6.1.tar.bz2
[root@centos7 ~]tar xvf httpd-2.4.43.tar.bz2
#将两个依赖包复制到httpd的安装目录下mv apr-1.7.0 httpd-2.4.43/srclib/aprmv apr-util-1.6.1 httpd-2.4.43/srclib/apr-utills httpd-2.4.43/srclib/apr apr-util Makefile.in
cd httpd2.4.43 ./configure \ --prefix=/app/httpd24 \ --enable-so \ --enable-ssl \ --enable-cgi \ --enable-rewrite \ --with-zlib \ --with-pcre \ --with-included-apr \ --enable-modules=most \ --enable-mpms-shared=all \ --with-mpm=prefork make-j4 && make install
创建用户 [root@ysd bin]useradd -s /sbin/nologin -r apache 启动httpd服务 [root@ysd bin] /app/httpd24/bin/apachectl status 检查httpd默认80端口是否启用了 [root@ysd bin]# ss -ntl State Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 128 *:111 *:* LISTEN 0 5 192.168.122.1:53 *:* LISTEN 0 128 *:22 *:* LISTEN 0 128 127.0.0.1:631 *:* LISTEN 0 100 127.0.0.1:25 *:* LISTEN 0 128 [::]:111 [::]:* LISTEN 0 128 [::]:80 [::]:* LISTEN 0 128 [::]:22 [::]:* LISTEN 0 128 [::1]:631 [::]:* LISTEN 0 100 [::1]:25 [::]:*
3、利用sed 取出ifconfig命令中本机的IPv4地址
[root@ysd bin]# ifconfig ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 10.0.0.129 netmask 255.255.255.0 broadcast 10.0.0.255 inet6 fe80::bff6:c9fe:e98f:eb48 prefixlen 64 scopeid 0x20<link> ether 00:0c:29:01:53:8e txqueuelen 1000 (Ethernet) RX packets 283854 bytes 405119691 (386.3 MiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 108109 bytes 7140892 (6.8 MiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 只选出IP地址的行
[root@ysd bin]# ifconfig | sed -n 2p
inet 10.0.0.129 netmask 255.255.255.0 broadcast 10.0.0.255
去除IP地址前面的字符
[root@ysd bin]# ifconfig | sed -n 2p | sed 's/^.*inet//g'
10.0.0.129 netmask 255.255.255.0 broadcast 10.0.0.255
去除IP地址后面的字符
[root@ysd bin]# ifconfig | sed -n 2p | sed 's/^.*inet//g' | sed 's/net.*$//g'
10.0.0.129
4、删除/etc/fstab文件中所有以#开头,后面至少跟一个空白字符的行的行首的#和空白字符
[root@ysd bin]# sed -r 's/^#[[:space:]]+//p' /etc/fstab # /etc/fstab /etc/fstab Created by anaconda on Sat Nov 28 09:46:11 2020 Created by anaconda on Sat Nov 28 09:46:11 2020 # Accessible filesystems, by reference, are maintained under '/dev/disk' 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 See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info # UUID=26a178ba-c9de-44fd-8a7b-b5595eb5f8ec / xfs defaults 0 0 UUID=0133e8b2-2206-40f5-ba58-324c0458ff6a /boot xfs defaults 0 0 UUID=effe7691-200f-45e3-8f72-b84a12f9d924 swap swap defaults 0 0
5、处理/etc/fstab路径,使用sed命令取出其目录名和基名
可以使用sed命令对目录进行分组,分别取出目录名和基名
#取目录名 [root@centos7 ~]#echo /etc/fstab/ | sed -rn 's#(.*)/([^/]+)/?#\1#p' /etc #取基名 [root@centos7 ~]#echo /etc/fstab/ | sed -rn 's#(.*)/([^/]+)/?#\2#p' fstab

浙公网安备 33010602011771号