yum安装和源码包安装

Linux中软件安装有三种方式1、rpm安装
2、yum安装
3、源码包安装

window中安装软件,都需要基础环境,即安装软件依赖某一个环境配置才能安装。同样的在Linux中安装软件也存在这样的依赖关系。rpm和源码包安装不会解决依赖关系,用着两种方式安装需要根据提示依赖关系一个个去安装,yum安装虽然解决了依赖关系,但是默认的yum源是国外的,访问速度相对比较慢,导致安装软件速度慢,需要将默认的国外源修改为国内的。
下面介绍yum安装和源码包安装两种。
1、yum安装
1.1yum源存储位置
Linux中使用yum安装,默认的源文件存储在/etc/yum.repos.d目录下
[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# ls
CentOS-Base.repo CentOS-CR.repo CentOS-Debuginfo.repo CentOS-fasttrack.repo CentOS- Media.repo CentOS-Sources.repo CentOS-Vault.repo

在该目录下可以看到恨到repo结尾的文件,这些都是源,其中最主要的是Centos-Base.repo这个源,里面设置了默认的下载更新以及扩展的源路径。
查看Centos-Base.repo这个源文件内容:cat /etc/yum.repos.d/Centos-Base.repo
[base]
name=CentOS- r e l e a s e v e r − B a s e m i r r o r l i s t = h t t p : / / m i r r o r l i s t . c e n t o s . o r g / ? r e l e a s e = releasever - Base mirrorlist=http://mirrorlist.centos.org/?release= releaseverBasemirrorlist=http://mirrorlist.centos.org/?release=releasever&arch=KaTeX parse error: Expected 'EOF', got '&' at position 9: basearch&̲repo=os&infra=infra
#baseurl=http://mirror.centos.org/centos/ r e l e a s e v e r / o s / releasever/os/ releasever/os/basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
#released updates
[updates]
name=CentOS- r e l e a s e v e r − U p d a t e s m i r r o r l i s t = h t t p : / / m i r r o r l i s t . c e n t o s . o r g / ? r e l e a s e = releasever - Updates mirrorlist=http://mirrorlist.centos.org/?release= releaseverUpdatesmirrorlist=http://mirrorlist.centos.org/?release=releasever&arch=KaTeX parse error: Expected 'EOF', got '&' at position 9: basearch&̲repo=updates&in…infra
#baseurl=http://mirror.centos.org/centos/ r e l e a s e v e r / u p d a t e s / releasever/updates/ 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- r e l e a s e v e r − E x t r a s m i r r o r l i s t = h t t p : / / m i r r o r l i s t . c e n t o s . o r g / ? r e l e a s e = releasever - Extras mirrorlist=http://mirrorlist.centos.org/?release= releaseverExtrasmirrorlist=http://mirrorlist.centos.org/?release=releasever&arch=KaTeX parse error: Expected 'EOF', got '&' at position 9: basearch&̲repo=extras&inf…infra
#baseurl=http://mirror.centos.org/centos/ r e l e a s e v e r / e x t r a s / releasever/extras/ 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- r e l e a s e v e r − P l u s m i r r o r l i s t = h t t p : / / m i r r o r l i s t . c e n t o s . o r g / ? r e l e a s e = releasever - Plus mirrorlist=http://mirrorlist.centos.org/?release= releaseverPlusmirrorlist=http://mirrorlist.centos.org/?release=releasever&arch=KaTeX parse error: Expected 'EOF', got '&' at position 9: basearch&̲repo=centosplus…infra
#baseurl=http://mirror.centos.org/centos/ r e l e a s e v e r / c e n t o s p l u s / releasever/centosplus/ releasever/centosplus/basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

mirrorlist设置了源路径,可以通过修改这里修改源路径,
修改了源路径清楚原有源缓存,然后对新源建立新的缓存,以后源就会变为自己设置的源

1.2、将源路径设置为国内阿里源。
(Linux无法直接将源修改为阿里源,因为阿里源需要下载,但是Linux中默认没有wget命令,所以在更改之前需要安装wget命令,然后备份目前源的配置,清空/etc/yum.repos.d下的内容,下载阿里源到改目录下,清楚原有源的缓存,建立阿里源的缓存)
1、安装wget:yum -y install wget 输入以后直接回车,用的源是国外的,所以相对会比较慢,耐心等待
2、备份现有源:
[root@localhost yum.repos.d]# cp CentOS-Base.repo / 备份
[root@localhost yum.repos.d]# cd /
[root@localhost /]# ls 验证
bin boot CentOS-Base.repo dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var

3、清楚现存所有源
**[root@localhost yum.repos.d]# rm -rf * ** 清楚当前目录下所有内容
4、下载阿里源
[root@localhost yum.repos.d]# wget -O /etc/yum.repos.d/Centos-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
[root@localhost yum.repos.d]# ls 查看下载结果
Centos-Base.repo

第一条命令表示从https://mirrors.aliyun.com/repo/Centos-7.repo 这个地址下载阿里源,下载到/etc/yum.repos.d/目录下,-O表示内容写到Centos-Base.repo,如果该文件存在,则覆盖
5、清楚源缓存:
[root@localhost yum.repos.d]# yum clean all 清楚原有源缓存
Loaded plugins: fastestmirror
Cleaning repos: base extras updates
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
6、建立源缓存
[root@localhost yum.repos.d]# yum makecache 建立源缓存
Loaded plugins: fastestmirror
http://mirrors.aliyuncs.com/centos/7/os/x86_64/repodata/repomd.xml: [Errno 12] Timeout on http://mirrors.aliyuncs.com/centos/7/os/x86_64/repodata/repomd.xml: (28, ‘Connection timed out after 30001 milliseconds’)
Trying other mirror.
http://mirrors.cloud.aliyuncs.com/centos/7/os/x86_64/repodata/repomd.xml: [Errno 14] curl#6 - “Could not resolve host: mirrors.cloud.aliyuncs.com; Name or service not known”
Trying other mirror.
base | 3.6 kB 00:00:00
extras | 2.9 kB 00:00:00
updates | 2.9 kB 00:00:00
(1/10): base/7/x86_64/group_gz | 153 kB 00:00:00
(2/10): base/7/x86_64/filelists_db | 7.1 MB 00:00:08
(3/10): extras/7/x86_64/filelists_db | 217 kB 00:00:00
(4/10): extras/7/x86_64/other_db | 125 kB 00:00:00
(5/10): extras/7/x86_64/primary_db | 205 kB 00:00:01
(6/10): updates/7/x86_64/filelists_db | 1.7 MB 00:00:04
(7/10): updates/7/x86_64/primary_db | 3.0 MB 00:00:05
(8/10): base/7/x86_64/other_db | 2.6 MB 00:00:06
(9/10): updates/7/x86_64/other_db | 249 kB 00:00:01
(10/10): base/7/x86_64/primary_db | 6.1 MB 00:00:23
Determining fastest mirrors

  • base: mirrors.aliyun.com
  • extras: mirrors.aliyun.com
  • updates: mirrors.aliyun.com
    Metadata Cache Created

到此我们将国外源更改为国内源,更改为国内源以后最直观表现是用yum安装软件速度提高了

1.3yum操作
使用yum安装rz命令,该命令是用来Linux系统与windows系统文件互传
[root@localhost yum.repos.d]# yum -y install rz
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile

  • base: mirrors.aliyun.com
  • extras: mirrors.aliyun.com
  • updates: mirrors.aliyun.com
    No package rz available.
    Error: Nothing to do
    通过结果看出什么操作都没有做,因为找不到rz这个包,我们要先知道rz命令包的名称,所以先使用 yum provides rz 命令 来查看那个包提供rz命令
    [root@localhost yum.repos.d]# yum provides rz
    Loaded plugins: fastestmirror
    Loading mirror speeds from cached hostfile
  • base: mirrors.aliyun.com
  • extras: mirrors.aliyun.com
  • updates: mirrors.aliyun.com
    lrzsz-0.12.20-36.el7.x86_64 : The lrz and lsz modem communications programs
    Repo : base
    Matched from:
    Filename : /usr/bin/rz
    通过命令看出rz包名是lrzsz-0.12.20-36.el7.x86_64。
    [root@localhost yum.repos.d]# yum -y install lrzsz-0.12.20-36.el7.x86_64 安装rz命令

通过yum -y install 命令 这种格式无法直接安装包就需要查找一下包名,然后通过 yum -y install 包名 这种格式安装

验证rz命令是否安装成功
在这里插入图片描述
输入rz命令按回车,出现如上界面,可以直接从windows中选择文件,选择好文件以后,点击确定,该文件就存储到当前目录下。
下载:sz 文件名 使用这个命令可以将文件下载到桌面上

卸载命令:yum -y remove 软件名 -y表示确定卸载

yum安装软件总结:1、修改yum源为阿里源
2、使用安装命令 yum -y install 软件名 如果这个命令不能安装软件,则先查看命令的软件包名,yum provides 命令 得出包名以后,在使用yum -y install 包名 进行安装
3、不想使用软件可以对软件卸载:yum -y remove 软件名

2、源码包安装
服务器在刚安装时候可能没有联网,则无法使用yum安装,就只能通过源码包进行安装,同时使用源码包安装后期对软件的操作会更方便,例如升级扩展。源码包安装不会解决以爱关系,所以在安装源码包时候,有可能会提示我要依赖于某一个软件安装,此时我们就要先安装依赖的那个软件,然后再回来安装我们要的软件。
源码包安装步骤:1、找包 2、配置源码包安装环境(很多包都是依赖于c语言编写,安装一些c语言的环境)3、上传包 、解压 4、进入到解压目录里面 6、指定安装位置,一般都是再/usr/local 7、预编译 8、安装
源码包安装nginx
第一步:网上找nginx包,nginx官网查找,下载1.6版本
第二步:配置源码包安装环境 yum -y install make gcc zlib-devel pcre pcre-devel openssl-devel
在这里插入图片描述
第三步:上传到/tmp目录 (rz命令),解压(tar xf 文件名)
在这里插入图片描述
第四步:进入到解压文件目录
第五步:指定安装路径 ./configrure --prefix=/usr/local/nginx (指定安装路径是/usr/local目录下的nginx,安装成功以后会在/usr/local下创建nginx目录,所有源码包安装都是再/usr/local下,创建软件名字的目录)
在这里插入图片描述
第六步:执行预编译: make
在这里插入图片描述

第七步:执行安装:make install
在这里插入图片描述

执行完以上七步,nginx就安装完成。

如何验证nginx是否安装成功,首先进入到/usr/local查看是否有nginx文件。有文件就去启动nginx服务,查看是否有nginx服务。
在这里插入图片描述红色箭头表示启动,蓝色箭头表示查看是都有对应服务

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值