如何在centos上面搭建本身的ftp服務器

背景:有時候有這樣一個需求,團隊中有新人進來須要一些軟件好比jdk,eclipse等開發工具及軟件須要共享等等須要考慮可以經過瀏覽器的方式訪問,而且可以直接將軟件下載下來 這時候就須要考慮搭建ftp服務器了html

安裝篇

原材料:node

centos6.5以上nginx

1.首先判斷是否安裝vsftpd服務 能夠經過命令查看centos

ps -ef|grep vsftpd

2.若是未安裝vsftpd 經過命令安裝瀏覽器

# 安裝vsftpd
yum -y install vsftpd

# 啓動
service vsftpd start

# 開啓啓動
chkconfig vsftpd on

由於要考慮到用瀏覽器的方式訪問 因此須要經過nginx進行轉發bash

#安裝nginx

yum install nginx

 

如何配置

1.對nginx配置以下:服務器

nginx.conf:app

# For more information on configuration, see:
#   * Official English Documentation: http://nginx.org/en/docs/
#   * Official Russian Documentation: http://nginx.org/ru/docs/

user  root;
worker_processes 4;
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;

# Load dynamic modules. See /usr/share/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;

events {
    worker_connections  1024;
}


http {
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;
                                                                                                      17,0-1       頂端

conf.d/default.conf配置以下:eclipse

server {
    listen       80;
    server_name  localhost;

    autoindex on;
    # Load configuration files for the default server block.
    include /etc/nginx/default.d/*.conf;

    location / {
        root  /home/cdn;//靜態資源
        index index.html index.htm;
    }

    location ~* \.(eot|ttf|woff|svg|otf)$ {
                 root   /home/cdn;
                index  index.html index.htm;
                add_header Access-Control-Allow-Origin *;
      }


   # error_page 404 /404.html;
    #    location = /40x.html {
   # }

    #error_page 500 502 503 504 /50x.html;
     #   location = /50x.html {
   # }
"conf.d/default.conf" 32L, 696C                                                                       1,5          頂端

/etc/vsftpd/vsftpd.conf文件配置以下:tcp

anonymous_enable=NO
local_enable=YES
write_enable=YES
local_umask=022
anon_mkdir_write_enable=YES
dirmessage_enable=YES
xferlog_enable=YES
connect_from_port_20=YES
xferlog_std_format=YES
chroot_list_enable=YES
chroot_list_file=/etc/vsftpd/chroot_list
listen=YES
pam_service_name=vsftpd
userlist_enable=YES
tcp_wrappers=YES

/etc/vsftpd/chroot_list文件配置以下:添加ftp用戶cdn

cdn

2.給目錄受權要在/home/cdn 目錄給予755權限

至此ftp已經搭建好了 咱們能夠在瀏覽器上能夠訪問了輸入http://192.168.102.240以下:

若是訪問出現 directory index of "/data/cdn/" is forbidden錯誤

在nginx中加上  autoindex on;

server {

    listen       80;

    server_name  _;

    autoindex on;

    root         /usr/share/nginx/html;

}

接下來咱們須要配置用戶,能夠經過客戶端工具鏈接進行文件上傳操做

useradd cdn -d /data/cdn/ -s /sbin/nologin ; //爲用戶cdn建立/data/cdn/ 目錄
chown -R cdn /data/cdn/ ;//給/data/cdn受權給cdn用戶
chmod -R 777 /data/cdn/

爲cdn用戶設置口令密碼執行下面的命令

passwd cdn;

 

最後咱們經過用戶名和密碼就能夠連上服務器端了

另外考慮到須要經過瀏覽器端下載文件 或者上傳文件,由於經過nginx代理 nginx默認對上傳文件大小設置成1M, 因此須要進行配置

location / {
        root   /data/cdn;
        index  index.html index.htm;
        client_max_body_size 1000m;
}

至此cdn 服務器搭建完成

這裏有可能在客戶端鏈接ftp服務器鏈接不上 顯示沒法列出目錄,主要緣由多是防火牆致使,解決方案將客戶端傳輸模式改成主動鏈接

命令行如何操做ftp

命令行輸入ftp命令

open 111.120.230.11;//打開ftp服務器地址

輸入用戶名和密碼

put hello.txt;//將文件上傳到ftp服務器

get hello.txt;//從ftp服務器下載文件

lcd;//列出ftp文件目錄
相關文章
相關標籤/搜索