红帽系统软件包安装

软件包安装有三种方式:rpm包安装、yum安装、源码包安装



1、RPM工具

RPM:Red Hat Package Manager。rpm包一般后缀为.rpm。

rpm命令使用:rpm  [选项]  包名

选项:

-i:安装

-v:显示安装信息

-h:显示安装进度

--nodeps:不检查包的依赖性

--force:强制操作

-U:升级

-e:卸载

-q:查询某个包是否安装

-qa:查询已安装的包

-qi:查询已经安装的包的信息

-ql:列出安装包的安装文件

-qf:查询某个文件属于哪个包

部分选项使用演示:

-qa:查询已安装的包

[root@node5 ~]# rpm -qa vim-enhanced
vim-enhanced-7.4.160-4.el7.x86_64
[root@node5 ~]#

-qi选择:查询已经安装的包的信息

[root@node5 ~]# rpm -qi vim-enhanced
Name        : vim-enhanced
Epoch       : 2
Version     : 7.4.160
Release     : 4.el7
Architecture: x86_64
Install Date: Thu 24 May 2018 09:50:24 PM CST
Group       : Applications/Editors
Size        : 2296714
License     : Vim
Signature   : RSA/SHA256, Wed 25 Apr 2018 07:50:34 PM CST, Key ID 24c6a8a7f4a80eb5
Source RPM  : vim-7.4.160-4.el7.src.rpm
Build Date  : Wed 11 Apr 2018 07:55:09 AM CST
Build Host  : x86-01.bsys.centos.org
Relocations : (not relocatable)
Packager    : CentOS BuildSystem <http://bugs.centos.org>
Vendor      : CentOS
URL         : http://www.vim.org/
Summary     : A version of the VIM editor which includes recent enhancements
Description :
VIM (VIsual editor iMproved) is an updated and improved version of the
vi editor.  Vi was the first real screen-based editor for UNIX, and is
still very popular.  VIM improves on vi by adding new features:
multiple windows, multi-level undo, block highlighting and more.  The
vim-enhanced package contains a version of VIM with extra, recently
introduced features like Python and Perl interpreters.

Install the vim-enhanced package if you'd like to use a version of the
VIM editor which includes recently added enhancements like
interpreters for the Python and Perl scripting languages.  You'll also
need to install the vim-common package.
[root@node5 ~]#

-qf选项使用:vim属于vim-enhaced软件包

[root@node5 ~]# rpm -qf `which vim`
vim-enhanced-7.4.160-4.el7.x86_64
[root@node5 ~]#

-ql选项:列出安装包的安装文件:

[root@node5 ~]# rpm -ql vim-enhanced
/etc/profile.d/vim.csh
/etc/profile.d/vim.sh
/usr/bin/rvim
/usr/bin/vim
/usr/bin/vimdiff
/usr/bin/vimtutor

rpm 校验:

[root@node5 ~]# rpm -Va
S.5....T.  c /etc/profile
.M.......  g /boot/initramfs-3.10.0-862.el7.x86_64.img
.M.......  g /etc/selinux/targeted/active/seusers
.M.......    /etc/selinux/targeted/active/users_extra
.M.......  c /etc/machine-id
.M.......  g /etc/udev/hwdb.bin
.M.......  g /var/lib/systemd/random-seed
.M.......  g /var/log/dmesg
.M.......  g /var/log/dmesg.old
missing     /var/run/wpa_supplicant
.......T.    /etc/redhat-release
S.5....T.  c /etc/sysconfig/authconfig
.M.......  c /etc/audit/rules.d/audit.rules
....L....  c /etc/pam.d/fingerprint-auth
....L....  c /etc/pam.d/password-auth
....L....  c /etc/pam.d/postlogin
....L....  c /etc/pam.d/smartcard-auth
....L....  c /etc/pam.d/system-auth
.M.......  g /var/lib/sepolgen/interface_info
.M.......  g /etc/pki/ca-trust/extracted/java/cacerts
.M.......  g /etc/pki/ca-trust/extracted/openssl/ca-bundle.trust.crt
.M.......  g /etc/pki/ca-trust/extracted/pem/email-ca-bundle.pem
.M.......  g /etc/pki/ca-trust/extracted/pem/objsign-ca-bundle.pem
.M.......  g /etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem
.M.......  c /etc/sysconfig/kernel
S.5....T.  c /etc/my.cnf

结果选项解释:

        S:file Size differs
       M:Mode differs (includes permissions and file type)
       5: digest (formerly MD5 sum) differs
       D: Device major/minor number mismatch
       L: readLink(2) path mismatch
       U: User ownership differs
       G:Group ownership differs
       T: mTime differs
       P: caPabilities differ



2、yum工具

yum  list:列出全部rpm包资源

yum  search [关键词] :搜索

安装rpm包:yum  install  -y  包名

升级rpm包:yum  update  -y包名

卸载rpm包:yum  remove  -y  包名

其中:-y可以省略。

yum  provides  查看特定文件或命令工具属于哪个软件包

例如:

[root@node5 ~]# yum provides */ab
Loaded plugins: product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
updates/x86_64/filelists_db                                                                                                                          | 1.3 MB  00:00:00     
filesystem-3.2-25.el7.x86_64 : The basic directory layout for a Linux system
Repo        : base
Matched from:
Filename    : /usr/share/man/ab
Filename    : /usr/share/locale/ab



httpd-tools-2.4.6-80.el7.centos.x86_64 : Tools for use with the Apache HTTP Server
Repo        : base
Matched from:
Filename    : /usr/bin/ab



[root@node5 ~]#

ab命令属于httpd-tools包,所以安装这个包就可以使用ab命令,此命令可以做web服务压力测试。

yum  serch功能:

[root@node5 ~]# yum search httpd
Loaded plugins: product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
============================================================================ N/S matched: httpd ============================================================================
keycloak-httpd-client-install.noarch : Tools to configure Apache HTTPD as Keycloak client
libmicrohttpd-devel.i686 : Development files for libmicrohttpd
libmicrohttpd-devel.x86_64 : Development files for libmicrohttpd
libmicrohttpd-doc.noarch : Documentation for libmicrohttpd
python2-keycloak-httpd-client-install.noarch : Tools to configure Apache HTTPD as Keycloak client
httpd.x86_64 : Apache HTTP Server
httpd-devel.x86_64 : Development interfaces for the Apache HTTP server
httpd-manual.noarch : Documentation for the Apache HTTP server
httpd-tools.x86_64 : Tools for use with the Apache HTTP Server
libmicrohttpd.i686 : Lightweight library for embedding a webserver in applications
libmicrohttpd.x86_64 : Lightweight library for embedding a webserver in applications
mod_auth_mellon.x86_64 : A SAML 2.0 authentication module for the Apache Httpd Server
mod_dav_svn.x86_64 : Apache httpd module for Subversion server

  Name and summary matches only, use "search all" for everything.
[root@node5 ~]#

软件组管理命令:

yum  grouplist:列出全部包组

yum  groupinstall  包组名:安装包组

yum  groupremove  包组名:卸载包组

利用yum下载rpm包

yum  install 包名  -y  --downloadonly  --downloaddir=/path/

如果包已经安装了,就使用reinstall:

yum  reinstall 包名  -y  --downloadonly  --downloaddir=/path/

例如:查看系统的包组情况:

[root@node5 ~]# yum  grouplist
Loaded plugins: product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
There is no installed groups file.
Maybe run: yum groups mark convert (see man yum)
Available Environment Groups:
   Minimal Install
   Compute Node
   Infrastructure Server
   File and Print Server
   Basic Web Server
   Virtualization Host
   Server with GUI
   GNOME Desktop
   KDE Plasma Workspaces
   Development and Creative Workstation
Available Groups:
   Compatibility Libraries
   Console Internet Tools
   Development Tools
   Graphical Administration Tools
   Legacy UNIX Compatibility
   Scientific Support
   Security Tools
   Smart Card Support
   System Administration Tools
   System Management
Done
[root@node5 ~]#

yumdownloader 命令:下载包

例如: yumdownloader vim-enhanced

[root@node5 ~]# yumdownloader vim-enhanced
-bash: yumdownloader: command not found
[root@node5 ~]#

报错,命令不存在。怎么办?查看一下这个yumdownloader命令属于哪个软件包的,然后安装即可。

[root@node5 ~]# yum provides */yumdownloader 
Loaded plugins: product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
yum-utils-1.1.31-45.el7.noarch : Utilities based around the yum package manager
Repo        : base
Matched from:
Filename    : /usr/bin/yumdownloader

[root@node5 ~]#

结果显示,yumdownloader命令属于yum-utils包,所以安装这个包即可:

[root@node5 ~]# yum install -y yum-utils

安装好之后,就可以使用yumdownloader命令下载软件包了,比如下载vim-enhanced包:

[root@node5 ~]# yumdownloader vim-enhanced
Loaded plugins: product-id, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
vim-enhanced-7.4.160-4.el7.x86_64.rpm                                                | 1.0 MB  00:00:01     
[root@node5 ~]# ls 
anaconda-ks.cfg             mariadb-10.3.6-linux-glibc_214-x86_64.tar.gz
auto_install_lnmp_v2.0.sh   nginx-1.14.0
ipvs.txt                    nginx-1.14.0.tar.gz
jdk-8u131-linux-x64.tar.gz  php-7.2.5
libmcrypt-2.5.8             php-7.2.5.tar.gz
libmcrypt-2.5.8.tar.gz      vim-enhanced-7.4.160-4.el7.x86_64.rpm
[root@node5 ~]#

保留yum安装所下载的包:编辑 /etc/yum.conf 文件

[root@node5 ~]# vim /etc/yum.conf 
[main]
cachedir=/var/cache/yum/$basearch/$releasever
keepcache=0
debuglevel=2
logfile=/var/log/yum.log
exactarch=1
obsoletes=1
gpgcheck=1
plugins=1
installonly_limit=3

keepcache=0改成keepcache=1,软件包就保留在:

cachedircachedir=/var/cache/yum/$basearch/$releasever

[root@node5 ~]# ls /var/cache/yum/x86_64/7Server/
base  extras  timedhosts  updates



3、源码包安装

源码包安装步骤:

第1步:下载及解压源码包文件。源码包文件通常会在归档后使用gzip或bzip2等格式进行压缩,因此一般有.tar.gz与.tar.bz2的后缀。

 [root@localhost ~]# tar  xzvf  FileName.tar.gz

[root@localhost ~]# cd  FileDirectory

第2步:编译源码包代码,生成Makefile安装文件。

[root@localhost ~]# ./configure --prefix=/usr/local/program

第3步:生成二进制安装程序。

[root@localhost ~]# make

第4步:运行二进制的服务程序安装包。如果没有自行使用参数定义目录的话,一般会被默认安装到/usr/local/bin目录中。

[root@localhost ~]# make install

例如:编译安装apr

下载编译安装apr包:

[root@node5 ~]# wget http://mirrors.hust.edu.cn/apache/apr/apr-1.6.3.tar.gz

解压apr包:

[root@node5 ~]# tar xf apr-1.6.3.tar.gz

编译:

[root@node5 ~]# cd apr-1.6.3
[root@node5 apr-1.6.3]# ./configure --prefix=/usr/local/apr
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking target system type... x86_64-pc-linux-gnu
Configuring APR library
Platform: x86_64-pc-linux-gnu
checking for working mkdir -p... yes
APR Version: 1.6.3
checking for chosen layout... apr

生成二进制安装程序,并安装:

[root@node5 apr-1.6.3]# make && make install

源码包安装过程就这几步。如果编译过程中报错,一般是缺少依赖包,可以通过yum安装解决,之后再重新编译,直到编译成功。

编译安装httpd2.4版本演示

要编译安装httpd2.4版本,得事先安装apr、apr-util包:

(1)、编译安装apr、apr-util

[root@node5 ~]#  wget http://mirrors.hust.edu.cn/apache/apr/apr-1.6.3.tar.gz
  [root@node5 ~]# wget http://mirrors.hust.edu.cn/apache/apr/apr-util-1.6.1.tar.gz
  [root@node5 ~]#  tar xf apr-1.6.3.tar.gz
  [root@node5 ~]#  tar xf apr-util-1.6.1.tar.gz
  [root@node5 ~]#  cd  apr-1.6.3
  [root@node5 apr-1.6.3]#  ./configure  --prefix=/usr/local/apr
  [root@node5 apr-1.6.3]# make  &&  make  install
  [root@node5 apr-1.6.3]#cd /root/apr-util-1.6.1
  [root@node5 apr-util-1.6.1]# ./configure  --prefix=/usr/local/apr-util  --with-apr=/usr/local/apr/
  [root@node5 apr-util-1.6.1]#make  &&  make  install

(2)、下载httpd

[root@node5 ~]#  wget http://mirrors.hust.edu.cn/apache/httpd/httpd-2.4.33.tar.gz

(3)、解压httpd

[root@node5 ~]#  tar xf httpd-2.4.33.tar.gz

(4)、编译httpd

[root@node5 ~]# cd httpd-2.4.33
   [root@node5 httpd-2.4.33]#./configure --prefix=/usr/local/apache\
   --sysconfdir=/etc/httpd24\
   --enable-so\
   --enable-ssl\
   --enable-cgi\
   --enable-rewrite\
   --with-zlib\
   --with-pcre\
   --with-apr=/usr/local/apr\
   --with-apr-util=/usr/local/apr-util/\
   --enable-modules=all\
   --enable-mpms-shared=all\
   --with-mpm=prefork

(5)、安装

[root@node5 httpd-2.4.33]#make  &&  make  install



4、部署内网的yum源

比如公司内部建个yum源,仅供内部使用。实验机:rhel7.5,ip:192.168.10.205

(1)创建存放软件的目录

[root@node5 ~]# mkdir /data/yumdata -pv
mkdir: created directory ‘/data’
mkdir: created directory ‘/data/yumdata’

(2)虚拟机挂载光盘,这里使用RHEL7.5演示:

RPM安装 java 安装.rpm_vim

(3)将光盘挂载到/mnt

[root@node5 ~]# mount /dev/cdrom /mnt/
mount: /dev/sr0 is write-protected, mounting read-only
[root@node5 ~]#

(4)复制 /mnt/Packages/目录中的包到 /data/yumdata/目录

[root@node5 ~]# cp /mnt/Packages/* /data/yumdata/

(5)安装createrepo工具,创建yum仓库

[root@node5 ~]# yum install createrepo -y
[root@node5 ~]# cd /data/yumdata/
[root@node5 yumdata]# 
[root@node5 yumdata]# createrepo ./
Spawning worker 0 with 1275 pkgs
Spawning worker 1 with 1275 pkgs
Spawning worker 2 with 1275 pkgs
Spawning worker 3 with 1274 pkgs
Workers Finished
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete
[root@node5 yumdata]#

(6)安装nginx及配置

编译安装nginx过程省略。

nginx配置文件server段中 location / {}中添加autoindex on; root路径改为 root   /data/yumdata;
       

location / {
        autoindex on;
        root   /data/yumdata/;
......
}

清空防火墙并启动nginx:

[root@node5 ~]#iptables -F
[root@node5 ~]# /usr/local/nginx/sbin/nginx

浏览器打开:192.168.10.205

RPM安装 java 安装.rpm_java_02

OK,可以看到包了。

(7)同步其他镜像站的源到本地

[root@node5 ~]#rsync -av rsync://mirrors.ustc.edu.cn/centos/7/os/x86_64/Packages/  /data/yumdata/

同步后,更新:

[root@node5 ~]# createrepo  –update /data/yumdata

(8)客户端创建repo文件

客户端ip:192.168.10.101,RHEL7.5系统。

创建repo文件:

[root@node2 yum.repos.d]# pwd
/etc/yum.repos.d
[root@node2 yum.repos.d]# ls
[root@node2 yum.repos.d]# vim my.repo
[node5]
name=node5
baseurl=http://192.168.10.205
enabled=1
gpgcheck=0
~

清空及生成缓存:

[root@node2 yum.repos.d]# yum clean all
Loaded plugins: product-id, search-disabled-repos, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Cleaning repos: node5
Cleaning up everything
[root@node2 yum.repos.d]# yum makecache
Loaded plugins: product-id, search-disabled-repos, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
node5                                                                                | 2.9 kB  00:00:00     
(1/3): node5/filelists_db                                                            | 3.4 MB  00:00:00     
(2/3): node5/primary_db                                                              | 4.1 MB  00:00:00     
(3/3): node5/other_db                                                                | 1.5 MB  00:00:00     
Metadata Cache Created
[root@node2 yum.repos.d]#

安装一个软件测试一下:

[root@node2 yum.repos.d]# yum install -y samba
Loaded plugins: product-id, search-disabled-repos, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Resolving Dependencies
--> Running transaction check
---> Package samba.x86_64 0:4.7.1-6.el7 will be installed
--> Processing Dependency: samba-libs = 4.7.1-6.el7 for package: samba-4.7.1-6.el7.x86_64
--> Processing Dependency: samba-common-tools = 4.7.1-6.el7 for package: samba-4.7.1-6.el7.x86_64
--> Processing Dependency: samba-common-libs = 4.7.1-6.el7 for package: samba-4.7.1-6.el7.x86_64
--> Processing Dependency: samba-common = 4.7.1-6.el7 for package: samba-4.7.1-6.el7.x86_64
--> Processing Dependency: samba-common = 4.7.1-6.el7 for package: samba-4.7.1-6.el7.x86_64
--> Processing Dependency: samba-client-libs = 4.7.1-6.el7 for package: samba-4.7.1-6.el7.x86_64
--> Processing Dependency: libwbclient = 4.7.1-6.el7 for package: samba-4.7.1-6.el7.x86_64
--> Processing Dependency: libxattr-tdb-samba4.so(SAMBA_4.7.1)(64bit) for package: samba-4.7.1-6.el7.x86_64
--> Processing Dependency: libutil-tdb-samba4.so(SAMBA_4.7.1)(64bit) for package: samba-4.7.1-6.el7.x86_64
--> Processing Dependency: libutil-reg-samba4.so(SAMBA_4.7.1)(64bit) for package: samba-4.7.1-6.el7.x86_64
--> Processing Dependency: libtevent.so.0(TEVENT_0.9.9)(64bit) for package: samba-4.7.1-6.el7.x86_64
--> Processing Dependency: libtevent.so.0(TEVENT_0.9.16)(64bit) for package: samba-4.7.1-6.el7.x86_64
......


Installed:
  samba.x86_64 0:4.7.1-6.el7                                                                                                                                                

Dependency Installed:
  libldb.x86_64 0:1.2.2-1.el7                 libtalloc.x86_64 0:2.1.10-1.el7            libtevent.x86_64 0:0.9.33-2.el7       libwbclient.x86_64 0:4.7.1-6.el7          
  pytalloc.x86_64 0:2.1.10-1.el7              samba-client-libs.x86_64 0:4.7.1-6.el7     samba-common.noarch 0:4.7.1-6.el7     samba-common-libs.x86_64 0:4.7.1-6.el7    
  samba-common-tools.x86_64 0:4.7.1-6.el7     samba-libs.x86_64 0:4.7.1-6.el7           

Dependency Updated:
  dbus.x86_64 1:1.10.24-7.el7                                                        dbus-libs.x86_64 1:1.10.24-7.el7                                                       

Complete!

OK。没问题。

参考资料:http://blog.lishiming.net/?p=500