Linux第四周

大鹏一日同风起,扶摇直上九万里。这篇文章主要讲述Linux第四周相关的知识,希望能为你提供帮助。
1、自建yum仓库,分别为网络源和本地源

#更换为国内网络源
mkdir /etc/yum.repos.d/bak
mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/bak
vim base.repo
[BaseOS]
name=BaseOS
baseurl=
https://mirrors.aliyun.com/centos/$releasever/BaseOS/$arch/os/
https://mirrors.cloud.tencent.com/centos/$releasever/BaseOS/$arch/os/
https://repo.huaweicloud.com/centos/$releasever/BaseOS/$arch/os/
https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/BaseOS/$arch/os/
gpgcheck=1
gpgkey=/etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial

[AppStream]
name=AppStream
baseurl=https://mirrors.aliyun.com/centos/$releasever/AppStream/$arch/os/
https://mirrors.cloud.tencent.com/centos/$releasever/AppStream/$arch/os/
https://repo.huaweicloud.com/centos/$releasever/AppStream/$arch/os/
https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/AppStream/$arch/os/
gpgcheck=1
gpgkey=/etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial


[epel]
name=epel
baseurl=https://mirrors.aliyun.com/epel/$releasever/Everything/$arch/
https://mirrors.cloud.tencent.com/epel/$releasever/Everything/$arch/
https://mirrors.huaweicloud.com/epel/$releasever/Everything/$arch/
https://mirrors.tuna.tsinghua.edu.cn/epel/$releasever/Everything/$arch/
gpgcheck=0

[extras]
name=extras
baseurl=https://mirrors.aliyun.com/centos/$releasever/extras/$arch/os/
https://mirrors.cloud.tencent.com/centos/$releasever/extras/$arch/os/
https://mirrors.huaweicloud.com/centos/$releasever/extras/$arch/os/
https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/extras/$arch/os/
gpgcheck=0

#虚拟机先将linux镜像挂载至虚拟机,先做第二题将http2.4编译安装完
#自建yum仓库创建目录
[root@localhost httpd]# cd htdocs/
[root@localhost htdocs]# ls
index.html
[root@localhost htdocs]# mkdir centos
[root@localhost htdocs]# ls
centosindex.html
[root@localhost htdocs]# cd centos
[root@localhost centos]# ls
[root@localhost centos]# mkdir 8
[root@localhost centos]# ls
8
[root@localhost centos]# cd 8
[root@localhost 8]# mkdir local
[root@localhost 8]# ls
local
#将光盘挂载到虚拟机
[root@localhost ~]# cd/sys/class/scsi_host/
[root@localhost scsi_host]# ls
host0host1host2
host0host1host2
[root@localhost scsi_host]# echo "- - -" > /sys/class/scsi_host/host2/scan
[root@localhost scsi_host]# lsblk
sr111:11 10.1G0 rom
[root@localhost scsi_host]# mount /dev/sr1 /app/httpd/htdocs/centos/8/local/
mount: /app/httpd/htdocs/centos/8/local: WARNING: device write-protected, mounted read-only.
#挂载成功


#将地址写入repo并把网络源禁用
[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# vim base.repo
[BaseOS]
name=BaseOS
baseurl=http://192.168.17.128/centos/8/local/BaseOS/
#https://mirrors.aliyun.com/centos/$releasever/BaseOS/$arch/os/
#https://mirrors.cloud.tencent.com/centos/$releasever/BaseOS/$arch/os/
#https://repo.huaweicloud.com/centos/$releasever/BaseOS/$arch/os/
#https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/BaseOS/$arch/os/
gpgcheck=0
gpgkey=/etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial

[AppStream]
name=AppStream
baseurl=http://192.168.17.128/centos/8/local/AppStream/
#https://mirrors.aliyun.com/centos/$releasever/AppStream/$arch/os/
#https://mirrors.cloud.tencent.com/centos/$releasever/AppStream/$arch/os/
#https://repo.huaweicloud.com/centos/$releasever/AppStream/$arch/os/
#https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/AppStream/$arch/os/
gpgcheck=0
gpgkey=/etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
#测试
[root@localhost yum.repos.d]# yum list vsftpd
vsftpd.x86_643.0.3-34.el8AppStream
[root@localhost yum.repos.d]# yum install -y vsftpd
已安装:
vsftpd-3.0.3-34.el8.x86_64

完毕!

2、编译安装http2.4,实现可以正常访问,并将编译步骤和结果提交。
#下载源码
[root@localhost ~]# wget https://dlcdn.apache.org//httpd/httpd-2.4.51.tar.bz2
下载完毕 --2021-12-10 07:23:02--
总用时:1m 41s
下载了:1 个文件,1m 40s (74.9 KB/s) 中的 7.3M
#解包
[root@localhost ~]# mv httpd-2.4.51.tar.bz2 /usr/local/src
[root@localhost ~]# cd /usr/local/src
[root@localhost src]# tar -xvf httpd-2.4.51.tar.bz2
#解包完成后查看是否成功
[root@localhost src]# ls
httpd-2.4.51httpd-2.4.51.tar.bz2
#使用configure生成makefile文件
[root@localhost src]# cd httpd-2.4.51/
[root@localhost httpd-2.4.51]# ./configure --prefix=/app/httpd
#第一次使用编译安装缺少大量包,根据报错安装对应包
#报错 configure: error: APR not found.Please read the documentation.
[root@localhost httpd-2.4.51]# yum install -y apr-devel
#报错configure: error: APR-util not found.Please read the documentation.
[root@localhost httpd-2.4.51]# yum install -y apr-util-devel#包名小写
#报错configure: error: pcre-config for libpcre not found. PCRE is required and available from http://pcre.org/
[root@localhost httpd-2.4.51]# yum install -y pcre-devel
#再次使用命令./configure --prefix=/app/httpd提示成功
Server Version: 2.4.51
Install prefix: /app/httpd
C compiler:gcc
CFLAGS:-pthread
CPPFLAGS:-DLINUX -D_REENTRANT -D_GNU_SOURCE
LDFLAGS:
LIBS:
C preprocessor: gcc -E
#configure运行成功后,使用make
[root@localhost httpd-2.4.51]# make -j 8
#表示完成(未出现errer)
make[4]: 离开目录“/usr/local/src/httpd-2.4.51/modules/mappers”
make[3]: 离开目录“/usr/local/src/httpd-2.4.51/modules/mappers”
make[2]: 离开目录“/usr/local/src/httpd-2.4.51/modules”
make[2]: 进入目录“/usr/local/src/httpd-2.4.51/support”
make[2]: 离开目录“/usr/local/src/httpd-2.4.51/support”

make[1]: 离开目录“/usr/local/src/httpd-2.4.51”
#执行make install
#显示make[1]: 离开目录“/usr/local/src/httpd-2.4.51” 安装完成
#放入PATH且验证可以运行
[root@localhost app]# cd httpd
[root@localhost httpd]# ls
binbuildcgi-binconferrorhtdocsiconsincludelogsmanmanualmodules
[root@localhost httpd]# echo PATH=/app/httpd/bin/:$PATH > /etc/profile.d/httpd.sh
[root@localhost httpd]# . /etc/profile.d/httpd.sh
[root@localhost httpd]# apachectl start
AH00558: httpd: Could not reliably determine the servers fully qualified domain name,
using localhost.localdomain. Set the ServerName directive globally to suppress this message
#输入IP地址查看是否成功


#更换httpd的用户
[root@localhost ~]# groupadd -r -g 88 apache
[root@localhost ~]# useradd -r -g apache -s /sbin/nologin -d /var/www/ apache
[root@localhost ~]# cd /app/httpd/conf/
[root@localhost conf]# ls
extrahttpd.confmagicmime.typesoriginal
[root@localhost conf]# vim httpd.conf
#修改user和group
< IfModule unixd_module>
#
# If you wish httpd to run as a different user or group, you must run
# httpd as root initially and it will switch.
#
# User/Group: The name (or #number) of the user/group to run httpd as.
# It is usually good practice to create a dedicated user and group for
# running httpd, as with most system services.
#
User apache
Group apache
[root@localhost ~]# apachectl -k stop
[root@localhost ~]# apachectl -k start
[root@localhost ~]# ps aux


3、利用sed 取出ifconfig命令中本机的IPv4地址
[root@localhost ~]# ifconfig |sed -nr 2s/^[^0-9]+([0-9.]+).*/\\1/p

4、删除/etc/fstab文件中所有以#开头,后面至少跟一个空白字符的行的行首的#和空白字符
sed -ri.bak s/^#[[:space:]]+(.*)/\\1/ /etc/fstab

5、处理/etc/fstab路径,使用sed命令取出其目录名和基名
[root@localhost etc]# vim /etc/fstab
[root@localhost etc]# echo /etc/fstab | sed -nr s#^(.*)/([^/]+)/?$#\\1#p
/etc
[root@localhost etc]# echo /etc/fstab | sed -nr s#^(.*)/([^/]+)/#$@\\2@p
fstab

【Linux第四周】6、列出ubuntu软件管理工具apt的一些用法(自由总结)
一、安装软件包
apt install sl
二、删除软件包
apt remove sl
三、列出仓库软件包
apt list
四、搜索软件包
apt search sl
五、查看某个软件包的详细信息
apt show sl
六、更新包索引
apt update


    推荐阅读