rpm包来源
1、来源网络下载
2、来源本地:自己的镜像自带的rpm包
rpm命令
#安装
rpm -ivh xxx.rpm
#http://nginx.org/packages/centos/7/x86_64/RPMS/
-v : 显示安装过程
-i :显示安装包的详细信息
-h : 安装包哈希标记
#下载Nginx rpm安装包的全名
[root@localhost ~]# wget http://nginx.org/packages/centos/7/x86_64/RPMS/nginx-1.18.0-1.el7.ngx.x86_64.rpm
--2021-03-17 12:16:47-- http://nginx.org/packages/centos/7/x86_64/RPMS/nginx-1.18.0-1.el7.ngx.x86_64.rpm
Resolving nginx.org (nginx.org)... 52.58.199.22, 3.125.197.172, 2a05:d014:edb:5702::6, ...
Connecting to nginx.org (nginx.org)|52.58.199.22|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 790284 (772K) [application/x-redhat-package-manager]
Saving to: ‘nginx-1.18.0-1.el7.ngx.x86_64.rpm’
100%[====================================================>] 790,284 339KB/s in 2.3s
2021-03-17 12:16:51 (339 KB/s) - ‘nginx-1.18.0-1.el7.ngx.x86_64.rpm’ saved [790284/790284]
#安装rpm安装包
[root@localhost ~]# rpm -ivh nginx-1.18.0-1.el7.ngx.x86_64.rpm
warning: nginx-1.18.0-1.el7.ngx.x86_64.rpm: Header V4 RSA/SHA1 Signature, key ID 7bd9bf62: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:nginx-1:1.18.0-1.el7.ngx #################################[100%]
Thanks for using nginx!
Please find the official documentation for nginx here:
* http://nginx.org/en/docs/
Please subscribe to nginx-announce mailing list to get
the most important news about nginx:
* http://nginx.org/en/support.html
Commercial subscriptions for nginx are available on:
* http://nginx.com/products/
#验证nginx是否安装成功
[root@localhost ~]# nginx -v
nginx version: nginx/1.18.0
#卸载
[root@localhost ~]# rpm -e nginx (软件包名称)
[root@localhost ~]# nginx -v
-bash: /usr/sbin/nginx: No such file or directory
[root@localhost ~]#
#查看系统当中安装了哪些rpm软件包
rpm -qa
#查看系统当中是否安装了某个rpm软件包
rpm -q
[root@localhost ~]# rpm -q nginx(软件包名)
nginx-1.18.0-1.el7.ngx.x86_64
[root@localhost ~]# rpm -q safsdgsfdgfd
package safsdgsfdgfd is not installed
#显示已经安装过的rpm包详细信息。
[root@localhost ~]# rpm -qi nginx
Name : nginx
Epoch : 1
Version : 1.18.0
Release : 1.el7.ngx
Architecture: x86_64
Install Date: Wed 17 Mar 2021 04:18:55 PM CST
Group : System Environment/Daemons
Size : 2830028
License : 2-clause BSD-like license
Signature : RSA/SHA1, Tue 21 Apr 2020 11:19:18 PM CST, Key ID abf5bd827bd9bf62
Source RPM : nginx-1.18.0-1.el7.ngx.src.rpm
Build Date : Tue 21 Apr 2020 11:07:33 PM CST
Build Host : ip-10-1-17-101.eu-central-1.compute.internal
Relocations : (not relocatable)
Vendor : Nginx, Inc.
URL : http://nginx.org/
Summary : High performance web server
Description :
nginx [engine x] is an HTTP and reverse proxy server, as well as
a mail proxy server.
#查看安装包的内容
[root@localhost nginx]# rpm -ql nginx
/etc/logrotate.d/nginx
/etc/nginx
/etc/nginx/conf.d
/etc/nginx/conf.d/default.conf
/etc/nginx/fastcgi_params
/etc/nginx/koi-utf
/etc/nginx/koi-win
/etc/nginx/mime.types
/etc/nginx/modules
/etc/nginx/nginx.conf
/etc/nginx/scgi_params
/etc/nginx/uwsgi_params
/etc/nginx/win-utf
/etc/sysconfig/nginx
/etc/sysconfig/nginx-debug
/usr/lib/systemd/system/nginx-debug.service
/usr/lib/systemd/system/nginx.service
/usr/lib64/nginx
/usr/lib64/nginx/modules
/usr/libexec/initscripts/legacy-actions/nginx
/usr/libexec/initscripts/legacy-actions/nginx/check-reload
/usr/libexec/initscripts/legacy-actions/nginx/upgrade
/usr/sbin/nginx
/usr/sbin/nginx-debug
/usr/share/doc/nginx-1.18.0
/usr/share/doc/nginx-1.18.0/COPYRIGHT
/usr/share/man/man8/nginx.8.gz
/usr/share/nginx
/usr/share/nginx/html
/usr/share/nginx/html/50x.html
/usr/share/nginx/html/index.html
/var/cache/nginx
/var/log/nginx
#查看配置信息
[root@localhost nginx]# rpm -qc nginx
/etc/logrotate.d/nginx
/etc/nginx/conf.d/default.conf
/etc/nginx/fastcgi_params
/etc/nginx/koi-utf
/etc/nginx/koi-win
/etc/nginx/mime.types
/etc/nginx/nginx.conf
/etc/nginx/scgi_params
/etc/nginx/uwsgi_params
/etc/nginx/win-utf
/etc/sysconfig/nginx
/etc/sysconfig/nginx-debug
#查看文件帮助信息
[root@localhost nginx]# rpm -qd zlib
/usr/share/doc/zlib-1.2.7/ChangeLog
/usr/share/doc/zlib-1.2.7/FAQ
/usr/share/doc/zlib-1.2.7/README
[root@localhost ~]# rpm -qf /usr/sbin/nginx
nginx-1.18.0-1.el7.ngx.x86_64
#用 -p 可以查看未安装软件包的详细信息
[root@localhost ~]# rpm -qip nginx-1.18.0-1.el7.ngx.x86_64.rpm
warning: nginx-1.18.0-1.el7.ngx.x86_64.rpm: Header V4 RSA/SHA1 Signature, key ID 7bd9bf62: NOKEY
Name : nginx
Epoch : 1
Version : 1.18.0
Release : 1.el7.ngx
Architecture: x86_64
Install Date: (not installed)
Group : System Environment/Daemons
Size : 2830028
License : 2-clause BSD-like license
Signature : RSA/SHA1, Tue 21 Apr 2020 11:19:18 PM CST, Key ID abf5bd827bd9bf62
Source RPM : nginx-1.18.0-1.el7.ngx.src.rpm
Build Date : Tue 21 Apr 2020 11:07:33 PM CST
Build Host : ip-10-1-17-101.eu-central-1.compute.internal
Relocations : (not relocatable)
Vendor : Nginx, Inc.
URL : http://nginx.org/
Summary : High performance web server
Description :
nginx [engine x] is an HTTP and reverse proxy server, as well as
a mail proxy server.
#升级软件包
[root@localhost ~]# rpm -Uvh nginx-1.18.0-1.el7.ngx.x86_64.rpm
warning: nginx-1.18.0-1.el7.ngx.x86_64.rpm: Header V4 RSA/SHA1 Signature, key ID 7bd9bf62: NOKEY
Preparing… ################################# [100%]
Updating / installing…
1:nginx-1:1.18.0-1.el7.ngx ################################# [ 50%]
Cleaning up / removing…
2:nginx-1:1.14.0-1.el7_4.ngx ################################# [100%]
[root@localhost ~]# nginx -v
nginx version: nginx/1.18.0
#强制删除软件包–nodeps
[root@localhost ~]# rpm -e zlib --nodeps
yum
yum是CentOS的软件包管理工具,自动为我们解决软件依赖问题。yum包管理工具必须使用yum源指定软件下载地址去下载需要安装的软件包。配置的路径是:/etc/yum.repos.d
#清空本机所有的yum源
[root@www yum.repos.d]# rm -rf /etc/yum.repos.d/*
yum源的执行原理
1、需要在/etc/yum.repos.d目录下配置yum源地址
2、清空缓存建立新的缓存
3、安装软件(自动解决依赖关系)
yum常用的基础命令
#查看当前系统的yum源列表
[root@www yum.repos.d]# yum repolist
yum repolist all # 查看系统中所有的yum仓库
[root@www yum.repos.d]# yum repolist all
#yum清空缓存
[root@www yum.repos.d]# yum clean all
#建立yum缓存
[root@www yum.repos.d]# yum makecache
#yum安装
[root@www yum.repos.d]# yum install 软件包名称 -y(免交互安装)
#卸载软件(直接将软件的依赖包一起删除)
yum remove 软件包名称
#查看当前系统需要更新软件
yum check-update
#更新所有的需要更新的软件
yum update
#重装软件
yum reinstall (软件包名称)
#搜索软件包
[root@www httpd]# yum search (软件包名称)
#查看yum执行历史
[root@www httpd]# yum history info (历史ID号)
[root@www httpd]# yum history undo (历史ID号)
#启用repo仓库
yum install yum-utils -y
启用一个yum仓库:yum-config-manager --enable (仓库名称)
关闭一个yum仓库:yum-config-manager --disable (仓库名称)
#查看一个仓库中的软件包列表
[root@www yum.repos.d]# yum list
#查看软件包组
[root@www yum.repos.d]# yum grouplist
#安装软件包组
[root@www yum.repos.d]# yum groupinstall “Development Tools”
建立本地仓库
克隆两台主机
yum仓库主机
外网地址:192.168.15.30
内网地址:172.16.1.30
yum测试主机
外网地址:192.168.15.31
内网地址:172.16.1.31
修改的命令:
vim /etc/sysconfig/network-scripts/ifcfg-eth0
vim /etc/sysconfig/network-scripts/ifcfg-eth1
重启网卡:systemctl restart network
修改主机名:
yum仓库主机:hostnamectl set-hostname warehouse
yum测试主机:hostnamectl set-hostname yum-test
2、配置yum仓库
1、需要有一个软件包目录,存放软件包的
[root@warehouse ~]# mkdir /backup
1.1、缓存yum安装下载的软件包
[root@warehouse 7]# vim /etc/yum.conf
[main]
cachedir=/var/cache/yum/$basearch/$releasever
keepcache=1
[root@warehouse ~]# yum install mariadb -y
1.2、将缓存的软件包复制到yum仓库目录
[root@warehouse ~]# cd /var/cache/yum/x86_64/7/base/packages/
[root@warehouse packages]# cp -rp ./* /backup/
[root@warehouse packages]# cd /backup/
[root@warehouse backup]# ll
total 8964
-rw-r--r-- 1 root root 9175948 Oct 15 02:55 mariadb-5.5.68-1.el7.x86_64.rpm
2、建立软件包依赖关系
[root@warehouse backup]# yum install createrepo -y
[root@warehouse backup]# createrepo /backup/
Spawning worker 0 with 1 pkgs
Spawning worker 1 with 0 pkgs
Workers Finished
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete
[root@warehouse backup]# ll
total 8968
-rw-r--r-- 1 root root 9175948 Oct 15 02:55 mariadb-5.5.68-1.el7.x86_64.rpm
drwxr-xr-x 2 root root 4096 Mar 18 08:54 repodata
[root@warehouse backup]# ll repodata/
total 28
-rw-r--r-- 1 root root 1970 Mar 18 08:54 5d54624b2aa7a1fe974ff5553a9a78289683189c6a7b60c8c1421ecf011d270f-other.sqlite.bz2
-rw-r--r-- 1 root root 3449 Mar 18 08:54 5e68ee34f7e8f1a11a039f55c990bcc044f16bceb6af7f4486b55d518ad91346-primary.sqlite.bz2
-rw-r--r-- 1 root root 539 Mar 18 08:54 6e94b0fa1d98955542fb8238348ea171be7a130ba97573eb3ac756e1aadcec50-filelists.xml.gz
-rw-r--r-- 1 root root 1291 Mar 18 08:54 a9afb0b2457f41f5c2d64744a07d5d12599e6c2588c870ae73568cf345a0abca-other.xml.gz
-rw-r--r-- 1 root root 1333 Mar 18 08:54 cf41627875b17ef4bea5f0ea566ac63a5c83adc606d3ca730a74944ceb969028-primary.xml.gz
-rw-r--r-- 1 root root 1158 Mar 18 08:54 f34cbfd9e5608e8402041e98100f853e913f3df04d6946874c73ba31a78969ba-filelists.sqlite.bz2
-rw-r--r-- 1 root root 2969 Mar 18 08:54 repomd.xml
[root@warehouse backup]#
测试连接(本地版)
1、备份系统所有的yum源
[root@warehouse yum.repos.d]# cd /etc/yum.repos.d/
[root@warehouse yum.repos.d]# mkdir backup1
[root@warehouse yum.repos.d]# mv *.repo backup1
[root@warehouse yum.repos.d]# vim local.repo
[local]
name="This is xxx"
baseurl=file:///backup
gpgcheck=0
enabled=1
# 清理yum缓存
[root@warehouse ~]# yum clean all
[root@warehouse ~]# rm -rf /var/cache/yum/x86_64/7/*
# 生成新的yum缓存
[root@warehouse ~]# yum makecache
# 测试连接
[root@warehouse yum.repos.d]# rpm -e mariadb
[root@warehouse yum.repos.d]# rpm -ql mariadb
package mariadb is not installed
[root@warehouse yum.repos.d]# yum install mariadb
测试连接(远程版)
1、备份系统所有的yum源
[root@warehouse yum.repos.d]# cd /etc/yum.repos.d/
[root@warehouse yum.repos.d]# mkdir local
[root@warehouse yum.repos.d]# mv *.repo local
2、安装远程访问软件
[root@warehouse yum.repos.d]# cd /etc/yum.repos.d/
[root@warehouse yum.repos.d]# mv backup1/* .
[root@warehouse yum.repos.d]# yum install vsftpd -y
[root@warehouse yum.repos.d]# systemctl enable --now vsftpd
Created symlink from /etc/systemd/system/multi-user.target.wants/vsftpd.service to /usr/lib/systemd/system/vsftpd.service.
3、配置系统yum仓库
[root@warehouse yum.repos.d]# cd /var/ftp
[root@warehouse ftp]# mkdir yum_warehouse
4、将软件包复制到yum仓库目录
[root@warehouse ftp]# cp -rp /backup/* /var/ftp/yum_warehouse/
[root@warehouse ftp]# ll yum_warehouse/
total 8968
-rw-r--r-- 1 root root 9175948 Oct 15 02:55 mariadb-5.5.68-1.el7.x86_64.rpm
drwxr-xr-x 2 root root 4096 Mar 18 08:54 repodata
5、建立yum软件包依赖关系
[root@warehouse ftp]# createrepo /var/ftp/yum_warehouse/
######################### yum测试机器上执行 ###################################
1、本机测试网络连接
1、备份系统所有的yum源
[root@warehouse ftp]# cd /etc/yum.repos.d/
[root@warehouse yum.repos.d]# mv *.repo backup1
[root@warehouse yum.repos.d]# vim local.repo
[root@warehouse yum.repos.d]# cat local.repo
[local-ftp]
name="This is ftp server"
baseurl=ftp://172.16.1.30/yum_warehouse
gpgcheck=0
enabled=1
# 清理yum缓存
[root@warehouse ~]# yum clean all
[root@warehouse ~]# rm -rf /var/cache/yum/x86_64/7/*
# 生成新的yum缓存
[root@warehouse ~]# yum makecache
# 测试连接
[root@warehouse yum.repos.d]# rpm -e mariadb
[root@warehouse yum.repos.d]# rpm -ql mariadb
package mariadb is not installed
[root@warehouse yum.repos.d]# yum install mariadb
2、yum测试机器执行
1、备份yum仓库内容
[root@yum-test ~]# cd /etc/yum.repos.d/
[root@yum-test yum.repos.d]# mkdir backup1
[root@yum-test yum.repos.d]# mv *.repo backup1
[root@yum-test yum.repos.d]# ll
total 0
drwxr-xr-x. 2 root root 187 Mar 4 09:55 backup
drwxr-xr-x 2 root root 220 Mar 18 09:20 backup1
[root@yum-test yum.repos.d]#
2、编写本地yum源配置文件
[root@yum-test yum.repos.d]# vim local.repo
[root@yum-test yum.repos.d]# cat local.repo
[loacl-ftp-30]
name="This is 30 ftp server"
baseurl=ftp://172.16.1.30/yum_warehouse
gpgcheck=0
enabled=1
3、清理yum缓存
[root@yum-test yum.repos.d]# yum clean all
[root@yum-test yum.repos.d]# rm -rf /var/cache/yum/x86_64/7/*
4、生成yum缓存
[root@yum-test yum.repos.d]# yum makecache
5、测试安装
[root@yum-test yum.repos.d]# yum install mariadb
同步远程yum源到本机
1、安装华为云镜像仓库
[root@warehouse yum.repos.d]# rm -rf /etc/yum.repos.d/*
[root@warehouse yum.repos.d]# wget -O /etc/yum.repos.d/CentOS-Base.repo https://repo.huaweicloud.com/repository/conf/CentOS-7-reg.repo
2、生成yum缓存
[root@warehouse yum.repos.d]# yum clean all
[root@warehouse yum.repos.d]# rm -rf /var/cache/yum/x86_64/7/*
[root@warehouse yum.repos.d]# yum makecache
3、同步华为云镜像站软件包到本地yum仓库
[root@warehouse ftp]# yum install yum-utils -y
[root@warehouse ftp]# reposync -r (仓库名称:yum repolist)
4、建立依赖关系
[root@warehouse ftp]# createrepo base
5、测试
[loacl-ftp-30]
name="This is 30 ftp server"
baseurl=ftp://172.16.1.30/base
gpgcheck=0
enabled=1
将网络yum源同步到本地源供其他机器安装(精简版)
一、保证机器可以联网
二、在本地仓库机器上按照如下步骤操作
vim /etc/yum.conf
将下图的0改为1(默认为0,意为安装成功后立即删除安装包)
1、在命令行中输入:
yum install createrepo vsftpd wget -y #这三个软件下面要用到,没有请自行安装
2、安装成功后: 输入:systemctl enable --now vsftpd #立即启用ftp
3、rm -rf /etc/yum.repos.d/* #删除本地源
4、wget -O /etc/yum.repos.d/CentOS-Base.repo https://repo.huaweicloud.com/repository/conf/CentOS-7-reg.repo #将华为源同步到本地(也可采用其他源,阿里云、163自行更改)
5、cd /var/ftp #此处一定要切换目录
6、yum install yum-utils -y
7、reposync -r (仓库名称,不知道的可以用yum repolist查看) #将网络仓库保存到本地
8、同步好以后输入:createrepo base #建立依赖关系
9、输入vim /etc/yum.repos.d/local.repo将以下内容粘贴即可:
[loacl-ftp-30] #仓库名,可自定义
name="This is 30 ftp server" #描述信息
baseurl=ftp://172.16.1.30(自己的内网地址或外网地址)/base #yum源地址
gpgcheck=0 #0不检查秘钥,1为检查秘钥
enabled=1 #1为启用,0为不启用
在远程测试机上输入:
rm -rf /etc/yum.repos.d/*
输入vim /etc/yum.repos.d/local.repo将以下内容粘贴即可:
[loacl-ftp-30] #仓库名,可自定义
name="This is 30 ftp server" #描述信息
baseurl=ftp://172.16.1.30(与本地仓库机的配置文件地址相同即可)/base #yum源地址
gpgcheck=0 #0不检查秘钥,1为检查秘钥
enabled=1 #1为启用,0为不启用
#测试环境
yum clean all #清除缓存
yum makecache #生成新缓存
yum install zsh #安装zsh软件
yum repolist #查看本地下载源仓库,此时应该只有一个ftp源