文本处理sed&软件管理

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

/etc/yum.repos.d/*.repo: #为每个仓库的提供配置文件,即告诉客户端仓库地址源。
在这里插入图片描述本次实验将网络源的配置文件命名为Internet.repo,本地源命名为Local.repo,并将系统原先自带的配置文件存放在其子目录bak中。
在这里插入图片描述
在这里插入图片描述

1.配置本地源

1.1 为CentOS7用系统安装光盘作的本地yum仓库

查看光盘挂载路径

df -Th

在这里插入图片描述

1.2 创建配置文件

[root@Centos7 yum.repos.d]# cat Local.repo 
[Local]
name=local
baseurl=file:///misc/cd
gpgcheck=0
enabled=1

2.创建网络源

yum的repo配置文件中可用的变量:
$releasever: 当前OS的发行版的主版本号,如:8,7,6
$arch: CPU架构,如:aarch64, i586, i686,x86_64等
$basearch:系统基础平台;i386, x86_64
$contentdir:表示目录,比如:centos-8,centos-7
Y U M 0 − YUM0- YUM0YUM9:自定义变量

2.1 以阿里云的epel和extras作为本机yum的网络源

[root@Centos7 yum.repos.d]# vim Internet.repo 
[epel]
name=EPEL
baseurl=http://mirrors.aliyun.com/epel/$releasever/$basearch
gpgcheck=1
enabled=1
[extras]
name=extras
baseurl=https://mirrors.aliyun.com/centos/$releasever/extras/$basearch
gpgcheck=1
enabled=1

3.常看本机yum仓库列表

[root@Centos7 yum.repos.d]# yum repolist

在这里插入图片描述
加上-v 可显示本机yum仓库的详细信息
在这里插入图片描述

二、编译安装http2.4,实现可以正常访问

2.1查看httpd下载链接

[root@Centos8 httpd-2.4.49]#  yum info httpd

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

2.2 下载解压httpd源代码

[root@Centos8 ~]# wget https://dlcdn.apache.org//httpd/httpd-2.4.49.tar.bz2 #下载
[root@Centos8 ~]# ls
anaconda-ks.cfg  httpd-2.4.49.tar.bz2  initial-setup-ks.cfg
[root@Centos8 ~]# mv httpd-2.4.49.tar.bz2  /usr/local/src
[root@Centos8 ~]# ll
total 8
-rw-------. 1 root root 1479 Sep 18 15:10 anaconda-ks.cfg
-rw-r--r--. 1 root root 1771 Sep 18 15:12 initial-setup-ks.cfg
[root@Centos8 ~]# cd /usr/local/src/
[root@Centos8 src]# ll
total 7032
-rw-r--r-- 1 root root 7199599 Sep 15 16:10 httpd-2.4.49.tar.bz2
[root@Centos8 src]# tar xvf httpd-2.4.49.tar.bz2  #解压

2.3 运行 configure 脚本,生成 Makefile 文件在这里插入图片描述

./configure  --prefix=/apps/httpd --sysconfdir=/etc/httpd --enable-ssl #自定义安装路径,配置文件路径以及加密特性

在这里插入图片描述

[root@Centos8 httpd-2.4.49]# yum install apr-devel

在这里插入图片描述

[root@Centos8 httpd-2.4.49]# yum install -y apr-util-devel

在这里插入图片描述

[root@Centos8 httpd-2.4.49]# yum -y install gcc

在这里插入图片描述

[root@Centos8 httpd-2.4.49]# yum -y install pcre-devel

在这里插入图片描述

[root@Centos8 httpd-2.4.49]# yum list openssl*

在这里插入图片描述

[root@Centos8 httpd-2.4.49]# yum -y install openssl-devel

2.4 根据Makefile文件,会检测依赖的环境,进行构建应用程序

[root@Centos8 httpd-2.4.49]# make -j 2 #使用2个CPU进行安装

在这里插入图片描述

[root@Centos8 httpd-2.4.49]# yum provides /usr/lib/rpm/redhat/redhat-hardened-ld

在这里插入图片描述

[root@Centos8 httpd-2.4.49]# yum install -y redhat-rpm-config-125-1.el8.noarch

2.5 复制文件到相应路径并安装

[root@Centos8 httpd-2.4.49]# make install

在这里插入图片描述

[root@Centos8 httpd-2.4.49]# echo 'PATH=/apps/httpd/bin/:$PATH' > /etc/profile.d/httpd.sh #定义环境变量,执行时可不用指定绝对路径
[root@Centos8 httpd-2.4.49]# . /etc/profile.d/httpd.sh #声明
[root@Centos8 httpd-2.4.49]# ap
apachectl           aplaymidi           appstream-compose   apr-1-config        apu-1-config        
aplay               applygnupgdefaults  appstream-util      apropos             apxs                
[root@Centos8 httpd-2.4.49]# apachectl start #启动Apache服务

在这里插入图片描述

2.6指定Apache用户可执行该程序

[root@Centos8 httpd-2.4.49]# vim /etc/httpd/httpd.conf #进入配置文件
[root@Centos8 httpd-2.4.49]# apachectl restart #重启该服务
[root@Centos8 httpd-2.4.49]# ps aux

在这里插入图片描述
在这里插入图片描述

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

[17:30:14-root@Centos8 ~][#ifconfig ens33 | sed -nr '2s/.* inet ([0-9.]+) .*/\1/p'
10.0.0.150

在这里插入图片描述

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

[18:00:52-root@Centos8 ~][#sed -ri.bak '/^#/s/^#//' /etc/fstab

在这里插入图片描述

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

[18:50:34-root@Centos8 ~][#echo '/etc/fstab' | sed -n -r 's#(.*)/([^/]+)#\1#p'
/etc
[18:50:43-root@Centos8 ~][#echo '/etc/fstab' | sed -n -r 's#(.*)/([^/]+)#\2#p'
fstab

六、列出ubuntu软件管理工具apt的一些用法

Debian软件包通常为预编译的二进制格式的扩展名".deb",类似rpm文件,因此安装快速,无需编译软件。包文件包括特定功能或软件所必需的文件、元数据和指令

[root@ubuntu1804 main]$pwd
/mnt/pool/main
[root@ubuntu1804 main]$ls
a  c  e  g  i  k  liba  libc  libe  libg  libi  libk  libm  libo  libq  libs  libu  libw  liby  m  o  q  s  u  w  y
b  d  f  h  j  l  libb  libd  libf  libh  libj  libl  libn  libp  libr  libt  libv  libx  libz  n  p  r  t  v  x  z
#.deb软件包文件路径

在这里插入图片描述

6.1 dpkg

dpkg:package manager for Debian,类似于rpm, dpkg是基于Debian的系统的包管理器。可以安装,删除和构建软件包,但无法自动下载和安装软件包或其依赖项。

[root@ubuntu1804 main]$dpkg -r tree  #卸载 tree
(Reading database ... 82782 files and directories currently installed.)
Removing tree (1.7.0-5) ...
Processing triggers for man-db (2.8.3-2ubuntu0.1) ...
[root@ubuntu1804 ~]$dpkg -l #列出系统上已安装全部的包,类似rpm -qa
[root@ubuntu1804 main]$dpkg -l zlib1g:amd64 #显示该包的简要说明
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name                                        Version                    Architecture               Description
+++-===========================================-==========================-==========================-============================================================================================
ii  zlib1g:amd64                                1:1.2.11.dfsg-0ubuntu2     amd64                      compression library - runtime

在这里插入图片描述

[root@ubuntu1804 ~]$dpkg -L yum #列出软件包安装的文件,类似rpm –ql

在这里插入图片描述

[root@ubuntu1804 ~]$dpkg -S var/cache/yum 
yum: /var/cache/yum
#查看var/cache/yum 来自于哪个软件包,类似rpm –qf
[root@ubuntu1804 main]$dpkg -c /mnt/pool/main/z/zerofree/zerofree_1.0.4-1_amd64.deb  #列出 deb 包的内容,类似rpm –qpl
drwxr-xr-x root/root         0 2016-11-14 22:44 ./
drwxr-xr-x root/root         0 2016-11-14 22:44 ./usr/
drwxr-xr-x root/root         0 2016-11-14 22:44 ./usr/sbin/
-rwxr-xr-x root/root     10232 2016-11-14 22:44 ./usr/sbin/zerofree
drwxr-xr-x root/root         0 2016-11-14 22:44 ./usr/share/
drwxr-xr-x root/root         0 2016-11-14 22:44 ./usr/share/doc/
drwxr-xr-x root/root         0 2016-11-14 22:44 ./usr/share/doc/zerofree/
-rw-r--r-- root/root      1035 2016-11-14 22:44 ./usr/share/doc/zerofree/changelog.Debian.gz
-rw-r--r-- root/root      1320 2014-03-31 21:58 ./usr/share/doc/zerofree/copyright
drwxr-xr-x root/root         0 2016-11-14 22:44 ./usr/share/man/
drwxr-xr-x root/root         0 2016-11-14 22:44 ./usr/share/man/man8/
-rw-r--r-- root/root      1676 2016-11-14 22:44 ./usr/share/man/man8/zerofree.8.gz

6.2 apt

apt:Advanced Packaging Tool,功能强大的软件管理工具,甚至可升级整个Ubuntu的系统,基于客户/服务器架构,类似于yum。apt 相当于 apt-get、apt-cache 和 apt-config 中最常用命令选项的集合,apt 具有更精减但足够的命令选项,而且参数选项的组织方式更为有效。

[root@ubuntu1804 main]$apt list #列出包含条件的包(已安装,可升级等)

在这里插入图片描述

#搜索安装包
[root@ubuntu1804 main]$apt search tree

在这里插入图片描述

#查看某个安装包的详细信息
[root@ubuntu1804 main]$apt show tree
Package: tree
Version: 1.7.0-5
Priority: optional
Section: universe/utils
Origin: Ubuntu
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Original-Maintainer: Florian Ernst <florian@debian.org>
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Installed-Size: 105 kB
Depends: libc6 (>= 2.14)
Homepage: http://mama.indstate.edu/users/ice/tree/
Task: lubuntu-qt-desktop
Supported: 9m
Download-Size: 40.7 kB
APT-Manual-Installed: yes
APT-Sources: http://us.archive.ubuntu.com/ubuntu bionic/universe amd64 Packages
Description: displays an indented directory tree, in color
 Tree is a recursive directory listing command that produces a depth indented
 listing of files, which is colorized ala dircolors if the LS_COLORS environment
 variable is set and output is to tty.
#更新本地软件包列表索引,修改了apt仓库后必须执⾏
[root@ubuntu1804 main]$apt update
Get:1 http://security.ubuntu.com/ubuntu bionic-security InRelease [88.7 kB]
Hit:2 http://us.archive.ubuntu.com/ubuntu bionic InRelease
Get:3 http://us.archive.ubuntu.com/ubuntu bionic-updates InRelease [88.7 kB]        
Get:4 http://us.archive.ubuntu.com/ubuntu bionic-backports InRelease [74.6 kB]
Get:5 http://us.archive.ubuntu.com/ubuntu bionic-updates/main amd64 Packages [2,218 kB]
Fetched 2,470 kB in 12s (204 kB/s)                                                                                                                                                                  
Reading package lists... Done
Building dependency tree       
Reading state information... Done
162 packages can be upgraded. Run 'apt list --upgradable' to see them.
#查看仓库中软件包有哪些版本可以安装
[root@ubuntu1804 main]$apt-cache madison nginx 
     nginx | 1.14.0-0ubuntu1.9 | http://us.archive.ubuntu.com/ubuntu bionic-updates/main amd64 Packages
     nginx | 1.14.0-0ubuntu1.9 | http://us.archive.ubuntu.com/ubuntu bionic-updates/main i386 Packages
     nginx | 1.14.0-0ubuntu1.9 | http://security.ubuntu.com/ubuntu bionic-security/main amd64 Packages
     nginx | 1.14.0-0ubuntu1.9 | http://security.ubuntu.com/ubuntu bionic-security/main i386 Packages
     nginx | 1.14.0-0ubuntu1 | http://us.archive.ubuntu.com/ubuntu bionic/main amd64 Packages
     nginx | 1.14.0-0ubuntu1 | http://us.archive.ubuntu.com/ubuntu bionic/main i386 Packages
#安装软件包的时候指定安装具体的版本
apt install nginx=1.14.0-0ubuntu1.6
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值