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

本地源:



10.0.0.5搭建本地仓库:
[root@cenos7 ~]# mount /dev/sr0 /mnt/cdrom
[root@cenos7 ~]# vim /etc/yum.repos.d/base.repo
[CentOS7]
name=CentOS7
baseurl=file:///mnt/cdrom
gpgcheck=0
enabled=1
[root@cenos7 ~]# yum repolist
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
repo id repo name status
CentOS7 CentOS7 10,072
repolist: 10,072
[root@cenos7 ~]# yum install -y httpd
[root@cenos7 ~]# systemctl enable httpd --now
[root@cenos7 ~]# cp -r /mnt/cdrom/ /var/www/html/CentOS7


linux笔记-第四周_安装包



10.0.0.7使用10.0.0.5仓库:
[root@centos7 ~]# vim /etc/yum.repos.d/base1.repo
[BaseOS]
name=BaseOS
baseurl=http://10.0.0.5/CentOS7
gpgcheck=0
enable=1
[root@centos7 ~]# yum repolist
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
repo id repo name status
BaseOS BaseOS 10,072
repolist: 10,072


网络源: 



[root@centos8 Packages]# vim /etc/yum.repos.d/base.repo
[BaseOS]
name=BaseOS
baseurl=https://mirrors.aliyun.com/centos/$releasever/BaseOS/$basearch/os/
https://mirrors.huaweicloud.com/centos/$releasever/BaseOS/$basearch/os/
https://mirrors.cloud.tencent.com/centos/$releasever/BaseOS/$basearch/os/
https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/BaseOS/$basearch/os/
http://mirrors.163.com//centos/$releasever/BaseOS/$basearch/os/
http://mirrors.sohu.com/centos/$releasever/BaseOS/$basearch/os/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial

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

[EPEL]
name=EPEL
baseurl=https://mirrors.aliyun.com/epel/$releasever/Everything/$basearch/
https://mirrors.huaweicloud.com/epel/$releasever/Everything/$basearch/
https://mirrors.cloud.tencent.com/epel/$releasever/Everything/$basearch/
https://mirrors.tuna.tsinghua.edu.cn/epel/$releasever/Everything/$basearch/
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/epel/RPM-GPG-KEY-EPEL-$releasever
[root@centos8 Packages]# yum repolist
repo id repo name
AppStream AppStream
BaseOS BaseOS
EPEL EPEL
centosplus centosplus
extras extras


扩展:下载阿里云的extras源,制作私有yum源



[root@repo-server ~]#dnf reposync --repoid=extras --download-metadata -p  /var/www/html/centos


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

安装路径设定 --prefix=/PATH:指定默认安装位置,默认为/usr/local/ --sysconfdir=/PATH:配置文件安装位置 System types:支持交叉编译 软件特性和相关指定: Optional Features: 可选特性 --disable-FEATURE --enable-FEATURE[=ARG] Optional Packages: 可选包 --with-PACKAGE[=ARG] 依赖包 --without-PACKAGE 禁用依赖关系



#安装依赖包
[root@centos8 ~]# dnf install gcc make autoconf apr-devel apr-util-devel pcredevel openssl-devel redhat-rpm-config
#准备安装包并解压
[root@centos8 ~]# tar zxvf httpd-2.4.48.tar.gz -C /usr/local/src/
#./configure配置
[root@centos8 ~]# cd /usr/local/src/httpd-2.4.48/
[root@centos8 httpd-2.4.48]# ./configure --prefix=/apps/httpd --sysconfdir=/etc/httpd --enable-ssl
#编译安装
[root@centos8 httpd-2.4.48]# make && make install
#配置环境
[root@centos8 ~]# echo 'PATH=/apps/httpd/bin:$PATH' > /etc/profile.d/httpd.sh
[root@centos8 ~]# . /etc/profile.d/httpd.sh
#指定用户
[root@centos8 ~]# useradd -r -s /sbin/nologin -d /var/www -c Apache -u 48 apache
[root@centos8 ~]# vim /etc/httpd/httpd.conf
user apache
group apache
#开启apachetcl
[root@centos8 ~]# apachectl start
#验证
[root@centos8 ~]# ps -aux |grep httpd
root 26844 0.0 0.3 103172 6308 ? Ss 15:27 0:00 /apps/httpd/bin/httpd -k start
apache 26948 0.0 0.4 1323796 7676 ? Sl 15:29 0:00 /apps/httpd/bin/httpd -k start
apache 26949 0.0 0.4 1323796 7676 ? Sl 15:29 0:00 /apps/httpd/bin/httpd -k start
apache 26950 0.3 0.7 1323796 13796 ? Sl 15:29 0:00 /apps/httpd/bin/httpd -k start
root 27040 0.0 0.0 12132 1024 pts/1 S+ 15:29 0:00 grep --color=auto httpd


linux笔记-第四周_apache_02

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



[root@centos8 ~]# ifconfig eth0 |sed -nr "2s/[^0-9]+([0-9.]+).*/\1/p"
10.0.0.9


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



[root@centos8 ~]# cat -A /etc/fstab 
$
#$
# /etc/fstab$
# Created by anaconda on Mon Jul 5 07:45:22 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.$
#$
# After editing this file, run 'systemctl daemon-reload' to update systemd$
# units generated from this file.$
#$
UUID=dcd5339a-76e6-4673-bc37-320330b860bf / xfs defaults 0 0$
UUID=204033f4-cb11-466d-9b57-e1605a89c49d /boot xfs defaults 0 0$
UUID=6796b590-6726-4d7e-ae58-8c761ae32882 /data xfs defaults 0 0$
UUID=e7f83157-0245-4857-afd9-5fe688715d4a none swap defaults 0 0$



[root@centos8 ~]# sed -E '/^#/s@^#|[ \t]+@@g' /etc/fstab


/etc/fstab
CreatedbyanacondaonMonJul507:45:222021

Accessiblefilesystems,byreference,aremaintainedunder'/dev/disk/'.
Seemanpagesfstab(5),findfs(8),mount(8)and/orblkid(8)formoreinfo.

Aftereditingthisfile,run'systemctldaemon-reload'toupdatesystemd
unitsgeneratedfromthisfile.

UUID=dcd5339a-76e6-4673-bc37-320330b860bf / xfs defaults 0 0
UUID=204033f4-cb11-466d-9b57-e1605a89c49d /boot xfs defaults 0 0
UUID=6796b590-6726-4d7e-ae58-8c761ae32882 /data xfs defaults 0 0
UUID=e7f83157-0245-4857-afd9-5fe688715d4a none swap defaults


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



#目录名
[root@centos8 ~]# echo /etc/fstab |sed -En 's@(^/.*)/(.*)$@\1@p' 
/etc
#基名
[root@centos8 ~]# echo /etc/fstab |sed -En 's@(^/.*)/(.*)$@\2@p'
fstab


6、列出ubuntu软件管理工具apt的一些用法(自由总结)



Ubuntu 软件管理
dpkg 包管理器
dpkg 常见用法:
#安装包
dpkg -i package.deb
#删除包,不建议,不自动卸载依赖于它的包
dpkg -r package
#删除包(包括配置文件)
dpkg -P package
#列出当前已安装的包,类似rpm -qa
dpkg -l
#显示该包的简要说明
dpkg -l package
#列出该包的状态,包括详细信息,类似rpm –qi
dpkg -s package
#列出该包中所包含的文件,类似rpm –ql
dpkg -L package
#搜索包含pattern的包,类似rpm –qf
dpkg -S <pattern>
#配置包,-a 使用,配置所有没有配置的软件包
dpkg --configure package
#列出 deb 包的内容,类似rpm –qpl
dpkg -c package.deb
#解开 deb 包的内容
dpkg --unpack package.deb
apt:
APT包索引配置文件
/etc/apt/sources.list
/etc/apt/sources.list.d
apt命令操作(如安装和删除软件包)日志文件
/var/log/dpkg.log

#安装包:
apt install tree zip
#安装图形桌面
apt install ubuntu-desktop
#删除包:
apt remove tree zip
#说明:apt remove中添加--purge选项会删除包配置文件,谨慎使用
#更新包索引,相当于yum clean all;yum makecache
apt update
#升级包:要升级系统,请首先更新软件包索引,再升级
apt upgrade
#apt列出仓库软件包,等于yum list
apt list
#搜索安装包
apt search nginx
#查看某个安装包的详细信息
apt show apache2
#在线安装软件包
apt install apache2
#卸载单个软件包但是保留配置⽂件
apt remove apache2
#删除安装包并解决依赖关系
apt autoremove apache2
#更新本地软件包列表索引,修改了apt仓库后必须执⾏
apt update
#卸载单个软件包删除配置⽂件
apt purge apache2
#升级所有已安装且可升级到新版本的软件包
apt upgrade
#升级整个系统,必要时可以移除旧软件包。
apt full-upgrade
#编辑source源⽂件
apt edit-sources
#查看仓库中软件包有哪些版本可以安装
apt-cache madison nginx
#安装软件包的时候指定安装具体的版本
apt install nginx=1.14.0-0ubuntu1.6
#查看文件来自于哪个包,类似redhat中的yum provides <filename>
apt-file search 'string' #默认是包含此字符串的文件
apt-file search -x '正则表达式'
案例1: 查看文件来自于哪个包
查找存在的文件来自于哪个包:
#dpkg -S filename :在当前安装的包里查找文件
[root@ubuntu1804 ~]#dpkg -S /bin/ls
coreutils: /bin/ls
案例2: 查看包相关信息
#显示系统安装包的统计信息,可以统计已经安装包的数量,大小,占用空间等
#apt-cache stats
#显示xxx包的信息,可以看到某个包的源、版本等信息
#apt-cache show xxx #更详细
#apt show xxx
案例3: 查看仓库中的指定软件的所有版本
[root@ubuntu1804 ~]#apt-cache madison docker-ce
#安装指定版本
[root@ubuntu1804 ~]#apt -y install docker-ce=5:19.03.13~3-0~ubuntu-bionic
案例4: 查看文件的依赖
#查询软件xxx依赖哪些包
#apt depends xxx
#apt-cache depends xxx
#查询软件xxx被哪些包依赖
#apt rdepends xxx
#apt-cache rdepends xxx