Centos7制作本地yum倉(cāng)庫(kù),共享給局域網(wǎng)其他設(shè)備
準(zhǔn)備好安裝好Centos7的虛機(jī)A(服務(wù)端)和虛機(jī)B(客戶端)
配置兩臺(tái)虛機(jī)網(wǎng)絡(luò)使其互通,關(guān)閉selinux和firewalld等限制
下載完整的ISO鏡像(CentOS-7-x86_64-Everything-2207-02_3.iso):http://isoredirect.centos.org/centos/7/isos/x86_64/ ?
??
1、配置虛機(jī)A的yum源(本次使用的外國(guó)語的源,阿里的源因?yàn)榫W(wǎng)絡(luò)問題同步太慢了,哪個(gè)網(wǎng)絡(luò)速度快用哪個(gè))
方法一、配置阿里的源-----------具體幫助見https://developer.aliyun.com/mirror/
?curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo ?#替換CentOS-Base.repo
?curl -o /etc/yum.repos.d/epel.repo https://mirrors.aliyun.com/repo/epel-7.repo ?#替換epel.repo
?# 重建yum源緩存
?yum clean all
?yum makecache方法二、配置外國(guó)語的源----------具體幫助見https://mirrors.bfsu.edu.cn/help/centos/
?# 替換CentOS-Base.repo
?sed ? ? ?-e 's|^mirrorlist=|#mirrorlist=|g' \
? ? ? ? ? -e 's|^#baseurl=http://mirror.centos.org/centos|baseurl=https://mirrors.bfsu.edu.cn/centos|g' \
? ? ? ? ? -i.bak \
? ? ? ? ? /etc/yum.repos.d/CentOS-*.repo
?# 安裝epel源,替換epel.repo
?yum install -y epel-release
?sed -e 's!^metalink=!#metalink=!g' \
? ? ?-e 's!^#baseurl=!baseurl=!g' \
? ? ?-e 's!https\?://download\.fedoraproject\.org/pub/epel!https://mirrors.bfsu.edu.cn/epel!g' \
? ? ?-e 's!https\?://download\.example/pub/epel!https://mirrors.bfsu.edu.cn/epel!g' \
? ? ?-i /etc/yum.repos.d/epel*.repo
?# 重建yum源緩存
?yum clean all
?yum makecache
2、創(chuàng)建yum源用到的目錄,安裝yum倉(cāng)庫(kù)用的的軟件包
?mkdir -p ?/data/soft/centos7 ?/data/soft/epel ? /data/soft/extras ?/data/soft/updates ? ? ?#創(chuàng)建本地yum源需要的目錄
?yum install -y yum-utils createrepo ? ? ? ? ? ? ?#安裝軟件包
3、同步y(tǒng)um源(epel,updates,extras),制作本地yum倉(cāng)庫(kù)
?reposync -r epel -p /data/soft/epel ? ? ?#把yum源的軟件包,依賴下載到本地yum倉(cāng)庫(kù)目錄(同步時(shí)間比較長(zhǎng))
?reposync -r extras -p /data/soft/extras
?reposync -r updates -p /data/soft/updates
?createrepo -v /data/soft/epel ? ? ? ? ?#創(chuàng)建yum倉(cāng)庫(kù)信息
?createrepo -v /data/soft/extras
?createrepo -v /data/soft/updates
?#上傳CentOS-7-x86_64-Everything-2207-02_3.iso到虛機(jī)中
?mount CentOS-7-x86_64-Everything-2207-02_3.iso /mnt ?#掛載鏡像到/mnt目錄
?cp -a ?/mnt/* ? /data/soft/centos7 ? ?#復(fù)制鏡像的軟件包和依賴到本地
?createrepo -v /data/soft/centos7 ? ? #創(chuàng)建yum倉(cāng)庫(kù)信息
4、配置安裝、配置vsftp
?yum install -y vsftpd ?#安裝vsftpd
?vim ?/etc/vsftpd/vsftpd #編輯vsftpd配置文件,設(shè)置匿名訪問,設(shè)置匿名訪問默認(rèn)目錄
?anonymous_enable=YES
?anon_root=/data/soft
?##################################
?systemctl enable vsftpd ? ?#設(shè)置自啟
?systemctl start vsftpd ? ? #啟動(dòng)服務(wù)
?systemctl stop firewalld ? #臨時(shí)關(guān)閉防火墻
?setenforce 0 ? ? ? ? ? ? ? #臨時(shí)關(guān)閉selinux
5、移除虛機(jī)B的.repo配置文件,測(cè)試搭建的yum倉(cāng)庫(kù)是否生效
?mv /etc/yum.repos.d/ ?/opt ?#移動(dòng)目錄到/opt
?# 重建本地yum源
?vi /etc/yum.repos.d/local.repo ?#新建local.repo配置文件,寫入以下內(nèi)容
?[centos7]
?name=centos
?baseurl=ftp://10.0.0.55/centos7 ?#IP為虛機(jī)A的IP地址
?gpgcheck=0
?enabled=1
?[epel]
?name=epel
?baseurl=ftp://10.0.0.55/epel
?gpgcheck=0
?enabled=1
?[extras]
?name=extras
?baseurl=ftp://10.0.0.55/extras
?gpgcheck=0
?enabled=1
?[updates]
?name=updates
?baseurl=ftp://10.0.0.55/updates
?gpgcheck=0
?enabled=1
?
?#######測(cè)試一波
?yum clean all ?#清除緩存
?yum makecache ?#生成緩存
?yum repolist ? #查看yum倉(cāng)庫(kù)軟件數(shù)量
?yum install -y ?tree ?vim wget ?bash-completion ?bash-completion-extras ?lrzsz ?net-tools sysstat ?iotop iftop htop unzip nc nmap telnet bc ?psmisc httpd-tools ?bind-utils nethogs expect cowsay sl ? #安裝一些常用軟件包驗(yàn)證local.repo文件是否生效