yum工具及源码包

什么是yum

yum是RedHat以及CentOS中的软件包管理器,能够通过互联网下载以rpm结尾的包,并且安装,并可以自动处理依赖性关系,无需繁琐的一次次下载安装。

1.联网获取软件

2.基于RPM管理

3.自动解决依赖

4.命令简单好记

5.生产最佳实践

什么是yum源

要成功的使用yum工具安装更新软件或系统,就需要有一个包含各种rpm软件包的repository(软件仓库),这个软件仓库我们习惯称之为yum源或者yum仓库这个源可以是本地的也可以是网络的。

可以理解为手机中的应用商店

yum源 镜像站 yum仓库 rpm仓库

换源

base源 和镜像中的linux基础包差不多
epel 一些拓展的包

# 本地yum储存
ll /etc/yum.repos.d

# 删除本地yum源
rm -fr /etc/yum.repos.d/*

# 安全点的方式
gzip /etc/yum.repos.d/*


# 更换base源
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
#或者
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

# 更换epel源
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo


yum开启缓存

vim /etc/yum.conf
把keepcache=0----->1

# 加载yum缓存
yum makecache

# 清除所有缓存
yum clean all 

# 查看本地缓存包(缓存路径)
/var/cache/yum/x86_64/7/updates/packages

yum查询

#列出软件仓库中可用的软件
[root@zls ~]# yum list
 
#进行模糊查找
[root@zls ~]# yum list|grep vim
# 包名                                   版本号 发布次数 系统平台               隶属于
vim-filesystem.x86_64                    2:7.4.629-8.el7_9             @updates 
vim-minimal.x86_64                       2:7.4.160-5.el7               @anaconda
vim-minimal.x86_64                       2:7.4.629-8.el7_9             updates  
xtuple-csvimp-devel.x86_64               0.5.4-8.el7                   epel     

#列出软件包详情
[root@zls ~]# yum info vim

yum安装

# 本地安装
- yum localinstall -y 包的路径
# yum源安装
- yum install -y 包名
# 网站上安装
- yum install -y 包名(网址)

# 选项
-y 免交互

# 特性
1)自动解决依赖的前提,在你的所有yum源中都要有该软件的依赖
2)如果要安装多个包,使用空格隔开

#安装软件只需要给出软件名称(前提是在仓库中必须有)
[root@zls ~]# yum install traceroute
 
#安装过程中分析依赖关系后, 直接安装, 无需交互
yum install -y 包名
[root@zls ~]# yum install php -y
 
#安装本地的rpm包, 如果有依赖关系, 会自动从软件仓库中下载所需依赖(非来自.repo定义的软件仓库)
yum localinstall 包名
[root@zls ~]# yum localinstall /mnt/Packages/bind-9.9.4-50.el7.x86_64.rpm
 
#安装网络上rpm包
yum install 包名(或网址)
[root@zls ~]# yum install http://repo.zabbix.com/zabbix/3.4/rhel/7/x86_64/zabbix-release-3.4-2.el7.noarch.rpm

yum重装

# 语法
yum reinstall -y 包名

# 选项
-y 免交互

# 特性
可以恢复最初配置文件

# 流程
#检查软件是否存在
[root@zls ~]# rpm -q vsftpd
vsftpd-2.2.2-24.el6.x86_64
 
#检查vsftpd软件配置文件
[root@zls ~]# rpm -qc vsftpd
/etc/logrotate.d/vsftpd
/etc/pam.d/vsftpd
/etc/vsftpd/ftpusers
/etc/vsftpd/user_list
/etc/vsftpd/vsftpd.conf
 
#不小心删除vsftpd配置文件
[root@zls ~]# rm -f /etc/vsftpd/vsftpd.conf
 
#重新安装软件
[root@zls ~]# yum reinstall vsftpd
 
#再次检查
[root@zls ~]# rpm -qc vsftpd
/etc/logrotate.d/vsftpd
/etc/pam.d/vsftpd
/etc/vsftpd/ftpusers
/etc/vsftpd/user_list
/etc/vsftpd/vsftpd.conf

yum更新

# 对比Linux已安装的软件和yum仓库中的软件, 有哪些需要升级
yum check-update

# 语法
yum update -y 包名

# 更新整个版本
yum update -y (将会更新所有东西,包括内核版本)

yum卸载

# 语法
yum remove -y 包名
yum erase -y 包名

#删除该软件包,会删除依赖, 但是我们尽可能不要使用删除软件操作

scp 推送

scp 推
# 语法
scp 要推的路径 用户名@ip:保存的路径
# 实例
scp /etc/yum.repos.d/epel.repo root@10.0.0.103:/etc/yum.repos.d/

yum仓库

yum 缓存
yum clean all 清除所有缓存
# 加载缓存
yum makecache
# 安装依赖
yum install -y yum-plugin-downloadonly
--downloadonly 仅下载不安装
--downloaddir 指定下载的目录

本地yum仓库详解

阿里云的base配置详细信息
# 仓库名字
[base]

# 对于仓库的一个描述
name=CentOS-$releasever - Base -
mirrors.aliyun.com

# 仓库的地址
baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/
http://mirrors.aliyuncs.com/centos/$releasever/os/$basearch/
http://mirrors.cloud.aliyuncs.com/centos/$releasever/os/$basearch/

# 是否检查公钥
gpgcheck=1

# 公钥的位置
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

# 检查仓库是否开启
enabled=1




# 将所有可用的仓库列出
yum repolist

# 将所有仓库全列出,无论可用与否
yum repolist all

# 包组管理
yum group list 查看所有的包组
yum group install 包组名字 # 包组下载
yum group remove 包组名字 # 包组卸载

# yum 历史命令
yum history 查看yum历史命令
yum history info id 查看指定的id详细信息
yum history undo id 撤销指定的yum命令

本地yum仓库制作

# 让原本的源失效
gzip /etc/yum.repo.d/*

# 创建一个本地仓库目录
mkdir /loacl_yum

# 挂载
mount /dev/cdrom /loacl_yum

# 添加一个.repo结尾的源文件
vim bendi.repo
[niubi]
name=wojiushidian
baseurl=file:///loacl_yum
gpgcheck=0
enabled=1

# 重新加载缓存
yum makecache

# 查看是否生效
yum repolist

远程yum仓库制作

# 安装vsftpd服务,让该机器能够用变成网络服务
yum install -y vsftpd

# 启动服务
systemctl start vsftpd
vim /etc/sysconfig/selinux

# 关闭selinux
vim /etc/sysconfig/selinux
SELINUX=disbaled

# 关闭防火墙
systemctl stop firewalld

# 在ftp目录下创建一个base目录
mkdir /var/ftp/pub/base

# 挂载光盘
mount /dev/cdrom /mnt/

# 拷贝所有的包至/var/ftp/pub/base/
cp /mnt/Packages/* /var/ftp/pub/base/

# 安装仓库制作命令
createrepo /var/ftp/pub/

# 添加一个.repo结尾的源文件
vim /etc/yum.repos.d/cssd.repo
[ll_base]                        # 仓库名字
name=miaoshu                     # 仓库描述
baseurl=ftp://10.0.0.100/pub/    # 源网站地址
gpgcheck=0                       # 关闭签名检测机制
enabled=1                        # 开启仓库 默认开启 可写可不写

# 检查yum仓库是否加载成功
yum repolist

源码安装nginx

linux中软件的安装方式

安装包 安装方式
rpm包 rpm yum
源码包 编译安装
二进制包 免安装

获取源码包

想要什么源码包,就去他的官网

image.png

# nginx官网,下载源码包
wget https://nginx.org/download/nginx-1.20.2.tar.gz

# 使用tar解压源码包
tar xf nginx-1.20.2.tar.gz 

# 生成
./configure --prefix=/opt/nginx-1.20.2 --with-http_ssl_module --with-http_stub_status_module

# 报错1 缺少c语言
./configure: error: C compiler cc is not found
# 解决方法
yum install -y gcc gcc-c++ glibe

# 报错2 缺少pcre依赖
./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

# 报错3 缺少openssl依赖
./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 pcre-devel openssl openssl-devel

# 总解决方法
yum install -y openssl-devel pcre-devel gcc gcc-c++ glibc 

# 编译(为了让系统能识别你的代码,并把刚才指定的功能和路径编译到源码中)
##在解包所在目录下进行编译
make

# 安装
make install

# 做软链接
ln -s /opt/nginx-1.20.2/ /opt/nginx

# 增加环境变量
vim /etc/profile.d/nginx.sh
# 编辑
export PATH="$PATH:/opt/nginx/sbin"

# 生效环境变量
source /etc/profile

# 启动nginx
nginx

# 关闭防火墙
systemctl stop firewalld
setenforce 0

# 关闭selinux
vim /etc/sysconfig/selinux
selinux=disabled

image.png