下面分別對三個場景進行傻瓜式配置 :joy:html
將光盤插入,經過mount掛在光驅至/mnt/cdrom目錄下linux
mkdir /mnt/cdrom
nginx
mount /dev/cdrom /mnt/cdrom
docker
echo "/dev/cdrom /mnt/cdrom iso9660 defaults 0 0" >> /etc/fstab
shell
測試是否生效vim
umount /dev/cdrom
centos
mount -a
<!--加載/etc/fstab配置的掛載項-->緩存
df -h
查看/dev/sr0已經被掛載,OKbash
vim Centos7.repo
服務器
[Centos7] #yum惟一標識 name=Centos7_iso #yum名稱,任意 baseurl=file:///mnt/cdrom #yum鏡像路徑地址(還有ftp:// 和 http://) enable=1 #1啓用,0禁用 gpgcheck=0 #1校驗,0不校驗
yum clean all && yum makecache
yum list | grep nginx
顯示正常即OK
mv /etc/yum.repos.d/Centos-Base.repo /etc/yum.repos.d/Centos-Base.repo.bak20200709
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
yum clean all && yum makecache
yum list | grep nginx
場景:若是須要安裝的包在Base yum源沒有,就須要安裝外部擴展yum源,<u>以下以ansible安裝爲例</u>
yum install ansible -y
經過查看ansible 須要安裝EPEL源
yum list | grep ansible
cat /etc/redhat-release
wget https://mirrors.aliyun.com/centos/7.8.2003/extras/x86_64/Packages/epel-release-7-11.noarch.rpm
rpm -ivh epel-release-7-11.noarch.rpm
yum clean all && yum makecache
yum install ansible -y
正常顯示OK
場景:iso鏡像只能本機使用,若是須要內網中其餘服務器使用,就須要構建http yum源倉庫,也是企業中經常使用的配置方式。(ftp 也是能夠的)
yum install httpd httpd-devel -y
systemctl restart httpd.service
setenforce 0 #臨時關閉SELinux sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config #永久關閉SELinux(重啓生效) systemctl stop firewalld.service #臨時關閉防火牆 systemctl disable firewalld.service #永久關閉防火牆
mkdir -p /var/www/html/yum/centos7.8
cp -R /mnt/cdrom/Packages/* /var/www/html/yum/centos7.8
yum install createrepo* -y
createrepo /var/www/html/yum/centos7.8/
建立完成會有repodata文件夾生產
vim /etc/yum.repos.d/Centos7.8-http.repo
[centos7.8] name=centos7.8-http baseurl=http://192.168.197.128/yum/centos7.8 enable=1 gpgcheck=0
yum clean all && yum makecache
yum list | grep nginx
客戶端能正常獲取yum服務器文件,OK
企業研發發佈新rpm,如何更新yum服務器,讓其餘客戶端正常獲取,如下以docker安裝爲例
/var/www/html/yum/centos7.8
wget https://mirrors.aliyun.com/opensuse/history/20200218/tumbleweed/repo/oss/x86_64/docker-19.03.5_ce-4.1.x86_64.rpm
cp docker-19.03.5_ce-4.1.x86_64.rpm /var/www/html/yum/centos7.8/
createrepo --update /var/www/html/yum/centos7.8/
yum clean all
yum list | grep docker
yum install # 安裝 yum remove #卸載 yum update #更新 yum clean all #清除緩存 yum makecache #加載緩存 yum info #查看信息 yum list #查看包列表