08.Linux rpm&yum&源码安装软件

1.Linux安装软件

1.1三种方式
Linux中安装软件的三种方式:
1.rpm安装
2.yum安装
3.源代码编译安装
1.2区别
1.rpm安装类似于windows中的安装包,
下载下来之后直接安装。缺点是不能自动解决依赖。

2.yum安装基于rpm安装,也就是在rpm上增加了自动解决依赖的功能。

3.源代码安装:通过编译源代码,得到软件包。
优点是可以自定制软件包,缺点是比较复杂。

2.RPM安装

1.安装命令
	安装:rpm -ivh [软件包全名]
2.卸载命令
	卸载:rpm -e [软件名称]
3.升级命令
	升级:rpm -Uvh [软件包名称]
4.查询是否安装某个软件
	存在: rpm -q [软件名称]
5.查询所有安装软件
	所有: rpm -qa 
6.查询否个软件的配置文件
	配置: rpm -qc [软件名称]
2.1练习
1.需要先下载一个包

* 去清华源的包 , 下载到本地 选择 vim包 ctrl + f 搜索

地址:
https://mirrors.tuna.tsinghua.edu.cn/centos/7.9.2009/os/x86_64/Packages/

image-20211216195310186

# 2. 将文件之间托到虚拟机中.需要 lrzsz 软件的辅助.  
[root@localhost ~]# yum install -y  lrzsz
# Error: Nothing to do
# 如果无法安装就修改镜像源为清华源再尝试下载 lrzsz
[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# sudo sed -e 's|^mirrorlist=|#mirrorlist=|g' \
>          -e 's|^#baseurl=http://mirror.centos.org|baseurl=https://mirrors.tuna.tsinghua.edu.cn|g' \
>          -i.bak \
>          /etc/yum.repos.d/CentOS-*.repo
[root@localhost ~]# yum install -y  lrzsz
安装好之后直接将下载好安装包托拽到xhell界面
会自动执行re -E命令

image-20211216195350851

软件包名称
zsh-5.0.2-34.el7_8.2.x86_64.rpm 
软件包名称:zsh
版本号:5.0.2
第多少次编译:34
适用的平台:el7_8(CentOS 7
适用的系统位数:x86_64
扩展名:rpm

image-20211216195411375

# 查看
[root@localhost ~]# ll
...
-rw-r--r--. 1 root root 2497380 Dec 16 19:53 zsh-5.0.2-34.el7_8.2.x86_64_(1).rpm
# 3.执行rpm命令安装 zsh
[root@localhost ~]# rpm -ivh zsh-5.0.2-34.el7_8.2.x86_64_\(1\).rpm 

image-20211216195643628

# zsh 是一个解释器 输入zsh切换为zsh解释器
[root@localhost ~]# zsh
[root@localhost]~# ls
[root@localhost]~# bash
# 查看软件的配置文件
[root@localhost ~]# rpm -qc zsh
/etc/skel/.zshrc
/etc/zlogin
/etc/zlogout
/etc/zprofile
/etc/zshenv
/etc/zshrc
# 查看是否安装某软件, 
[root@localhost ~]# rpm -q zsh
# 安装了显示软件版本信息
zsh-5.0.2-34.el7_8.2.x86_64
[root@localhost ~]# rpm -q vim
# 没安装
package vim is not installed
# 卸载 软件
[root@localhost]~# rpm -e zsh
[root@localhost]~# zsh
zsh: command not found: zsh
# 查看所有安装软件
[root@localhost ~]# rpm -qa
....

3.YUM安装

yum安装是基于rpm进行安转,最大的作用自动解决暗转包的依赖问题.
3.1常用命令
1.安装命令
	yum install [软件包的名称] 安装指定版本
	yum install [软件包]  选定版本
	-y 免交互 提示是否安装自动回复y 
        yum install [软件包的名称] -y 
        yum install -y [软件包的名称]  
	-nogpgcheck 忽略公钥认证
2.卸载命令
	yum remove [软件名称]
	-y 免交互
3.更新命令
	yum update [软件名称]
	-y 免交互
	注意:如果跟具体的软件包名称,就会更新指定软件包;
	如果没有指定,则更新系统所有的需要更新的软件包。
3.2yum运行周期
* /etc/yum.conf 是yum的配置文件
1.执行 yum install zsh -y
2.先去/etc/yum.repos.d/下找 .repo结尾的文件 
3.通过.repo文件中的配置文件提供的链接找到对应的软件仓库
4.在对应的软件仓库中招待指定的软件报
5.缓存到本地/var/cache/yum/
6.根据缓存安装软件包
7.删除软件包(keepcache 为保存缓存 0代表不保存, 1代表保存)
"""
[root@localhost ~]# cat  /etc/yum.conf | grep keepcache
keepcache=0
"""
3.3练习
# 安装python3  
[root@localhost ~]# yum install -y python3
...
# 卸载python3 
[root@localhost ~]# yum remove -y python3
...
# 更新软件 
[root@localhost ~]# yum update -y vi

4.YUM私用云

4.1本地搭建
# 1.下载两个软件包 yum-utils yum-utils
[root@localhost ~]# yum install -y createrepo yum-utils  lrzsz
# 2.创建仓库
[root@localhost ~]# mkdir -p /opt/repos  
# 3.创建 Packages 目录  上面这条可以不要之间执行下面这条
[root@localhost ~]# mkdir -p /opt/repos/Packages
# 4.下载软件 复制到 Packages 目录中
[root@localhost ~]# mv zsh-5.0.2-34.el7_8.2.x86_64.rpm  /opt/repos/Packages

# 5.初始化仓库
[root@localhost ~]# createrepo /opt/repos
Spawning worker 0 with 1 pkgs
Workers Finished
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete
# 添加yum源
"""
# 先备份下
cd /etc/yum.repos.d/
mkdir backup
mv *.repo backup/
"""
[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# yum-config-manager --add-repo=file:///opt/repos
Loaded plugins: fastestmirror
adding repo from: file:///opt/repos

[opt_repos]  #源的名字
name=added from: file:///opt/repos  # 源的简介
baseurl=file:///opt/repos           # 源的下载地址
enabled=1                  # 是否启用:1启用 ,  0不启用
# 6.生成缓存
[root@localhost yum.repos.d]# yum clean all
Loaded plugins: fastestmirror
Cleaning repos: base extras opt_repos updates
Cleaning up list of fastest mirrors
[root@localhost yum.repos.d]# yum makecache
Loaded plugins: fastestmirror
.....
# 7.测试安装
[root@localhost yum.repos.d]# yum install zsh
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Package zsh-5.0.2-34.el7_8.2.x86_64 already installed and latest version
Nothing to do
[root@localhost yum.repos.d]# zsh
# 安装成功
[root@localhost]/etc/yum.repos.d#
4.2远程版本
# 前7步与前面的一样不需要再重复执行,直接跳第八步
# 1.安装工具 
[root@localhost ~]# yum install -y createrepo  yum-utils  lrzsz
# 2.创建仓库
[root@localhost ~]# mkdir -p /opt/repos/Packages
# 3.复制文件到虚拟机
[root@localhost ~]# rz -E
# 4.移动文件到仓库
[root@localhost ~]# mv zsh-5.0.2-34.el7_8.2.x86_64.rpm  /opt/repos/Packages
# 5.创建仓库源
[root@localhost ~]# createrepo /opt/repos
# 6.配置源
[root@localhost ~]#  yum-config-manager --add-repo=file:///opt/repos
# 7.生成配置缓存文佳
[root@localhost ~]# yum clean all
[root@localhost ~]# yum makecache
# 8.更换源
[root@localhost ~]# curl -o /etc/yum.repos.d/CentOS-Base.repo 
[root@localhost ~]# yum-config-manager --add-repo=https://repo.huaweicloud.com/epel/7/x86_64/
# 9.安装服务器
[root@localhost ~]# yum install nginx --nogpgcheck
# 10.编辑服务器配置文件
[root@localhost ~]# vi /etc/nginx/nginx.conf
"""	
	# 后面有图
    # include /etc/nginx/conf.d/*.conf; 注释这行
	root         /opt/repos; # 改源地址
	# 添加展示仓库的软件
	autoindex on;
"""
# 11.测试更改是否成功
[root@localhost ~]# nginx -t
#....syntax is ok
#...test is successful 
# 12.启动服务
[root@localhost ~]# systemctl start nginx
# 13.关闭安全服务
[root@localhost ~]# systemctl disable --now firewalld
[root@localhost ~]# setenforce 0

# 14.添加源地址
[root@localhost ~]# yum-config-manager --add-repo=http://192.168.15.100/

# 15.刷新配置缓存
[root@localhost ~]# yum clean all
[root@localhost ~]# yum makecache

# 16.安装测试  & 网页输入 192.168.15.100访问
[root@localhost ~]# yum install zsh -y

# 17.测试
[root@localhost ~]# zsh
[root@localhost]~# 
# 18.
# 在写一个 a.txt 复制到仓库去

image-20211217102248751

image-20211217102515873

image-20211217102542587

5.源码安装

使源代码编译&打包软件.特点:
1.可以自定义软件
2.按需构建软件
5.1 编译步骤
nginx服务器安装包下载
http://nginx.org/en/download.html

image-20211217163008018

image-20211217163035033

image-20211217163156919

https://nginx.org/download/nginx-1.20.2.tar.gz
# 0.安装wget工具
[root@localhost ~]# yum install -y wget

# 1.先下载一个源码包
[root@localhost ~]# wget https://nginx.org/download/nginx-1.20.2.tar.gz

# 2.下载依赖库
[root@localhost ~]#  yum install pcre pcre-devel zlib zlib-devel -y

#3. 解压
[root@localhost ~]#  tar -xf nginx-1.20.2.tar.gz

# 4.进入软件包
[root@localhost ~]# cd nginx-1.20.2
"""
自定义服务器名称(装逼用的)
vi ./src/core/nginx.h
"""
# 5.自动设置参数
[root@localhost nginx-1.20.2]# ./configure
# 6.编译
make

# 7.安装
make install
# 8.关闭安全服务
[root@localhost ~]# systemctl disable --now firewalld
[root@localhost ~]# setenforce 0
# 9.启动
[root@localhost nginx-1.20.2]# /usr/local/nginx/sbin/nginx

# 10.关闭
[root@localhost nginx-1.20.2]# /usr/local/nginx/sbin/nginx -s stop
[root@localhost nginx-1.20.2]# systemctl stop nginx

image-20211217172710081

image-20211217171218834

image-20211217172956795

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值