搭建ftp服務(wù)(yum源)

在Linux上我們少不了安裝軟件,在centos7中有兩種方法rpm與yum安裝方式。但在我們用rpm安裝過程中你會發(fā)現(xiàn),我們往往裝個軟件命令行要寫的很長,要寫那個包的完整路徑。有時候還要解決包的依賴問題,那么有沒有一種短一點的呢?
那就是我們配yum源來安裝,基本用yum install {rpmfile}就可以安裝,不僅方便還解決了包之間的依賴問題。那么最大的問題就是創(chuàng)建yum倉庫。
下面我們搭建一個屬于自己的ftp(yum源)倉庫:
1.我們要準(zhǔn)備光盤(centos 6 準(zhǔn)備6的光盤,centos7準(zhǔn)備7的光盤);
2.安裝ftp所需的程序包vsftpd,默認(rèn)沒安裝

[root@centos7 ~]#rpm -qi vsftp  
package vsftp is not installed  注:通過查詢沒有安裝
[root@centos7 ~]#rpm -ivh /misc/cd/Packages/vsftpd-3.0.2-21.el7.x86_64.rpm  注:安裝vsftpd包
warning: /misc/cd/Packages/vsftpd-3.0.2-21.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:vsftpd-3.0.2-21.el7              ################################# [100%]
[root@centos7 ~]#rpm -qi vsftpd  安裝成功顯示詳細(xì)信息
Name        : vsftpd
Version     : 3.0.2
Release     : 21.el7
Architecture: x86_64
Install Date: Tue 13 Jun 2017 09:51:15 PM +10
Group       : System Environment/Daemons
Size        : 356228
.......
vsftpd is a Very Secure FTP daemon. It was written completely from
scratch.

3.啟動ftp服務(wù):

[root@centos7 ~]#netstat -ntl
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State      
tcp        0      0 0.0.0.0:111             0.0.0.0:*               LISTEN     
tcp        0      0 192.168.122.1:53        0.0.0.0:*               LISTEN     
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN     
tcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN     
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN     
tcp6       0      0 :::111                  :::*                    LISTEN     
tcp6       0      0 :::22                   :::*                    LISTEN     
tcp6       0      0 ::1:631                 :::*                    LISTEN     
tcp6       0      0 ::1:25                  :::*                    LISTEN  
[root@centos7 ~]#systemctl start vsftpd  注:啟動ftp服務(wù)
[root@centos7 ~]#netstat -ntl   注:打開了21端口
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State      
tcp        0      0 0.0.0.0:111             0.0.0.0:*               LISTEN     
tcp        0      0 192.168.122.1:53        0.0.0.0:*               LISTEN     
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN     
tcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN     
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN     
tcp6       0      0 :::111                  :::*                    LISTEN     
tcp6       0      0 :::21                   :::*                    LISTEN     
tcp6       0      0 :::22                   :::*                    LISTEN     
tcp6       0      0 ::1:631                 :::*                    LISTEN     
tcp6       0      0 ::1:25                  :::*                    LISTEN 

這個啟動只是相對暫時的,等到下次再啟動Linux就失效了,因此我們可以設(shè)置開機(jī)啟動

[root@centos7 ~]#systemctl enable vsftpd
Created symlink from /etc/systemd/system/multi-user.target.wants/vsftpd.service to /usr/lib/systemd/system/vsftpd.service.

注:在centos上安裝方式一樣,但啟動有點不一樣:

[root@centos6 ~]#service vsftpd start 注:啟動服務(wù)打開21端口
Starting vsftpd for vsftpd:                                [  OK  ]
[root@centos6 ~]#chkconfig vsftpd on注:開機(jī)啟動

現(xiàn)在我們可以看到有了這個文件夾

[root@centos7 ~]#cd /var/ftp
[root@centos7 ftp]#ls
pub
[root@centos7 pub]#touch hello.txt  注:在ftp/pub下創(chuàng)建一個文件
[root@centos7 pub]#cat >hello.txt
hello world!
[root@centos7 pub]#ls
hello.txt

我們可以通過ifconfig來查詢IP通過IP訪問下,我們會發(fā)現(xiàn)我們并不能打開它!

[root@centos7 ~]#ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.18.138  netmask 255.255.255.0  broadcast 192.168.18.255
       ......
ens34: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.17.253.83  netmask 255.255.0.0  broadcast 172.17.255.255

這是因為 我們還沒有禁用防火墻,默認(rèn)情況下現(xiàn)在還不能訪問!

[root@centos7 ~]#iptables -nvL   注:查詢防火墻(目前是開啟狀態(tài))
Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination         
    0     0 ACCEPT     udp  --  virbr0 *       0.0.0.0/0            0.0.0.0/0            udp dpt:53
    0     0 ACCEPT     tcp  --  virbr0 *       0.0.0.0/0            0.0.0.0/0            tcp dpt:53
    0     0 ACCEPT     udp  --  virbr0 *       0.0.0.0/0            0.0.0.0/0            udp dpt:67
    0     0 ACCEPT     tcp  --  virbr0 *       0.0.0.0/0            0.0.0.0/0            tcp dpt:67
99841  304M ACCEPT     all  --  *      *       0.0.0.0/0            0.0.0.0/0            ctstate RELATED,ESTABLISHED
    0     0 ACCEPT     all  --  lo     *       0.0.0.0/0            0.0.0.0/0           
 5150  708K INPUT_direct  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
 5150  708K INPUT_ZONES_SOURCE  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
 5150  708K INPUT_ZONES  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
    0     0 DROP       all  --  *      *       0.0.0.0/0            0.0.0.0/0            ctstate INVALID
 5147  708K REJECT     all  --  *      *       0.0.0.0/0            0.0.0.0/0            reject-with icmp-host-prohibited

Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination         
    0     0 ACCEPT     all  --  *      virbr0  0.0.0.0/0            192.168.122.0/24     ctstate RELATED,ESTABLISHED
    0     0 ACCEPT     all  --  virbr0 *       192.168.122.0/24     0.0.0.0/0           
    0     0 ACCEPT     all  --  virbr0 virbr0  0.0.0.0/0            0.0.0.0/0           
    0     0 REJECT     all  --  *      virbr0  0.0.0.0/0            0.0.0.0/0            reject-with icmp-port-unreachable
    0     0 REJECT     all  --  virbr0 *       0.0.0.0/0            0.0.0.0/0            reject-with icmp-port-unreachable
........
 pkts bytes target     prot opt in     out     source               destination         

Chain IN_public_log (1 references)
 pkts bytes target     prot opt in     out     source               destination         

Chain OUTPUT_direct (1 references)
 pkts bytes target     prot opt in     out     source               destination         
[root@centos7 ~]#systemctl stop firewalld.service  注:關(guān)閉防護(hù)墻
[root@centos7 ~]#iptables -nvL   注:現(xiàn)已關(guān)閉
Chain INPUT (policy ACCEPT 0 packets, 0 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 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination  
[root@centos7 ~]#systemctl disable firewalld.service 注:默認(rèn)情況下開機(jī)啟動了防火墻,如果下次還繼續(xù)用,可暫時開啟開機(jī)禁用防火墻。 
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
Removed symlink /etc/systemd/system/basic.target.wants/firewalld.service. 

然后我們在進(jìn)行訪問ftp



就可以訪問了......
4.在pub下創(chuàng)建yum倉庫并從光盤拷貝

[root@centos7 pub]#cd /var/ftp/pub
[root@centos7 pub]#mkdir centos7
[root@centos7 pub]#ls
centos7
[root@centos7 pub]#cp -ar /misc/cd/* centos7
[root@centos7 pub]#cd centos7/
[root@centos7 centos7]#ls
CentOS_BuildTag  EULA  images    LiveOS    repodata              RPM-GPG-KEY-CentOS-Testing-7
EFI              GPL   isolinux  Packages  RPM-GPG-KEY-CentOS-7  TRANS.TBL

現(xiàn)在我們已經(jīng)拷貝完畢!可以配置yum的[name].repo文件

[root@centos7 pub]#cd /etc/yum.repos.d/
[root@centos7 yum.repos.d]#ls  注:這是原有的repo配置文件
CentOS-Base.repo  CentOS-Debuginfo.repo  CentOS-Media.repo    CentOS-Vault.repo
CentOS-CR.repo    CentOS-fasttrack.repo  CentOS-Sources.repo
[root@centos7 yum.repos.d]#mkdir backup
[root@centos7 yum.repos.d]#mv *.repo backup 注:我們可以把原有的repo文件移動到創(chuàng)建的backup目錄下
[root@centos7 yum.repos.d]#ls 
backup
[root@centos7 yum.repos.d]#vim base.repo  注:創(chuàng)建新的repo文件
[root@centos7 yum.repos.d]#cat base.repo
[base]                       
name=centos 7
baseurl=ftp://192.168.18.138/pub/centos7/
gpgcheck=0

現(xiàn)在我們就可以正常訪問ftp了,也可以用自己搭建的yum源安裝軟件

[root@centos7 ~]#yum install tree
Loaded plugins: fastestmirror, refresh-packagekit, security
.........
--> Running transaction check
---> Package tree.x86_64 0:1.6.0-10.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

==============================================================================================================
 Package                Arch                     Version                          Repository             Size
==============================================================================================================
Installing:
 tree                   x86_64                   1.6.0-10.el7                            base            46 k


Transaction Summary
============================================
......

如有不足請多多指教。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容