码迷,mamicode.com
首页 > 其他好文 > 详细

yum工具入门

时间:2019-07-04 14:15:54      阅读:115      评论:0      收藏:0      [点我收藏+]

标签:proc   firewall   plugin   自动   run   安全   ethernet   vsftp   oda   

 

 

 

 

 

 

一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的配置文件

[root@centos71 ~]# 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 wont see if the metadata
# is newer on the remote and so youll "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 dont keep old packages around. If you dont like this checking
# interupting your command line usage, its 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表示的就是缓存存放的路径。

[root@centos71 ~]# 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 wont see if the metadata
# is newer on the remote and so youll "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 dont keep old packages around. If you dont like this checking
# interupting your command line usage, its 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的变量值。这样在其他版本就不要修改了,因为使用的是变量。

[root@centos71 ~]# cd /var/cache/yum
[root@centos71 yum]# ls
x86_64
[root@centos71 yum]# cd x86_64/
[root@centos71 x86_64]# ls
7

 

 

 

 

 

 

使用光盘作为Yum的仓库。

[root@centos71 ~]# 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
[root@centos71 ~]# 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
[root@centos71 ~]# 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表示的是包的个数。

[root@centos71 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

 

 

 

 

 

 

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

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

 

 

 

 

 

 

查看缓存

[root@centos71 ~]# du -sh    /var/lib/yum/
14M    /var/lib/yum/
[root@centos71 ~]# du -sh    /var/cache/yum/
65M    /var/cache/yum/

 

 

 

 

 

 

 

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

[root@centos71 ~]# rpm  -q  httpd
httpd-2.4.6-80.el7.centos.x86_64
[root@centos71 ~]# 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

 

 

 

 

 

可以一次性安装很多包

[root@centos71 ~]# 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

 

 

 

 

 

在文件中配置多个仓库

[root@centos71 ~]# 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 
#如果不想使用这个仓库就可以禁用。

 

 

 

 

 

 

 

[root@centos71 ~]# 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
[root@centos71 ~]# 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仓库

[root@centos71 ~]# 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  
#如果不想使用这个仓库就可以禁用。

 

 

 

 

 

[root@centos71 ~]# yum  repolist 
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
repo id                                                                                    repo name                                                                                  status
centos71                                                                                   centos71                                                                                   3,971
repolist: 3,971

 

 

 

 

 

 

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

[root@centos71 ~]# 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

[root@centos71 ~]# 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

[root@centos71 ~]# 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包,还要有元数据。

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

[root@centos71 ~]# 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

[root@centos71 ~]# 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

 

 

 

 

 

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

[root@centos71 ~]# cd  /var/cache/
abrt-di/    cups/       fontconfig/ gdm/        httpd/      ibus/       krb5rcache/ ldconfig/   libvirt/    man/        PackageKit/ realmd/     yum/        
[root@centos71 ~]# cd  /var/cache/yum/
[root@centos71 yum]# ls
x86_64
[root@centos71 yum]# cd  x86_64/7/
[root@centos71 7]# ls
base  centos71  epel  EPEL  extras  timedhosts  timedhosts.txt  updates
[root@centos71 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
[root@centos71 7]# cd  centos71/
[root@centos71 centos71]# ls
29b154c359eaf12b9e35d0d5c649ebd62ce43333f39f02f33ed7b08c3b927e20-c7-x86_64-comps.xml.gz  ffd73c1d2203629a3b5e0c0c47d663dec2be6e9bb8377be604476ceaae563024-primary.sqlite.bz2  packages
cachecookie                                                                              gen                                                                                  repomd.xml
[root@centos71 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卸载下来。

[root@centos71 centos71]# umount   /mnt/
[root@centos71 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/

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

4 directories, 0 files

 

 

 

 

 

 

 

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

[root@centos71 ~]# 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
[root@centos71 ~]# 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

 

 

 

 

 

 

 

把光盘挂到这个目录下

[root@centos71 ~]# cd  /var/ftp/pub/
[root@centos71 pub]# ls
centos
[root@centos71 pub]# ll
total 0
drwxr-xr-x. 3 root root 15 Jan 11 20:50 centos
[root@centos71 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
[root@centos71 pub]# mount   /dev/sr0    centos/6/os/x86_64/
mount: /dev/sr0 is write-protected, mounting read-only
[root@centos71 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
[root@centos71 pub]# pwd
/var/ftp/pub
[root@centos71 pub]# cd    /var/ftp/pub/centos/6/os/x86_64
[root@centos71 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
[root@centos71 x86_64]# pwd这个目录就是仓库的路径。
/var/ftp/pub/centos/6/os/x86_64

 

 

 

 

 

 

 

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

[root@centos71 x86_64]# systemctl   start   vsftpd
[root@centos71 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                                                                          :::*           
[root@centos71 x86_64]# #端口是21

 

 

 

 

 

 

关闭防火墙

[root@centos71 x86_64]# systemctl   stop    firewalld
[root@centos71 x86_64]# iptables   -nvl
iptables v1.4.21: unknown option "-nvl"
Try `iptables -h or ‘iptables --help for more information.
[root@centos71 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的问题没有解决。

[root@centos71 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 


[root@centos71 x86_64]# sed  -i.bak    s/SELINUX=enforcing/SELINUX=permissive/‘     /etc/selinux/config 
[root@centos71 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 


[root@centos71 x86_64]# setenforce   0
[root@centos71 x86_64]# getenforce   
Permissive

 

 

 

 

 

?[root@centos71 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

 

 

 

[root@centos6 ~]# 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)

[root@centos6 ~]# 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

 

 

 

 

[root@centos6 ~]# chkconfig iptables off
[root@centos6 ~]# service iptables stop  
iptables: Setting chains to policy ACCEPT: filter          [  OK  ]
iptables: Flushing firewall rules:                         [  OK  ]
iptables: Unloading modules:                               [  OK  ]
[root@centos6 ~]# service iptables status
iptables: Firewall is not running.

 

 

 

 

 

[root@centos6 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
[root@centos6 yum.repos.d]# vim   base.repo
[root@centos6 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
[root@centos6 yum.repos.d]# cat  ba
bak/       base.repo  
[root@centos6 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
[root@centos6 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


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


[root@centos6 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的主机名。修改了两处之后就要重启

[root@centos6 yum.repos.d]# vim    /etc/sysconfig/network
[root@centos6 yum.repos.d]# cat     /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=centos61.huawei.com
[root@centos6 yum.repos.d]# vi /etc/hosts
vi                view              vim               vimtutor          vino-preferences  virt-what         
via_regs_dump     vigr              vimdiff           vino-passwd       vipw              visudo            
[root@centos6 yum.repos.d]# vim /etc/hosts
[root@centos6 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

 

 

 

 

 

 

 

技术图片

 

 

 

 

 

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

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

[root@centos71 ~]# echo   - - -‘ >  /sys/class/scsi_host/host2/scan 
[root@centos71 ~]# 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" 
[root@centos71 ~]# 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

[root@centos71 ~]# 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

 

 

 

 

 

 

 

技术图片

 

 

 

 

 

[root@centos71 ~]# 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  
[root@centos71 ~]# 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
[root@centos71 ~]# !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" 

 

 

 

 

 

[root@centos71 ~]# cd  /var/ftp/pub/centos/6/os/x86_64/
[root@centos71 x86_64]# ls
[root@centos71 x86_64]# pwd
/var/ftp/pub/centos/6/os/x86_64
[root@centos71 x86_64]# cd
[root@centos71 ~]# mkdir   /var/ftp/pub/centos/6/os/x86_64/
mkdir: cannot create directory ‘/var/ftp/pub/centos/6/os/x86_64/’: File exists
[root@centos71 ~]# mkdir   /var/ftp/pub/centos/7/os/x86_64/   -pv
mkdir: created directory ‘/var/ftp/pub/centos/7mkdir: created directory ‘/var/ftp/pub/centos/7/os’
mkdir: created directory ‘/var/ftp/pub/centos/7/os/x86_64/’

 

 

 

 

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

 

 

 

 

 技术图片

 

 

 

 

 

 

[root@centos71 ~]# 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)
[root@centos71 ~]# 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                                                                          :::*                  
[root@centos71 ~]#  systemctl   start   vsftpd
[root@centos71 ~]# 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                                                                          :::*                  
[root@centos71 ~]# getenforce 
Permissive
[root@centos71 ~]# setenforce  0
[root@centos71 ~]# getenforce 
Permissive
[root@centos71 ~]# 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 

 

 

 

 

 

 

[root@centos71 ~]# tree    /var/ftp/pub/centos/
/var/ftp/pub/centos/
├── 6
│   └── os
│       └── x86_64
└── 7
    └── os
        └── x86_64

6 directories, 0 files

 

 

 

 

 

 

要挂载光盘

[root@centos71 ~]# mount   /dev/sr0    centos/6/os/x86_64/
mount: mount point centos/6/os/x86_64/ does not exist
[root@centos71 ~]# 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
[root@centos71 ~]# mount   /dev/sr0    /var/ftp/pub/centos/6/os/x86_64/
mount: /dev/sr0 is write-protected, mounting read-only
[root@centos71 ~]# 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
[root@centos71 ~]# tree    /var/ftp/pub/centos/6/os/x86_64/    |  wc
   4029   12087  229902

 

 

 

 

 

重新挂载光盘

[root@centos71 ~]# 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
[root@centos71 ~]# umount    /var/ftp/pub/centos/7/os/x86_64
[root@centos71 ~]# 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
[root@centos71 ~]# umount    /var/ftp/pub/centos/6/os/x86_64
[root@centos71 ~]# 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
[root@centos71 ~]# mount   /dev/sr0   /var/ftp/pub/centos/7/os/x86_64/
mount: /dev/sr0 is write-protected, mounting read-only
[root@centos71 ~]# mount   /dev/sr1   /var/ftp/pub/centos/6/os/x86_64/
mount: /dev/sr1 is write-protected, mounting read-only
[root@centos71 ~]# 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上面对修改文件,添加仓库

通过变量调用这个版本。

[root@centos71 ~]# 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) <security@centos.org>"
 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

 

 

 

 

 

 

 


客户端配置

[root@centos61 ~]#  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仓库

[root@centos71 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/[root@centos71 yum.repos.d]# ls  /var/ftp/pub/app/
tree-1.5.3-3.el6.x86_64.rpm
[root@centos71 yum.repos.d]# cd    /var/ftp/pub/app/
[root@centos71 app]# ls
tree-1.5.3-3.el6.x86_64.rpm

 

 

 

 

 

 

制作元数据

[root@centos71 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
[root@centos71 app]# ls
repodata  tree-1.5.3-3.el6.x86_64.rpm
[root@centos71 app]# cd  repodata/
[root@centos71 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

 

 

 

 

 

[root@centos71 ~]# rpm -q   tree
package tree is not installed
[root@centos71 ~]# 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
[root@centos71 ~]# yum  install   tree
tree-1.6.0-10.el7.x86_64.rpm  tree.x86_64                   
[root@centos71 ~]# yum  install   tree
Loaded plugins: fastestmirror, langpacks

 

 

 

 

 

 

 

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

createrepo    /var/ftp/pub/app/

[root@centos71 app]# cp   /var/ftp/pub/centos/7/os/x86_64/Packages/lftp-4.4.8-8.el7_3.2.x86_64.rpm     .
[root@centos71 app]# ls
lftp-4.4.8-8.el7_3.2.x86_64.rpm  repodata  tree-1.5.3-3.el6.x86_64.rpm
[root@centos71 app]# yum  repolist 
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
repo id                                                                                      repo name                                                                                status
app                                                                                          app                                                                                      1
repolist: 1
[root@centos71 app]# rm  -rf  repodata/
[root@centos71 app]# ls
lftp-4.4.8-8.el7_3.2.x86_64.rpm  tree-1.5.3-3.el6.x86_64.rpm
[root@centos71 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
[root@centos71 app]# ls
lftp-4.4.8-8.el7_3.2.x86_64.rpm  repodata  tree-1.5.3-3.el6.x86_64.rpm
[root@centos71 app]# yum  repolist 
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
repo id                                                                                      repo name                                                                                status
app                                                                                          app                                                                                      1
repolist: 1
[root@centos71 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
[root@centos71 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

 

 

 

 

 

 

把刚才安装的卸载了。

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

 

 

 

 

 

 

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

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

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

 

yum工具入门

标签:proc   firewall   plugin   自动   run   安全   ethernet   vsftp   oda   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!