一、概述

㈠ 软件的类型

A. 二进制包 已编译 mysql-community-common-5.7.12-1.el7.x86_64.rpm

B. 源码包 需要编译 nginx-1.8.1.tar.gz 

RPM Package Manager(原Red Hat Package Manager,现在是一个递归缩写)

注意: 不管是源码包,还是二进制包,安装时都可能会有依赖关系!

㈡ 常见二进制包(了解):系统平台;包类型;工具;在线安装(自动解决依赖关系)

RedHat/Centos;RPM;rpm,rpmbuild;yum

Ubuntu/Debian;DPKG;dpkg;apt


二 RPG 包管理

㈠  YUM源(YUM仓库)

1.本地源:安装光盘 [了解]

目的:通过系统光盘安装软件(90%都有)

① 删除YUM库

[root@tianyun ~]# rm -rf /etc/yum.repos.d/*

② 挂载安装光盘(临时):

[root@tianyun ~]# mount /dev/cdrom  /mnt

③ 编写配置文件

[root@tianyun ~]# vim /etc/yum.repos.d/dvd.repo 

[dvd] 

name=dvd 

baseurl=file:///mnt/

gpgcheck=0 

④ 使用YUM 安装和卸载程序即可。

[root@tianyun ~]#yum install -y httpd


2.使用官方源

目的:使用厂商提供的软件包作为YUM的仓库。

①阿里云

Base/Extras/Updates: 默认(国外源)

1 删除原先YUM库

rm -rf /etc/yum.repos.d/*

3 下载阿里源

wget http://mirrors.aliyun.com/repo/Centos-7.repo  -O /etc/yum.repos.d/CentOS-Base.repo 

4 更新YUM源

yum makecache

wget -O或者curl -O

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

已加载插件:fastestmirror, langpacks

base                                                                                                                 | 3.6 kB  00:00:00     

extras                                                                                                               

| 3.4 kB  00:00:00     

updates                                                                                                               | 3.4 kB  00:00:00     

(1/4): extras/7/x86_64/primary_db                                                                                             

| 110 kB  00:00:00     

(2/4): base/7/x86_64/group_gz                                                                                                 | 156 kB  00:00:01     

(3/4): updates/7/x86_64/primary_db                                                                                             | 2.7 MB  00:00:01     

base/7/x86_64/primary_db   FAILED                                          

http://mirrors.aliyuncs.com/centos/7/os/x86_64/repodata/0c34273ad0292747ee5e15c047d3e51c67ca59861a446972db45d71abacc7ad7-primary.sqlite.bz2: [Errno 12] Timeout on http://mirrors.aliyuncs.com/centos/7/os/x86_64/repodata/0c34273ad0292747ee5e15c047d3e51c67ca59861a446972db45d71abacc7ad7-primary.sqlite.bz2: (28, 'Connection timed out after 30001 milliseconds')

正在尝试其它镜像。

(4/4): base/7/x86_64/primary_db                                                                                               | 5.7 MB  00:00:04     

Loading mirror speeds from cached hostfile

 * base: mirrors.aliyun.com

 * extras: mirrors.aliyun.com

 * updates: mirrors.aliyun.com

                                                                                                                 

源标识                      源名称                       状态

base/7/x86_64      CentOS-7 - Base - mirrors.aliyun.com              9,591                                                            

extras/7/x86_64     CentOS-7 - Extras - mirrors.aliyun.com             227                


updates/7/x86_64    CentOS-7 - Updates - mirrors.aliyun.com            740                             


repolist: 10,558

    

教程:http://mirrors.aliyun.com/



② EPEL: 

wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo (aliyun)


④ Nginx:(配置文件)

目的:通过查找官网了解构建官方源的原理。

第一步:找到提示

第二步:根据提示创建YUM配置文件

第三步: 查看服务器是否已经具备软件官方源。

网站:

document文档》install安装》packet包说明

12.PNG

13.png

14.png

1 根据提示创建YUM配置文件

2 根据提示替换关键字,centos和7

配置示例:

[root@localhost ~]# vim /etc/yum.repos.d/nginx.repo

[nginx]

name=nginx repo

baseurl=http://nginx.org/packages/centos/7/$basearch/

gpgcheck=0

enabled=1

结果示例

提示:

系统的更新和升级,可以使用基础源(aliyun,163)。

软件的使用建议使用官方源(nginx.com/mysql.com)


③ MySQL:(链接地址)

帮助:

21.png

参考指南:

22.png

安装指南(左边栏)

23.png

24.png

下载YUM源配置文件(网站主页)

25.png

不登录,直接使用

26.png


下载后复制链接

27.png

在服务器上,下载该链接

wget  https://repo.mysql.com.........

ls   查看是否下载完成。

然后使用yum 再装该软件包。

yum -y install mysql57-community-release-el7-9.noarch.rpm

终极大法

yum -y install https://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm

查看源

28.png

总结:当官方源配置完成,服务器就可以进行安装软件并使用该软件了。


④ Zabbix:(链接地址)

网址

1 打开官网

https://www.zabbix.com

41.png


42.png

43.png

rpm -ivh .....

yum list | grep zabbix

1 找到安装源

2 安装 

rpm -ivh http://repo.zabbix.com/zabbix/3.2/rhel/7/x86_64/zabbix-release-3.2-1.el7.noarch.rpm

44.png


⑤ openstack:

网站路径

61.png



62.png

63.png

yum install -y centos-release-openstack-newton

注意:

校内有DNS服务器。可能导致外网源故障,vim /etc/resolv.conf 

nameserver 8.8.8.8

nameserver 114.114.114.114

nameserver 202.106.0.20


2、使用YUM管理RPM包

① 查看可用仓库

[root@tianyun ~]# yum clean all //清空缓存及其它文件(可以通过清理nginx.rpm观察)

[root@tianyun ~]# yum makecache //重建缓存

[root@tianyun ~]# yum repolist //查询可用的仓库


② 安装

全新安装

# yum -y install httpd vsftpd *vnc

# yum -y install https://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm //从互联网安装


③ 重新安装

# yum -y reinstall httpd //有损坏才重新部署修复。(尝试损坏httpd程序)


④ 升级安装

# yum -y update httpd

# yum -y update //系统更新,请在安装系统后立即执行。(实验室请不要执行)

# yum -y update kernal //升级内核。重启就看到了。(已更新)

⑤ 组安装

# yum -y groupinstall mariadb


⑥ 查询

查询HTTP程序

# yum list httpd

带@ 是已经安装的。

查询类似vnc程序

# yum list *vnc*

查询安装过程序

# yum list installed

查询HTTTP程序的详细信息

# yum info httpd

查询程序组=

# yum group list

查询程序组的详细信息

# yum groupinfo mariadb


⑦ 卸载

卸载程序

[root@tianyun ~]# yum -y remove mysql-server

卸载程序组

[root@tianyun ~]# yum -y groupremove mysql-server


⑧ history

# yum history

# yum history info 4

# yum history undo 4


⑨ 扩展查询

(通过命令找包)( provides)

前言

如果遇到命令不支持的情况,就说明该命令的程序没有安装。

可以通过pro 来查询到程序的名称。

示例

1.没有发现命令

[root@server0 ~]# gnuplot

bash: gnuplot: command not found...

2.查询命令属于哪个程序

[root@server0 ~]# yum provides gnuplot

Loaded plugins: langpacks

gnuplot-4.6.2-3.el7.x86_64 : A program for plotting mathematical expressions and data

Repo : cla***oom_content_rhel7.0_x86_64_dvd

3.安装并使用命令

#yum install -y gnuplot


3、RPM

① 认识RPM包

软件包名 版本号(Version) 发布版本(Release5/6/7) 系统平台(32/64)


ntfs-3g-2011.4.12-5.el5.x86_64.rpm 套件名


ntfs-3g-2011.4.12-5.el6.i686.rpm 套件名


yum-utils-1.1.30-14.el6.noarch.rpm 套件名


php-5.6.20-1.fc23.ppc64p7.rpm // IBM 小型机CPU Power


② 安装(i)

路径

rpm -ivh local_path

rpm -ivh url_path

示例

rpm - ivh http://ftp.altlinux.org/pub/distributions/ALTLinux/Sisyphus/i586/RPMS.classic//ntfs-3g-2017.3.23-alt1.i586.rpm

必须在线

准备工作:下载软件包

71.png

72.png

73.png

安装示例

[root@localhost ~]# rpm -ivh mysql57-community-release-el7-11.noarch.rp


额外选项:

--nodeps //忽略依赖关系

1.发现有依赖关系

[root@localhost Packages]# rpm -ivh wireshark-1.10.14-14.el7.x86_64.rpm

错误:依赖检测失败:

libcares.so.2()(64bit) 被 wireshark-1.10.14-14.el7.x86_64 需要

libsmi.so.2()(64bit) 被 wireshark-1.10.14-14.el7.x86_64 需要

2.放弃某些功能时

[root@localhost Packages]# rpm -ivh wireshark-1.10.14-14.el7.x86_64.rpm  --nodeps

准备中...                          ################################# [100%]

正在升级/安装...

1:wireshark-1.10.14-14.el7         ################################# [100%]


--nosignature //不检验软件包的签名

--force //强制安装软件包

rpm 无法将已经安装的软件包,重复安装。

比如你装过这个rpm的版本1,如果你想装这个rpm的版本2,就需要用--force强制安装

注意:

RPM包安装信息存储到本地RPM数据库中。。。


③ 查询(q)

从本地的rpm数据库

[root@tianyun ~]# rpm -q wireshark //查询指定包是否安装

[root@tianyun ~]# rpm -qa |grep wireshark    //在所有已经安装的包中查询wireshark

[root@tianyun ~]# rpm -ql wireshark //查询wireshark安装的文件  

[root@localhost ~]# rpm -qf /usr/share/wireshark/ws.css  //查询该文件属于哪个rpm包(which)

[root@tianyun ~]#  rpm -qi wireshark //查询包的information

[root@tianyun ~]# rpm -qc httpd   //查询某个包安装的配置文件(无)

[root@tianyun ~]# rpm -qd httpd //查安装的帮助文档

从rpm套件中查询(未安装)qi------p---package

扩展知识: 针对没有安装的包,直接从套件中查询

[root@tianyun ~]# rpm -e ntfs-3g  //-e卸载

[root@tianyun ~]# rpm -qip ntfs-3g-2011.4.12-5.el6.x86_64.rpm

[root@tianyun ~]# rpm -qlp ntfs-3g-2011.4.12-5.el6.x86_64.rpm

[root@tianyun ~]# rpm -qcp ntfs-3g-2011.4.12-5.el6.x86_64.rpm

[root@tianyun ~]# rpm -qdp ntfs-3g-2011.4.12-5.el6.x86_64.rpm

rpm -qip ntfs-3g-2017.3.23-1.el7.x86_64.rpm 

警告:ntfs-3g-2017.3.23-1.el7.x86_64.rpm: 头V3 RSA/SHA256 Signature, 密钥 ID 352c64e5: NOKEY

Name        : ntfs-3g

Epoch       : 2

Version    : 2017.3.23

Release     : 1.el7

Architecture: x86_64

Install Date: (not installed)

Group       : System Environment/Base

Size        : 626404

License     : GPLv2+

Signature   : RSA/SHA256, 2017年05月31日 星期三 04时43分38秒, Key ID 6a2faea2352c64e5

Source RPM  : ntfs-3g-2017.3.23-1.el7.src.rpm

Build Date  : 2017年05月31日 星期三 01时09分56秒

Build Host  : buildhw-04.phx2.fedoraproject.org

Relocations : (not relocatable)

Packager    : Fedora Project

Vendor      : Fedora Project

URL         : http://www.ntfs-3g.org/

Summary     : Linux NTFS userspace driver

Description :

NTFS-3G is a stable, open source, GPL licensed, POSIX, read/write NTFS

driver for Linux and many other operating systems. It provides safe

handling of the Windows XP, Windows Server 2003, Windows 2000, Windows

Vista, Windows Server 2008 and Windows 7 NTFS file systems. NTFS-3G can

create, remove, rename, move files, directories, hard links, and streams;

it can read and write normal and transparently compressed files, including

streams and sparse files; it can handle special files like symbolic links,

devices, and FIFOs, ACL, extended attributes; moreover it provides full

file access right and ownership support.

[root@localhost ~]# 


卸载(e)

[root@localhost ~]# rpm -q httpd

httpd-2.4.6-67.el7.centos.6.x86_64

[root@localhost ~]# rpm -e httpd

[root@localhost ~]# rpm -q httpd

未安装软件包 httpd 


总结

命令

安装 -i -v  -h  --force  --nodeps  --nosignature

查询 -q  -a  -l  -f  -i  -c  -d

卸载 -e


缺点

1. 很难解决包依赖关系

2.使用YUM管理软件包

注意

注意系统版本和架构和软件包是否相符

[root@tianyun ~]# uname -m

x86_64

[root@tianyun ~]# cat /etc/redhat-release 

CentOS Linux release 7.2.1511 (Core)


三、源码包管理

1. 获得源码包途径

官方网站,可以获得最新的软件包 

Apache: www.apache.org 

Nginx: www.nginx.org

Tengine: tengine.taobao.org


2. 实战案例

部署Tengine  /Nginx服务器/WEB服务器

1. 下载源码包,准备软件包

2.准备编译环境如编译器gcc、make

# yum -y install   gcc   make   zlib-devel  pcre  pcre-devel  openssl-devel

(pcre: 支持正则表达式,地址重写rewrite)


3.解压

# useradd www

# tar xvf tengine-2.2.0.tar.gz

# cd tengine-2.2.0


4.配置

./configure \

--user=www \

--group=www \

--prefix=/usr/local/nginx \

--with-http_stub_status_module \

--with-http_sub_module \

--with-http_ssl_module \

--with-pcre


 

5.编译

# make

6.安装

# make install


7.启动测试

# /usr/local/nginx/sbin/nginx //启动nginx服务器

# systemctl stop firewalld

看到网页,说明部署成功。


源码安装错误:

error1:

./configure: error: the HTTP gzip module requires the zlib library.

You can either disable the module by using --without-http_gzip_module

option, or install the zlib library into the system, or build the zlib library

statically from the source with nginx by using --with-zlib=<path> option.

解决方案:

# yum -y install zlib-devel

 or install the zlib library into the system


error2:

./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.

解决方案:

# yum -y install openssl-devel


error3:

checking for C compiler ... not found

./configure: error: C compiler cc is not found

解决方案:

# yum -y install gcc gcc-c++ make


error4:

./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.

解决方案:

# yum -y install pcre-devel


安装源码的技巧:

README

INSTALL