實現系統 ftp網絡yum服務器
在centos7中禁用關閉防火墻
[root@centos7 yum.repos.d]#systemctl disable firewalld.service 禁用防火墻 下次開機不啟用
[root@centos7 yum.repos.d]#systemctl stop firewalld.service 關閉防火墻
Centos6與centos7 以上操作命令不同
[root@centos7 yum.repos.d]#iptables -vnL 查看防火墻定義規則的詳細信息
Chain INPUT (policy ACCEPT 115K packets, 12M bytes)
pkts bytes target prot opt in out source destination
Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
Chain OUTPUT (policy ACCEPT 2030 packets, 247K bytes)
pkts bytes target prot opt in out source destination
[root@centos7 7]#vim /etc/selinux/config
[root@centos7 7]#setenforce 0 setenforce是Linux的selinux防火墻配置命令 執行setenforce 0 表示關閉selinux防火墻。
在centos6中 禁用關閉防火墻
[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 ]
2安裝ftp服務包
假如沒有倉庫,首先看是否有vsftpd 包 ,vsftpd 是搭建ftp服務器應用,高效穩定。
[root@centos7 yum.repos.d]#rpm -q vsftpd
package vsftpd is not installed
[root@centos7 yum.repos.d]#rpm -ivh /run/media/root/CentOS\ 7\ x86_ 64/Packages/vsftpd-3.0.2-10.el7.x86_64.rpm
Preparing... ################################# [100%] yum倉庫未搭建 選rpm安裝
Updating / installing...
1:vsftpd-3.0.2-10.el7 ################################# [100%]
[root@centos7 yum.repos.d]#rpm -ql vsftpd
…….
…….
/usr/lib/systemd/system/vsftpd.service 啟動此服務 ftp網絡共享服務才能運行
/usr/lib/systemd/system/vsftpd.target
/usr/lib/systemd/system/[email protected]
/usr/sbin/vsftpd
…….
/var/ftp 訪問服務器路徑 也即是網絡共享路徑
/var/ftp/pub
[root@centos7 yum.repos.d]#ss -tnl ftp網絡共享服務會占用網絡端口 查看當前監聽的tcp端口
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 5 192.168.122.1:53 *:*
LISTEN 0 128 *:22 *:* ftp為21端口 服務未啟動 沒有21端口
LISTEN 0 128 127.0.0.1:631 *:*
LISTEN 0 128 :::22 :::*
LISTEN 0 128 ::1:631
[root@centos7 yum.repos.d]#systemctl start vsftpd.service 啟動ftp共享服務
[root@centos7 yum.repos.d]#ss -tnl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 5 192.168.122.1:53 *:*
LISTEN 0 128 *:22 *:*
LISTEN 0 128 127.0.0.1:631 *:*
LISTEN 0 32 :::21 :::* 21端口打開
LISTEN 0 128 :::22 :::*
[root@centos7 yum.repos.d]#systemctl enable vsftpd.service 設置為開機啟動
[root@centos7 ~]#cd /var/ftp
[root@centos7 ftp]#ls
pub
測試如下:
3 準備服務端yum 倉庫安裝包
[root@centos7 ftp]#cd pub
[root@centos7 pub]#mkdir -p centos/{6,7} 可以參考阿裏雲路徑格式
[root@centos7 pub]#cp -r /run/media/root/CentOS 7 x86_64/* /var/ftp/pub/centos/7
[root@centos7 pub]#cp -r /media/root/CentOS 6 x86_64/* /var/ftp/pub/centos/6
[root@centos7 7]#ls 切換到pub/centos/6 同樣查看
CentOS_BuildTag EULA images LiveOS repodata RPM-GPG-KEY-CentOS-Testing-7
EFI GPL isolinux Packages RPM-GPG-KEY-CentOS-7 TRANS.TBL
4客戶端配置
[root@centos7 ~]#cat>/etc/yum.repos.d/pud.repo<<eof
[centos-ftp]
name=repulic
baseurl=ftp://172.18.254.154/pub/centos/$releasever 倉庫路徑為repodata的所在目錄
gpgcheck=1
gpgkey=ftp://172.18.254.154/pub/centos/$releasever/RPM-GPG-KEY-CentOS-$releasever
$releasever: 當前OS的發行版的主版本號
[root@centos7 yum.repos.d]#yum repolist
repo id repo name status
centos-ftp/7 repulic 9,007
repolist: 9,007
實現系統 ftp網絡yum服務器