基础篇

Linux学习

一、安装软件包的三种方法
二、rpm包介绍
三、rpm工具用法
四、yum工具用法
五、yum搭建本地仓库

一、安装软件包的三种方法

  • 三种方法:rpm工具(redhat packges manager)、yum工具(Python开发的工具,支持自动安装依赖包)、源码包(源代码,需要编译成可执行的文件后再安装,三种方法中难度系数最大)
  • rpm工具安装类似于Windows下.exe文件,安装路径和文件名基本都是固定的
  • yum是另一种rpm工具

二、rpm包介绍

  • rpm工具使用
    1、设置光驱挂载
    2、rpm包格式,包名、版本号、发布版本号、平台
    3、rpm -ivh rpm包文件 安装
    4、rpm -Uvh rpm包文件 升级
    5、rpm -e 包名 卸载
    6、rpm -qa 查询安装的包
    7、rpm -q包名 查询指定包是否安装
    8、rpm -qi 包名 查询指定包信息
    9、rpm -ql包名 列出包安装的文件
    10、rpm -qf 文件绝对路径 查看一个文件是由哪个包安装的
挂载光驱
[root@01 ~]# df -h
文件系统        容量  已用  可用 已用% 挂载点
/dev/sda3        26G  1.2G   25G    5% /
devtmpfs        903M     0  903M    0% /dev
tmpfs           912M     0  912M    0% /dev/shm
tmpfs           912M  8.6M  904M    1% /run
tmpfs           912M     0  912M    0% /sys/fs/cgroup
/dev/sda1       197M  113M   85M   58% /boot
tmpfs           183M     0  183M    0% /run/user/1001
[root@01 ~]# mount /dev/cdrom /mnt/
mount: /dev/sr0 写保护,将以只读方式挂载
[root@01 ~]# cd /mnt/
[root@01 mnt]# ls
CentOS_BuildTag  EULA  images    LiveOS    repodata              RPM-GPG-KEY-CentOS-Testing-7
EFI              GPL   isolinux  Packages  RPM-GPG-KEY-CentOS-7  TRANS.TBL
[root@01 mnt]# cd Packages/
[root@01 Packages]# 
  • rpm包都存放在Packages/目录下
  • 第一部分字符串是包名
  • 第二部分-后面是版本号(主版本号,次版本号,小版本或者修正版本)
  • 第三部分是发布版本号(el7)
  • 第四部分是平台位数(32位和64位,centos7不区分32位和64位)64位向下兼容32位
  • 第五部分是后缀名
操作
[root@01 Packages]# ls | tail
yum-plugin-tmprepo-1.1.31-42.el7.noarch.rpm
yum-plugin-verify-1.1.31-42.el7.noarch.rpm
yum-plugin-versionlock-1.1.31-42.el7.noarch.rpm
yum-utils-1.1.31-42.el7.noarch.rpm
zenity-3.22.0-1.el7.x86_64.rpm
zip-3.0-11.el7.x86_64.rpm
zlib-1.2.7-17.el7.x86_64.rpm
zlib-devel-1.2.7-17.el7.x86_64.rpm
zsh-5.0.2-28.el7.x86_64.rpm
zziplib-0.13.62-5.el7.x86_64.rpm
[root@01 Packages]# 

三、rpm工具用法

  • 安装rpm包:rpm -ivh
  • 升级rpm包:rpm -Uvh
  • 卸载rpm包:rpm -e zsh(卸载包是会有提示依赖包)
  • 查询已经安装的rpm包:rpm -qa
  • 参数-q查询指定包是否已经安装过
操作
[root@01 Packages]# pwd
/mnt/Packages
[root@01 Packages]# rpm -ivh zsh-5.0.2-28.el7.x86_64.rpm 
准备中...                          ################################# [100%]
正在升级/安装...
   1:zsh-5.0.2-28.el7                 ################################# [100%]
[root@01 Packages]# 

root@01 Packages]# rpm -e zsh
[root@01 Packages]# rpm -qi zsh-5.0.2-28.el7.x86_64.rpm 
未安装软件包 zsh-5.0.2-28.el7.x86_64.rpm 
[root@01 Packages]# rpm -qi cryptsetup-libs-1.7.4-3.el7.x86_64.rpm 
未安装软件包 cryptsetup-libs-1.7.4-3.el7.x86_64.rpm 
[root@01 Packages]# rpm -q cryptsetup-libs-1.7.4-3.el7.x86_64.rpm 
未安装软件包 cryptsetup-libs-1.7.4-3.el7.x86_64.rpm 
[root@01 Packages]# rpm -qf cryptsetup-libs-1.7.4-3.el7.x86_64.rpm 
文件 /mnt/Packages/cryptsetup-libs-1.7.4-3.el7.x86_64.rpm 不属于任何软件包

四、yum工具

  • yum list 列出可用的rpm包
  • ls /etc/yum.repos.d
  • yum search vim 搜索包
  • yum install [-y]
  • yum grouplist
  • yum groupinstall [-y]
  • yum remove [-y]
  • yum update [-y]
  • yum provides "/*/vim"
  • rpm安装时如果包有依赖则提示错误,yum则可以自动解决依赖关系
  • yum list 第一列是包名,第二列是版本号,第三列是仓库名
  • base配置文件在/etc/yum.repos.d/CentOS-Base.repo下
  • yum search vim 搜索vim相关的包
  • yum install -y 包名,参数-y安装时不再询问是否安装
  • yum grouplist列出组
  • yum groupinstall -y 包名,安装组件
  • yum remove 卸载包
  • yum update 不加任何包名则默认升级所有(包括系统)
  • yum provides "/*/vim"搜索出所有关于vim命令的包
操作
[root@01 Packages]# rpm -ivh texlive-2012-38.20130427_r30134.el7.x86_64.rpm 
错误:依赖检测失败:
    texlive-scheme-basic 被 texlive-2:2012-38.20130427_r30134.el7.x86_64 需要
    texlive-collection-latexrecommended 被 texlive-2:2012-38.20130427_r30134.el7.x86_64 需要
    tex-kpathsea 被 texlive-2:2012-38.20130427_r30134.el7.x86_64 需要
    tex-tetex 被 texlive-2:2012-38.20130427_r30134.el7.x86_64 需要
[root@01 Packages]# 


[root@01 Packages]# yum list | tail
zlib-devel.x86_64                           1.2.7-17.el7               base     
zlib-static.i686                            1.2.7-17.el7               base     
zlib-static.x86_64                          1.2.7-17.el7               base     
zsh.x86_64                                  5.0.2-28.el7               base     
zsh-html.x86_64                             5.0.2-28.el7               base     
zziplib.i686                                0.13.62-5.el7              base     
zziplib.x86_64                              0.13.62-5.el7              base     
zziplib-devel.i686                          0.13.62-5.el7              base     
zziplib-devel.x86_64                        0.13.62-5.el7              base     
zziplib-utils.x86_64                        0.13.62-5.el7              base     
[root@01 Packages]# 
配置
[root@01 Packages]# cat /etc/yum.repos.d/CentOS-Base.repo 
# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client.  You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the 
# remarked out baseurl= line instead.
#
#

[base]
name=CentOS-$releasever - Base
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#released updates 
[updates]
name=CentOS-$releasever - Updates
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

[root@01 Packages]# 
搜索vim相关的包
[root@01 Packages]# yum search vim
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.zju.edu.cn
 * extras: mirrors.tuna.tsinghua.edu.cn
 * updates: mirrors.cn99.com
================================================== N/S matched: vim ===================================================
protobuf-vim.x86_64 : Vim syntax highlighting for Google Protocol Buffers descriptions
vim-X11.x86_64 : The VIM version of the vi editor for the X Window System
vim-common.x86_64 : The common files needed by any version of the VIM editor
vim-enhanced.x86_64 : A version of the VIM editor which includes recent enhancements
vim-filesystem.x86_64 : VIM filesystem layout
vim-minimal.x86_64 : A minimal version of the VIM editor

名称和简介匹配 only,使用“search all”试试。
[root@01 Packages]# 
精准搜索
[root@01 Packages]# yum list |grep 'vim'
vim-common.x86_64                           2:7.4.160-4.el7            @base    
vim-enhanced.x86_64                         2:7.4.160-4.el7            @base    
vim-filesystem.x86_64                       2:7.4.160-4.el7            @base    
vim-minimal.x86_64                          2:7.4.160-2.el7            @anaconda
protobuf-vim.x86_64                         2.5.0-8.el7                base     
vim-X11.x86_64                              2:7.4.160-4.el7            base     
vim-minimal.x86_64                          2:7.4.160-4.el7            base     
[root@01 Packages]# 


[root@01 Packages]# yum grouplist
已加载插件:fastestmirror
没有安装组信息文件
Maybe run: yum groups mark convert (see man yum)
Loading mirror speeds from cached hostfile
 * base: mirrors.zju.edu.cn
 * extras: mirrors.tuna.tsinghua.edu.cn
 * updates: mirrors.cn99.com
可用的环境分组:
   最小安装
   基础设施服务器
   计算节点
   文件及打印服务器
   基本网页服务器
   虚拟化主机
   带 GUI 的服务器
   GNOME 桌面
   KDE Plasma Workspaces
   开发及生成工作站
可用组:
   传统 UNIX 兼容性
   兼容性程序库
   图形管理工具
   安全性工具
   开发工具
   控制台互联网工具
   智能卡支持
   科学记数法支持
   系统管理
   系统管理工具
完成
[root@01 Packages]# 

五、yum搭建本地仓库

  • 挂载镜像到/mnt目录
  • cp -r /etc/yum.repos.d /etc/yum.repos.d.bak
  • rm -f /etc/yum.repos.d/*
  • vim /etc/yum.repos.d/dvd.repo 内容如下
  • yum clean all 清空yum
  • yum list |less 查看本地yum仓库
  • 搭建本地yum仓库便于安装,如果使用rpm安装则提示依赖包
  • 使yum保留已经下载的rpm包
  • 目的:升级或者重新安装使用
  • 操作:修改/etc/yum.conf文件
  • yum局域网软件源搭建
    http://ask.apelearn.com/question/7627
操作
[root@01 ~]# cp -r /etc/yum.repos.d /etc/yum.repos.d.bak
[root@01 ~]# cd /etc/
[root@01 etc]# ls
adjtime                  environment         ld.so.cache               polkit-1        skel
aliases                  ethertypes          ld.so.conf                popt.d          ssh
aliases.db               exports             ld.so.conf.d              postfix         ssl
alternatives             favicon.png         libaudit.conf             ppp             statetab
anacrontab               filesystems         libnl                     prelink.conf.d  statetab.d
asound.conf              firewalld           libuser.conf              printcap        subgid
audisp                   fstab               locale.conf               profile         subuid
audit                    fuse.conf           localtime                 profile.d       sudo.conf
bash_completion.d        gcrypt              login.defs                protocols       sudoers
bashrc                   GeoIP.conf          logrotate.conf            python          sudoers.d
binfmt.d                 GeoIP.conf.default  logrotate.d               rc0.d           sudo-ldap.conf
centos-release           gnupg               machine-id                rc1.d           sysconfig
centos-release-upstream  GREP_COLORS         magic                     rc2.d           sysctl.conf
chkconfig.d              groff               makedumpfile.conf.sample  rc3.d           sysctl.d
chrony.conf              group               man_db.conf               rc4.d           systemd
chrony.keys              group-              mke2fs.conf               rc5.d           system-release
cron.d                   grub2.cfg           modprobe.d                rc6.d           system-release-cpe
cron.daily               grub.d              modules-load.d            rc.d            terminfo
cron.deny                gshadow             motd                      rc.local        tmpfiles.d
cron.hourly              gshadow-            mtab                      redhat-release  tuned
cron.monthly             gss                 my.cnf                    resolv.conf     udev
crontab                  host.conf           my.cnf.d                  rpc             updatedb.conf
cron.weekly              hostname            NetworkManager            rpm             vconsole.conf
crypttab                 hosts               networks                  rsyslog.conf    vimrc
csh.cshrc                hosts.allow         nsswitch.conf             rsyslog.d       virc
csh.login                hosts.deny          nsswitch.conf.bak         rwtab           vmware-tools
dbus-1                   init.d              openldap                  rwtab.d         wpa_supplicant
default                  inittab             opt                       sasl2           X11
depmod.d                 inputrc             os-release                securetty       xdg
dhcp                     iproute2            pam.d                     security        xinetd.d
DIR_COLORS               issue               passwd                    selinux         yum
DIR_COLORS.256color      issue.net           passwd-                   services        yum.conf
DIR_COLORS.lightbgcolor  kdump.conf          pkcs11                    sestatus.conf   yum.repos.d
dracut.conf              kernel              pki                       shadow          yum.repos.d.bak
dracut.conf.d            krb5.conf           plymouth                  shadow-
e2fsck.conf              krb5.conf.d         pm                        shells
[root@01 etc]# 



[root@01 etc]# cd /etc/yum.repos.d
[root@01 yum.repos.d]# ls
CentOS-Base.repo  CentOS-Debuginfo.repo  CentOS-Media.repo    CentOS-Vault.repo
CentOS-CR.repo    CentOS-fasttrack.repo  CentOS-Sources.repo
[root@01 yum.repos.d]# rm -f ./*
[root@01 yum.repos.d]# ls
[root@01 yum.repos.d]# 



[root@01 yum.repos.d]# vim dvd.repo
[root@01 yum.repos.d]# cat dvd.repo 
[dvd]
name=install dvd
baseurl=file:///mnt            //baseurl指定路径
enable=1                       //是否可用:1表示可用,0表示不可用
gpgcheck=0                     //0表示不检测
[root@01 yum.repos.d]# 


[root@01 yum.repos.d]# yum clean all
已加载插件:fastestmirror
正在清理软件源: dvd
Cleaning up everything
Maybe you want: rm -rf /var/cache/yum, to also free up space taken by orphaned data from disabled or removed repos
Cleaning up list of fastest mirrors
[root@01 yum.repos.d]# yum list |less
[root@01 yum.repos.d]# yum list |tail
yum-plugin-changelog.noarch             1.1.31-42.el7                  dvd      
yum-plugin-tmprepo.noarch               1.1.31-42.el7                  dvd      
yum-plugin-verify.noarch                1.1.31-42.el7                  dvd      
yum-plugin-versionlock.noarch           1.1.31-42.el7                  dvd      
yum-utils.noarch                        1.1.31-42.el7                  dvd      
zenity.x86_64                           3.22.0-1.el7                   dvd      
zip.x86_64                              3.0-11.el7                     dvd      
zlib-devel.x86_64                       1.2.7-17.el7                   dvd      
zsh.x86_64                              5.0.2-28.el7                   dvd      
zziplib.x86_64                          0.13.62-5.el7                  dvd         //dvd表示本地搭建的yum仓库
coreutils.x86_64                        8.22-18.el7                    @anaconda   //@anaconda表示已安装表示已经安装可安装的软件包
cpio.x86_64                             2.11-24.el7                    @anaconda
cracklib.x86_64                         2.9.0-11.el7                   @anaconda
cracklib-dicts.x86_64                   2.9.0-11.el7                   @anaconda
cronie.x86_64                           1.4.11-17.el7                  @anaconda
[root@01 yum.repos.d]# 



[root@01 yum.repos.d]# cat /etc/yum.conf 
[main]
cachedir=/var/cache/yum/$basearch/$releasever                    /cachedir是指一个路径,存放下载的包的位置
keepcache=0                                                      /keepcache=1时表示保存已经下载的rpm包
debuglevel=2
logfile=/var/log/yum.log
exactarch=1
obsoletes=1
gpgcheck=1
plugins=1
installonly_limit=5
bugtracker_url=http://bugs.centos.org/set_project.php?project_id=23&ref=http://bugs.centos.org/bug_report_page.php?category=yum
distroverpkg=centos-release


#  This is the default, if you make this bigger yum won't see if the metadata
# is newer on the remote and so you'll "gain" the bandwidth of not having to
# download the new metadata and "pay" for it by yum not having correct
# information.
#  It is esp. important, to have correct metadata, for distributions like
# Fedora which don't keep old packages around. If you don't like this checking
# interupting your command line usage, it's much better to have something
# manually check the metadata once an hour (yum-updatesd will do this).
# metadata_expire=90m

# PUT YOUR REPOS HERE OR IN separate files named file.repo
# in /etc/yum.repos.d
[root@01 yum.repos.d]# 

你可能感兴趣的:(基础篇)