一、软件运行和编译
ABI和API
ABI:Application Binary Interface(应用程序二进制接口)——systemcall
API:Application Programming Interface (应用程序开发接口)可以在各种不同的操作系统上实现给应用程序提供完全相同的接口
POSIX:Portable Operating System Interface 可移植操作系统接口,定义了操作系统应该为应用程序提供的接口标准,是IEEE为要在各种UNIX操作系统上运行的软件而定义的一系列API标准的总称。Linux和windows都要实现基本的posix标准,程序就在源代码级别可移植了
开发语言
系统级开发:汇编语言、C、C++ (底层开发)
应用级开发:java、Python、go、php、perl、delphi、basic、ruby、bash
C语言程序编译过程:
C 程序源代码(hello.c) —> 预处理 (hello.i)—> 编译(hello.s) —> 汇编(hello.o) —> 链接(hello)
#分步骤编译运行
gcc -E hello.c -o hello.i 对hello.c文件进行预处理,生成了hello.i 文件
gcc -S hello.i -o hello.s 对预处理文件进行编译,生成了汇编文件
gcc -c hello.s -o hello.o 对汇编文件进行编译,生成了目标文件
gcc hello.o -o hello 对目标文件进行链接,生成可执行文件
#一步实现编译过程
gcc hello.c -o hello 直接编译链接成可执行目标文件
软件模块的静态和动态链接
链接主要作用是把各个模块之间相互引用的部分处理好,使得各个模块之间能够正确地衔接,分为静态和动态链接
二进制程序所依赖的库文件ldd
查看二进制程序所依赖的库文件:ldd`` /PATH/TO/BINARY_FILE
[root@CentOS ~]$ cat `find /etc/ -name "*"` |wc -l (#查看该目录下文件总行数)
416190
[root@CentOS ~]$ ldd /bin/ls (#查看ls所依赖的库)
linux-vdso.so.1 => (0x00007ffd463aa000)
libselinux.so.1 => /lib64/libselinux.so.1 (0x00007f52fb9b5000)
libcap.so.2 => /lib64/libcap.so.2 (0x00007f52fb7b0000)
libacl.so.1 => /lib64/libacl.so.1 (0x00007f52fb5a7000)
libc.so.6 => /lib64/libc.so.6 (0x00007f52fb1d9000)
libpcre.so.1 => /lib64/libpcre.so.1 (0x00007f52faf77000)
libdl.so.2 => /lib64/libdl.so.2 (0x00007f52fad73000)
/lib64/ld-linux-x86-64.so.2 (0x00007f52fbbdc000)
libattr.so.1 => /lib64/libattr.so.1 (0x00007f52fab6e000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f52fa952000)
[root@CentOS ~]$ mv /lib64/libc.so.6 . (#库文件破坏后,将导致依赖的程序无法正常运行)
[root@CentOS ~]$ ls
ls: error while loading shared libraries: libc.so.6: cannot open shared object file: No such file or directory
[root@CentOS ~]$ reboot
reboot: error while loading shared libraries: libc.so.6: cannot open shared object file: No such file or directory
如何修复系统(利用光盘模式)
重置→ESC(进度条时按一次)→3.CD-EROM(光盘)→Troubleshooting(排错)→Rescue a CentOS Linuxsysytem(恢复系统)→lsblk下面的/nmt/sysimage
二、软件包和包管理器rpm
开源软件最初只提供了.tar.gz的打包的源码文件,用户必须自已编译每个想在GNU/Linux上运行的软件。用户急需系统能提供一种更加便利的方法来管理这些软件,当Debian诞生时,这样一个管理工具dpkg也就应运而生,可用来管理deb后缀的”包”文件。从而著名的“package”概念第一次出现在GNU/Linux系统中,稍后Red Hat才开发自己的rpm包管理系统
**光盘的挂载
一个设备要访问必须要有一个挂载点,访问光盘如下:
[root@CentOS ~]$ yum install autofs -y(#autofs这个服务是在客户端上面,它会持续的检测某个指定的目录,并预先设置当使用到该目录的某个子目录时,将会取得来自服务器端的NFS文件系统资源,并进行自动挂载的操作。)
[root@CentOS ~]$ systemctl start autofs (#autofs实现自动将光盘挂载到/misc文件夹下,可以直接进入cd查看)
[root@CentOS ~]$ ls /misc/cd (#查看centos7上光盘里面的文件)######################centos7
CentOS_BuildTag GPL LiveOS RPM-GPG-KEY-CentOS-7
EFI images Packages(包的存放文件) RPM-GPG-KEY-CentOS-Testing-7
EULA isolinux repodata TRANS.TBL
[root@localhost ~]$ ls /misc/cd (#centos8上光盘里面的文件)########################centos8
AppStream(常用软件) BaseOS(必要核心软件包) EFI images isolinux media.repo TRANS.TBL
[root@localhost /misc/cd]$ du -sh * (#查看当前目录下各个文件及目录占用空间大小)
6.1G AppStream
1014M BaseOS
[root@ununtu ~]$ mount /dev/cdrom /mnt (#Ubuntu需要自己手动挂载)########################Ubuntu
mount: /mnt: WARNING: device write-protected, mounted read-only.
[root@ununtu ~]$ df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sr0 973824 973824 0 100% /mnt
[root@CentOS ~]$ ls /misc/cd/Packages (#红帽包的包文件全部是rpm后缀)
ypserv-2.31-12.el7.x86_64.rpm
yum-3.4.3-163.el7.centos.noarch.rpm
[root@ununtu /mnt/pool]$ ls main/a/acl (#Debian的包文件全部是deb后缀)
acl_2.2.52-3build1_amd64.deb libacl1_2.2.52-3build1_amd64.deb
**软件包中的文件分类
软件包中的文件:二进制文件、库文件、配置文件、帮助文件
可以利用 cpio工具查看包文件列表
rpm2cpio 包文件 |cpio –itv 预览包内文件
rpm2cpio 包文件 |cpio –id “*.conf” 释放包内文件
[root@CentOS /misc/cd/Packages]$ cp xz-5.2.2-1.el7.x86_64.rpm /data
[root@CentOS /misc/cd/Packages]$ cd /data
[root@CentOS /data]$ ls
script xz-5.2.2-1.el7.x86_64.rpm
[root@CentOS /data]$ rpm2cpio xz-5.2.2-1.el7.x86_64.rpm |cpio -itv (#用cpio工具查看并预览包文件里面的内容)
lrwxrwxrwx 1 root root 2 Nov 5 2016 ./usr/bin/unxz -> xz
-rwxr-xr-x 1 root root 75280 Nov 5 2016 ./usr/bin/xz
lrwxrwxrwx 1 root root 2 Nov 5 2016 ./usr/bin/xzcat -> xz
[root@CentOS /data]$ rpm2cpio xz-5.2.2-1.el7.x86_64.rpm |cpio -idv ./usr/bin/xz (#释放包内的文件)
./usr/bin/xz
1569 blocks
[root@CentOS /data/usr/bin]$ ls
xz
[root@CentOS /data/usr/bin]$ ll /usr/bin/xz ./xz (#包内的文件经过释放变成可执行的二进制文件)
-rwxr-xr-x. 1 root root 75280 Nov 5 2016 /usr/bin/xz
-rwxr-xr-x 1 root root 75280 Aug 19 23:55 ./xz
//如果不小心删掉了系统中的xz文件,可以找到系统中的包文件释放出来//
[root@CentOS /data/usr/bin]$ rpm -qf /usr/bin/xz (#可以查询该文件来自于哪个包)
xz-5.2.2-1.el7.x86_64
[root@localhost ~]$ ls /misc/cd/{BaseOS,AppStream}/Packages/ |wc -l (#该目录下文件总个数)
7005
(#统计rmp的架构类型以及相应的包数量)
[root@localhost ~]$ ls /misc/cd/{BaseOS,AppStream}/Packages/ |sed -nr 's@(.*)\.(.*)\.rpm$@\2@p' |sort |uniq -c
[root@localhost ~]$ ls /misc/cd/{BaseOS,AppStream}/Packages/*.rpm |rev |cut -d. -f2 |rev |sort |uniq -c
1288 i686
2168 noarch
3544 x86_64
🔣包管理器rpm
软件包管理器功能:将编译好的应用程序的各组成文件打包一个或几个程序包文件,利用包管理器可以方便快捷地实现程序包的安装、卸载、查询、升级和校验等管理操作
主流的程序包管理器
redhat:rpm文件, rpm 包管理器,rpm:Redhat Package Manager,RPM Package Manager
debian:deb文件, dpkg 包管理器
rpm包命名方式:name-VERSION-release.arch(cpu架构).rpm
CentOS系统上使用rpm命令管理程序包(安装、卸载、升级、查询、校验、数据库维护)
** 安装
rpm {-i``|--install} [install-options] PACKAGE_FILE…
常用组合:rpm -``ivh`` PACKAGE_FILE ...
[install-options]:—test: 测试安装,但不真正执行安装,即dry run模式
—nodeps:忽略依赖关系
—replacepkgs | replacefiles
—nosignature: 不检查来源合法性
—nodigest:不检查包完整性
—noscripts:不执行程序包脚本
%pre: 安装前脚本 —nopre
%post: 安装后脚本 —nopost
%preun: 卸载前脚本 —nopreun
%postun: 卸载后脚本 —nopostun
**查询**
rpm {-q``|--query} [select-options] [query-options]
[select-options]:-a:所有包
-f:查看指定的文件由哪个程序包安装生成
-p rpmfile:针对尚未安装的程序包文件做查询操作
[query-options]:—changelog:查询rpm包的changelog
-c:查询程序的配置文件
-d:查询程序的文档
-i:information
-l:查看指定的程序包安装后生成的所有文件
—scripts:程序包自带的脚本
#和CAPABILITY相关:—whatprovides CAPABILITY:查询指定的CAPABILITY由哪个包所提供
—whatrequires CAPABILITY:查询指定的CAPABILITY被哪个包所依赖
—provides:列出指定程序包所提供的CAPABILITY
-R:查询指定的程序包所依赖的CAPABILITY
[root@localhost ~]$ rpm -qa |grep vsft (#记不清包名了,想要查询该包)
[root@localhost ~]$ rpm -qa "vsft*"
vsftpd-3.0.3-31.el8.x86_64
(#用短路或实现‘如果未安装就继续安装,如果安装成功就不执行安装了’)
[root@localhost ~]$ rpm -q vsftpd &> /dev/null || rpm -ivh /misc/cd/AppStream/Packages/vsftpd*.rpm
Verifying... ################################# [100%]
Preparing... ################################# [100%]
Updating / installing...
1:vsftpd-3.0.3-31.el8 ################################# [100%]
[root@localhost ~]$ rpm -q vsftpd &> /dev/null || rpm -ivh /misc/cd/AppStream/Packages/vsftpd*.rpm
[root@localhost]$ rm -f /etc/bin/tree (#删除该二进制文件之后依旧可以查询该文件的文件包信息)
[root@localhost]$ rpm -qi tree (#因为我们查的是数据库/var/lib/rpm/里面存放的现有包的信息)
Name : tree
Version : 1.7.0
Release : 15.el8
Architecture: x86_64
Install Date: Sat 08 May 2021 05:18:57 PM CST
Group : Unspecified
Size : 111603
License : GPLv2+
Signature : RSA/SHA256, Tue 02 Jul 2019 09:53:45 AM CST, Key ID 05b555b38483c65d
Source RPM : tree-1.7.0-15.el8.src.rpm
Build Date : Sat 11 May 2019 11:54:52 PM CST
Build Host : x86-01.mbox.centos.org
Relocations : (not relocatable)
Packager : CentOS Buildsys <bugs@centos.org>
Vendor : CentOS
URL : http://mama.indstate.edu/users/ice/tree/
Summary : File system tree viewer
Description :
The tree utility recursively displays the contents of directories in a
tree-like format. Tree is basically a UNIX port of the DOS tree
utility.
**卸载**
rpm {-e``|--erase} [--allmatches] [--nodeps] [--noscripts] [--notriggers] [--test] PACKAGE_NAME ...
(当包卸载时,对应的配置文件不会删除, 以FILENAME.rpmsave形式保留)
强行删除rpm包,并恢复
[root@centos7 ~]#rpm -e rpm --nodeps
#恢复过程
#重启进入rescue模式
#mkdir /mnt/cdrom
#mount /dev/sr0 /mnt/cdrom
#rpm -ivh /mnt/cdrom/Packages/rpm-4.11.3-40.el7.x86_64.rpm --root=/mnt/sysimage
#reboot
**升级
rpm {-U``|--upgrade} [install-options] PACKAGE_FILE...
,rpm {-F``|--freshen} [install-options] PACKAGE_FILE.
**校验
rpm -K``|--checksig rpmfile
在检查包的来源和完整性前,必须先导入所需要公钥
[root@CentOS ~]$ cat /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 (#CentOS-7里面直接命名公钥)
[root@localhost ~]$ cat /etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial (#CentOS-8的公钥)
[root@localhost ~]$ rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial (#导入公钥)
[root@localhost ~]$ rpm -qa "gpg-pubkey*" (#查看该公钥)
gpg-pubkey-8483c65d-5ccc5b19
[root@localhost ~]$ rpm -K /misc/cd/BaseOS/Packages/tree-1.7.0-15.el8.x86_64.rpm (#校验包文件的签名,并不校验包的完整性)
/misc/cd/BaseOS/Packages/tree-1.7.0-15.el8.x86_64.rpm: digests signatures OK
#软件在安装时,会将包里的每个文件的元数据,如:大小,权限,所有者,时间等记录至rpm相关的数据库中
[root@CentOS ~]$ rpm -V tree(#可以用来检查包中的文件是否和当初安装时有所变化)
[root@CentOS ~]$ chown zhuyuany /usr/bin/tree
[root@CentOS ~]$ rpm -V tree
.....U... /usr/bin/tree
**数据库
rpm包安装时生成的信息,都放在rpm数据库中/var/lib/rpmrpm {--initdb|--rebuilddb}
可以重建数据库
initdb: 初始化,如果事先不存在数据库,则新建之,否则,不执行任何操作
rebuilddb:重建已安装的包头的数据库索引目录
三、yum和dnf
CentOS 使用 yum, dnf 解决rpm的包依赖关系
YUM: Yellowdog Update Modifier,rpm的前端程序,可解决软件包相关依赖性,可在多个库之间定位软件包,up2date的替代工具
[root@localhost ~]$ ll /usr/bin/yum (#CentOS 8用dnf代替了yum ,不过保留了和yum的兼容性,配置也是通用的)
lrwxrwxrwx. 1 root root 5 Apr 25 2020 /usr/bin/yum -> dnf-3
🔣工作原理
- 需事先创建一个服务器,在yum服务器创建 yum repository(仓库)—众多rpm包;包的相关的元数据文件(放置于特定目录repodata下)
- 在我的系统(yum客户端)中想装一个包,需要配置仓库服务器的地址—配置文件必须放在/etc/yum.repos.d里面,必须是.repo后缀
- 输入yum install app时,会自动从指向服务器的仓库中下载元数据过来,放在缓存区;
- 查询元数据是否存在相关的包及依赖关系后,找到要下载的包后从包列表中下载安装
ping: www.baidu.com: Name or service not known解决方案
当我ping IP地址的时候可以ping通,但是ping域名却不可以,这说明绝大部分原因是由于dns服务器没有配置导致的问题
在/etc/sysconfig/network-scripts/ifcfg-eth0里面添加:
DNS1=8.8.8.8
DNS2=114.114.114.114
[root@localhost hadoop]# cat /etc/resolv.conf
# Generated by NetworkManager
nameserver 8.8.8.8
nameserver 114.114.114.114
①创建yum仓库配置文件
[root@CentOS ~]$ cd /etc/yum.repos.d (#在/etc/yum.repos.d里面配置yum仓库)
[root@localhost /etc/yum.repos.d]$ vim test.repo
[epel](仓库标识)
name=Extra Packages for Enterprise Linuxp
baseurl=https://mirrors.aliyun.com/epel/8/Everything/x86_64/(#指向的仓库服务器路径)
enabled=1(关闭禁用)
gpgcheck=0(检查包的安全性)
[root@localhost /etc/yum.repos.d]$ yum repolist (#查看所有配置的仓库)
repo id repo name
AppStream CentOS-8 - AppStream
BaseOS CentOS-8 - Base
epel epel extra
[root@localhost /etc/yum.repos.d]$ yum install sl (#安装一个epel源仓库里面的包文件)
[root@localhost /etc/yum.repos.d]$ sl
[root@localhost /etc/yum.repos.d]$ sl -a
[root@localhost /etc/yum.repos.d]$ rpm -ql sl
/usr/bin/sl
/usr/lib/.build-id
/usr/lib/.build-id/cb
②阿里云上下载新的yum仓库配置文件
#linux rocky 的yum源仓库配置
sed -e 's|^mirrorlist=|#mirrorlist=|g' -e 's|^#baseurl=http://dl.rockylinux.org/$contentdir|baseurl=https://mirrors.sjtug.sjtu.edu.cn/rocky|g' -i /etc/yum.repos.d/Rocky-*.repo
或者
sed -e 's|^mirrorlist=|#mirrorlist=|g' \
-e 's|^#baseurl=http://dl.rockylinux.org/$contentdir|baseurl=https://mirrors.aliyun.com/rockylinux|g' \
-i.bak \
/etc/yum.repos.d/Rocky-*.repo
date -s '2021/12/21 23:46:30' 确保时间正确
dnf makecache
[root@localhost /etc/yum.repos.d]$ mkdir backup
[root@localhost /etc/yum.repos.d]$ mv *.repo backup
[root@localhost /etc/yum.repos.d]$ curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-8.repo
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 2595 100 2595 0 0 23378 0 --:--:-- --:--:-- --:--:-- 23378
[root@localhost /etc/yum.repos.d]$ ls
backup CentOS-Base.repo
[root@localhost /etc/yum.repos.d]$ vim CentOS-Base.repo (#自己设置yum仓库配置文件Base、AppStream、extras)
[Base]
name=BaseOS
failovermethod=priority
baseurl=https://mirrors.aliyun.com/centos/$releasever/BaseOS/$basearch/os/
http://mirrors.huaweicloud.com/centos/$releasever/BaseOS/$basearch/os/
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-Official
[AppStream]
name=AppStream
failovermethod=priority
baseurl=https://mirrors.aliyun.com/centos/$releasever/AppStream/$basearch/os/
http://mirrors.huaweicloud.com/centos/$releasever/AppStream/$basearch/os/
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-Official
[extras]
name=extras
failovermethod=priority
baseurl=https://mirrors.aliyun.com/centos/8/extras/x86_64/os/
https://mirrors.huaweicloud.com/centos/8/extras/x86_64/os/
gpgcheck=0
[root@localhost /etc/yum.repos.d]$ yum repolist
repo id repo name
AppStream AppStream
Base BaseOS
extras extras
[root@localhost /etc/yum.repos.d]$ yum install epel-release (#安装一个来自extras库里面的包文件,安装epel-release可以生成epel源)
[root@localhost /etc/yum.repos.d]$ ls
backup CentOS-Base.repo epel-modular.repo epel-playground.repo epel.repo epel-testing-modular.repo epel-testing.repo
[root@localhost /etc/yum.repos.d]$ yum remove epel-release (#仓库服务器的地址指向了国外官方站点,卸载)
[root@localhost /etc/yum.repos.d]$ ls
backup CentOS-Base.repo
[root@localhost /etc/yum.repos.d]$ vim CentOS-Base.repo (#添加一个yum仓库配置文件epel)
[epel]
name=epel
failovermethod=priority
baseurl=https://repo.huaweicloud.com/epel/8/Everything/x86_64/
https://repo.aliyun.com/epel/8/Everything/x86_64/
gpgcheck=0
[root@localhost /etc/yum.repos.d]$ yum install cowsay -y (#安装一个来自epel源的包文件,由于接的是国内的站点下载速度非常滴快)
[root@localhost /etc/yum.repos.d]$ cowsay zhuyuanyuan
_____________
< zhuyuanyuan >
-------------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
③写一个yum仓库配置脚本reset.sh
[root@centos7 ~]# cat yum.sh
#!/bin/bash
mkdir /etc/yum.repos.d/backup
mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/backup
cat > /etc/yum.repos.d/base.repo <<EOF
[base]
name=base
baseurl=https://mirrors.aliyun.com/centos/\$releasever/os/\$basearch
gpgcheck=0
EOF
🔣yum命令的用法
列出包的名称yum list
[root@localhost /etc/yum.repos.d]$ yum list nginx(#列出包的名称,默认显示最新版本)
[root@localhost /etc/yum.repos.d]$ yum list nginx*(#列出以nginx开头的包)
[root@localhost /etc/yum.repos.d]$ yum list nginx --showduplicates(#显示该包的所有版本)
Available Packages
nginx.x86_64 1:1.14.1-9.module_el8.0.0+184+e34fea82
[root@localhost /etc/yum.repos.d]$ yum install nginx-1:1.14.1-9.module_el8.0.0+184+e34fea82 (#选择安装指定的版本)
查看该文件所在的包yum provides
[root@localhost /etc/yum.repos.d]$ yum provides /etc/mime.types(#查看该文件所在的包)
Last metadata expiration check: 1:04:37 ago on Fri 20 Aug 2021 10:12:42 PM CST.
mailcap-2.1.48-3.el8.noarch : Helper application and MIME type associations for file types
Repo : @System
Matched from:
Filename : /etc/mime.types
mailcap-2.1.48-3.el8.noarch : Helper application and MIME type associations for file types
Repo : Base
Matched from:
Filename : /etc/mime.types
缓存信息(/var/lib/dnf)
[root@localhost /var/lib/dnf]$ du -sh /var/lib/dnf(#yum的缓存信息存放路径,主要指元数据的缓存)
5.9M /var/lib/dnf
[root@localhost /var/lib/dnf]$ yum clean all(#清除yum的缓存信息)
49 files removed
[root@localhost /var/lib/dnf]$ yum makecache(#构建缓存信息,因为会自动生成所以一般不会主动构建滴)
BaseOS 7.3 MB/s | 5.6 MB 00:00
AppStream 9.7 MB/s | 8.8 MB 00:00
extras 28 kB/s | 10 kB 00:00
epel 6.7 MB/s | 10 MB 00:01
Last metadata expiration check: 0:00:01 ago on Fri 20 Aug 2021 11:24:09 PM CST.
Metadata cache created.
安装历史yum history
[root@localhost /var/lib/dnf]$ yum history(#查看yum安装历史)
ID | Command line | Date and time | Action(s) | Altered
-------------------------------------------------------------------------------
10 | install nginx-1:1.14.1-9 | 2021-08-20 23:09 | Install | 8
9 | install cowsay -y | 2021-08-20 22:12 | Install | 1
8 | remove epel-release | 2021-08-20 22:02 | Removed | 1
7 | install epel-release | 2021-08-20 21:46 | Install | 1
6 | install sl | 2021-08-20 20:37 | Install | 1
5 | install postfix -y | 2021-07-28 03:23 | Install | 1
4 | | 2021-07-28 02:38 | Install | 1
3 | install lrzsz | 2021-07-21 16:08 | Install | 1
2 | install tmux | 2021-06-23 17:05 | Install | 1
1 | | 2021-05-08 17:12 | Install | 1349 EE
[root@localhost /var/lib/dnf]$ yum history undo 6(#用yum安装历史撤销某个操作)
[root@localhost /var/lib/dnf]$ yum history redo 6(#用yum安装历史再做一次某个操作)
查看包组yum grouplist
[root@localhost /var/lib/dnf]$ yum grouplist (#查看包组)
Last metadata expiration check: 0:07:00 ago on Fri 20 Aug 2021 11:24:09 PM CST.
Available Environment Groups:
Server
Minimal Install
Workstation
KDE Plasma Workspaces
Custom Operating System
Virtualization Host
Installed Environment Groups:
Server with GUI
Installed Groups:
Container Management
Headless Management
Available Groups:
Legacy UNIX Compatibility
Development Tools
.NET Core Development
Graphical Administration Tools
Network Servers
[root@localhost /var/lib/dnf]$ yum groupinstall "Virtualization Host" (#安装包组)#用的不多
[root@localhost /var/lib/dnf]$ yum groupremove "Virtualization Host" (#卸载包组)
🔣实现私用yum仓库服务器
1、下载yum的仓库源到指定路径,搭建yum服务器(下载所有yum仓库的相关包和meta 数据)dnf reposync`` ``--repoid=REPOID`` ``--download-metadata`` -p ``/path
(只下载rpm包) (指定仓库的名称) (下载元数据) (指定下载到的路径)
2、为yum客户端设置仓库配置文件,指定baseurl
创建前确保:
▲确认设备状态(光盘是在挂着的)
yum install autofs (下载一个autofs工具,可以实现光盘的自动挂载)
systemctl enable —now autofs (开启此功能)
ls /misc/cd (就可以在此路径下面访问了)
▲关闭防火墙
systemctl disable —now firewalld (立即关闭)
▲禁用selinux(重启后失效)
①临时关闭:
setenforce 0
getenforce 查看selinux状态
②永久关闭:修改selinux配置文件
vim /etc/selinux/config (设置SELINUX=disabled)
sed -i ‘/SELINUX/s/enforcing/disabled/‘ /etc/selinux/config
(sed -nri.bak ‘s/(^SELINUX=).*/\1disabled/p’ /etc/selinux/config 错误,太危险了,用sed修改文件时候一定记得备份!)
▲开启http服务:systemctl enable —now httpd(下载:yum -y install httpd)
①创建局域网的基于Base的yum源
(一、下载yum的仓库源到指定路径,搭建yum服务器)
[root@localhost ~]$ mkdir /var/www/html/centos/8 -pv
[root@localhost ~]$ cp -a /misc/cd/* /var/www/html/centos/8
[root@localhost ~]$ ls /var/www/html/centos/8
AppStream BaseOS EFI images isolinux media.repo TRANS.TBL
(http://192.168.50.150/centos/8/ 可以在网页上查看已经搭建好的yum服务器)
(二、为yum客户端设置仓库配置文件,指定baseurl)
[root@localhost /etc/yum.repos.d]$ vim test2.repo
[BaseOS]
name=BaseOS
baseurl=http://192.168.50.150/centos/8/BaseOS
gpgcheck=0
[AppStream]
name=AppStream
baseurl=http://192.168.50.150/centos/8/AppStream
gpgcheck=0
[root@localhost /etc/yum.repos.d]$ yum repolist
repo id repo name
AppStream AppStream
BaseOS BaseOS
②下载阿里云的extras源制作yum源
(一、下载yum的仓库源到指定路径,搭建yum服务器)
[root@localhost ~]$ mkdir /var/www/html/centos/8 -pv
[root@localhost ~]$ yum repolist
repo id repo name
AppStream AppStream
Base BaseOS
[root@localhost ~]$ dnf reposync --repoid=extras --download-metadata -p /var/www/html/centos
(http://192.168.50.150/centos/extras/ 可以在网页上查看已经搭建好的yum服务器)
[root@localhost ~]$ ls /var/www/html/centos/
8 extras
(二、为yum客户端设置仓库配置文件,指定baseurl)
[root@localhost /etc/yum.repos.d]$ vim test.repo
[extras]
name=extras
baseurl=http://192.168.50.150/centos/extras/
gpgcheck=0
[root@localhost /etc/yum.repos.d]$ yum repolist
repo id repo name
extras extras
③升级最新内核
[root@CentOS ~]$ uname -r (升级前)
3.10.0-1062.el7.x86_64
[root@CentOS ~]$ uname -r (升级后)
5.4.142-1.el7.elrepo.x86_64
[root@CentOS ~]$ rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org(导入密钥)
[root@CentOS ~]$ yum install https://www.elrepo.org/elrepo-release-7.el7.elrepo.noarch.rpm(安装该包,生成yum的一个配置文件)
[root@CentOS ~]$ ls /etc/yum.repos.d/
elrepo.repo
[root@CentOS ~]$ yum repolist
repo id repo name status
elrepo ELRepo.org Community Enterprise Linux Repository - el7 128
[root@CentOS ~]$ yum list --disablerepo=* --enablerepo=elrepo (#只启用elrepo这一个仓库,查看其中的包列表)
[root@CentOS ~]$ yum list --disablerepo=* --enablerepo=elrepo-kernel(#启用elrepo-kernel这一个仓库,查看其中的包列表)
Available Packages
kernel-lt.x86_64 5.4.142-1.el7.elrepo elrepo-kernel
kernel-lt-devel.x86_64 5.4.142-1.el7.elrepo elrepo-kernel
kernel-lt-doc.noarch 5.4.142-1.el7.elrepo elrepo-kernel
[root@CentOS ~]$ yum install kernel-lt.x86_64 --enablerepo=elrepo-kernel(安装新的该内核,重启后可以选择新安装的内核)
[root@CentOS ~]$ yum remove kernel-lt-5.4.142-1.el7.elrepo.x86_64(想要卸载内核时要重启选择旧内核才能卸载正在使用的内核)
四、程序包编译
第一步:运行 configure 脚本,生成Makefile 文件
第二步:make 编译
第三步:make install 安装
编译安装新版tree
[root@localhost ~]$ tree --version
tree v1.7.0 (c) 1996 - 2014 by Steve Baker, Thomas Moore, Francesc Rocher, Florian Sesser, Kyosuke Tokoro
(http://mama.indstate.edu/users/ice/tree/ 官网下载源文件。复制好下载链接后由wget下载,用-P指定到/usr/local/src路径下,此路径一般存放源代码文件;也可在windows上面下载好后放在linux中)
[root@CentOS ~]$ wget ftp://mama.indstate.edu/linux/tree/tree-1.8.0.tgz -P /usr/local/src
[root@CentOS /usr/local/src]$tar xvf tree-1.8.0.tgz (一、下载源码并解压)
[root@CentOS /usr/local/src/tree-1.8.0]$ sed -i 's@v1\.8\.0@v8.8.8@' tree.c (二、修改源码的版本号)
[root@CentOS /usr/local/src/tree-1.8.0]$ yum -y install gcc (三、安装相关的依赖包)
[root@CentOS /usr/local/src/tree-1.8.0]$ vim Makefile → prefix = /apps/tree (四、编译准备:更改指定路径)
[root@CentOS /usr/local/src/tree-1.8.0]$ make -j 4 (五、编译)
[root@CentOS /usr/local/src/tree-1.8.0]$ make install (六、安装)
[root@CentOS /usr/local/src/tree-1.8.0]$ /apps/tree/bin/tree --version
tree v8.8.8 (c) 1996 - 2018 by Steve Baker, Thomas Moore, Francesc Rocher, Florian Sesser, Kyosuke Tokoro
[root@CentOS /usr/local/src/tree-1.8.0]$ echo $PATH
/data/script:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
[root@CentOS /usr/local/src/tree-1.8.0]$ ln -s /apps/tree/bin/tree /usr/local/sbin(#创建一个软连接到变量路径里面)
编译安装 cmatrix
[root@localhost ~]$ wget https://github.com/abishekvashok/cmatrix/releases/download/v2.0/cmatrix-v2.0-Butterscotch.tar -P /usr/local/src
[root@localhost /usr/local/src]$ tar xvf cmatrix-v2.0-Butterscotch.tar
[root@localhost /usr/local/src/cmatrix]$ cat INSTALL
[root@localhost /usr/local/src/cmatrix]$ ./configure --prefix=/apps/cmatrix
[root@localhost /usr/local/src/cmatrix]$ make -j 2(缺失autoheader)
(CDPATH="${ZSH_VERSION+.}:" && cd . && /bin/sh /usr/local/src/cmatrix/missing autoheader)
/usr/local/src/cmatrix/missing: line 81: autoheader: command not found
[root@localhost /usr/local/src/cmatrix]$ yum provides */autoheader(查询autoheader相关包)
autoconf-2.69-27.el8.noarch : A GNU tool for automatically configuring source code
[root@localhost /usr/local/src/cmatrix]$ yum install autoconf -y(安装该包)
[root@localhost /usr/local/src/cmatrix]$ make -j 2(缺失curses.h)
cmatrix.c:43:10: fatal error: curses.h: No such file or directory
[root@localhost /usr/local/src/cmatrix]$ yum provides */curses.h(查询curses.h相关包)
ncurses-devel-6.1-7.20180224.el8.i686 : Development files for the ncurses library
[root@localhost /usr/local/src/cmatrix]$ yum install ncurses-devel(安装该包)
[root@localhost /usr/local/src/cmatrix]$ make -j 2(出现以下错误)
collect2: error: ld returned 1 exit status
[root@localhost /usr/local/src/cmatrix]$ ./configure --prefix=/apps/cmatrix(重新执行一次 ./configure)
‘
[root@localhost /usr/local/src/cmatrix]$ make -j 2
[root@localhost /usr/local/src/cmatrix]$ make install
[root@localhost /usr/local/src/cmatrix]$ echo 'PATH=/apps/cmatrix/bin/:$PATH' > /etc/profile.d/cmatrix.sh(写入变量)
[root@localhost /usr/local/src/cmatrix]$ cat /etc/profile.d/cmatrix.sh
PATH=/apps/cmatrix/bin/:$PATH
[root@localhost /usr/local/src/cmatrix]$ . /etc/profile.d/cmatrix.sh(生效一下)
[root@localhost /usr/local/src/cmatrix]$ echo $PATH
/apps/cmatrix/bin/:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
[root@localhost /usr/local/src/cmatrix]$ cmatrix
[root@localhost /usr/local/src/cmatrix]$ cmatrix -C red
编译安装 httpd 2.4
[root@localhost ~]$ yum info httpd
Repository extras is listed more than once in the configuration
Repository AppStream is listed more than once in the configuration
Last metadata expiration check: 0:42:52 ago on Tue 24 Aug 2021 03:03:20 AM CST.
Installed Packages
Name : httpd
Version : 2.4.37
Release : 39.module_el8.4.0+778+c970deab
Architecture : x86_64
Size : 4.3 M
Source : httpd-2.4.37-39.module_el8.4.0+778+c970deab.src.rpm
Repository : @System
From repo : AppStream
Summary : Apache HTTP Server
URL : https://httpd.apache.org/
License : ASL 2.0
Description : The Apache HTTP Server is a powerful, efficient, and extensible
: web server.
[root@localhost ~]$ wget https://dlcdn.apache.org//httpd/httpd-2.4.48.tar.bz2 -P /usr/local/src
[root@localhost /usr/local/src/httpd-2.4.48]$ cat README
[root@localhost /usr/local/src/httpd-2.4.48]$ cat INSTALL
[root@localhost /usr/local/src/httpd-2.4.48]$ ./configure --prefix=/apps/httpd --enable-ssl
[root@localhost /usr/local/src/httpd-2.4.48]$ dnf -y install apr-devel(缺什么大写的如APR,就加上*-devel)
[root@localhost /usr/local/src/httpd-2.4.48]$ dnf -y install apr-util-devel
[root@localhost /usr/local/src/httpd-2.4.48]$ dnf -y install pcre-devel
[root@localhost /usr/local/src/httpd-2.4.48]$ dnf -y install openssl-devel
[root@localhost /usr/local/src/httpd-2.4.48]$ make -j 2 && make install
[root@localhost /usr/local/src/httpd-2.4.48]$ yum provides /usr/lib/rpm/redhat/redhat-hardened-ld(检查出缺失该包)
redhat-rpm-config-125-1.el8.noarch : Red Hat specific rpm configuration files
[root@localhost /usr/local/src/httpd-2.4.48]$ yum install redhat-rpm-config-125-1.el8.noarch -y(安装该包)
[root@localhost /usr/local/src/httpd-2.4.48]$ make -j 2 && make install
[root@localhost /usr/local/src/httpd-2.4.48]$ tree /apps/httpd/
[root@localhost /usr/local/src/httpd-2.4.48]$ cat INSTALL
$ ./configure --prefix=PREFIX
$ make
$ make install
$ PREFIX/bin/apachectl start
[root@localhost /usr/local/src/httpd-2.4.48]$ /apps/httpd/bin/apachectl start
[root@localhost /usr/local/src/httpd-2.4.48]$ ip a(就可以网页访问此机了呢)
[root@localhost /usr/local/src/cmatrix]$ echo 'PATH=/apps/httpd/bin/:$PATH' > /etc/profile.d/httpd.sh(写入变量)
[root@localhost /usr/local/src/httpd-2.4.48]$ . /etc/profile.d/httpd.sh
[root@localhost /usr/local/src/httpd-2.4.48]$ apachectl stop
[root@localhost /usr/local/src/httpd-2.4.48]$ vim /apps/httpd/conf/httpd.conf (指定用apache用户运行)
user apache
group apache
五、Ubuntu软件管理
Debian软件包通常为预编译的二进制格式的扩展名“.deb”,类似rpm文件,因此安装快速,无需编译软件。包文件包括特定功能或软件所必需的文件、元数据和指令
dpkg:package manager for Debian,类似于rpm, dpkg是基于Debian的系统的包管理器。可以安装,删除和构建软件包,但无法自动下载和安装软件包或其依赖项
apt:Advanced Packaging Tool,功能强大的软件管理工具,甚至可升级整个Ubuntu的系统,基于客户/服务器架构,类似于yum
[root@ubuntu1804 ~]$ mount /dev/sr0 /mnt
[root@ubuntu1804 /mnt/pool/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
[root@ubuntu1804 /mnt/pool/main]$ tree
[root@ubuntu1804 /mnt/pool/main]$ dpkg -l |wc -l (#查看现安装包的个数)
519
apt 命令 | 被取代的命令 | 命令的功能 |
---|---|---|
apt install | apt-get install | 安装软件包 |
apt remove | apt-get remove | 移除软件包 |
apt purge | apt-get purge | 移除软件包及配置文件 |
apt update | apt-get update | 刷新存储库索引 |
apt upgrade | apt-get upgrade | 升级所有可升级的软件包 |
apt autoremove | apt-get autoremove | 自动删除不需要的包 |
配置APT包索引配置文件 /etc/apt/sources.list
( apt edit-sources
该命令可直接编辑源列表 )
存放第三方源的APT包索引配置文件目录: /etc/apt/sources.list.d