1.软件包分类
源码包
二进制包
2.源码包
优点
可修改
可自由选择需要的功能
软件是编译安装,更加适合系统,更加稳定和高效
卸载方便
缺点
编译时间长
错误新手不容易解决
3.二进制包
DPKG:是由Debian Linux开发出来的包管理机制,通过DPKG包,Debian Linux就可以进行软件的包管理,主要用于Debain和ubuntu中。dpkg 是Debian Packager 的简写。俗称deb包。
root@ubuntu:/home/yanyanzhang/shell_study# 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 a11y-profile-manager-indicator 0.1.10-0ubuntu3 amd64 Accessibility Profile Manager - Unity desktop indicator
ii account-plugin-facebook 0.12+16.04.20160126-0u all GNOME Control Center account plugin for single signon - facebook
ii account-plugin-flickr 0.12+16.04.20160126-0u all GNOME Control Center account plugin for single signon - flickr
ii account-plugin-google 0.12+16.04.20160126-0u all GNOME Control Center account plugin for single signon
ii accountsservice 0.6.40-2ubuntu11.6 amd64 query and manipulate user account information
ii acl 2.2.52-3 amd64 Access control list utilities
ii acpi-support 0.142 amd64 scripts for handling many ACPI events
ii acpid 1:2.0.26-1ubuntu2 amd64 Advanced Configuration and Power Interface event daemon
ii activity-log-manager 0.9.7-0ubuntu23.16.04. amd64 blacklist configuration user interface for Zeitgeist
ii adduser 3.113+nmu3ubuntu4 all add and remove users and groups
ii adium-theme-ubuntu 0.3.4-0ubuntu1.1 all Adium message style for Ubuntu
ii adwaita-icon-theme 3.18.0-2ubuntu3.1 all default icon theme of GNOME (small subset)
ii aisleriot 1:3.18.2-1ubuntu1 amd64 GNOME solitaire card game collection
ii alien 8.95 all convert and install rpm and other packages
ii alsa-base 1.0.25+dfsg-0ubuntu5 all ALSA driver configuration files
ii alsa-utils 1.1.0-0ubuntu5 amd64 Utilities for configuring and using ALSA
ii amd64-microcode 3.20191021.1+really3.2 amd64 Processor microcode firmware for AMD CPUs
ii anacron 2.3-23 amd64 cron-like program that doesn't go by time
RPM:是由Red Hat 公司开发的包管理系统,功能强大,安装升级查询卸载非常简单,Fedora, Centos都是用这种管理系统。
RPM包的优缺点
优点
包管理系统简单
安装速度快
缺点
不能看原码
功能选择不如源码包灵活
依赖性强,安装a需要先安装b
软件包选择建议:
源码包:给客户大量访问,建议源码包,源码包效率更高(LAMP)
RPM包:少量用户访问或者本地使用,建议RPM包,管理方便
4.安装rpm包
rpm包的命名规则
httpd-2.4.4-1.x86_64.rpm:apache在linux里面就叫httpd,2.4.4版本号,1发布次数,x86_64适合的硬件平台。
包全名:操作未安装的软件包,则使用包全名,而且需要注意绝对路径
包名:操作已经安装的包,使用包名即可,因为系统会产生RPM包的数据库(/var/lib/rpm), 而且不需要注意绝对路径。
练习:centos7用rpm的形式,安装apache
rmp -ivh 全包名
-i: install安装
-v:显示详细信息
-h:打印安装进度
原因:需要先下载挂载到指定目录下,因此这些包都得先挂载,特别麻烦,而且安装中各种依赖,对于安装顺序也有要求,因此出现了 yum 在线安装,解决这些问题。
常见的目rpm安装源有:http://mirrors.163.com/centos/6/os/x86_64/Packages/,下载后用 rmp -ivh 包名 安装即可
YUM
1. rpm软件包形式的管理虽然方便,但是需要手工解决软件包的依赖关系。很多时候安装一个软件安装一个软件需要安装1个或者多个其他软件,手动解决时,很复杂,yum解决这些问题。Yum是rpm的前端程序,主要目的是设计用来自动解决rpm的依赖关系,其特点:
1) 自动解决依赖关系
2) 可以对rpm进行分组,基于组进行安装操作
3) 引入仓库概念,支持多个仓库
4) 配置简单
2. yum仓库用来存放所有的现有的.rpm包,当使用yum安装一个rpm包时,需要依赖关系,会自动在仓库中查找依赖软件并安装。仓库可以是本地的,也可以是HTTP、FTP、nfs形式使用的集中地、统一的网络仓库。
3. 仓库的配置文件/etc/yum.repos.d目录下
1)先将httpd需要的几个rpm包下载到指定目录,不安装,目录为/mnt/cdfom/Packages
yum -y install --downloadonly httpd --downloaddir=/mnt/cdrom/Packages/ 将包下载到指定目录下
[root@macbook Packages]# yum -y install --downloadonly httpd --downloaddir=/mnt/cdrom/Packages/
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.tuna.tsinghua.edu.cn
* extras: mirrors.tuna.tsinghua.edu.cn
* updates: mirrors.tuna.tsinghua.edu.cn
正在解决依赖关系
--> 正在检查事务
---> 软件包 httpd.x86_64.0.2.4.6-97.el7.centos 将被 安装
--> 正在处理依赖关系 httpd-tools = 2.4.6-97.el7.centos,它被软件包 httpd-2.4.6-97.el7.centos.x86_64 需要
--> 正在处理依赖关系 /etc/mime.types,它被软件包 httpd-2.4.6-97.el7.centos.x86_64 需要
--> 正在处理依赖关系 libaprutil-1.so.0()(64bit),它被软件包 httpd-2.4.6-97.el7.centos.x86_64 需要
--> 正在处理依赖关系 libapr-1.so.0()(64bit),它被软件包 httpd-2.4.6-97.el7.centos.x86_64 需要
--> 正在检查事务
---> 软件包 apr.x86_64.0.1.4.8-7.el7 将被 安装
---> 软件包 apr-util.x86_64.0.1.5.2-6.el7 将被 安装
---> 软件包 httpd-tools.x86_64.0.2.4.6-97.el7.centos 将被 安装
---> 软件包 mailcap.noarch.0.2.1.41-2.el7 将被 安装
--> 解决依赖关系完成
依赖关系解决
==========================================================================================================================
Package 架构 版本 源 大小
==========================================================================================================================
正在安装:
httpd x86_64 2.4.6-97.el7.centos updates 2.7 M
为依赖而安装:
apr x86_64 1.4.8-7.el7 base 104 k
apr-util x86_64 1.5.2-6.el7 base 92 k
httpd-tools x86_64 2.4.6-97.el7.centos updates 93 k
mailcap noarch 2.1.41-2.el7 base 31 k
事务概要
==========================================================================================================================
安装 1 软件包 (+4 依赖软件包)
总下载量:3.0 M
安装大小:10 M
Background downloading packages, then exiting:
Delta RPMs disabled because /usr/bin/applydeltarpm not installed.
(1/5): apr-1.4.8-7.el7.x86_64.rpm | 104 kB 00:00:00
(2/5): apr-util-1.5.2-6.el7.x86_64.rpm | 92 kB 00:00:00
(3/5): httpd-tools-2.4.6-97.el7.centos.x86_64.rpm | 93 kB 00:00:00
(4/5): httpd-2.4.6-97.el7.centos.x86_64.rpm | 2.7 MB 00:00:00
(5/5): mailcap-2.1.41-2.el7.noarch.rpm | 31 kB 00:00:00
--------------------------------------------------------------------------------------------------------------------------
总计 4.6 MB/s | 3.0 MB 00:00:00
exiting because "Download Only" specified
[root@macbook Packages]# ls
apr-1.4.8-7.el7.x86_64.rpm httpd-2.4.4-1.x86_64.rpm httpd-tools-2.4.6-97.el7.centos.x86_64.rpm
apr-util-1.5.2-6.el7.x86_64.rpm httpd-2.4.6-97.el7.centos.x86_64.rpm mailcap-2.1.41-2.el7.noarch.rpm
2)使用 rpm -ivh xxxx.rpm安装
[root@macbook Packages]# ls
apr-1.4.8-7.el7.x86_64.rpm httpd-2.4.4-1.x86_64.rpm httpd-tools-2.4.6-97.el7.centos.x86_64.rpm
apr-util-1.5.2-6.el7.x86_64.rpm httpd-2.4.6-97.el7.centos.x86_64.rpm mailcap-2.1.41-2.el7.noarch.rpm
[root@macbook Packages]# rpm -ivh /mnt/cdrom/Packages/httpd-tools-2.4.6-97.el7.centos.x86_64.rpm
错误:依赖检测失败:
libapr-1.so.0()(64bit) 被 httpd-tools-2.4.6-97.el7.centos.x86_64 需要
libaprutil-1.so.0()(64bit) 被 httpd-tools-2.4.6-97.el7.centos.x86_64 需要
这种依赖关系就很强,先安装libapr-1.so.0,还要先下载这个包东西,rpm可能适合先将所有需要的依赖都下载下来,然后在执行安装。
5.安装dpkg包
版本 | 格式 | 工具 |
Ubuntu | .deb | apt,apt-cache,apt-get,dpkg |
Debian | .deb | apt,apt-cache,apt-get,dpkg |
apt和dpkg的区别
apt是会解决和安装模块的依赖问题,并会咨询软件仓库,是在线安装。
dpkg只能安装本地的deb文件,不会关心Ubuntu的软件仓库内的软件,不会解决模块的依赖关系。
两者的区别是dpkg绕过apt包管理数据库对软件包进行操作,所以你用dpkg安装过的软件包用apt可以再安装一遍,系统不知道之前安装过了,将会覆盖之前dpkg的安装。
apt和dpkg就相当于centos的 rpm和yum的关系。
公司项目中基本都是使用dpkg的形式从自己搭建的服务器上安装离线包。
dpkg常用指令
dpkg -i package.deb # 安装一个 Debian 软件包,如手动下载的文件。
dpkg -c package.deb # 列出 package.deb 的内容。
dpkg -I package.deb # 从 package.deb 中提取包信息。
dpkg -r package # 移除一个已安装的包。
dpkg -P package # 完全清除一个已安装的包。和 remove 不同的是,remove 只是删掉数据和可执行文件,purge 另外还删除所有的配制文件。
dpkg -L package # 列出 package 安装的所有文件清单。
dpkg -s package # 显示已安装包的信息。
dpkg -reconfigure package # 重新配制一个已经安装的包,如果它使用的是 debconf (debconf 为包安装提供了一个统一的配置界面)。
dpkg -S package # 查看软件在哪个包里;
dpkg -b ${DIR_BUILD} ./icsPortal_${VERSION}_amd64.deb
apt常用指令
sudo apt-get install # package 安装包
sudo apt-get reinstall # package - - reinstall 重新安装包
sudo apt-get remove # package 删除包
sudo apt-get remove --purge # package 删除包,包括删除配置文件等
sudo apt-get autoremove --purge # package 删除包及其依赖的软件包配置文件等
sudo apt-get update # 更新源
sudo apt-get upgrade # 更新已安装的包
sudo apt-get dist-upgrade # 升级系统
apt search :搜索能够安装的xx版本
root@ubuntu:/# apt search pymysql
Sorting... Done
Full Text Search... Done
python-pymysql/xenial-updates,xenial-updates 0.7.2-1ubuntu1 all
Pure-Python MySQL driver - Python 2.x
python3-pymysql/xenial-updates,xenial-updates 0.7.2-1ubuntu1 all
Pure-Python MySQL Driver - Python 3.x
apt-get install -d package_name:只下载不安装xxx二进制包
root@ubuntu:/# apt-get install -d redis-server Reading package lists... Done Building dependency tree Reading state information... Done The following additional packages will be installed: libjemalloc1 redis-tools Suggested packages: ruby-redis The following NEW packages will be installed: libjemalloc1 redis-server redis-tools # 需要下载三个包 0 upgraded, 3 newly installed, 0 to remove and 96 not upgraded. 2 not fully installed or removed. Need to get 519 kB of archives. After this operation, 1,507 kB of additional disk space will be used. Do you want to continue? [Y/n] y Get:1 http://us.archive.ubuntu.com/ubuntu xenial/universe amd64 libjemalloc1 amd64 3.6.0-9ubuntu1 [78.9 kB] Get:2 http://us.archive.ubuntu.com/ubuntu xenial-updates/universe amd64 redis-tools amd64 2:3.0.6-1ubuntu0.4 [95.5 kB] Get:3 http://us.archive.ubuntu.com/ubuntu xenial-updates/universe amd64 redis-server amd64 2:3.0.6-1ubuntu0.4 [344 kB] Fetched 519 kB in 6s (77.5 kB/s) Download complete and in download only mode
看redis包的安装位置
root@ubuntu:/var/cache/apt/archives# ls |grep redis
redis-server_2%3a3.0.6-1ubuntu0.4_amd64.deb # .deb包
redis-tools_2%3a3.0.6-1ubuntu0.4_amd64.deb
root@ubuntu:/var/cache/apt/archives# pwd
/var/cache/apt/archives # 默认的安装位置
注意:apt-get install -d xxx, 只能将包下载到 /var/cache/apt/archives 下,用户无法指定下载目录,都是用默认目录(因为这个目录是包作者维护的,一般都是默认目录)
apt-get source pkgname --download-only 只下载不安装源码包
xiaoming@iZwz9434lxf5ptexiu13giZ:~$ apt-get source redis-server --download-only
Reading package lists... Done
Picking 'redis' as source package instead of 'redis-server'
NOTICE: 'redis' packaging is maintained in the 'Git' version control system at:
git://github.com/lamby/pkg-redis.git
Please use:
git clone git://github.com/lamby/pkg-redis.git
to retrieve the latest (possibly unreleased) updates to the package.
Need to get 1,413 kB of source archives.
Get:1 http://mirrors.cloud.aliyuncs.com/ubuntu xenial-updates/universe redis 2:3.0.6-1ubuntu0.4 (dsc) [2,135 B]
Get:2 http://mirrors.cloud.aliyuncs.com/ubuntu xenial-updates/universe redis 2:3.0.6-1ubuntu0.4 (tar) [1,373 kB]
Get:3 http://mirrors.cloud.aliyuncs.com/ubuntu xenial-updates/universe redis 2:3.0.6-1ubuntu0.4 (diff) [38.3 kB]
Fetched 1,413 kB in 1s (1,030 kB/s)
Download complete and in download only mode
xiaoming@iZwz9434lxf5ptexiu13giZ:~$ cd /var/cache/ap
apparmor/ apt/
xiaoming@iZwz9434lxf5ptexiu13giZ:~$ cd /var/cache/apt/archives/ # 源码包并没有在默认的位置,源码包在哪里下载就在哪里放置
xiaoming@iZwz9434lxf5ptexiu13giZ:/var/cache/apt/archives$ ls
lock partial ssl-cert_1.0.37_all.deb vsftpd_3.0.3-3ubuntu2_amd64.deb
xiaoming@iZwz9434lxf5ptexiu13giZ:/var/cache/apt/archives$
# 源码包位置,建议要统一目录存放源码包
root@iZwz9434lxf5ptexiu13giZ:/home/xiaoming# ls
redis_3.0.6-1ubuntu0.4.debian.tar.xz redis_3.0.6-1ubuntu0.4.dsc redis_3.0.6.orig.tar.gz
# .dsc 源码包的描述文件,包含包的名称,文件列表和校验信息。
# .tar.xz debian包的打包文件,里面包含编译次源码包并将其打包为debain包的控制文件
# .orig.tar.gz 真正的源代码,dpkg-source xxxx.orig.tar.gz 专门的解压命令解压
apt list:查看已经安装的包
apt几个缺省路径
下载的软件存放位置:/var/cache/apt/archives # apt-get二进制包位置,
安装后软件默认位置:/usr/share
可执行文件位置:/usr/bin
配置文件位置:/etc
库文件位置:/usr/lib
apt-cache 搜索包的管理
apt-cache search redis-server
root@ubuntu:/var/cache/apt/archives# apt-cache search redis-server # 搜索这个包的简要信息,以及使用情况
python-hiredis - redis protocol reader for Python 2.X using hiredis
python3-hiredis - redis protocol reader for Python using hiredis
redis-server - Persistent key-value database with network interface
apt-cache show redis-server:显示这个包的详细信息,大小,依赖等
root@ubuntu:/var/cache/apt/archives# apt-cache show redis-server
Package: redis-server
Architecture: amd64
Version: 2:3.0.6-1ubuntu0.4
Priority: optional
Section: universe/misc
Source: redis
Origin: Ubuntu
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Original-Maintainer: Chris Lamb <lamby@debian.org>
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Installed-Size: 897
Depends: adduser, redis-tools (= 2:3.0.6-1ubuntu0.4), init-system-helpers (>= 1.18~), libc6 (>= 2.14), libjemalloc1 (>= 2.1.1)
Filename: pool/universe/r/redis/redis-server_3.0.6-1ubuntu0.4_amd64.deb
Size: 344118
MD5sum: b5df6ebd74a56c5b2b0151d48c6af898
SHA1: 48459cffc057f3f6a1445ee7ff4cced8b6a5f653
SHA256: f955dec576fa3cf5beb5354aed586f9c0f59fd159eab9631454a1198cac012e2
SHA512: 24f939178cc792fd27a25109f18d9c988df8c98c503d110afe948c90dc204a094ef3b5eb8bcff87d00e6862fcb56c340fa67fe12e0b4209e6720896b5fcf1f3e
Homepage: http://redis.io/
Description-en: Persistent key-value database with network interface
Redis is a key-value database in a similar vein to memcache but the dataset
is non-volatile. Redis additionally provides native support for atomically
manipulating and querying data structures such as lists and sets.
.
The dataset is stored entirely in memory and periodically flushed to disk.
Description-md5: 9160ed1405585ab844f8750a9305d33f
Package: redis-server
Priority: optional
Section: universe/misc
Installed-Size: 896
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Original-Maintainer: Chris Lamb <lamby@debian.org>
sudo apt-cache showpkg package 显示软件包信息,包括包的依赖关系,包的提供者
sudo apt-cache pkgnames 打印软件包列表中所有包的名字
sudo apt-cache dumpavail 打印软件包列表中所有包的简介信息
sudo apt-cache depends package 了解使用依赖
sudo apt-cache rdepends package 是查看该包被哪些包依赖
6. deb包
deb包的特点
1. 主要用于Debain和ubuntu中。dpkg 是Debian Packager 的简写。俗称deb包。
2. 基于tar包,所以同样会记录着文件的权限信息(读、写、可执行)、所有者、用户组等
为什么要将代码打包发布?
1. 新功能新依赖,不能让用这个产品的机器装这个依赖,因此需要把项目运行及所需的环境打成一个包,例如 docker的image,只要在本地机上装上docker执行运行镜像的容器即可。
2.安全考虑,打包其实就是将源代码编译成字节码,二进制形式,防止代码泄露。
练习一:将一个.py文件打成一个deb包
step1:任意位置创建一个空的文件夹
root@iZwz9434lxf5ptexiu13giZ:/home# ls deb_test1 deb_test1.log deb_test1_v1.0.deb test_output uftp vsftpd搭建.md xiaoming xiaowang xiaowang.txt yyz
step2: 按照debain包的规范文件结构,创建目录和文件
boot:放置文件夹的地方,一般是真个工程,我这里放置的是一个.pyc文件
DEBIAN:固定写法
control:这个文件主要描述软件包的名称(Package),版本(Version),Installed-Size(大小),Maintainer(打包人和联系方式)以及描述(Description)等,是deb包必须具备的描述性文件,以便于软件的安装管理和索引。最后一行必须为空
Package:yyztest # 程序名称 Version:1.0 # 版本 Description:let me take you to happy planet # 程序说明 Section:net # 类别 utils, net, mail, text, x11 Priority:standard # 软件对于系统重要程序,require, standard, optional, extra Essential:no # 是否是系统最基本的软件包 yes/no yes的话,不允许卸载,除非强制卸载 Architecture:amd64 # 软件支持的平台架构 i386, amd64, m68k, sparc, alpha, powerpc Source:flask_test # 软件包源代码名称 maintainer:yan # 拥有者
#####----没用的到参数----#######
Pre-Depends 软件安装前需要依赖的包
Suggests 建议安装的其他软件和包
Recommends 推荐安装的其他软件和包
postinst:负责完成安装包时的配置工作。如新安装或升级的软件重启服务。软件安装完后,执行该Shell脚本,一般用来配置软件执行环境,必须以“#!/bin/sh”为首行。
root@iZwz9434lxf5ptexiu13giZ:/home/deb_test1/DEBIAN# cat postinst #!/bin/bash # deb安装完成后先执行这个脚本 # 覆盖重定向 echo "welcome to my wrold, deb already installed " > /home/deb_test1.log
preinst:在Deb包文件解包之前(即软件安装前),将会运行该脚本。可以停止作用于待升级软件包的服务,直到软件包安装或升级完成。本例为空文件
prerm:该脚本负责停止与软件包相关联的daemon服务。它在删除软件包关联文件之前执行。本例为空文件
postrm:负责修改软件包链接或文件关联,或删除由它创建的文件。软件卸载后,执行该Shell脚本,一般作为清理收尾工作,必须以“#!/bin/sh”为首行。
root@iZwz9434lxf5ptexiu13giZ:/home/deb_test1/DEBIAN# cat postrm #!/bin/bash # 软件卸载后会执行这个脚本 rm -rf /home/deb_test1.log echo "goodbye!"
本例中etc、tmp、opt、usr都是空文件夹
网上usr的使用:
step3:开始打包
# TODO