如何在centos上面搭建自己的ftp服务器

背景:有时候有这样一个需求,团队中有新人进来需要一些软件比如jdk,eclipse等开发工具及软件需要共享等等需要考虑能够通过浏览器的方式访问,并且能够直接将软件下载下来 这时候就需要考虑搭建ftp服务器了

安装篇

原材料:

centos6.5以上

1.首先判断是否安装vsftpd服务 可以通过命令查看

ps -ef|grep vsftpd

2.如果未安装vsftpd 通过命令安装

# 安装vsftpd
yum -y install vsftpd

# 启动
service vsftpd start

# 开启启动
chkconfig vsftpd on

因为要考虑到用浏览器的方式访问 所以需要通过nginx进行转发

#安装nginx

yum install nginx

 

如何配置

1.对nginx配置如下:

nginx.conf:

# 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配置如下:

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文件配置如下:

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文件目录

 

转载于:https://my.oschina.net/chenxiaobian/blog/792549

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值