一、YUM源仓库的部署
1、YUM概述
基于RPM包构建的软件更新机制
可以自动解决依赖关系
所有软件包由集中的YUM软件仓库提供
2、学习部署yum源仓库的作用
学习YUM软件仓库,可以完成安装、卸载、自动升级RPM软件包等任务,能够自动查找并解决 rpm 包之间的依赖关系,而无须管理员逐个、手工地去安装每个 rpm 包,使管 理员在维护大量 Linux 服务器时更加轻松自如。特别是在拥有大量 Linux 主机的本地网络中, 构建一台“源”服务器可以大大缓解软件安装、升级等对 Internet 的依赖。
3、软件仓库的提供方式
FTP服务:ftp://....
HTTP服务:http://.....
本地目录: file://.....
RPM软件包的来源:CentOS发布RPM包集合,第三方组织发布的RPM包集合,用户自定义的RPM包集合
4、构建CentOS7软件仓库(配置FTP源)重点
(1)RPM包来自CentOS 7DVD光盘
(2)通过FTP方式提供给客户机
服务器配置:
1)安装vsftpd服务端软件
2)创建并制作yum远程ftp站点的源
3)启动ftp服务
rpm -qa|grep vsftpd
yum -y install vsftpd
mkdir /var/ftp/centos7 #创建挂盘挂载目录
mount /dev/sr0 /mnt #镜像挂载
cp -rf /mnt/* /var/ftp/centos7/ &
mkdir /var/ftp/other # 创建目录repodata 数据文件
cd /var/ftp/other/
createrepo -g /mnt/repodata/repomd.xml ./ #工具建立仓库数据文件
systemctl start vsftpd
客户端配置:
1)创建远程yum源的配置文件
2)yum安装软件验证结果
客户端配置:
vi /etc/yum.repos.d/centos7.repo
[root@fbc yum.repos.d]# cat centos7.repo
[centos7] #仓库类别
name=centos7 #仓库名称(说明)
baseurl=ftp://192.168.154.19/centos7 #URL 访问路径
enabled=1 #启用此软件仓库
gpgcheck=1 #验证软件包的签名
gpgkey=ftp://192.168.154.19/centos/RPM-GPG-KEY-CentOS-7 #GPG 公钥文件的位置
[other]
name=centos7
baseurl=ftp://192.168.154.19/other
enabled=1 #启用此软件仓库
gpgcheck=0 #验证软件包的签名
5.在软件仓库中加入非官方RPM包组
包括存在依赖关系的所有RPM包
使用createrepo工具建立仓库数据文件
mkdir /var/ftp/other
cd /var/ftp/other
createrepo -g /media/cdrom/repodata/repomd.xml ./ #非官方的RPM要先放入该目录下
6、配置本地yum源
直接以centos 7 光盘作软件仓库
将Centos7 光盘放入光驱,挂载镜像到仓库位置,URL地址为file://media/cdrom
cd /etc/yum.repos.d/
vim local.repo
[local] #仓库类别
name=local #仓库名称
baseurl=file:///mnt #指定URL 访问路径为光盘挂载目录
enabled=1 #开启此yum源,此为默认项,可省略
gpgcheck=0 #不验证软件包的签名
mount /dev/sr0 /mnt #把光盘挂载到/mnt目录下(前提虚拟机是光盘挂载)
7、YUM工具概述和YUM配置文件
关于yum命令 :
由软件包yum-3.4.3-150.el7.centos.noarch提供
用来访问YUM仓库,查询、下载及安装、卸载软件包
YUM的配置文件
基本设置:/etc/yum.conf
仓库设置:/etc/yum.repos.d/*.repo
日志文件:/var/log/yum.log
8、YUM工具概述
YUM缓存目录 :存放下载的软件包、仓库信息等数据
位于/var/cache/yum/$basearch/$releaserver
[root@localhost~]# yum clean all
9、软件包查询
查询软件包
yum list [软件名]
yum info [软件名]
yum search<关键词>
yum whatprovides <关键词>
示例
[root@localhost~]#yum list
[root@localhost~]#yum list httpd
[root@localhost~]#yum info vsftpd
[root@localhost~]#yum search gcc
[root@localhost~]#yum whatprovides vim
10、软件的安装升级
安装软件
yum install [软件名]
yum groupinstall <包组名>
升级软件
yum updata
yum groupupdate
示例
[root@localhost~]#yum -y install net-snmp
[root@localhost~]#yum -y groupinstall gnome-desktop
[root@localhost~]#yum -y update
11、软件卸载
软件卸载
yum remove <软件名>
yum groupremove <包组名>
示例
[root@localhost~]#yum -y remove autofs
[root@localhost~]#yum -y groupremove gnome-desktop
12、YUM其他命令
#yum whatprovides 命令 #查询命令属于哪个软件包
#yum whatprovides netstat
下载RPM包而不安装
#yum install 包名 -y --downloadonly
#yum reinstall -y bash --downloadonly #下载已安装过的rpm包
#yum install 包名 -y --downloadonly --downloaddir=/tmp/ #下载RPM包到指定目录
yum history 查看历史记录来找到它所依赖的包,然后删除,
如:yum history list 列出最近的历史
yum history info id 列出某次的详细信息,
yum history undo id 撤销某次更改
yum history help 查看帮助
yum history redo加入序号重新执行序号里的操作
13、常用的软件网络源配置的方法
(1)centOS7清华源vim CentOS7-Base-tsinghua.repo
[base]
name=CentOS-$releasever - Base
baseurl=http://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7#released updates
[updates]
name=CentOS-$releasever - Updates
baseurl=http://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
baseurl=http://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus
baseurl=http://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
(2) 163 yum 源
下载链接:wget http://mirrors.163.com/.help/CentOS7-Base-163.repo
vim CentOS7-Base-163.repo #编辑163 yum 网络源
[base]
name=CentOS-$releasever - Base - 163.com
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
baseurl=http://mirrors.163.com/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7#released updates
[updates]
name=CentOS-$releasever - Updates - 163.com
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
baseurl=http://mirrors.163.com/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras - 163.com
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
baseurl=http://mirrors.163.com/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus - 163.com
baseurl=http://mirrors.163.com/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7
③ 阿里云
下载地址:wget http://mirrors.aliyun.com/repo/Centos-7.repovim CentOS7-Base-aliyun.repo #编辑阿里云yum 网络源
[base]
name=CentOS-$releasever - Base - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/
http://mirrors.aliyuncs.com/centos/$releasever/os/$basearch/
http://mirrors.cloud.aliyuncs.com/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
#released updates
[updates]
name=CentOS-$releasever - Updates - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/updates/$basearch/
http://mirrors.aliyuncs.com/centos/$releasever/updates/$basearch/
http://mirrors.cloud.aliyuncs.com/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/extras/$basearch/
http://mirrors.aliyuncs.com/centos/$releasever/extras/$basearch/
http://mirrors.cloud.aliyuncs.com/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/centosplus/$basearch/
http://mirrors.aliyuncs.com/centos/$releasever/centosplus/$basearch/
http://mirrors.cloud.aliyuncs.com/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
#contrib - packages by Centos Users
[contrib]
name=CentOS-$releasever - Contrib - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/contrib/$basearch/
http://mirrors.aliyuncs.com/centos/$releasever/contrib/$basearch/
http://mirrors.cloud.aliyuncs.com/centos/$releasever/contrib/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
注:其他网络源
1)http://ftp.sjtu.edu.cn/centos #上海交大,但服务器位于北京,中国教育网网络中心,我看像是朝阳区那边的IP,以前在那边上过 班,下载速度高达十M。 北方用户与教育网用户推荐,速度飞快。2)http://centos.ustc.edu.cn,#中国科技大学,服务器位于合肥。 南方用户推荐。
3)http://mirrors.sohu.com/,sohu的开源镜像服务器,服务器位于山东省联通。 速度飞快,全国用户推荐,经常用FireFox下载CD镜像
二、NFS共享存储服务
1、NFS 网络文件系统
依赖于RPC(远端过程调用)
需要安装nfs-utils、rpcbind软件包
系统服务:nfs、rpcbind
共享配置文件:/etc/exports
2、安装nfs-utils、rpcbind软件包
[root@fbc ~]#yum -y install nfs-utils rpcbind
[root@fbc ~]#systemctl enable nfs
[root@fbc ~]#systemctl enable rpcbind
设置共享目录
[root@fbc ~]#mkdir -p /opt/www/root
[root@fbc ~]#vim /etc/export
/opt/www/root 192.168.154.0/24(rw,sync,no_root_squahs)
/var/ftp/pub 192.168.
3、nfs的理论知识
NFS(网络文件服务)
NFS一种基于TCP/IP传输的网络文件系统协议,最初由 Sun 公司开发。通过使用NFS协议,客户机可以像访问本地目录一样访问远程服务器中的共享资源 NFS 也是NAS存储设然支持的一种协议 NAS存储:
NFS 服务的实现依赖于RPC(Remote Process Call,远端过程调用)机制,以完成远程到本地的映射过程。在Centos 7
系统中,需要安装nfs-utils、rpcbind软件包来提供NFS共享服务,前者用于NFS共享发布和访问,后者用于RPC支持。手动加载 NFS 共享服务时,应该先启动 rpcbind,再启动 nfs。 nfs端口号2049 RPC端口号111
特点:
采用TCP/IP传输网络文件 安全性低 简单易操作
适合局域网环境
4、nfs实现原理图
5、NFS配置实验
实现服务端于两台客户端的web读写互通
(1)实验拓扑
第一步配置服务器
yum install -y nfs-uilts rpcbind 安装两个协议
systemctl start nfs rpcbind # 开启协议并安装防火墙
netstat -anp|grep rpc #查看协议是否运行
创建一个 /opt/web 的目录
Vim /etc/exports #编辑内容是可用连接的用户网段 和用户权限
systemctl restart nfs #配置完成重启服务
showmount -e localhost #查看共享是否成功
第二步:配置客户机1
yum install -y nfs-utils rpcbind
showmount -e 192.168.154.19 #测试能否与154.19这台主机互通
mount -t nfs 192.168.154.19:/opt/web /var/www/html
df -h #查看挂载
Curl 127.0.0.1 # 查看网页
第三步:配置客户机2和客户机一步骤相同,测试结果
测试在客户机1中echo “hanxuhaoshuai” > /var/www/html/index.html
cat /var/www/html/index.html
在服务机中查看文件
在客户机2中从定向echo “hello” >> /var/www/html/index.html
在客户机1中查看
总结
1、yum源常用命令与配置
2、NFS协议的配置