API即Application Programming Interface,API可以在各种不同的操作系统上实现给应用程序提供完全相同的接口,而它们本身在这些系统上的实现却可能迥异,主流的操作系统有两种,一种是Windows系统,另一种是Linux系统。由于操作系统的不同,API又分为Windows API 和 Linux API。在Windows平台开发出来的软件在Linux上无法运行,在Linux上开发的软件在Windows上又无法运行,这就导致了软件移植困难,POSIX 标准的出现就是为了解决这个问题。
POSIX:Portable Operating System Interface 可移植操作系统接口,定义了操作系统应该为应用程序提供的接口标准,是IEEE为要在各种UNIX操作系统上运行的软件而定义的一系列API标准的总称。
linux和windows都要实现基本的posix标准,程序就在源代码级别可移植了。
1 2 3 4 5 6 7 8 9 10
//这段代码在win和 linux 下都可以编译通过,是因为 win 和 linux 中都有相同的头文件,都能找到 printf和 sleep 函数,且参数一样 #include<stdio.h> #include<unistd.h> intmain() { while (true){ printf("hello world\n"); sleep(1); } return0; }
[root@rocky86 h]# rpm -qi nginx Name : nginx Epoch : 1 Version : 1.14.1 Release : 9.module+el8.4.0+542+81547229 Architecture: x86_64 Install Date: Thu 14 Jul 2022 10:11:12 AM CST Group : System Environment/Daemons Size : 1669719 License : BSD Signature : RSA/SHA256, Thu 10 Jun 2021 05:22:38 PM CST, Key ID 15af5dac6d745a60 Source RPM : nginx-1.14.1-9.module+el8.4.0+542+81547229.src.rpm Build Date : Thu 10 Jun 2021 05:10:40 PM CST Build Host : ord1-prod-x86build005.svc.aws.rockylinux.org Relocations : (not relocatable) Packager : infrastructure@rockylinux.org Vendor : Rocky URL : http://nginx.org/ Summary : A high performance web server and reverse proxy server Description : Nginx is a web server and a reverse proxy server for HTTP, SMTP, POP3 and IMAP protocols, with a strong focus on high concurrency, performance and low memory usage.
#没有安装,可以指定程序包 [root@rocky86 h]# rpm -qi httpd package httpd is not installed
#-p指定rpm 包文件,新版可以省略此选项 [root@rocky86 h]# rpm -qip httpd-2.4.37-47.module+el8.6.0+823+f143cee1.1.x86_64.rpm Name : httpd Version : 2.4.37 Release : 47.module+el8.6.0+823+f143cee1.1 Architecture: x86_64 Install Date: (not installed) Group : System Environment/Daemons Size : 4499434 License : ASL 2.0 Signature : RSA/SHA256, Wed 11 May 2022 02:40:26 AM CST, Key ID 15af5dac6d745a60 Source RPM : httpd-2.4.37-47.module+el8.6.0+823+f143cee1.1.src.rpm Build Date : Wed 11 May 2022 02:06:03 AM CST Build Host : ord1-prod-x86build003.svc.aws.rockylinux.org Relocations : (not relocatable) Packager : infrastructure@rockylinux.org Vendor : Rocky URL : https://httpd.apache.org/ Summary : Apache HTTP Server Description : The Apache HTTP Server is a powerful, efficient, and extensible web server.
#字段说明 S #文件大小不一样 M #文件权限不一样或文件类型不一样 5 #md5 校验值不一样 D #版本号值不一样 L #链接路径不一样 U #属主发生了改变 G #属组发生了改变 T #修改时间发生了改变 P #功能发生了改变 c|d|g|l|r #文件类型 c配置文件, d数据文件,g该文件不属于此处,l许可文件(licens file),r自述文件(READ ME)
#参数写法,位置不一样,但结果相同 [root@rocky86 ~]# yum list sos --installed Installed Packages sos.noarch 4.2-15.el8 @anaconda
[root@rocky86 ~]# yum list --installed sos Installed Packages sos.noarch 4.2-15.el8 @anacond
#子命令写法,位置不一样,结果不同 [root@rocky86 ~]# yum list installed sos Installed Packages sos.noarch 4.2-15.el8 @anaconda
[root@rocky86 ~]# yum list sos installed Last metadata expiration check: 1:01:48 ago on Thu 28 Jul 2022 09:55:02 AM CST. Installed Packages sos.noarch 4.2-15.el8 @anaconda Available Packages sos.noarch 4.2-19.el8_6 aliyun-baseo
不带包名时,结果一致
1 2 3 4 5 6 7
#子命令写法 [root@rocky86 ~]# yum list installed | wc -l 1421
#选项写法 [root@rocky86 ~]# yum list --installed | wc -l 1421
#显示所有包,包括己安装的和repo源中的可用包 [root@rocky86 yum.repos.d]# yum list
#默认同 all [root@rocky86 yum.repos.d]# yum list | wc -l 7168
[root@rocky86 yum.repos.d]# yum list --all | wc -l 7168
#所有可用包 [root@rocky86 yum.repos.d]# yum list --available | wc -l 5747
#所有己安装的包 [root@rocky86 yum.repos.d]# yum list --installed
#所有可更新的包 [root@rocky86 yum.repos.d]# yum list --updates
#己安装的是 4.2-15 [root@rocky86 yum.repos.d]# yum list --installed | grep sos sos.noarch 4.2-15.el8 @anaconda
#可更新到 4.2-19 [root@rocky86 yum.repos.d]# yum list --updates | grep sos sos.noarch 4.2-19.el8_6 aliyun-baseos
#所有以 z 开头的包,包括己安装的和可安装的 [root@rocky86 yum.repos.d]# yum list --all z*
范例:显示所有可用包
1 2 3 4 5 6 7 8 9 10 11 12 13
#默认显示4.2-19 [root@rocky86 ~]# yum list --available sos Last metadata expiration check: 1:13:48 ago on Thu 28 Jul 2022 09:55:02 AM CST. Available Packages sos.noarch 4.2-19.el8_6 aliyun-baseos
#其实有两个版本 [root@rocky86 ~]# yum list --available --showduplicates sos Last metadata expiration check: 1:14:00 ago on Thu 28 Jul 2022 09:55:02 AM CST. Available Packages sos.noarch 4.2-15.el8 aliyun-baseos sos.noarch 4.2-19.el8_6 aliyun-baseo
#两个源都有php包 [root@rocky86 yum.repos.d]# yum list --available php Last metadata expiration check: 0:00:50 ago on Thu 28 Jul 2022 11:15:47 AM CST. Available Packages php.x86_64 7.2.24-1.module+el8.4.0+413+c9202dda aliyun-appstream php.x86_64 7.2.24-1.module+el8.4.0+413+c9202dda cdrom-appstream
#禁用某个源 [root@rocky86 yum.repos.d]# yum list --available --disablerepo=cdrom-appstream php Last metadata expiration check: 0:03:10 ago on Thu 28 Jul 2022 11:15:47 AM CST. Available Packages php.x86_64 7.2.24-1.module+el8.4.0+413+c9202dda aliyun-appstrea
#只能使用某个源 [root@rocky86 yum.repos.d]# yum list --available --repo=cdrom-appstream php Last metadata expiration check: 14:19:19 ago on Wed 27 Jul 2022 09:00:08 PM CST. Available Packages php.x86_64 7.2.24-1.module+el8.4.0+413+c9202dda cdrom-appstrea
#通配符写法 [root@rocky86 yum.repos.d]# yum list --available --repo=cd* php Last metadata expiration check: 14:19:48 ago on Wed 27 Jul 2022 09:00:08 PM CST. Available Packages php.x86_64 7.2.24-1.module+el8.4.0+413+c9202dda cdrom-appstrea
范例:通配符写法
1 2 3 4 5 6 7 8 9 10 11 12 13 14
[root@rocky86 yum.repos.d]# yum list --available --repoid=a* --repoid=cd* *sos* Last metadata expiration check: 0:08:32 ago on Thu 28 Jul 2022 11:15:47 AM CST. Available Packages abrt-plugin-sosreport.x86_64 2.10.9-21.el8.rocky.0 aliyun-appstream abrt-plugin-sosreport.x86_64 2.10.9-21.el8.rocky.0 cdrom-appstream sos.noarch 4.2-19.el8_6 aliyun-baseos sos-audit.noarch 4.2-19.el8_6 aliyun-baseos sos-collector.noarch 1.8-2.el8 aliyun-appstream sos-collector.noarch 1.8-2.el8 cdrom-appstream
#所有包 [root@rocky86 yum.repos.d]# yum info sos Last metadata expiration check: 1:10:03 ago on Thu 28 Jul 2022 01:19:46 PM CST. Installed Packages Name : sos Version : 4.2 Release : 15.el8 Architecture : noarch Size : 2.5 M Source : sos-4.2-15.el8.src.rpm Repository : @System From repo : anaconda Summary : A set of tools to gather troubleshooting information from a system URL : https://github.com/sosreport/sos License : GPLv2+ Description : Sos is a set of tools that gathers information about system : hardware and configuration. The information can then be used for : diagnostic purposes and debugging. Sos is commonly used to help : support technicians and developers. Available Packages Name : sos Version : 4.2 Release : 19.el8_6 Architecture : noarch Size : 776 k Source : sos-4.2-19.el8_6.src.rpm Repository : aliyun-baseos Summary : A set of tools to gather troubleshooting information from a system URL : https://github.com/sosreport/sos License : GPLv2+ Description : Sos is a set of tools that gathers information about system : hardware and configuration. The information can then be used for : diagnostic purposes and debugging. Sos is commonly used to help : support technicians and developers. #己安装的包 [root@rocky86 yum.repos.d]# yum info --installed sos Installed Packages Name : sos Version : 4.2 Release : 15.el8 Architecture : noarch Size : 2.5 M Source : sos-4.2-15.el8.src.rpm Repository : @System From repo : anaconda Summary : A set of tools to gather troubleshooting information from a system URL : https://github.com/sosreport/sos License : GPLv2+ Description : Sos is a set of tools that gathers information about system : hardware and configuration. The information can then be used for : diagnostic purposes and debugging. Sos is commonly used to help : support technicians and developers.
[root@rocky86 yum.repos.d]# rpm -qi sos Name : sos Version : 4.2 Release : 15.el8 Architecture: noarch Install Date: Sun 03 Jul 2022 08:50:37 PM CST Group : Applications/System Size : 2597877 License : GPLv2+ Signature : RSA/SHA256, Mon 02 May 2022 06:18:20 PM CST, Key ID 15af5dac6d745a60 Source RPM : sos-4.2-15.el8.src.rpm Build Date : Tue 12 Apr 2022 03:03:04 PM CST Build Host : ord1-prod-a64build004.svc.aws.rockylinux.org Relocations : (not relocatable) Packager : infrastructure@rockylinux.org Vendor : Rocky URL : https://github.com/sosreport/sos Summary : A set of tools to gather troubleshooting information from a system Description : Sos is a set of tools that gathers information about system hardware and configuration. The information can then be used for diagnostic purposes and debugging. Sos is commonly used to help support technicians and developers.
#默认所有 [root@rocky86 yum.repos.d]# yum provides /usr/sbin/sos Last metadata expiration check: 1:19:01 ago on Thu 28 Jul 2022 01:19:46 PM CST. sos-4.2-15.el8.noarch : A set of tools to gather troubleshooting information from a system Repo : @System Matched from: Filename : /usr/sbin/sos sos-4.2-15.el8.noarch : A set of tools to gather troubleshooting information from a system Repo : aliyun-baseos Matched from: Filename : /usr/sbin/sos sos-4.2-19.el8_6.noarch : A set of tools to gather troubleshooting information from a system Repo : aliyun-baseos Matched from: Filename : /usr/sbin/sos
#指定repo源 [root@rocky86 yum.repos.d]# yum provides /usr/sbin/nginx --repoid=cdrom-appstream Last metadata expiration check: 17:52:24 ago on Wed 27 Jul 2022 09:00:08 PM CST. nginx-1:1.14.1-9.module+el8.4.0+542+81547229.x86_64 : A high performance web server and reverse proxy server Repo : @System Matched from: Filename : /usr/sbin/nginx nginx-1:1.14.1-9.module+el8.4.0+542+81547229.x86_64 : A high performance web server and reverse proxy server Repo : cdrom-appstream Matched from: Filename : /usr/sbin/nginx
在包名和关键字中搜索
1 2 3 4 5 6 7 8 9 10 11 12 13 14
[root@rocky86 ~]# yum search redis Last metadata expiration check: 1:46:18 ago on Thu 28 Jul 2022 01:19:46 PM CST. ====================== Name Exactly Matched: redis ====================== redis.x86_64 : A persistent key-value database ===================== Name & Summary Matched: redis ====================== pcp-pmda-redis.x86_64 : Performance Co-Pilot (PCP) metrics for Redis redis-devel.x86_64 : Development header for Redis module development redis-doc.noarch : Documentation for Redis including man pages
#多个关键字,且 关系 [root@rocky86 ~]# yum search redis key-value Last metadata expiration check: 1:49:16 ago on Thu 28 Jul 2022 01:19:46 PM CST. ===================== Name & Summary Matched: key-value, redis ============== redis.x86_64 : A persistent key-value database
#查询 root@ubuntu22:~# dpkg -V firmware-sof-signed dpkg: package 'firmware-sof-signed' is not installed
#安装 root@ubuntu22:~# dpkg -i /cdrom/pool/restricted/f/firmware-sof/firmware-sof-signed_2.0-1ubuntu2_all.deb Selecting previously unselected package firmware-sof-signed. (Reading database ... 108476 files and directories currently installed.) Preparing to unpack .../firmware-sof-signed_2.0-1ubuntu2_all.deb ... Unpacking firmware-sof-signed (2.0-1ubuntu2) ... Setting up firmware-sof-signed (2.0-1ubuntu2) ...
#查询 root@ubuntu22:~# dpkg -l firmware-sof-signed 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 firmware-sof-signed 2.0-1ubuntu2 all Intel SOF firmware - signed
#卸载 root@ubuntu22:~# dpkg -r firmware-sof-signed (Reading database ... 108702 files and directories currently installed.) Removing firmware-sof-signed (2.0-1ubuntu2) ...
mage@ubuntu22:~$ dpkg -l 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 adduser 3.118ubuntu5 all add and remove users and groups ii amd64-microcode 3.20191218.1ubuntu2 amd64 Processor microcode firmware for AMD CPUs ii apparmor 3.0.4-2ubuntu2 amd64 user-space parser utility for AppArmor ii apport-symptoms 0.24 all symptom scripts for apport ii apt 2.4.5 amd64 commandline package manager ii apt-utils 2.4.5 amd64 package management related utility programs ii base-files 12ubuntu4 amd64 Debian base system miscellaneous files ii base-passwd 3.5.52build1 amd64 Debian base system master password and group files ii bash 5.1-6ubuntu1 amd64 GNU Bourne Again SHell ii bash-completion 1:2.11-5ubuntu1 all programmable completion for the bash shell
范例:通配符
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
mage@ubuntu22:~$ dpkg -l "vi*" 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 vim 2:8.2.3995-1ubuntu2 amd64 Vi IMproved - enhanced vi editor un vim-athena <none> <none> (no description available) ii vim-common 2:8.2.3995-1ubuntu2 all Vi IMproved - Common files un vim-doc <none> <none> (no description available) un vim-gtk3 <none> <none> (no description available) un vim-nox <none> <none> (no description available) ii vim-runtime 2:8.2.3995-1ubuntu2 all Vi IMproved - Runtime files un vim-scripts <none> <none> (no description available) ii vim-tiny 2:8.2.3995-1ubuntu2 amd64 Vi IMproved - enhanced vi editor - compact version un virtualbox-guest-modules <none> <none> (no description available)
范例:具体包名
1 2 3 4 5 6 7
mage@ubuntu22:~$ dpkg -l vim 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 vim 2:8.2.3995-1ubuntu2 amd64 Vi IMproved - enhanced vi editor
#Desired Status Err Name Version Architecture Description
#Desired 期望状态 u Unknown 没有安装过 i Install 请求安装 r Remove 请求卸载 p Purge 请求卸载并清理 h Hold 保持 #Status 当前状态 n Not 软件没有安装 i Inst 安装完成并完成配置 c Conf-files 己卸载,但还有保留配置文件 u Unpacked 己解压缩,但没有配置 f halF-conf 配置时出错 h Half-inst 安装时出错 w trig-aWait 触发器等待 t Trig-pend 触发器是未决状态
#Err 错误状态 正常情况下为空 h 被锁定,有其它包对此依赖,无法升级 r Reinst-required, 被损坏,需要重装才能正常使用 x 被损坏且被锁定
deb https://mirrors.aliyun.com/ubuntu jammy main restricted #表示使用主仓中的 main和 restricted 源 # deb-src https://mirrors.aliyun.com/ubuntu jammy main restricted
deb https://mirrors.aliyun.com/ubuntu jammy-updates main restricted # deb-src https://mirrors.aliyun.com/ubuntu jammy-updates main restricted
#指定安装目录,开启ssl模块,开始编译 [root@rocky86 nginx-1.23.0]# ./configure --prefix=/lnmp/nginx --with-http_ssl_module checking for OS + Linux 4.18.0-372.9.1.el8.x86_64 x86_64 checking for C compiler ... not found
#再次编译 [root@rocky86 nginx-1.23.0]# ./configure --prefix=/lnmp/nginx --with-http_ssl_module ./configure: error: the HTTP rewrite module requires the PCRE library. You can either disable the module by using --without-http_rewrite_module option, or install the PCRE library into the system, or build the PCRE library statically from the source with nginx by using --with-pcre=<path> option.
#再次编译 [root@rocky86 nginx-1.23.0]# ./configure --prefix=/lnmp/nginx --with-http_ssl_module ./configure: error: SSL modules require the OpenSSL library. You can either do not enable the modules, or install the OpenSSL library into the system, or build the OpenSSL library statically from the source with nginx by using --with-openssl=<path> option.
#查看版本信息 [root@rocky86 nginx-1.23.0]# /lnmp/nginx/sbin/nginx -V nginx version: nginx/1.23.0 built by gcc 8.5.0 20210514 (Red Hat 8.5.0-10) (GCC) built with OpenSSL 1.1.1k FIPS 25 Mar 2021 TLS SNI support enabled configure arguments: --prefix=/lnmp/nginx --with-http_ssl_module