服务管理-文件服务器

FTP工作原理

FTP Transfer Protocol 传输协议的缩写。

FTP会话包含了两个通道,一个叫控制通道,一个叫数据通道。

控制通道:控制通道是和FTP服务器进行沟通的通道,链接FTP,发送FTP指令都是通过控制通道来完成的。
数据通道:数据通道是和FTP服务器进行文件传输或者列表的通道。

FTP协议中,控制连接均有客户端发起,而数据链接有两种方式:PORT方式和PASV方式

PORT模式(主动方式)

PORT模式简历数据传输通道是由服务器端发起的,服务器使用20端口链接客户端的某一个大于1024的端口。
FTP客户端首先和FTP 服务端的tcp 21端口建立连接,通过这个通道发送命令,客户端需要接受数据的时候在这个通道上发送PORT命令。PORT命令包含了客户端
用什么端口(大于1024 的端口)接受数据,在传送数据的时候,服务器端通过自己的TCP
20 端口发送数据,FTP 服务端必须和客户端建立一个新的链接来传送数据。

客户端使用1024以上的端口链接服务器的21号端口,并且会实现开启一个1024+N的dua扣准备让服务器来链接,服务器得知客户端准备的端口后,用20号端口与客户端链接,其中21号端口称为链接链路,20号端口称为数据链路,创建数据链路时server端处于主动链接客户端的状态,称为:主动传输模式。

PASV模式(被动方式)

PASV模式中,数据传输的通道的建立是由FTP客户端发起的,他是用一个大于1024的端口链接服务器的1024以上的某一个端口。在建立控制通道的时候和PORT模式
类似,当客户端通过这个通道发送PASV命令的时候,FTP server打开一个大于1024的随机端口并进行数据的传输,这个时候FTP server 不再需要建立一个新的
和客户端之间的链接传送数据。

客户端使用1024以上的端口链接服务器端的21端口,服务器接到链接请求后,开启一个1024+M的端口,等待客户端来链接,在通知客户端这个等待连接的端口号是1024+M,客户端接到服务器端的信息后,开启新的一个1024+N的端口与1024+M进行链接,其中21号端口为连接链路,1024+M端口为数据链路,创建数据链接时,server端处于被客户端链接的状态,所以称为:被动传输模式。

[root@localhost ~]# cat /etc/vsftpd/vsftpd.conf 
# Example config file /etc/vsftpd/vsftpd.conf
#
# The default compiled in settings are fairly paranoid. This sample file
# loosens things up a bit, to make the ftp daemon more usable.
# Please see vsftpd.conf.5 for all compiled in defaults.
#
# READ THIS: This example file is NOT an exhaustive list of vsftpd options.
# Please read the vsftpd.conf.5 manual page to get a full idea of vsftpd's
# capabilities.
#
# Allow anonymous FTP? (Beware - allowed by default if you comment this out).
anonymous_enable=YES              # 匿名用户是否可以访问FTP
#
# Uncomment this to allow local users to log in.
# When SELinux is enforcing check for SE bool ftp_home_dir
local_enable=YES                   # 本地用户是否登录
#
# Uncomment this to enable any form of FTP write command.
write_enable=YES                   # 允许FTP的写指令
#
# Default umask for local users is 077. You may wish to change this to 022,
# if your users expect that (022 is used by most other ftpd's)
local_umask=022                    # 本地用户建立文件的权限
#
# Uncomment this to allow the anonymous FTP user to upload files. This only
# has an effect if the above global write enable is activated. Also, you will
# obviously need to create a directory writable by the FTP user.
# When SELinux is enforcing check for SE bool allow_ftpd_anon_write, allow_ftpd_full_access
#anon_upload_enable=YES             # 允许匿名用户创建文件
#
# Uncomment this if you want the anonymous FTP user to be able to create
# new directories.
#anon_mkdir_write_enable=YES        # 允许匿名用户创建新目录
#
# Activate directory messages - messages given to remote users when they
# go into a certain directory.
dirmessage_enable=YES
#
# Activate logging of uploads/downloads.
xferlog_enable=YES                   # 使用日志功能
#
# Make sure PORT transfer connections originate from port 20 (ftp-data).
connect_from_port_20=YES              # 主动模式传输使用20端口
#
# If you want, you can arrange for uploaded anonymous files to be owned by
# a different user. Note! Using "root" for uploaded files is not
# recommended!
#chown_uploads=YES
#chown_username=whoever
#
# You may override where the log file goes if you like. The default is shown
# below.
#xferlog_file=/var/log/xferlog        # 日志文件位置
#
# If you want, you can have your log file in standard ftpd xferlog format.
# Note that the default log file location is /var/log/xferlog in this case.
xferlog_std_format=YES                # 使用标准模式
#
# You may change the default value for timing out an idle session.
#idle_session_timeout=600             # 空闲链接超时
#
# You may change the default value for timing out a data connection.
#data_connection_timeout=120           # 数据传输超时
#
# It is recommended that you define on your system a unique user which the
# ftp server can use as a totally isolated and unprivileged user.
#nopriv_user=ftpsecure
#
# Enable this and the server will recognise asynchronous ABOR requests. Not
# recommended for security (the code is non-trivial). Not enabling it,
# however, may confuse older FTP clients.
#async_abor_enable=YES
#
# By default the server will pretend to allow ASCII mode but in fact ignore
# the request. Turn on the below options to have the server actually do ASCII
# mangling on files when in ASCII mode.
# Beware that on some FTP servers, ASCII support allows a denial of service
# attack (DoS) via the command "SIZE /big/file" in ASCII mode. vsftpd
# predicted this attack and has always been safe, reporting the size of the
# raw file.
# ASCII mangling is a horrible feature of the protocol.
#ascii_upload_enable=YES
#ascii_download_enable=YES
#
# You may fully customise the login banner string:
#ftpd_banner=Welcome to blah FTP service.
#
# You may specify a file of disallowed anonymous e-mail addresses. Apparently
# useful for combatting certain DoS attacks.
#deny_email_enable=YES
# (default follows)
#banned_email_file=/etc/vsftpd/banned_emails
#
# You may specify an explicit list of local users to chroot() to their home
# directory. If chroot_local_user is YES, then this list becomes a list of
# users to NOT chroot().
# (Warning! chroot'ing can be very dangerous. If using chroot, make sure that
# the user does not have write access to the top level directory within the
# chroot)
#chroot_local_user=YES
#chroot_list_enable=YES
# (default follows)
#chroot_list_file=/etc/vsftpd/chroot_list
#
# You may activate the "-R" option to the builtin ls. This is disabled by
# default to avoid remote users being able to cause excessive I/O on large
# sites. However, some broken FTP clients such as "ncftp" and "mirror" assume
# the presence of the "-R" option, so there is a strong case for enabling it.
#ls_recurse_enable=YES
#
# When "listen" directive is enabled, vsftpd runs in standalone mode and
# listens on IPv4 sockets. This directive cannot be used in conjunction
# with the listen_ipv6 directive.
listen=NO
#
# This directive enables listening on IPv6 sockets. By default, listening
# on the IPv6 "any" address (::) will accept connections from both IPv6
# and IPv4 clients. It is not necessary to listen on *both* IPv4 and IPv6
# sockets. If you want that (perhaps because you want to listen on specific
# addresses) then you must run two copies of vsftpd with two configuration
# files.
# Make sure, that one of the listen options is commented !!
listen_ipv6=YES

pam_service_name=vsftpd              # 定义PAM所使用的名称
userlist_enable=YES                  # user_list文件有效,
tcp_wrappers=YES                     # 开启tcp_wrappers支持
[root@localhost ~]# 

 FTP本地用户访问

首先安装ftp:yum install ftp ,,,然后通过ftp即可在本地访问

首先确保下面三项为YES

anonymous_enable=YES
anon_upload_enable=YES
anon_mkdir_write_enable=YES
[root@localhost ~]# systemctl start vsftpd.service 
[root@localhost ~]# systemctl status vsftpd.service 
● vsftpd.service - Vsftpd ftp daemon
   Loaded: loaded (/usr/lib/systemd/system/vsftpd.service; enabled; vendor preset: disabled)
   Active: active (running) since 三 2018-09-12 11:12:50 CST; 1s ago
  Process: 57386 ExecStart=/usr/sbin/vsftpd /etc/vsftpd/vsftpd.conf (code=exited, status=0/SUCCESS)
 Main PID: 57388 (vsftpd)
   CGroup: /system.slice/vsftpd.service
           └─57388 /usr/sbin/vsftpd /etc/vsftpd/vsftpd.conf

9月 12 11:12:49 localhost.localdomain systemd[1]: Starting Vsftpd ftp daemon...
9月 12 11:12:50 localhost.localdomain systemd[1]: Started Vsftpd ftp daemon.
[root@localhost ~]# 

NFS服务器

NFS最初是由SUN公司开发的,目的就是在计算机不同操作系统之间可以彼此共享文件,NFS配置简单,快捷。客户端可以通过mount挂载之后像使用本地文件系统一样来只用远端共享目录。

在centos 7 上搭建NFS服务器比以往其实更加简单,卸掉了protmap服务,而是用rpcbind服务。

NFS服务器实现共享

/etc/exports 文件指定了那个文件系统的NFS应该输出(有时候也可以称之为“共享”)

/etc/exports 里面每行指定一个输出的文件系统和那些机器可以访问该文件系统。

在指定机器访问权限的同时,访问选项开关也可以被指定。

/ect/export 格式:

共享目录  主机1或ip1(选项1,选项2) 主机2或ip2(选项3,选项4)

主机名称格式:

单个主机/IP:station1.uplooking.com 192.168.1.1
IP网络: 192.168.1.0/255.255.255.0 172.16.1.0/15
通配符: *.uplooking.com

一般选项:

ro :read only
rw :允许nfs read write 请求
sync:同步存储后回应请求
async:在同步之前回应请求

用户ID映射:

root_squash :映射uid/gid 0 到匿名 uid/gid
no_root_squash: 关闭root squashing
all_squash:映射所有的uid/gid到匿名的uid/gid
anonuid and anongid:映射uid/gid到指定的uid/gid

exportfs 命令用来管理当前NFS共享的文件系统列表。这个列表保存在一个单独的文件/var/lib/nfs/etab中,当远端主机要求对一个文件系统树加载并访问时由mountd读取,列表中活动的一部分也保存在内核共享表中。通常etab在执行exportfs -a。的时候,根据/etc/exports中定义的共享列表来初始化。但是,管理员可以选择添加或者删除独立的文件系统,不必修改/etc/exports,只要执行exportfs就可以了

-a:全部挂载(或卸载) /etc/exports 文件内的设定。
-r :重新挂载/etc/exports中的设置,此外同步更新/etc/exports以及/var/lib/nfs/etab中的内容
-u:卸载某一目录
-v:在export时将共享的目录显示在屏幕上
[root@localhost ~]# exportfs -rv       # 全部重新export一次
[root@localhost ~]# exportfs -au       # 全部卸载
[root@localhost ~]# 

。。。更多请移驾百度。。。

Samba服务器

Samba,是一种自由软件,用来让Unix系列的操作系统与微软Windows操作系统的SMB/CIFS网络协议做联结。

应用环境:

文件和打印机共享:文件和打印机共享是Samba的主要功能,SMB进程实现资源的共享,将文件和打印机发布到网络之中,以供用户可以访问。
身份验证和权限设置:smbd服务支持user mode和domain mode等身份验证和权限设置模式,通过加密方式可以保护共享的文件和打印机。
名称解析:Samba通过nmbd服务可以搭建NBNS服务器,提供名称解析,将计算机的NetBIOS名解析为IP地址。
浏览服务:局域网中,Samba服务器可以成为贝蒂主浏览服务器(LMB),保存可用资源列表,当使用客户端访问Windows网上邻居时,会提供浏览器列表,显示共享目录,打印机等资源

更多请百度。。等用到了再补充。。

 

posted @ 2018-09-12 12:03  前方、有光  阅读(477)  评论(0编辑  收藏  举报