yum工具入门

一yum介绍

注意学完了yum之后,rpm的使用频率就少了。有些功能yum用起来不如rpm更方便。

CentOS: yum, dnf
YUM: Yellowdog Update Modifier,rpm的前端程序,可解决软件包相关依赖性,可在多个库之间定位软件包,up2date的替代工具。

yum的工作原理

yum有一个仓库,客户端要想利用yum进行包的安装,就要配置一下仓库。如果仓库没在同一台电脑上,有可能是网络上的主机。

这个路径就叫做baseurl

如果是网络路径就可以使用http://,https://,ftp://,file://作为路径。

yum repository: yum repo,这个就是yum仓库。存储了众多rpm包,以及包的相关的元数据文件(放置于特定目录repodata下)

安装的时候只要写上包名就可以了。就会通过路径找仓库的服务器了。

在仓库的服务器记录了包的相关信息,比如包的依赖关系。还记录包是怎么分组的。

同一个类型的包放到同一个组。

文件服务器:http://,https://,ftp://,file://。

在6版本之前是把rpm包和包元数据放在一起。在之后就单独放rpm包了。

baseurl的路径是/repodata上一级的路径。

如果这个仓库是本机的,那么也是需要配置仓库的路径的。

为什么是3个/,因为最后一个/表示的是根。前面的//是本地和网络路径都要加的。

当配置好了进行安装包的时候就会从仓库里面下载包元数据,包组信息等等,并且缓存到客户端了,也就是要安装包的机器上。

安装好了之后就客户端上就会包删了,只留缓存。

下次查询包的时候就只要查缓存里面的内容。

如果对服务器的地址修改了,那么包元数据的内容和服务器的元数据就不一样了,那么就要清除缓存了,否则对包的操作就可能会失败了,

yum的最重要两点:1会写配置文件,2会清理缓存。出问题一般和这两个有关。

二yum的配置

注意在工作中配的一般是网络路径。

原来的yum配置文件是不符合要求的,可以删除,也可以备份。

下面的yum的配置文件

[[email protected] ~]# cat    /etc/yum.conf
[main]
cachedir=/var/cache/yum/$basearch/$releasever
keepcache=0
debuglevel=2
logfile=/var/log/yum.log
exactarch=1
obsoletes=1
gpgcheck=1
plugins=1
installonly_limit=5
bugtracker_url=http://bugs.centos.org/set_project.php?project_id=23&ref=http://bugs.centos.org/bug_report_page.php?category=yum
distroverpkg=centos-release

#  This is the default, if you make this bigger yum won‘t see if the metadata
# is newer on the remote and so you‘ll "gain" the bandwidth of not having to
# download the new metadata and "pay" for it by yum not having correct
# information.
#  It is esp. important, to have correct metadata, for distributions like
# Fedora which don‘t keep old packages around. If you don‘t like this checking
# interupting your command line usage, it‘s much better to have something
# manually check the metadata once an hour (yum-updatesd will do this).
# metadata_expire=90m

# PUT YOUR REPOS HERE OR IN separate files named file.repo
# in /etc/yum.repos.d

客户端在安装软件之前是要到yum服务器下载相关的元数据再缓存到自己的机器上。

cachedir=/var/cache/yum/$basearch/$releasever表示的就是缓存存放的路径。

[[email protected] ~]# cat    /etc/yum.conf
[main]
cachedir=/var/cache/yum/$basearch/$releasever
keepcache=0从yum仓库里面下载包安装好包之后是否保留包。0表示的是不保留。
debuglevel=2
logfile=/var/log/yum.log日志文件。
exactarch=1
obsoletes=1
gpgcheck=1检查包的完整性。这个要么把公钥导入,要么就设置为0.之前有说过。但是不安全。
plugins=1
installonly_limit=5
bugtracker_url=http://bugs.centos.org/set_project.php?project_id=23&ref=http://bugs.centos.org/bug_report_page.php?category=yum
distroverpkg=centos-release

#  This is the default, if you make this bigger yum won‘t see if the metadata
# is newer on the remote and so you‘ll "gain" the bandwidth of not having to
# download the new metadata and "pay" for it by yum not having correct
# information.
#  It is esp. important, to have correct metadata, for distributions like
# Fedora which don‘t keep old packages around. If you don‘t like this checking
# interupting your command line usage, it‘s much better to have something
# manually check the metadata once an hour (yum-updatesd will do this).
# metadata_expire=90m

# PUT YOUR REPOS HERE OR IN separate files named file.repo
# in /etc/yum.repos.d

x86_64就是$basearch的变量值,7就是$releasever的变量值。这样在其他版本就不要修改了,因为使用的是变量。

[[email protected] ~]# cd /var/cache/yum
[[email protected] yum]# ls
x86_64
[[email protected] yum]# cd x86_64/
[[email protected] x86_64]# ls
7

使用光盘作为Yum的仓库。

[[email protected] ~]# lsblk
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda      8:0    0  200G  0 disk
├─sda1   8:1    0    1G  0 part /boot
├─sda2   8:2    0   50G  0 part /
├─sda3   8:3    0   20G  0 part /app
├─sda4   8:4    0    1K  0 part
└─sda5   8:5    0    2G  0 part [SWAP]
sr0     11:0    1  4.2G  0 rom  /mnt
[[email protected] ~]# ls  /mnt/
CentOS_BuildTag  EFI  EULA  GPL  images  isolinux  LiveOS  Packages  repodata  RPM-GPG-KEY-CentOS-7  RPM-GPG-KEY-CentOS-Testing-7  TRANS.TBL
[[email protected] ~]# df
Filesystem     1K-blocks    Used Available Use% Mounted on
/dev/sda2       52403200 3777496  48625704   8% /
devtmpfs          533224       0    533224   0% /dev
tmpfs             549152       0    549152   0% /dev/shm
tmpfs             549152    9464    539688   2% /run
tmpfs             549152       0    549152   0% /sys/fs/cgroup
/dev/sda3       20961280   32944  20928336   1% /app
/dev/sda1        1038336  158040    880296  16% /boot
tmpfs             109832       4    109828   1% /run/user/42
tmpfs             109832      40    109792   1% /run/user/0
/dev/sr0         4364408 4364408         0 100% /mnt

yum客户端配置文件:

/etc/yum.conf:为所有仓库提供公共配置

/etc/yum.repos.d/*.repo:为仓库的指向提供配置

仓库指向的定义:
[repositoryID]
name=Some name for this repository
baseurl=url://path/to/repository/
enabled={1|0}
gpgcheck={1|0}
gpgkey=URL
enablegroups={1|0}
failovermethod={roundrobin|priority}
roundrobin:意为随机挑选,默认值
priority:按顺序访问
cost= 默认为1000

注意注意要另外起一行。看颜色就知道配置是否正确了。

[centos71]
#仓库名称。
name=centos71
#不写也可以,默认和仓库的名称相同。写的话可以和仓库名称不同。
baseurl=file:///mnt
gpgcheck=0
#如果不写默认就是1了,也就是要对包的完整性进行校验。如果导入了公钥就可以忽略这行了。

查看仓库的名称,3971表示的是包的个数。

[[email protected] yum.repos.d]# yum   repolist
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
repo id                                                                                    repo name                                                                                  status
centos71                                                                                   centos71                                                                                   3,971
repolist: 3,971

在文件中加入公钥。导入一次就可以了。进行验证会更安全。

[[email protected] ~]# cat    /etc/yum.repos.d/centos71.repo
[centos71]
#仓库名称。
name=centos71
#不写也可以,默认和仓库的名称相同。
baseurl=file:///mnt
gpgcheck=0
#如果不写默认就是1了,也就是要对包的完整性进行校验。如果导入了公钥就可以忽略这行了。
gpgkey=file:///mnt/RPM-GPG-KEY-CentOS-7

查看缓存

[[email protected] ~]# du -sh    /var/lib/yum/
14M    /var/lib/yum/
[[email protected] ~]# du -sh    /var/cache/yum/
65M    /var/cache/yum/

注意@加仓库名表示这个包已经安装了。

[[email protected] ~]# rpm  -q  httpd
httpd-2.4.6-80.el7.centos.x86_64
[[email protected] ~]# yum  list   httpd
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Installed Packages
httpd.x86_64                                                                          2.4.6-80.el7.centos                                                                          @centos71

可以一次性安装很多包

[[email protected] ~]# yum  install     vsftpd       tree
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Package tree-1.6.0-10.el7.x86_64 already installed and latest version
Resolving Dependencies
--> Running transaction check
---> Package vsftpd.x86_64 0:3.0.2-22.el7 will be installed
--> Finished Dependency Resolution

在文件中配置多个仓库

[[email protected] ~]# cat   /etc/yum.repos.d/centos71.repo
[centos71]
#仓库名称。
name=centos71
#不写也可以,默认和仓库的名称相同。
baseurl=file:///mnt
gpgcheck=0
#如果不写默认就是1了,也就是要对包的完整性进行校验。如果导入了公钥就可以忽略这行了。
gpgkey=file:///mnt/RPM-GPG-KEY-CentOS-7

[epel]
name=epel
baseurl=https://mirrors.aliyun.com/epel/$releasever/x86_64
gpgcheck=0
enabled=1
#如果不想使用这个仓库就可以禁用。
[[email protected] ~]# yum  repolist
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
centos71                                                                                                                                                             | 3.6 kB  00:00:00
epel                                                                                                                                                                 | 3.2 kB  00:00:00
(1/3): epel/7/group_gz                                                                                                                                               |  88 kB  00:00:06
(2/3): epel/7/primary                                                                                                                                                | 3.6 MB  00:00:01
(3/3): epel/7/updateinfo                                                                                                                                             | 948 kB  00:00:08
epel                                                                                                                                                                            12852/12852
repo id                                                                                    repo name                                                                                  status
centos71                                                                                   centos71                                                                                    3,971
epel/7                                                                                     epel                                                                                       12,852
repolist: 16,823
[[email protected] ~]# yum   list   nginx
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Available Packages
nginx.x86_64                                                                               1:1.12.2-2.el7                                                                               epel

禁用epel仓库

[[email protected] ~]# cat   /etc/yum.repos.d/centos71.repo
[centos71]
#仓库名称。
name=centos71
#不写也可以,默认和仓库的名称相同。
baseurl=file:///mnt
gpgcheck=0
#如果不写默认就是1了,也就是要对包的完整性进行校验。如果导入了公钥就可以忽略这行了。
gpgkey=file:///mnt/RPM-GPG-KEY-CentOS-7

[epel]
name=epel
baseurl=https://mirrors.aliyun.com/epel/$releasever/x86_64
gpgcheck=0
enabled=0
#如果不想使用这个仓库就可以禁用。
[[email protected] ~]# yum  repolist
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
repo id                                                                                    repo name                                                                                  status
centos71                                                                                   centos71                                                                                   3,971
repolist: 3,971

显示所有的,禁用的和没有禁用的。

[[email protected] ~]# yum  repolist   all
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
repo id                                                                                repo name                                                                              status
centos71                                                                               centos71                                                                               enabled: 3,971
epel/7                                                                                 epel                                                                                   disabled
repolist: 3,971

三定制yum仓库

在本机实现yum服务器的配置。

yum仓库是要给网络用户使用,下面的都是共享服务。使用其中的一个就可以了。

都有共享资源存放的目录。分别是/var/www/html,/var/ftp/pub

[[email protected] ~]# rpm -ql       httpd    |  tail
/usr/share/man/man8/httpd.8.gz
/usr/share/man/man8/rotatelogs.8.gz
/usr/share/man/man8/suexec.8.gz
/var/cache/httpd
/var/cache/httpd/proxy
/var/lib/dav
/var/log/httpd
/var/www
/var/www/cgi-bin
/var/www/html

[[email protected] ~]# rpm -ql       vsftpd     |  tail
/usr/share/doc/vsftpd-3.0.2/SECURITY/TRUST
/usr/share/doc/vsftpd-3.0.2/SIZE
/usr/share/doc/vsftpd-3.0.2/SPEED
/usr/share/doc/vsftpd-3.0.2/TODO
/usr/share/doc/vsftpd-3.0.2/TUNING
/usr/share/doc/vsftpd-3.0.2/vsftpd.xinetd
/usr/share/man/man5/vsftpd.conf.5.gz
/usr/share/man/man8/vsftpd.8.gz
/var/ftp
/var/ftp/pub

使用ftp

做yum仓库除了要有rpm包,还要有元数据。

下面就是元数据放置的地方

[[email protected] ~]# ls  /mnt/repodata/
018e9bc732f76918da880c1eab0daa54b576aaca01147c9bf5bfce20600f0b0a-other.sqlite.bz2        64148ea1f1a720283b6ceb9db49bd01491903a336fc864f7e038b7a46ff55b6b-other.xml.gz         repomd.xml
29b154c359eaf12b9e35d0d5c649ebd62ce43333f39f02f33ed7b08c3b927e20-c7-x86_64-comps.xml.gz  d85ec63d569619a208145d8f93a7cc459f91de04bc0e556d00717310e78ec4ca-filelists.xml.gz     TRANS.TBL
2c50202e3091f8e241627053a3ccda04d31afefb3771b96601428a84ac990090-primary.xml.gz          d87379a47bc2060f833000b9cef7f9670195fe197271d37fce5791e669265e8b-c7-x86_64-comps.xml
3787f2b5b084c56f39ca7cfaeb99f556c39862c13e689adc2ff7d20a48ea3568-filelists.sqlite.bz2    ffd73c1d2203629a3b5e0c0c47d663dec2be6e9bb8377be604476ceaae563024-primary.sqlite.bz2

[[email protected] ~]# ll   /mnt/repodata/
total 14363
-rw-rw-r--. 1 root root 1353408 May  4  2018 018e9bc732f76918da880c1eab0daa54b576aaca01147c9bf5bfce20600f0b0a-other.sqlite.bz2
-rw-rw-r--. 1 root root  169476 May  4  2018 29b154c359eaf12b9e35d0d5c649ebd62ce43333f39f02f33ed7b08c3b927e20-c7-x86_64-comps.xml.gz
-rw-rw-r--. 1 root root 1566556 May  4  2018 2c50202e3091f8e241627053a3ccda04d31afefb3771b96601428a84ac990090-primary.xml.gz
-rw-rw-r--. 1 root root 3246286 May  4  2018 3787f2b5b084c56f39ca7cfaeb99f556c39862c13e689adc2ff7d20a48ea3568-filelists.sqlite.bz2
-rw-rw-r--. 1 root root  987503 May  4  2018 64148ea1f1a720283b6ceb9db49bd01491903a336fc864f7e038b7a46ff55b6b-other.xml.gz
-rw-rw-r--. 1 root root 3194578 May  4  2018 d85ec63d569619a208145d8f93a7cc459f91de04bc0e556d00717310e78ec4ca-filelists.xml.gz
-rw-rw-r--. 1 root root  912297 May  4  2018 d87379a47bc2060f833000b9cef7f9670195fe197271d37fce5791e669265e8b-c7-x86_64-comps.xml
-rw-rw-r--. 1 root root 3268479 May  4  2018 ffd73c1d2203629a3b5e0c0c47d663dec2be6e9bb8377be604476ceaae563024-primary.sqlite.bz2
-rw-rw-r--. 1 root root    3732 May  4  2018 repomd.xml
-r--r--r--. 1 root root    2575 May  4  2018 TRANS.TBL

刚才安装包的时候有缓存。有些是从仓库下载下来的。

[[email protected] ~]# cd  /var/cache/
abrt-di/    cups/       fontconfig/ gdm/        httpd/      ibus/       krb5rcache/ ldconfig/   libvirt/    man/        PackageKit/ realmd/     yum/
[[email protected] ~]# cd  /var/cache/yum/
[[email protected] yum]# ls
x86_64
[[email protected] yum]# cd  x86_64/7/
[[email protected] 7]# ls
base  centos71  epel  EPEL  extras  timedhosts  timedhosts.txt  updates
[[email protected] 7]# ll
total 8
drwxr-xr-x. 4 root root  278 Jan 10 17:08 base
drwxr-xr-x. 4 root root  256 Jan 11 20:08 centos71
drwxr-xr-x. 4 root root 4096 Jan 11 20:08 epel
drwxr-xr-x. 4 root root   33 Jan 11 19:05 EPEL
drwxr-xr-x. 4 root root  183 Jan 10 17:08 extras
-rw-r--r--. 1 root root  183 Jan 11 20:08 timedhosts
-rw-r--r--. 1 root root    0 Jan 10 14:21 timedhosts.txt
drwxr-xr-x. 4 root root  183 Jan 10 17:08 updates
[[email protected] 7]# cd  centos71/
[[email protected] centos71]# ls
29b154c359eaf12b9e35d0d5c649ebd62ce43333f39f02f33ed7b08c3b927e20-c7-x86_64-comps.xml.gz  ffd73c1d2203629a3b5e0c0c47d663dec2be6e9bb8377be604476ceaae563024-primary.sqlite.bz2  packages
cachecookie                                                                              gen                                                                                  repomd.xml
[[email protected] centos71]# ll
total 3364
-rw-r--r--. 1 root root  169476 May  4  2018 29b154c359eaf12b9e35d0d5c649ebd62ce43333f39f02f33ed7b08c3b927e20-c7-x86_64-comps.xml.gz
-rw-r--r--. 1 root root       0 Jan 11 20:08 cachecookie
-rw-r--r--. 1 root root 3268479 May  4  2018 ffd73c1d2203629a3b5e0c0c47d663dec2be6e9bb8377be604476ceaae563024-primary.sqlite.bz2
drwxr-xr-x. 2 root root      48 Jan 10 17:12 gen
drwxr-xr-x. 2 root root       6 Jan 10 17:12 packages
-rw-r--r--. 1 root root    3732 May  4  2018 repomd.xml

在7上搭建Yum服务器让6可以使用。

把7上现在使用的光盘断开。并且使用umount卸载下来。

[[email protected] centos71]# umount   /mnt/
[[email protected] centos71]# df
Filesystem     1K-blocks    Used Available Use% Mounted on
/dev/sda2       52403200 3926772  48476428   8% /
devtmpfs          533224       0    533224   0% /dev
tmpfs             549152       0    549152   0% /dev/shm
tmpfs             549152    9464    539688   2% /run
tmpfs             549152       0    549152   0% /sys/fs/cgroup
/dev/sda3       20961280   32944  20928336   1% /app
/dev/sda1        1038336  158040    880296  16% /boot
tmpfs             109832       4    109828   1% /run/user/42
tmpfs             109832      40    109792   1% /run/user/0
/dev/sr0         4364408 4364408         0 100% /run/media/root/CentOS 7 x86_64

现在让7充当yum仓库

参考阿里云的目录结构 https://mirrors.aliyun.com/centos/6/os/x86_64/

[[email protected] centos71]# cd    /var/ftp/pub/
[[email protected] pub]# ls
[[email protected] pub]# mkdi
mkdict  mkdir
[[email protected] pub]# mkdir    centos/6/os/x86_64/
mkdir: cannot create directory ‘centos/6/os/x86_64/’: No such file or directory
[[email protected] pub]# mkdir    centos/6/os/x86_64/  -pv
mkdir: created directory ‘centos’
mkdir: created directory ‘centos/6’
mkdir: created directory ‘centos/6/os’
mkdir: created directory ‘centos/6/os/x86_64/’
[[email protected] pub]# tree
.
└── centos
    └── 6
        └── os
            └── x86_64

4 directories, 0 files

出现了下面的问题重启机器就可以了。

[[email protected] ~]# df
Filesystem     1K-blocks    Used Available Use% Mounted on
/dev/sda2       52403200 3926996  48476204   8% /
devtmpfs          533224       0    533224   0% /dev
tmpfs             549152       0    549152   0% /dev/shm
tmpfs             549152   16568    532584   4% /run
tmpfs             549152       0    549152   0% /sys/fs/cgroup
/dev/sda3       20961280   32944  20928336   1% /app
/dev/sda1        1038336  158040    880296  16% /boot
tmpfs             109832       8    109824   1% /run/user/42
tmpfs             109832      36    109796   1% /run/user/0
/dev/sr0         4364408 4364408         0 100% /run/media/root/CentOS 7 x86_64
[[email protected] ~]# umount     /run/media/root/CentOS 7 x86_64
umount: /run/media/root/CentOS: mountpoint not found
umount: 7: mountpoint not found
umount: x86_64: mountpoint not found

把光盘挂到这个目录下

[[email protected] ~]# cd  /var/ftp/pub/
[[email protected] pub]# ls
centos
[[email protected] pub]# ll
total 0
drwxr-xr-x. 3 root root 15 Jan 11 20:50 centos
[[email protected] pub]# df
Filesystem     1K-blocks    Used Available Use% Mounted on
/dev/sda2       52403200 3925676  48477524   8% /
devtmpfs          533224       0    533224   0% /dev
tmpfs             549152       0    549152   0% /dev/shm
tmpfs             549152    9156    539996   2% /run
tmpfs             549152       0    549152   0% /sys/fs/cgroup
/dev/sda3       20961280   32944  20928336   1% /app
/dev/sda1        1038336  158040    880296  16% /boot
tmpfs             109832       0    109832   0% /run/user/0
tmpfs             109832       8    109824   1% /run/user/42
[[email protected] pub]# mount   /dev/sr0    centos/6/os/x86_64/
mount: /dev/sr0 is write-protected, mounting read-only
[[email protected] pub]# df
Filesystem     1K-blocks    Used Available Use% Mounted on
/dev/sda2       52403200 3925676  48477524   8% /
devtmpfs          533224       0    533224   0% /dev
tmpfs             549152       0    549152   0% /dev/shm
tmpfs             549152    9152    540000   2% /run
tmpfs             549152       0    549152   0% /sys/fs/cgroup
/dev/sda3       20961280   32944  20928336   1% /app
/dev/sda1        1038336  158040    880296  16% /boot
tmpfs             109832       0    109832   0% /run/user/0
tmpfs             109832       8    109824   1% /run/user/42
/dev/sr0         3824484 3824484         0 100% /var/ftp/pub/centos/6/os/x86_64
[[email protected] pub]# pwd
/var/ftp/pub
[[email protected] pub]# cd    /var/ftp/pub/centos/6/os/x86_64
[[email protected] x86_64]# ls光盘内容
CentOS_BuildTag  EULA  images    Packages                  repodata              RPM-GPG-KEY-CentOS-Debug-6     RPM-GPG-KEY-CentOS-Testing-6
EFI              GPL   isolinux  RELEASE-NOTES-en-US.html  RPM-GPG-KEY-CentOS-6  RPM-GPG-KEY-CentOS-Security-6  TRANS.TBL
[[email protected] x86_64]# pwd这个目录就是仓库的路径。
/var/ftp/pub/centos/6/os/x86_64

客户端是通过网络来访问/var/ftp/pub/centos/6/os/x86_64这个目录,所以要开启vsftp服务。

[[email protected] x86_64]# systemctl   start   vsftpd
[[email protected] x86_64]# ss -tnl
State      Recv-Q Send-Q                                                 Local Address:Port                                                                Peer Address:Port
LISTEN     0      128                                                                *:111                                                                            *:*
LISTEN     0      5                                                      192.168.122.1:53                                                                             *:*
LISTEN     0      128                                                                *:22                                                                             *:*
LISTEN     0      128                                                        127.0.0.1:631                                                                            *:*
LISTEN     0      100                                                        127.0.0.1:25                                                                             *:*
LISTEN     0      128                                                        127.0.0.1:6010                                                                           *:*
LISTEN     0      128                                                               :::111                                                                           :::*
LISTEN     0      32                                                                :::21                                                                            :::*
LISTEN     0      128                                                               :::22                                                                            :::*
LISTEN     0      128                                                              ::1:631                                                                           :::*
LISTEN     0      100                                                              ::1:25                                                                            :::*
LISTEN     0      128                                                              ::1:6010                                                                          :::*
[[email protected] x86_64]# #端口是21

关闭防火墙

[[email protected] x86_64]# systemctl   stop    firewalld
[[email protected] x86_64]# iptables   -nvl
iptables v1.4.21: unknown option "-nvl"
Try `iptables -h‘ or ‘iptables --help‘ for more information.
[[email protected] x86_64]# systemctl   disable     firewalld
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.

在网站上输入ftp://192.168.137.71/pub/

没有显示x86_64说明是selinux的问题没有解决。

[[email protected] x86_64]# cat  /etc/selinux/config 

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=enforcing
# SELINUXTYPE= can take one of three two values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected.
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted 

[[email protected] x86_64]# sed  -i.bak    ‘s/SELINUX=enforcing/SELINUX=permissive/‘     /etc/selinux/config
[[email protected] x86_64]# cat  /etc/selinux/config 

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=permissive
# SELINUXTYPE= can take one of three two values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected.
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted 

[[email protected] x86_64]# setenforce   0
[[email protected] x86_64]# getenforce
Permissive

?[[email protected] x86_64]# sed -i.bak ‘s/SELINUX=enforcing/SELINUX=permissive/‘ /etc/selinux/config

总结准备工作

1关闭SELinux
sed -i.bak ‘s/SELINUX=enforcing/SELINUX=permissive/‘ /etc/selinux/config
setenforce 0

2关闭iptables
centos7
systemctl stop firewalld
systemctl disable firewalld开机不启动
centos6
chkconfig iptables off开机不启动
service iptables stop

[[email protected] ~]# ifconfig
eth0      Link encap:Ethernet  HWaddr 00:0C:29:82:5C:1B
          inet addr:192.168.137.61  Bcast:192.168.137.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:fe82:5c1b/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:155 errors:0 dropped:0 overruns:0 frame:0
          TX packets:105 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:16160 (15.7 KiB)  TX bytes:18124 (17.6 KiB)

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:72 errors:0 dropped:0 overruns:0 frame:0
          TX packets:72 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:5384 (5.2 KiB)  TX bytes:5384 (5.2 KiB)

[[email protected] ~]# cat   /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
TYPE=Ethernet
UUID=19fcf4dc-cade-47da-b79d-cff0c557664f
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=none
HWADDR=00:0C:29:82:5C:1B
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
IPV4_FAILURE_FATAL=yes
IPV6INIT=no
NAME="System eth0"
IPADDR=192.168.137.61
GATEWAY=192.168.137.1
NETMASK=255.255.255.0
DNS1=8.8.8.8
[[email protected] ~]# chkconfig iptables off
[[email protected] ~]# service iptables stop
iptables: Setting chains to policy ACCEPT: filter          [  OK  ]
iptables: Flushing firewall rules:                         [  OK  ]
iptables: Unloading modules:                               [  OK  ]
[[email protected] ~]# service iptables status
iptables: Firewall is not running.
[[email protected]ntos6 yum.repos.d]# df
Filesystem     1K-blocks    Used Available Use% Mounted on
/dev/sda2       50264772 3496000  44208772   8% /
tmpfs             552240     224    552016   1% /dev/shm
/dev/sda3       20027260   44992  18958268   1% /app
/dev/sda1         999320   33856    913036   4% /boot
/dev/sr0         3824484 3824484         0 100% /media/CentOS_6.8_Final
[[email protected] yum.repos.d]# vim   base.repo
[[email protected] yum.repos.d]# yum  repolist
Loaded plugins: fastestmirror, refresh-packagekit, security
base                                                                                                                                                                 | 4.0 kB     00:00
base/primary_db                                                                                                                                                      | 4.7 MB     00:00
repo id                                                                                     repo name                                                                                 status
base                                                                                        base                                                                                      6,696
repolist: 6,696
[[email protected] yum.repos.d]# cat  ba
bak/       base.repo
[[email protected] yum.repos.d]# cat  base.repo
[base]
name=base
baseurl=ftp://192.168.137.71/pub/centos/6/os/x86_64/
#可以通过变量调用这个版本。
gpgcheck=1
#gpgkey=ftp://192.168.137.71/pub/centos/6/os/x86_64/RPM-GPG-KEY-CentOS-6
[[email protected] yum.repos.d]# yum  install  gcc

注意没有导入公钥就从本地导入

warning: rpmts_HdrFromFdno: Header V3 RSA/SHA256 Signature, key ID c105b9de: NOKEY

Public key for ppl-0.10.2-11.el6.x86_64.rpm is not installed

[[email protected] yum.repos.d]# rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
[[email protected] yum.repos.d]# yum  install  gcc

[[email protected] yum.repos.d]# yum  install  gcc
Loaded plugins: fastestmirror, refresh-packagekit, security
Setting up Install Process
Loading mirror speeds from cached hostfile
Package gcc-4.4.7-17.el6.x86_64 already installed and latest version
Nothing to do

在同一个机器上配置多个仓库,再加一张光盘

注意我修改了6的主机名。修改了两处之后就要重启

[[email protected] yum.repos.d]# vim    /etc/sysconfig/network
[[email protected] yum.repos.d]# cat     /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=centos61.huawei.com
[[email protected] yum.repos.d]# vi /etc/hosts
vi                view              vim               vimtutor          vino-preferences  virt-what
via_regs_dump     vigr              vimdiff           vino-passwd       vipw              visudo
[[email protected] yum.repos.d]# vim /etc/hosts
[[email protected] yum.repos.d]# cat  /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.137.61   centos61.haiwei.com

注意生产中是不加光驱的。

如果不能显示光盘那么就重启虚拟机

[[email protected] ~]# echo   ‘- - -‘ >  /sys/class/scsi_host/host2/scan
[[email protected] ~]# blkid
/dev/sda1: UUID="a58a9a79-d59c-481a-8a72-553b400bc286" TYPE="xfs"
/dev/sda2: UUID="15ae6514-d661-4400-a1eb-18e0db94b776" TYPE="xfs"
/dev/sda3: UUID="ad4560f0-5443-40af-be6c-8d93a4898838" TYPE="xfs"
/dev/sda5: UUID="0c3a4e64-ca0c-4eef-acc5-1fbce3900008" TYPE="swap"
/dev/sr0: UUID="2016-05-22-18-51-38-00" LABEL="CentOS_6.8_Final" TYPE="iso9660" PTTYPE="dos"
[[email protected] ~]# lsblk
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda      8:0    0  200G  0 disk
├─sda1   8:1    0    1G  0 part /boot
├─sda2   8:2    0   50G  0 part /
├─sda3   8:3    0   20G  0 part /app
├─sda4   8:4    0    1K  0 part
└─sda5   8:5    0    2G  0 part [SWAP]
sr0     11:0    1  3.7G  0 rom  /var/ftp/pub/centos/6/os/x86_64

[[email protected] ~]# df
Filesystem     1K-blocks    Used Available Use% Mounted on
/dev/sda2       52403200 3926092  48477108   8% /
devtmpfs          533224       0    533224   0% /dev
tmpfs             549152       0    549152   0% /dev/shm
tmpfs             549152    9360    539792   2% /run
tmpfs             549152       0    549152   0% /sys/fs/cgroup
/dev/sda3       20961280   32944  20928336   1% /app
/dev/sda1        1038336  158040    880296  16% /boot
tmpfs             109832      28    109804   1% /run/user/0
/dev/sr0         3824484 3824484         0 100% /var/ftp/pub/centos/6/os/x86_64

[[email protected] ~]# lsblk
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda      8:0    0  200G  0 disk
├─sda1   8:1    0    1G  0 part /boot
├─sda2   8:2    0   50G  0 part /
├─sda3   8:3    0   20G  0 part /app
├─sda4   8:4    0    1K  0 part
└─sda5   8:5    0    2G  0 part [SWAP]
sr0     11:0    1  4.2G  0 rom
sr1     11:1    1  3.7G  0 rom
[[email protected] ~]# df
Filesystem     1K-blocks    Used Available Use% Mounted on
/dev/sda2       52403200 3926216  48476984   8% /
devtmpfs          533224       0    533224   0% /dev
tmpfs             549152       0    549152   0% /dev/shm
tmpfs             549152    9160    539992   2% /run
tmpfs             549152       0    549152   0% /sys/fs/cgroup
/dev/sda3       20961280   32944  20928336   1% /app
/dev/sda1        1038336  158040    880296  16% /boot
tmpfs             109832      12    109820   1% /run/user/42
tmpfs             109832       0    109832   0% /run/user/0
[[email protected] ~]# !b
blkid
/dev/sr0: UUID="2018-05-03-20-55-23-00" LABEL="CentOS 7 x86_64" TYPE="iso9660" PTTYPE="dos"
/dev/sda1: UUID="a58a9a79-d59c-481a-8a72-553b400bc286" TYPE="xfs"
/dev/sda2: UUID="15ae6514-d661-4400-a1eb-18e0db94b776" TYPE="xfs"
/dev/sda3: UUID="ad4560f0-5443-40af-be6c-8d93a4898838" TYPE="xfs"
/dev/sda5: UUID="0c3a4e64-ca0c-4eef-acc5-1fbce3900008" TYPE="swap"
/dev/sr1: UUID="2016-05-22-18-51-38-00" LABEL="CentOS_6.8_Final" TYPE="iso9660" PTTYPE="dos" 
[[email protected] ~]# cd  /var/ftp/pub/centos/6/os/x86_64/
[[email protected] x86_64]# ls
[[email protected] x86_64]# pwd
/var/ftp/pub/centos/6/os/x86_64
[[email protected] x86_64]# cd
[[email protected] ~]# mkdir   /var/ftp/pub/centos/6/os/x86_64/
mkdir: cannot create directory ‘/var/ftp/pub/centos/6/os/x86_64/’: File exists
[[email protected] ~]# mkdir   /var/ftp/pub/centos/7/os/x86_64/   -pv
mkdir: created directory ‘/var/ftp/pub/centos/7’
mkdir: created directory ‘/var/ftp/pub/centos/7/os’
mkdir: created directory ‘/var/ftp/pub/centos/7/os/x86_64/’

注意现在访问地址无法显示下面的内容那么是没有挂载光盘

[[email protected] ~]# systemctl   status  firewalld.service
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
   Active: inactive (dead)
     Docs: man:firewalld(1)
[[email protected] ~]# ss -tnl
State      Recv-Q Send-Q                                                 Local Address:Port                                                                Peer Address:Port
LISTEN     0      128                                                                *:111                                                                            *:*
LISTEN     0      5                                                      192.168.122.1:53                                                                             *:*
LISTEN     0      128                                                                *:22                                                                             *:*
LISTEN     0      128                                                        127.0.0.1:631                                                                            *:*
LISTEN     0      100                                                        127.0.0.1:25                                                                             *:*
LISTEN     0      128                                                        127.0.0.1:6010                                                                           *:*
LISTEN     0      128                                                               :::111                                                                           :::*
LISTEN     0      128                                                               :::22                                                                            :::*
LISTEN     0      128                                                              ::1:631                                                                           :::*
LISTEN     0      100                                                              ::1:25                                                                            :::*
LISTEN     0      128                                                              ::1:6010                                                                          :::*
[[email protected] ~]#  systemctl   start   vsftpd
[[email protected] ~]# ss -tnl
State      Recv-Q Send-Q                                                 Local Address:Port                                                                Peer Address:Port
LISTEN     0      128                                                                *:111                                                                            *:*
LISTEN     0      5                                                      192.168.122.1:53                                                                             *:*
LISTEN     0      128                                                                *:22                                                                             *:*
LISTEN     0      128                                                        127.0.0.1:631                                                                            *:*
LISTEN     0      100                                                        127.0.0.1:25                                                                             *:*
LISTEN     0      128                                                        127.0.0.1:6010                                                                           *:*
LISTEN     0      128                                                               :::111                                                                           :::*
LISTEN     0      32                                                                :::21                                                                            :::*
LISTEN     0      128                                                               :::22                                                                            :::*
LISTEN     0      128                                                              ::1:631                                                                           :::*
LISTEN     0      100                                                              ::1:25                                                                            :::*
LISTEN     0      128                                                              ::1:6010                                                                          :::*
[[email protected] ~]# getenforce
Permissive
[[email protected] ~]# setenforce  0
[[email protected] ~]# getenforce
Permissive
[[email protected] ~]# cat  /etc/selinux/config 

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=permissive
# SELINUXTYPE= can take one of three two values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected.
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted 
[[email protected] ~]# tree    /var/ftp/pub/centos/
/var/ftp/pub/centos/
├── 6
│   └── os
│       └── x86_64
└── 7
    └── os
        └── x86_64

6 directories, 0 files

要挂载光盘

[[email protected] ~]# mount   /dev/sr0    centos/6/os/x86_64/
mount: mount point centos/6/os/x86_64/ does not exist
[[email protected] ~]# df
Filesystem     1K-blocks    Used Available Use% Mounted on
/dev/sda2       52403200 3926284  48476916   8% /
devtmpfs          533224       0    533224   0% /dev
tmpfs             549152       0    549152   0% /dev/shm
tmpfs             549152    9160    539992   2% /run
tmpfs             549152       0    549152   0% /sys/fs/cgroup
/dev/sda3       20961280   32944  20928336   1% /app
/dev/sda1        1038336  158040    880296  16% /boot
tmpfs             109832      12    109820   1% /run/user/42
tmpfs             109832       0    109832   0% /run/user/0
[[email protected] ~]# mount   /dev/sr0    /var/ftp/pub/centos/6/os/x86_64/
mount: /dev/sr0 is write-protected, mounting read-only
[[email protected] ~]# df
Filesystem     1K-blocks    Used Available Use% Mounted on
/dev/sda2       52403200 3926284  48476916   8% /
devtmpfs          533224       0    533224   0% /dev
tmpfs             549152       0    549152   0% /dev/shm
tmpfs             549152    9160    539992   2% /run
tmpfs             549152       0    549152   0% /sys/fs/cgroup
/dev/sda3       20961280   32944  20928336   1% /app
/dev/sda1        1038336  158040    880296  16% /boot
tmpfs             109832      12    109820   1% /run/user/42
tmpfs             109832       0    109832   0% /run/user/0
/dev/sr0         4364408 4364408         0 100% /var/ftp/pub/centos/6/os/x86_64

下面图片显示不对是因为光盘挂载错误。

├── repodata
│?? ├── 018e9bc732f76918da880c1eab0daa54b576aaca01147c9bf5bfce20600f0b0a-other.sqlite.bz2
│?? ├── 29b154c359eaf12b9e35d0d5c649ebd62ce43333f39f02f33ed7b08c3b927e20-c7-x86_64-comps.xml.gz
│?? ├── 2c50202e3091f8e241627053a3ccda04d31afefb3771b96601428a84ac990090-primary.xml.gz
│?? ├── 3787f2b5b084c56f39ca7cfaeb99f556c39862c13e689adc2ff7d20a48ea3568-filelists.sqlite.bz2
│?? ├── 64148ea1f1a720283b6ceb9db49bd01491903a336fc864f7e038b7a46ff55b6b-other.xml.gz
│?? ├── d85ec63d569619a208145d8f93a7cc459f91de04bc0e556d00717310e78ec4ca-filelists.xml.gz
│?? ├── d87379a47bc2060f833000b9cef7f9670195fe197271d37fce5791e669265e8b-c7-x86_64-comps.xml
│?? ├── ffd73c1d2203629a3b5e0c0c47d663dec2be6e9bb8377be604476ceaae563024-primary.sqlite.bz2
│?? ├── repomd.xml
│?? └── TRANS.TBL
├── RPM-GPG-KEY-CentOS-7
├── RPM-GPG-KEY-CentOS-Testing-7
└── TRANS.TBL

9 directories, 4017 files
[[email protected] ~]# tree    /var/ftp/pub/centos/6/os/x86_64/    |  wc
   4029   12087  229902

重新挂载光盘

[[email protected] ~]# df  -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda2        50G  3.8G   47G   8% /
devtmpfs        521M     0  521M   0% /dev
tmpfs           537M     0  537M   0% /dev/shm
tmpfs           537M  9.0M  528M   2% /run
tmpfs           537M     0  537M   0% /sys/fs/cgroup
/dev/sda3        20G   33M   20G   1% /app
/dev/sda1      1014M  155M  860M  16% /boot
tmpfs           108M   12K  108M   1% /run/user/42
tmpfs           108M     0  108M   0% /run/user/0
/dev/sr0        4.2G  4.2G     0 100% /var/ftp/pub/centos/6/os/x86_64
/dev/sr1        3.7G  3.7G     0 100% /var/ftp/pub/centos/7/os/x86_64
[[email protected] ~]# umount    /var/ftp/pub/centos/7/os/x86_64
[[email protected] ~]# df  -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda2        50G  3.8G   47G   8% /
devtmpfs        521M     0  521M   0% /dev
tmpfs           537M     0  537M   0% /dev/shm
tmpfs           537M  9.0M  528M   2% /run
tmpfs           537M     0  537M   0% /sys/fs/cgroup
/dev/sda3        20G   33M   20G   1% /app
/dev/sda1      1014M  155M  860M  16% /boot
tmpfs           108M   12K  108M   1% /run/user/42
tmpfs           108M     0  108M   0% /run/user/0
/dev/sr0        4.2G  4.2G     0 100% /var/ftp/pub/centos/6/os/x86_64
[[email protected] ~]# umount    /var/ftp/pub/centos/6/os/x86_64
[[email protected] ~]# df  -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda2        50G  3.8G   47G   8% /
devtmpfs        521M     0  521M   0% /dev
tmpfs           537M     0  537M   0% /dev/shm
tmpfs           537M  9.0M  528M   2% /run
tmpfs           537M     0  537M   0% /sys/fs/cgroup
/dev/sda3        20G   33M   20G   1% /app
/dev/sda1      1014M  155M  860M  16% /boot
tmpfs           108M   12K  108M   1% /run/user/42
tmpfs           108M     0  108M   0% /run/user/0
[[email protected] ~]# mount   /dev/sr0   /var/ftp/pub/centos/7/os/x86_64/
mount: /dev/sr0 is write-protected, mounting read-only
[[email protected] ~]# mount   /dev/sr1   /var/ftp/pub/centos/6/os/x86_64/
mount: /dev/sr1 is write-protected, mounting read-only
[[email protected] ~]# df
Filesystem     1K-blocks    Used Available Use% Mounted on
/dev/sda2       52403200 3926212  48476988   8% /
devtmpfs          533224       0    533224   0% /dev
tmpfs             549152       0    549152   0% /dev/shm
tmpfs             549152    9192    539960   2% /run
tmpfs             549152       0    549152   0% /sys/fs/cgroup
/dev/sda3       20961280   32944  20928336   1% /app
/dev/sda1        1038336  158040    880296  16% /boot
tmpfs             109832      12    109820   1% /run/user/42
tmpfs             109832       0    109832   0% /run/user/0
/dev/sr0         4364408 4364408         0 100% /var/ftp/pub/centos/7/os/x86_64
/dev/sr1         3824484 3824484         0 100% /var/ftp/pub/centos/6/os/x86_64

在7上面对修改文件,添加仓库

通过变量调用这个版本。

[[email protected] ~]# cat     /etc/yum.repos.d/centos71.repo
[centos71]
#仓库名称。
name=centos71
#不写也可以,默认和仓库的名称相同。
baseurl=file:///mnt
gpgcheck=0
#如果不写默认就是1了,也就是要对包的完整性进行校验。如果导入了公钥就可以忽略这行了。
gpgkey=file:///mnt/RPM-GPG-KEY-CentOS-7
enabled=0

[epel]
name=epel
baseurl=https://mirrors.aliyun.com/epel/$releasever/x86_64
gpgcheck=0
enabled=0
#如果不想使用这个仓库就可以禁用。

[ftp-centos7]
name=ftp-centos7
baseurl=ftp://192.168.137.71/pub/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=ftp://192.168.137.71/pub/centos/$releasever/os/$basearch//RPM-GPG-KEY-CentOS-$releasever

安装一个程序,要导入公钥才可以。

在生产中是把一台机器当做服务器,其他的机器当做客户端。yum支持变量

warning: /var/cache/yum/x86_64/7/ftp-centos7/packages/pytalloc-2.1.10-1.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
Public key for pytalloc-2.1.10-1.el7.x86_64.rpm is not installed
(1/4): pytalloc-2.1.10-1.el7.x86_64.rpm                                                                                                                              |  17 kB  00:00:00
(2/4): samba-4.7.1-6.el7.x86_64.rpm                                                                                                                                  | 661 kB  00:00:00
(3/4): samba-common-tools-4.7.1-6.el7.x86_64.rpm                                                                                                                     | 463 kB  00:00:00
(4/4): samba-libs-4.7.1-6.el7.x86_64.rpm                                                                                                                             | 275 kB  00:00:00
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                                       6.4 MB/s | 1.4 MB  00:00:00
Retrieving key from    ftp://192.168.137.71/pub/centos/$releasever/os/$basearch//RPM-GPG-KEY-CentOS-$releasever
Importing GPG key 0xF4A80EB5:
 Userid     : "CentOS-7 Key (CentOS 7 Official Signing Key) <[email protected]>"
 Fingerprint: 6341 ab27 53d7 8a78 a7c2 7bb1 24c6 a8a7 f4a8 0eb5
 From       :ftp://192.168.137.71/pub/centos/$releasever/os/$basearch//RPM-GPG-KEY-CentOS-$releasever
Is this ok [y/N]: rpm --import  ftp://192.168.137.71/pub/centos/$releasever/os/$basearch//RPM-GPG-KEY-CentOS-$releasever
Is this ok [y/N]: y
Running transaction check
Running transaction test
Transaction test succeeded

总结操作过程——搭建yum仓库服务器

rpm     -ivh    /mnt/Packages/vsftpd-3.0.2-21.el7.x86_64.rpm

当没有yum仓库的时候就要使用rpm的方式安装包。

注意要没有依赖性。

systemctl start vsftpd 现在启动
systemctl enable vsftpd 下次开机自动启动
mkdir centos/{6,7}/os/x86_64/ -pv
mount /dev/sr0 centos/7/os/x86_64/

cat /etc/yum.repos.d/base.repo
[base]
name=ftp centos7.4
baseurl=file:///var/ftp/pub/centos/$releasever/os/$basearch/
gpgcheck=0

客户端配置

[[email protected] ~]#  cat     /etc/yum.repos.d/base.repo
[base]
name=base
baseurl=ftp://192.168.137.71/pub/centos/6/os/x86_64/
#可以通过变量调用这个版本。
gpgcheck=1
#gpgkey=ftp://192.168.137.71/pub/centos/6/os/x86_64/RPM-GPG-KEY-CentOS-6
[ftp-centos7]
name=ftp-centos7
baseurl=ftp://192.168.137.71/pub/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=ftp://192.168.137.71/pub/centos/$releasever/os/$basearch//RPM-GPG-KEY-CentOS-$releasever

注意如果仓库就在本机可以不使用网络路径,只要写成下面的即可。

baseurl=file:///var/ftp/pub/centos/$releasever/os/$basearch/

如果只有rpm包,如何制作yum仓库

[[email protected] yum.repos.d]# cp   /var/ftp/pub/centos/6/os/x86_64/Packages/tree-1.5.3-3.el6.x86_64.rpm    /var/ftp/pub/app/[[email protected] yum.repos.d]# ls  /var/ftp/pub/app/
tree-1.5.3-3.el6.x86_64.rpm
[[email protected] yum.repos.d]# cd    /var/ftp/pub/app/
[[email protected] app]# ls
tree-1.5.3-3.el6.x86_64.rpm

制作元数据

[[email protected] app]# createrepo   /var/ftp/pub/app/
Spawning worker 0 with 1 pkgs
Workers Finished
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete
[[email protected] app]# ls
repodata  tree-1.5.3-3.el6.x86_64.rpm
[[email protected] app]# cd  repodata/
[[email protected] repodata]# ls
21eeb24ed37b3459613e412f925298701785b5f330456edc7b4d45e8b2d7589f-filelists.sqlite.bz2  84e845d73b10ba33fb4348e9fbae3a97e3c38551faef16c1510c6289942c79f3-other.sqlite.bz2    repomd.xml
2ee1c7e7dd150886c3d35bd2e1d22e91255a0224722b4d56920cf9ba12937ee5-other.xml.gz          99397b1e5f65e239d593021a77ace5349693c641798a39390c0e41e2575523cd-filelists.xml.gz
54d672976ee8f9c5b571659bde7544e131e48d446436ae19540b15d70fac1417-primary.xml.gz        db6e9e674fd09a286d30a628ac072b2f311440ef0736210c848833a32592e2a9-primary.sqlite.bz2

添加第三方的仓库

[app]
name=app
baseurl=ftp://192.168.137.71/pub/app
gpgcheck=0
[[email protected] ~]# rpm -q   tree
package tree is not installed
[[email protected] ~]# yum  repolist
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
app                                                                                                                                                                  | 2.9 kB  00:00:00
app/primary_db                                                                                                                                                       | 1.8 kB  00:00:00
repo id                                                                                      repo name                                                                                status
app                                                                                          app                                                                                      1
repolist: 1
[[email protected] ~]# yum  install   tree
tree-1.6.0-10.el7.x86_64.rpm  tree.x86_64
[[email protected] ~]# yum  install   tree
Loaded plugins: fastestmirror, langpacks

如果有多了很多rpm包要做成yum仓库,那么就要把repodata目录删除了并且重新执行创建的操作

createrepo    /var/ftp/pub/app/

[[email protected] app]# cp   /var/ftp/pub/centos/7/os/x86_64/Packages/lftp-4.4.8-8.el7_3.2.x86_64.rpm     .
[[email protected] app]# ls
lftp-4.4.8-8.el7_3.2.x86_64.rpm  repodata  tree-1.5.3-3.el6.x86_64.rpm
[[email protected] app]# yum  repolist
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
repo id                                                                                      repo name                                                                                status
app                                                                                          app                                                                                      1
repolist: 1
[[email protected] app]# rm  -rf  repodata/
[[email protected] app]# ls
lftp-4.4.8-8.el7_3.2.x86_64.rpm  tree-1.5.3-3.el6.x86_64.rpm
[[email protected] app]# createrepo   .
Spawning worker 0 with 2 pkgs
Workers Finished
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete
[[email protected] app]# ls
lftp-4.4.8-8.el7_3.2.x86_64.rpm  repodata  tree-1.5.3-3.el6.x86_64.rpm
[[email protected] app]# yum  repolist
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
repo id                                                                                      repo name                                                                                status
app                                                                                          app                                                                                      1
repolist: 1
[[email protected] app]# yum   clean  all
Loaded plugins: fastestmirror, langpacks
Cleaning repos: app
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
[[email protected] app]# yum  repolist
Loaded plugins: fastestmirror, langpacks
Determining fastest mirrors
app                                                                                                                                                                  | 2.9 kB  00:00:00
app/primary_db                                                                                                                                                       | 3.2 kB  00:00:00
repo id                                                                                      repo name                                                                                status
app                                                                                          app                                                                                      2
repolist: 2

把刚才安装的卸载了。

[[email protected] ~]# rpm  -q   httpd
httpd-2.2.15-53.el6.centos.x86_64
[[email protected] ~]# rpm  -e   httpd
error: Failed dependencies:
    httpd >= 2.2.0 is needed by (installed) gnome-user-share-2.28.2-3.el6.x86_64
[[email protected] ~]# #因为有依赖性,所以要使用yum进行卸载了。
[[email protected] ~]# yum  remove   httpd
Loaded plugins: fastestmirror, refresh-packagekit, security

可以写一个脚本,在机器上先判断是否安装了软件,没有就安装了。

在最小化安装的时候跑初始化脚本reset就可以使用运行上面的脚本。

[[email protected] ~]# package=httpd;rpm -q $package  &> /dev/null || yum install $package -y &> /dev/null
[[email protected] ~]# rpm  -q  httpd
httpd-2.2.15-53.el6.centos.x86_64

原文地址:https://www.cnblogs.com/wang618/p/11121401.html

时间: 2024-11-02 10:02:49

yum工具入门的相关文章

Linux程序管理:yum工具

在Linux系统的一些发行版中使用rpm工具进行软件的管理,但是rpm使用过程中,对于程序之间的依赖关系的处理非常麻烦.所以一些发行商针对rpm工具进行了改进,在RedHat系列发行版中使用yum工具处理程序之间的依赖关系.yum是一种在线升级机制,通过这个机制,我们进行一些设置之后,在有网络的情况下,对于程序之间的各种依赖关系,缺什么程序,你就能在网上进行下载更新了.软件的安装升级也变得非常简单. CentOS现将发布的软件放置到YUM服务器内,然后分析这些软件之间的依赖关系,将软件内的信息记

解决安装rpm包依赖关系的烦恼 - yum工具介绍及本地源配置方法

版权声明:本文发布于http://www.cnblogs.com/yumiko/,版权由Yumiko_sunny所有,欢迎转载.转载时,请在文章明显位置注明原文链接.若在未经作者同意的情况下,将本文内容用于商业用途,将保留追究其法律责任的权利.如果有问题,请以邮箱方式联系作者([email protected]). 1.背景概述 在实际生产环境下,对于在linux系统上安装rpm包,主要面临两个实际的问题1)安装rpm包过程中,不断涌现的依赖关系问题,导致需要按照提示或者查询资料,手工安装更多的

SQL*Loader数据装载工具入门_超越OCP精通Oracle视频课程培训24

oracle视频教程目标     Oracle视频教程,风哥本套oracle教程培训学习Oracle SQL*Loader概念及用法及SQL*Loader两个案例,同时课件带有近20个案例用于大家自行练习.适用人群IT相关从业人员.Oracle数据库技术人员.想加工资的.想升职的都可以. 视频在线学习地址:http://edu.51cto.com/course/course_id-6987.html Oracle视频教程简介本课程介绍:Oracle视频教程,风哥本套oracle教程培训学习Ora

36.Linux软件管理--YUM工具

软件分类: v 源码软件包:软件开发者,源代码集合包.适用于所有的Linux系统. v 定制软件包:根据特定系统和版本从源码包提取的软件包.RPM包和DEB包都是属于定制软件包.RPM包适用于Redhat,CentOS,Fedora等操作系统.DEB包适用于Debian,Ubuntu等操作系统. 源码包和定制软件包的区别 源码包 RPM.DEB包 安装复杂,卸载容易 安装简单,卸载麻烦 安装目录集中 安装目录分散 兼容性好 兼容性差 命令执行需要跟全路径 命令执行不需要跟全路径 特定的软件也需要

7.1 安装软件包的三种方法7.2 rpm包介绍 7.3 rpm工具用法 7.4 yum工具用法7.5 yum搭建本地仓库

- 7.1 安装软件包的三种方法 - 7.2 rpm包介绍 - 7.3 rpm工具用法 - 7.4 yum工具用法 - 7.5 yum搭建本地仓库 - 扩展 1. yum保留已经安装过的包 http://www.360doc.com/content/11/0218/15/4171006_94080041.shtml 2. 搭建局域网yum源 http://ask.apelearn.com/question/7627 # 7.1 安装软件包的三种方法 - windows的.exe文件实际上是一种二

rpm包安装和卸载,rpm查询,yum工具详解,yum仓库搭建

rpm包安装和卸载 [[email protected] Packages]# rpm -ivh zip-3.0-1.el6.x86_64.rpm    安装rpm包命令   ivh I=安装的意思install    v=可视     h =显示安装进度 mount /dev/cdrom  /mnt/  挂载到mnt下 cd /mnt/ cd packages Ls    查看rpm包 遇到有相互依赖的包,两个包一起安装 卸载也是一样的 两个包同时卸载 rpm -e yp -tools ypb

Linux软件包安装和卸载(rpm、yum工具)

rpm工具 rpm是由红帽等工作.但是rpm软件包之间的依赖性问题往往会很繁琐,尤其是软件由多个rpm包组成时.公司开发的软件包管理方式,使用rpm我们可以方便的进行软件的安装.查询.卸载.升级 rpm包: RPM包的一般格式为: name-version-arch.rpm name-version-arch.src.rpm 1.name,如:xvattr,是软件的名称. 2.version,如:1.3 ,是软件的版本号.版本号的格式通常为"主版本号.次版本号.修正号".27,是发布版

5周第1次课 安装软件包的三种方法 rpm包介绍 yum工具用法 yum搭建本地仓库

Linux 安装软件的三种方式 rpm 工具:此种安装方式即通过rpm 工具对介质上的rpm 包进行安装. yum 工具:核心依然是rpm,但不同的是它是基于网络的源,并会自动安装依赖组件. 源码包:源代码包,需要相应的编译器进行编译,然后才能安装.三种方式里最难的. 1.rpm 工具 rpm包的来源:光盘或其他地方拷贝本次实验,将Centos7虚拟光盘加载到虚拟机上 1.1 进入系统后执行挂载 [[email protected] ~]# mount /dev/cdrom /mntmount:

7.1 安装软件包的三种方法;7.2 rpm工具;7.4 yum工具;7.5 yum搭建本地

扩展: 1. yum保留已经安装过的包 http://www.360doc.com/content/11/0218/15/4171006_94080041.shtml 2. 搭建局域网yum源 http://ask.apelearn.com/question/7627 7.1 安装软件包的三种方法 rpm工具 yum工具(简单) 源码包(复杂) 7.2 rpm包介绍 1. 设置光驱连接:光驱挂载如下: [[email protected] ~]# mount /dev/cdrom /mnt 2.