Linux软件管理

一,概述(以下工作需要提前加入一个系统镜像)

1,软件的类型

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,现在是一个递归缩写)

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

2,常见二进制包(了解)

系统平台;包类型;工具;在线安装(自动解决依赖关系)
RedHat/Centos;RPM;rpm,rpmbuild;yum
Ubuntu/Debian;DPKG;dpkg;apt

二,RPM包管理

1,YUM(重点

1.1 YUM源(YUM仓库)

安装的两种方式:

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

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

1 删除YUM库
[root@tianyun ~]# rm    -rf    /etc/yum.repos.d/*
2挂载安装光盘(临时):
[root@tianyun ~]# mount /dev/cdrom   /mnt
3编写配置文件。
[root@tianyun ~]# vim /etc/yum.repos.d/dvd.repo
[dvd]
name=dvd
baseurl=file:///mnt/
gpgcheck=0
4 使用YUM 安装和卸载程序即可。
[root@tianyun ~]#yum install -y httpd

1.1.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包说明




1 根据提示创建YUM配置文件
2 根据提示替换关键字,centos和7


提示

系统的更新和升级,可以使用基础源(aliyun,163)。
软件的使用建议使用官方源(nginx.com/mysql.com)

MySQL:(地址链接)

网站路径

帮助


查考指南


安装指南



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


不登录,直接使用


下载后复制链接


在服务器上,下载该链接
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

查看源


总结

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

Zabbix:(链接地址)

网站

1 打开官网
https://www.zabbix.com




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

   

openstack:

网站路径



         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

1.2 使用YUM管理RPM包

1.2.1 查看可用仓库

[root@tianyun ~]# yum clean all //清空缓存及其它文件(可以通过清理nginx.rpm观察)
[root@tianyun ~]# yum makecache //重建缓存
[root@tianyun ~]# yum repolist //查询可用的仓库

1.2.2 安装

全新安装

# 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

1.2.3 查询

查询HTTP程序                       # yum list httpd         //带@ 是已经安装的。
查询类似vnc程序                   # yum list *vnc*
查询安装过程序                     # yum list installed
查询HTTTP程序的详细信息    # yum info httpd
查询程序组                            # yum group list
查询程序组的详细信息           # yum groupinfo mariadb

1.2.4 卸载

卸载程序        [root@tianyun ~]# yum -y remove mysql-server

卸载程序组     [root@tianyun ~]# yum -y groupremove mysql-server

1.2.5 history

# yum history
# yum history info 4
# yum history undo 4

1.2.6 扩展查询

例1(从描述中搜索软件包)(search)

1.前言

#yum list  | grep  chinese   
只能查询软件包的名字中,是否包含chinese
    示例
[root@localhost tmp]# yum list |grep chinese
ibus-table-chinese.noarch                 1.4.6-3.el7                  @anaconda
fcitx-table-chinese.noarch                4.2.9.5-1.el7                epel     
只有软件包的名字中带chinese会被查到。

2.描述

# yum search chinese
search 可以关注软件包的名  或  描述,可以查询更多信息。
    示例
[root@localhost tmp]# yum search chinese

fcitx-table-chinese.noarch : Chinese table of Fcitx
ghostscript-chinese.noarch : Common files for
软件包的名字或描述中,包含chinese的的信息都会查出来。
查出的软件包更多了。。。

例2 (查询文件属于哪个包)

[root@server0 ~]# yum provides /etc/vsftpd/vsftpd.conf

[root@server0 ~]# yum provides */vsftpd.conf

例3 (通过命令找包)(provides)

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 : classroom_content_rhel7.0_x86_64_dvd

3.安装并使用命令

#yum install -y gnuplot

2,RPM

2.1.1 认识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

2.1.2 安装,卸载,查询

安装(i)

1.路径

rpm -ivh url_path  //从本地光盘,首先挂载,如: mount /dev/sr0 /mnt/  到/mnt/里面找到Packages包,进入后通过yum安装即可

rpm -ivh local_path

示例(必须在线)

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

2.准备工作

下载软件包




3.安装示例(必须在线)

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

4.额外选项

--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强制安装

5.注意

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

查询(q)

1.从本地的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     //查安装的帮助文档

2.从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

2.1.3 总结

命令

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

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

卸载 -e

缺点

很难解决包依赖关系

使用YUM管理软件包

2.1.4 注意

注意系统版本和架构和软件包是否相符
[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,安装源码包步骤

1.准备编译环境如编译器gcc、make
2.准备软件包 tengine-2.2.0.tar.gz
3.解压tar xf
4.配置 ./configure
5.编译 make
6.安装  make install

3,实战案例

部署Tengine  /Nginx服务器/WEB服务器
1. 下载源码包,准备软件包
2.准备编译环境如编译器gcc、make
# yum -y install   gcc   make   zlib-devel  pcre  pcre-devel  openssl-de
(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
看到网页,说明部署成功。

4,总结

详解源码安装三步曲
# ./configure
a. 指定安装路径,例如 --prefix=/usr/local/nginx
b. 启用或禁用某项功能, 例如 --enable-ssl, --disable-filter --with-http_ssl_module
c. 和其它软件关联,例如--with-pcre
d. 检查安装环境,例如是否有编译器gcc,是否满足软件的依赖需求
最终生成:Makefile
# make //按Makefile文件编译,可以使用-j 2指定两颗CPU编译,优化编译器参数
# make install //按Makefile定义的文件路径安装

5,安装错误

如果安装源码包之前没有# yum -y install   gcc   make   zlib-devel  pcre  pcre-devel  openssl-de 这个操作就会出现以下错误

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


















  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值