项目作业
200台服务器中只有一台可以链接外网,此台服务器为westos.westos.org。
200台服务器都需要安装ansible 软件
请合理规划资源给出最优的解决方案。
解答思路:首先我们可以下载高级源来达到可上网主机下载好ansible软件的需求,但是对于剩下的199台服务器来说显然是行不通的
所以我们需要先做一个本地yum仓库,再通过超文本传输协议(httpd服务)实现网络共享仓库(即其它主机能ping通连接外网主机,简称本机,就可以以共享下载本机仓库里的软件)
实现过程
#系统软件仓库的作用
##在系统中对软件进行管理
#rpm命令是不能解决依赖关系的
#如果需要软件在安装过程中自动解决依赖关系
#需要安装软件仓库
环境配置
设置一台主机的网络模式为仅主机模式
做node1节点域名映射
我们默认是没有把172.25.254和westos.westos.org对应的,这里需要做一个映射
首先我们需要配置一台只能和其它主机通信的机器(node1节点)
[root@localhost network-scripts]# cat ifcfg-ens3
BOOTPROTO=none
NAME=westos
DEVICE=ens160
ONBOOT=yes
IPADDR=172.25.254.50
NETMASK=255.255.255.0
可连接外网主机本地仓库搭建(yongyou_linux节点)
首先找到系统光驱文件,再与我们创建的目录进行挂载,通过挂载使得我们可以通过/rhel8.1目录(可根据自己版本设定)访问光驱文件的内容,直接查看是不行的
[root@localhost RHEL-8-1-0-BaseOS-x86_64]# ll /dev/cdrom #/dev/cdrom 为光驱文件
lrwxrwxrwx 1 root root 3 Dec 9 23:13 /dev/cdrom -> sr0
[root@localhost RHEL-8-1-0-BaseOS-x86_64]# mkdir /rhel8.1
[root@localhost RHEL-8-1-0-BaseOS-x86_64]# mount /dev/cdrom /rhel8.1
mount: /rhel8.1: WARNING: device write-protected, mounted read-only.
[root@localhost RHEL-8-1-0-BaseOS-x86_64]# ls /rhel8.1/
AppStream EULA images RPM-GPG-KEY-redhat-beta
BaseOS extra_files.json isolinux RPM-GPG-KEY-redhat-release
EFI GPL media.repo TRANS.TBL```
接着进入到/etc/yum.repos.d/ ##软件源指向文件配置目录
##在此目录中不能有无法访问的源指向
我们接着编写自己的repo文件(文件名需要以repo结尾,不然系统读取不到)
[root@localhost RHEL-8-1-0-BaseOS-x86_64]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# ls
redhat.repo
[root@localhost yum.repos.d]# vim westos.repo ##软件仓库指向文件
[AppStream] ##仓库名称
name=AppStream ##描述
baseurl=file:///rhel8.1/AppStream ##地址
gpgcheck=0 ##不检测gpgkey (跳过授权检测)
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-REDHAT-release ##检测地址
#enabled=1 #默认开启的,状态为1
[BaseOS]
name=BaseOS
baseurl=file:///rhel8.1/BaseOS/
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-REDHAT-release
#enabled=1
~
PS:baseurl=file:///rhel8.1/BaseOS/ 地址实际对应的位置在/rhel8.1/BaseOs
里面存放着各种基础的rpm软件包
软件管理命令-dnf
dnf repolist ##列出仓库信息
clean all ##清除系统中已经加载的仓库缓存信息 /var/cache/dnf
list all ##列出所有软件
list available ##列出未安装软件
list installed ##列出已安装软件
install ##安装
remove ##卸载
reinstall ##重新安装
search ##搜索
whatprovides ##搜索包含文件的软件包
history ##dnf执行历史
history info ##dnf执行历史详细信息
group list ##列出软件组
group list --installed ##列出已安装软件组
group list --available ##列出未安装软件组
group list --hidden ##列出隐藏软件案组
group install ##安装软件组
group info ##查看软件组信息
[root@localhost yum.repos.d]# dnf clean all
Updating Subscription Management repositories.
16 files removed
[root@localhost yum.repos.d]# dnf repolist
Updating Subscription Management repositories.
Red Hat Enterprise Linux 8 for x86_64 - BaseOS 1.8 kB/s | 4.1 kB 00:02
Red Hat Enterprise Linux 8 for x86_64 - AppStre 2.3 kB/s | 4.5 kB 00:01
Red Hat Enterprise Linux 8 for x86_64 - AppStre 1.3 MB/s | 37 MB 00:29
westos AppStream ##描述 0.0 B/s | 0 B 00:00
Failed to download metadata for repo 'AppStream'
Error: Failed to download metadata for repo 'AppStream'```
出错了,原因为配置文件里面带有##的注释,这是我们需要删除的
修改好就正常了
到这里本地仓库就搭建好了
[root@localhost network-scripts]# dnf clean all
Updating Subscription Management repositories.
28 files removed
[root@localhost network-scripts]# dnf repolist
Updating Subscription Management repositories.
Red Hat Enterprise Linux 8 for x86_64 - BaseOS 1.7 MB/s | 41 MB 00:24
Red Hat Enterprise Linux 8 for x86_64 - AppStr 3.2 MB/s | 37 MB 00:11
AppStream 5.7 MB/s | 5.6 MB 00:00
BaseOS 6.5 MB/s | 2.2 MB 00:00
Last metadata expiration check: 0:00:01 ago on Fri 10 Dec 2021 03:54:23 AM CST.
repo id repo name status
AppStream AppStream 4,795
BaseOS BaseOS 1,661
另外如果重启了仓库是否还存在呢? 不会存在了
因为我们的挂载采用的是命令挂载是没有写入文件的,重启在内存中就没有了
解决办法:把 mount /dev/cdrom /rhel8.1 写入 /etc/rc.local (此为开机自启动文件,系统会自动执行里面的内容)
所以我们也需要给它添加执行权限
echo " mount /dev/cdrom /rhel8.1 " >> /etc/rc.local
chmod 755 /etc/rc.d/rc.local
第二步 下载httpd服务
dnf install httpd -y
# -y 下载时不询问执行
在这里我们开启了http服务,并在防火墙策略给httpd添加了策略,使得防火墙开启下我们也能使用此服务
但是发现下载ansible出错了 我们不是搭建了yum仓库吗
[root@localhost network-scripts]# service httpd start
Redirecting to /bin/systemctl start httpd.service
[root@localhost network-scripts]# firewall-cmd --permanent --add-service=http
success
[root@localhost network-scripts]# firewall-cmd --reload
success
[root@localhost network-scripts]# dnf install ansible
Updating Subscription Management repositories.
Last metadata expiration check: 0:14:47 ago on Fri 10 Dec 2021 03:54:23 AM CST.
No match for argument: ansible
Error: Unable to find a match: ansible
原因:镜像自带的软件都是一些基础的软件,很多是不具备的,所以这里我们需要给他升升级
首先找到epel高级源,wget下载下来,并执行rpm安装,这样我们就可以下载更多高级的软件了
接着创建指定的目录,方便后面软件安装
这里使用了dnf的两个参数
–downloadonly 只下载软件包
–destdir 指定软件包下载的位置
oot@localhost network-scripts]# wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
--2021-12-10 04:12:52-- https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
Resolving dl.fedoraproject.org (dl.fedoraproject.org)... 38.145.60.22, 38.145.60.24, 38.145.60.23
Connecting to dl.fedoraproject.org (dl.fedoraproject.org)|38.145.60.22|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 23644 (23K) [application/x-rpm]
Saving to: ‘epel-release-latest-8.noarch.rpm’
epel-release-latest-8.noarch.rpm 100%[================================================================>] 23.09K 75.2KB/s in 0.3s
2021-12-10 04:12:54 (75.2 KB/s) - ‘epel-release-latest-8.noarch.rpm’ saved [23644/23644]
[root@localhost network-scripts]# rpm -ivh epel-release-latest-8.noarch.rpm
warning: epel-release-latest-8.noarch.rpm: Header V4 RSA/SHA256 Signature, key ID 2f86d6a1: NOKEY
Verifying... ################################# [100%]
Preparing... ################################# [100%]
Updating / installing...
1:epel-release-8-13.el8 ################################# [100%]
[root@localhost network-scripts]# mkdir /var/www/html/ansible
[root@localhost network-scripts]# dnf install ansible --downloadonly --destdir /var/www/html/ansible
这样ansible就下载好了
3.网络软件仓库的搭建
yongyou_linux: 172.25.254.100
node1: 172.25.254.50
在yongyou_linux中已经搭建好软件仓库, 在node1中是无法访问的
在企业中,我们维护的系统数量庞大,
当我们需要在每个系统安装软件管理软件时
可以在每个系统中各自搭建软件仓库
但是这样管理软件会浪费大量的资源
如何节省这部分重复的资源
需要把大家都要使用的资源共享到互联网中
这样大家就可以利用网络访问资源,不需要在每一台
主机中独立建立软件资源了
具体实现
下载 createrepo:安装采集工具
并 对共享目录中进行扫描生成repodate数据目录
[root@localhost network-scripts]# # dnf install createrepo -y
[root@localhost network-scripts]# createrepo /var/www/html/ansible
Directory walk started
Directory walk done - 0 packages
Temporary output repo path: /var/www/html/ansible/.repodata/
Preparing sqlite DBs
Pool started (with 5 workers)
Pool finished
这样我们就做好了包含第三方软件的源
远端主机配置
接着node1节点执行
dnf clean all
dnf repolist
dnf install ansible
软件下载成功