一、安装vsftpdhtml
[root@test ~]# yum -y install vsftpdnode
二、配置文件web
/etc/vsftpd/vsftpd.conf #vsftpd的核心配置文件算法
/etc/vsftpd/ftpusers: #用于指定哪些用户不能访问FTP,黑名单vim
/etc/vsftpd/user_list #指定容许使用vsftpd的用户列表文件缓存
#若是userlist_deny=YES(默认),毫不容许在这个文件中的用户登陆ftp,甚至不提示输入密码安全
/etcvsftpd/vsftpd_conf_migrate.sh #是vsftpd操做的一些变量和设置脚本服务器
/var/ftp/ #默认状况下匿名用户的根目录网络
三、启动服务并发
[root@test ~]# systemctl start vsftpd #启动服务
[root@test ~]# systemctl enable vsftpd #加入开启自启
Created symlink from /etc/systemd/system/multi-user.target.wants/vsftpd.service to /usr/lib/systemd/system/vsftpd.service.
[root@test ~]# netstat -antup | grep ftp #查看对应的端口是否启动起来
tcp6 0 0 :::21 :::* LISTEN 3350/vsftpd
四、经过配置文件来了解配置文件各个选项
例1:公司技术部准备搭建一台功能简单的FTP服务器,容许全部员工上传和下载文件,并容许建立用户本身的目录
分析:容许全部员工上传和下载,配置文件须要设置成容许匿名用户登陆而且须要将容许匿名用户上传功能开启
anon_mkdir_write_enable 该字段能够控制是否容许匿名用户建立目录
[root@test ~]# vim /etc/vsftpd/vsftpd.conf #打开配置文件,修改以下内容
容许匿名用户访问
anonymous_enable=YES
容许匿名用户上传文件并能够建立目录
anon_upload_enable=YES
anon_mkdir_write_enable=YES
[root@test ~]# systemctl restart vsftpd #重启服务测试
Windows经过访问ftp://192.168.135.8来验证是否正常
结果发现不能写,这是由于FTP共享的文件夹 的属主属组是root,而运行ftp的用户是ftp,因此不能写,修改/var/ftp/pub的属主属组后再验证
[root@test ~]# chown ftp:ftp /var/ftp/pub/
而后测试,是能够新建文件夹了,可是不能重命名,不能删除!
[root@test63 vsftpd]# vim vsftpd.conf
anon_other_write_enable=YES ##默认没有,须要手动添加下这行
重启服务,便可重命名文件夹。
可是能够删除文件夹了,这个参数对匿名用户来讲权限太大,不安全,均衡使用这个参数
注意,默认匿名用户家目录的权限是755,这个权限是不能改变的。切记!
下面咱们来一步一步的实现,先修改目录权限,建立一个公司上传用的目录,叫testdata,设置拥有者为ftp 用户全部,目录权限是755
[root@test63 vsftpd]# mkdir /var/ftp/testdata
[root@test63 vsftpd]# chown ftp.ftp /var/ftp/testdata/
[root@test63 vsftpd]# ll -d !$
ll -d /var/ftp/testdata/
drwxr-xr-x 2 ftp root 4096 Mar 9 19:30 /var/ftp/testdata/
而后从新启动服务
[root@test63 ~]# service vsftpd restart
Shutting down vsftpd: [ OK ]
Starting vsftpd for vsftpd: [ OK ]
测试
匿名登陆FTP
如今咱们匿名上传
如今匿名上传的文件是禁止删除滴~
这样匿名用户的上传就算成功了
注:工做中,匿名用户只是只读访问,写的权限也没有的。
例2:
公司内部如今有一台FTP 和WEB 服务器,FTP 的功能主要用于维护公司的网站内容,包括上传文
件、建立目录、更新网页等等。公司现有两个部门负责维护任务,他们分别适用team1 和team2
账号进行管理。先要求仅容许team1 和team2 账号登陆FTP 服务器,但不能登陆本地系统,并将
这两个账号的根目录限制为/var/www/html,不能进入该目录之外的任何目录。
ftp 和www web服务器相结合。
www web服务器根目录: /var/www/html
只容许:team1和team2两用户 能够上传。 vsftp禁止匿名。
分析:
将FTP 和WEB 服务器作在一块儿是企业常常采用的方法,这样方便实现对网站的维护,为了加强安
全性,首先须要使用仅容许本地用户访问,并禁止匿名用户登陆。其次使用chroot 功能将team1
和team2 锁定在/var/www/html 目录下。若是须要删除文件则还须要注意本地权限
解决方案:
(1)创建维护网站内容的ftp 账号team1 和team2 并禁止本地登陆,而后设置其密码
[root@test63 ~]# useradd -s /sbin/nologin team1
[root@test63 ~]# useradd -s /sbin/nologin team2
[root@test63 ~]# echo "123456" | passwd --stdin team1
Changing password for user team1.
passwd: all authentication tokens updated successfully.
[root@test63 ~]# echo "123456" | passwd --stdin team2
Changing password for user team2.
passwd: all authentication tokens updated successfully.
2)配置vsftpd.conf 主配置文件并做相应修改
[root@test63 vsftpd]# cp vsftpd.conf.back vsftpd.conf
vim /etc/vsftpd/vsftpd.conf
anonymous_enable=NO:禁止匿名用户登陆
local_enable=YES:容许本地用户登陆
改:
为:
local_root=/var/www/html:设置本地用户的根目录为/var/www/html
chroot_list_enable=YES:激chroot 功能
chroot_list_file=/etc/vsftpd/chroot_list:设置锁定用户在根目录中的列表文件。此文件存放要锁定的用户名
allow_writeable_chroot=YES :容许锁定的用户有写的权限
保存退出
(3)创建/etc/vsftpd/chroot_list 文件,添加team1 和team2 账号
[root@test63 vsftpd]# touch /etc/vsftpd/chroot_list
[root@test63 ~]# ll !$
ll /etc/vsftpd/chroot_list
-rw-r--r-- 1 root root 0 Nov 10 17:08 /etc/vsftpd/chroot_list
[root@test63 ~]# vim /etc/vsftpd/chroot_list #写入如下内容,一行,一个用户名
team1
team2
(5)修改本地权限
[root@test63 ~]# ll -d /var/www/html/
drwxr-xr-x. 2 root root 4096 Oct 6 2011 /var/www/html/
[root@test63 ~]# chmod -R o+w /var/www/html/
[root@test63 ~]# ll -d /var/www/html/
drwxr-xrwx. 2 root root 4096 Oct 6 2011 /var/www/html/
(6)重启vsftpd 服务使配置生效
service vsftpd restart
(7)测试
客户端用lftp登录查看:
root@test64 ~]# lftp 192.168.0.63 -u team1,123456
lftp team1@192.168.0.63:~> ls
-rw-r--r-- 1 0 0 1384 Jul 30 01:56 passwd
lftp team1@192.168.0.63:/>
补充: 配置vsftpd,使用SSL证书加密数据传输
FTP与HTTP同样缺省状态都是基于明文传输,但愿FTP服务器端与客户端传输保证安全,能够为FTP配置SSL
1, 使用OpenSSL生成自签证书
[root@test63 vsftpd]# openssl req -new -x509 -nodes -out vsftpd.pem -keyout vsftpd.pem -days 3560
Generating a 2048 bit RSA private key
..........................................................................................+++
.....................+++
writing new private key to 'vsftpd.pem'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]:ZH
State or Province Name (full name) []:JS
Locality Name (eg, city) [Default City]:NJ
Organization Name (eg, company) [Default Company Ltd]:XS
Organizational Unit Name (eg, section) []:XS
Common Name (eg, your name or your server's hostname) []:XS.COM
Email Address []:XS@QQ.COM
OpenSSL 简单参数解释:
req - 是 X.509 Certificate Signing Request (CSR,证书签名请求)管理的一个命令。
x509 - X.509 证书数据管理。
days - 定义证书的有效日期。
newkey - 指定证书密钥处理器。
keyout - 设置密钥存储文件。
out - 设置证书存储文件,注意证书和密钥都保存在一个相同的文件
2,建立证书文件存放目录
[root@test63 vsftpd]# mkdir .sslkey
[root@test63 vsftpd]# cp vsftpd.pem .sslkey/
[root@test63 vsftpd]# chmod 400 .sslkey/vsftpd.pem
3, 修改配置文件,支持SSL
[root@test63 vsftpd]# vim vsftpd.conf
添加以下配置:
ssl_enable=YES #启用SSL支持
allow_anon_ssl=NO
force_local_data_ssl=YES
force_local_logins_ssl=YES
force_anon_logins_ssl=YES
force_anon_data_ssl=YES
#上面四行force 表示强制匿名用户使用加密登录和数据传输
ssl_tlsv1=YES #指定vsftpd支持TLS v1[
ssl_sslv2=YES #指定vsftpd支持SSL v2
ssl_sslv3=YES #指定vsftpd支持SSL v3
require_ssl_reuse=NO #不重用SSL会话,安全配置项
ssl_ciphers=HIGH #容许用于加密 SSL 链接的 SSL 算法。这能够极大地限制那些尝试发现使用存在缺陷的特定算法的攻击者
rsa_cert_file=/etc/vsftpd/.sslkey/vsftpd.pem
rsa_private_key_file=/etc/vsftpd/.sslkey/vsftpd.pem
#定义 SSL 证书和密钥文件的位置
注意:上面的配置项不要添加到vsftpd.conf 文件最后,不然启动报错
4,配置FileZilla客户端验证:
链接成功,发现可使用TLS加密传输了
注意: 在工做中,内网FTP传输,能够不用证书加密传输
若是FTP服务器在公网,为了数据的安全性,就必定要配置证书加密传输
NFS概述-配置NFS服务器并实现开机自动挂载
NFS服务端概述:
NFS,是Network File System的简写,即网络文件系统。网络文件系统是FreeBSD支持的文件系统中的一种,也被称为NFS. NFS容许一个系统在网络上与他人共享目录和文件。经过使用NFS,用户和程序能够像访问本地文件同样访问远端系统上的文件。
模式: C/S 模式
端口:
RHEL7是以NFSv4做为默认版本,NFSv4使用TCP协议(端口号是2049)和NFS服务器创建链接
安装nfs
[root@test63 ~]# yum -y install rpcbind nfs-utils
配置文件位置
[root@test63 ~]# ls /etc/exports
/etc/exports
启动NFS服务
先查看2049端口是否开放:
[root@test63 ~]# netstat -antpu | grep 2049
[root@test63 ~]# systemctl start rpcbind
[root@test63 ~]# systemctl start nfs-server.service
再次查看端口监听状态
[root@test63 ~]# netstat -antpu | grep 2049
tcp 0 0 0.0.0.0:2049 0.0.0.0:* LISTEN -
tcp 0 0 :::2049 :::* LISTEN +
配置开机自动启动
[root@test63 ~]# chkconfig nfs-server on
服务的使用方法
showmount -e NFS服务器IP
例:
[root@test64 ~]# showmount -e 192.168.0.63
Export list for 192.168.0.63:
挂载
[root@test64 ~]# mount 192.168.0.63:/tmp /opt
修改配置文件,实战举例
[root@test63 ~]# vim /etc/exports
/media *(rw)
注意: * 表示对全部网段开放权限
也能够指定特定的网段
重启服务
[root@test63 ~]# exportfs -rv ##从新读取配置文件,不中断服务.
客户端查看:
[root@test64 ~]# showmount -e 192.168.0.63
Export list for 192.168.0.63:
/media *
挂载共享
[root@test64 ~]# mount -t nfs 192.168.0.63:/media/ /opt/
[root@test64 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 9.7G 4.0G 5.2G 44% /
tmpfs 996M 80K 996M 1% /dev/shm
/dev/sda1 485M 39M 421M 9% /boot
/dev/sr0 3.7G 3.7G 0 100% /mnt
192.168.0.63:/media/ 9.7G 4.0G 5.3G 43% /opt
开机自动挂载:
编辑 [root@test63 ~]# vim /etc/fstab
在文件最后添加自动挂载的信息:
验证写入权限
[root@test64 ~]# touch /opt/a.txt
touch: 没法建立"/opt/a.txt": 权限不够
解决方法:
设置访问权限通常包含2部分
1)服务自己权限
2)目录访问权限
nfs默认使用nfsnobody用户
[root@test63 ~]# grep nfs /etc/passwd
rpcuser:x:29:29:RPC Service User:/var/lib/nfs:/sbin/nologin
nfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin
修改权限
[root@test63 ~]# chmod 777 -R /media/
或
[root@test63 ~]# chown nfsnobody.nfsnobody -R /media/
再次验证写入权限
[root@test64 ~]# touch /opt/a.txt
[root@test64 ~]# ll !$
ll /opt/a.txt
-rw-r--r-- 1 nfsnobody nfsnobody 0 5月 24 2016 /opt/a.txt
下面是一些NFS共享的经常使用参数:
ro 只读访问
rw 读写访问
sync 资料同步写入到内存与硬盘当中
async 资料会先暂存于内存当中,而非直接写入硬盘
secure NFS经过1024如下的安全TCP/IP端口发送
insecure NFS经过1024以上的端口发送
wdelay 若是多个用户要写入NFS目录,则归组写入(默认)
no_wdelay 若是多个用户要写入NFS目录,则当即写入,当使用async时,无需此设置。
Hide 在NFS共享目录中不共享其子目录
no_hide 共享NFS目录的子目录
subtree_check 若是共享/usr/bin之类的子目录时,强制NFS检查父目录的权限(默认)
no_subtree_check 和上面相对,不检查父目录权限
all_squash 共享文件的UID和GID映射匿名用户anonymous,适合公用目录。
no_all_squash 保留共享文件的UID和GID(默认)
root_squash root用户的全部请求映射成如anonymous用户同样的权限(默认)
no_root_squash root用户具备根目录的彻底管理访问权限
[root@xue63 a]# cat /etc/exports
/tmp/a/no_root_squash *(rw,no_root_squash)
/tmp/a/sync 192.168.0.0/24(rw,sync)
/tmp/a/ro 192.168.1.64(ro)
/tmp/a/all_squash 192.168.0.0/24(rw,all_squash,anonuid=500,anongid=500)
/tmp/a/async 192.168.3.0/255.255.255.0(async)
/tmp/a/rw 192.168.3.0/255.255.255.0(rw) 192.168.4.0/255.255.255.0(rw)
/tmp/a/root_squash *(rw,root_squash)
注意:在发布共享目录的格式中除了共享目录是必跟参数外,其余参数都是可选的。而且共享
目录与客户端之间及客户端与客户端之间须要使用空格符号,可是客户端与参数之间是不能有
空格的
NFS客户端挂载参数的优化:
NFS高并发环境下的服务端重要优化(mount -o 参数)
async 异步同步,此参数会提升I/O性能,但会下降数据安全(除非对性能要求很高,对数据可靠性不要求的场合。通常生产环境,不推荐使用)
noatime 取消更新文件系统上的inode访问时间,提高I/O性能,优化I/O目的,推荐使用。
nodiratime 取消更新文件系统上的directory inode访问时间,高并发环境,推荐显式应用该选项,提升系统性能
intr:能够中断不成功的挂载
rsize/wsize 读取(rsize)/写入(wsize)的区块大小(block size),这个设置值能够影响客户端与服
务端传输数据的缓冲存储量。通常来讲,若是在局域网内,而且客户端与服务端都具备足够的内存,这个
值能够设置大一点,好比说32768(bytes),提高缓冲区块将可提高NFS文件系统的传输能力。但设置的值也不要太大,最好是实现网络可以传输的最大值为限。
内核优化:
net.core.wmem_default = 8388608 #内核默认读缓存
net.core.rmem_default = 8388608 #内核默认写缓存
net.core.rmem_max = 16777216 #内核最大读缓存
net.core.wmem_max = 16777216 #内核最大写缓存
用法:
mount -t nfs -o noatime,nodiratime,rsize=131072,wsize=131072,intr 192.168.0.63:/backup/NFS /mnt
或者写到挂载文件里:
192.168.0.63:/backup/NFS /mnt nfs noatime,nodiratime,rsize=131072,wsize=131072,intr 0 0