Linux系统——软件安装
一、软件安装包格式
1、Linux安装包格式
-
RHEL/CentOS
xxxx.rpm -
Debian/Ubuntu
xxxx.deb -
源码安装包
xxxx.tar.gz, xxxx.tar.bz2
2、软件安装包命名格式
[root@localhost ~]# mount /dev/sr0 /mnt/
mount: /dev/sr0 is write-protected, mounting read-only
[root@localhost ~]# ls /mnt/Packages/
wireshark-1.10.14-25.el7.x86_64.rpm
软件名-版本-系统版本.架构.rpm
二、软件操作
1、使用工具
- rpm
- yum
2、rpm工具
- 安装软件
# rpm -ivh 软件安装包
[root@localhost ~]# rpm -ivh /mnt/Packages/dhcp-4.2.5-82.el7.centos.x86_64.rpm
Preparing... ################################# [100%]
Updating / installing...
1:dhcp-12:4.2.5-82.el7.centos ################################# [100%]
[root@localhost ~]# rpm -ivh /mnt/Packages/wireshark-1.10.14-25.el7.x86_64.rpm
error: Failed dependencies: // 错误的依赖
libcares.so.2()(64bit) is needed by wireshark-1.10.14-25.el7.x86_64
libpcap.so.1()(64bit) is needed by wireshark-1.10.14-25.el7.x86_64
libsmi.so.2()(64bit) is needed by wireshark-1.10.14-25.el7.x86_64
- 查看软件是否安装
[root@localhost ~]# rpm -q dhcp
dhcp-4.2.5-82.el7.centos.x86_64
[root@localhost ~]# rpm -q wireshark
package wireshark is not installed
[root@localhost ~]# rpm -qa
[root@localhost ~]# rpm -qa | grep ssh
openssh-server-7.4p1-21.el7.x86_64
libssh2-1.8.0-4.el7.x86_64
openssh-clients-7.4p1-21.el7.x86_64
openssh-7.4p1-21.el7.x86_64
- 查询文件由哪个软件生成
[root@localhost ~]# which ifconfig
/usr/sbin/ifconfig
[root@localhost ~]# rpm -qf /usr/sbin/ifconfig
net-tools-2.0-0.25.20131004git.el7.x86_64
- 查询软件生成的文件
[root@localhost ~]# rpm -ql coreutils
- 卸载软件
[root@localhost ~]# rpm -q wireshark
wireshark-1.10.14-25.el7.x86_64
[root@localhost ~]# rpm -e wireshark
[root@localhost ~]# rpm -q wireshark
package wireshark is not installed
3、yum工具
优势:自动解决软件的依赖关系
前提条件:合适的yum源/仓库
yum源类型:本地源、FTP源、HTTP源(阿里、华为、网易、清华大学)
yum源存放位置: /etc/yum.repos.d/xxxxx.repo
3.1 替换国内的Base源
[root@localhost ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
--2024-10-17 10:52:30-- https://mirrors.aliyun.com/repo/Centos-7.repo
Resolving mirrors.aliyun.com (mirrors.aliyun.com)... 124.193.244.243, 124.193.244.240, 124.193.244.238, ...
Connecting to mirrors.aliyun.com (mirrors.aliyun.com)|124.193.244.243|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 2523 (2.5K) [application/octet-stream]
Saving to: ‘/etc/yum.repos.d/CentOS-Base.repo’
100%[==============================================================>] 2,523 --.-K/s in 0s
2024-10-17 10:52:30 (303 MB/s) - ‘/etc/yum.repos.d/CentOS-Base.repo’ saved [2523/2523]
- 安装软件
[root@localhost ~]# yum install httpd
[root@localhost ~]# rpm -q httpd
httpd-2.4.6-99.el7.centos.1.x86_64
- 卸载软件
[root@localhost ~]# yum remove httpd
[root@localhost ~]# rpm -q httpd
package httpd is not installed
- 更新软件
[root@localhost ~]# yum update 软件名称
[root@localhost ~]# yum update httpd
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
No packages marked for update
- 搜索
[root@localhost ~]# yum provides vim
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
2:vim-enhanced-7.4.629-7.el7.x86_64 : A version of the VIM editor which includes recent enhancements
Repo : base
Matched from:
Provides : vim = 7.4.629-7.el7
[root@localhost ~]# yum search ifconfig
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
========================================== Matched: ifconfig ===========================================
net-tools.x86_64 : Basic networking tools
3.2 编写yum源配置文件 (FTP源)
[root@localhost ~]# cat /etc/yum.repos.d/mysql80.repo
[mysql80]
name=mysql80
baseurl=ftp://10.11.0.254/software/mysql8.0.12/
enabled=1
gpgcheck=0
- 查看可用yum源
[root@localhost ~]# yum repolist
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
mysql80 | 2.9 kB 00:00:00
mysql80/primary_db | 8.6 kB 00:00:00
repo id repo name status
base/7/x86_64 CentOS-7 - Base - mirrors.aliyun.com 10,072
extras/7/x86_64 CentOS-7 - Extras - mirrors.aliyun.com 526
mysql80 mysql80 6
updates/7/x86_64 CentOS-7 - Updates - mirrors.aliyun.com 6,173
repolist: 16,777
[root@localhost ~]# yum install mysql-community-server
[root@localhost ~]# rpm -qa | grep mysql
mysql-community-common-8.0.12-1.el7.x86_64
mysql-community-client-8.0.12-1.el7.x86_64
mysql-community-libs-compat-8.0.12-1.el7.x86_64
mysql-community-libs-8.0.12-1.el7.x86_64
mysql-community-server-8.0.12-1.el7.x86_64
3.3 HTTP源的使用
[root@localhost ~]# cat /etc/yum.repos.d/openstack.repo
[openstack]
name=openstack
baseurl=https://mirrors.aliyun.com/centos/7.9.2009/cloud/x86_64/openstack-stein/
enabled=1
gpgcheck=0
[root@localhost ~]# yum repolist
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
openstack | 3.0 kB 00:00:00
openstack/primary_db | 1.1 MB 00:00:00
repo id repo name status
base/7/x86_64 CentOS-7 - Base - mirrors.aliyun.com 10,072
extras/7/x86_64 CentOS-7 - Extras - mirrors.aliyun.com 526
mysql80 mysql80 6
openstack openstack 2,737
updates/7/x86_64 CentOS-7 - Updates - mirrors.aliyun.com 6,173
repolist: 19,514
[root@localhost ~]# yum install openstack-keystone
[root@localhost ~]# rpm -q openstack-keystone
openstack-keystone-15.0.1-1.el7.noarch
epel源的使用
[root@localhost ~]# wget -O /etc/yum.repos.d/epel.repo https://mirrors.aliyun.com/repo/epel-7.repo
--2024-10-17 14:24:05-- https://mirrors.aliyun.com/repo/epel-7.repo
Resolving mirrors.aliyun.com (mirrors.aliyun.com)... 124.193.244.241, 124.193.244.242, 124.193.244.243, ...
Connecting to mirrors.aliyun.com (mirrors.aliyun.com)|124.193.244.241|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 664 [application/octet-stream]
Saving to: ‘/etc/yum.repos.d/epel.repo’
100%[==============================================================>] 664 --.-K/s in 0s
2024-10-17 14:24:05 (275 MB/s) - ‘/etc/yum.repos.d/epel.repo’ saved [664/664]
[root@localhost ~]# rpm -q ntfs-3g
ntfs-3g-2022.10.3-1.el7.x86_64
4、yum缓存
- 开启yum缓存
[root@localhost ~]# vim /etc/yum.conf
[main]
cachedir=/var/cache/yum/$basearch/$releasever
keepcache=1
- 获取缓存的安装包
[root@localhost ~]# yum install openstack-glance
[root@localhost ~]# mkdir /glance
[root@localhost ~]# find /var/cache/yum/ -name "*.rpm" -exec cp {} /glance/ \;
- 编写本地源
[root@localhost ~]# createrepo /glance/
Spawning worker 0 with 42 pkgs
Spawning worker 1 with 41 pkgs
Spawning worker 2 with 41 pkgs
Spawning worker 3 with 41 pkgs
Workers Finished
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete
[root@localhost ~]# cat /etc/yum.repos.d/glance.repo
[glance]
name=glance
baseurl=file:///glance
enabled=1
gpgcheck=0
[root@localhost ~]# yum install openstack-glance
三、源码软件的安装
灵活性高,支持自定义安装路径、功能参数
1、安装流程
1、下载软件安装包 (.tar.gz, .tar.bz2)
2、解压缩
3、切换软件的解压目录
4、配置软件安装路径、功能参数
5、编译, 将代码转换成计算机可执行的文件
6、安装,生成软件相关的文件
2、安装htop软件
htop: 性能监控工具,类似任务管理器
- 下载htop安装包
[root@localhost ~]# lftp 10.11.0.254
lftp 10.11.0.254:~> ls
drwxr-x--- 2 1007 1007 31 Aug 15 2023 myscore
drwxr-xr-x 6 0 0 80 Jul 14 01:23 robin
drwxr-xr-x 35 1000 1000 4096 Sep 29 08:34 software
drwxr-xr-x 10 1000 1000 4096 Sep 28 09:01 upload
lftp 10.11.0.254:/> cd software/htop/
lftp 10.11.0.254:/software/htop> ls
-rw-rw-r-- 1 1000 1000 308109 Apr 10 2018 htop-2.2.0.tar.gz
lftp 10.11.0.254:/software/htop>
lftp 10.11.0.254:/software/htop> get htop-2.2.0.tar.gz
308109 bytes transferred
lftp 10.11.0.254:/software/htop> exit
- 解压缩
[root@localhost ~]# tar xf htop-2.2.0.tar.gz
- 配置软件安装目录
[root@localhost ~]# cd htop-2.2.0/
[root@localhost htop-2.2.0]# ./configure --prefix=/usr/local/htop
- 编译
[root@localhost htop-2.2.0]# make
- 安装
[root@localhost htop-2.2.0]# make install
- 验证软件的运行
[root@localhost ~]# /usr/local/htop/bin/htop
3、系统环境变量PATH
-
作用
保存命令路径,系统在执行命令时,会在PATH的路径下查找命令,如果能找到会成功执行,否则提示命令未找到 -
查看PATH变量的值
[root@localhost ~]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/usr/local/htop/bin
- 修改PATH的值,添加新的路径
[root@localhost ~]# vim /etc/profile
export PATH=$PATH:/usr/local/htop/bin
[root@localhost ~]#
[root@localhost ~]# source /etc/profile