美文网首页
十三、NFS、FTP、DNS

十三、NFS、FTP、DNS

作者: 胖虎喜欢小红 | 来源:发表于2020-01-26 15:16 被阅读0次

1、构建NFS远程共享存储

存储分类:
文件系统级别共享(是NAS存储(网络附加存储通过网线)) --------- 已经做好了格式化,可以直接用。 速度慢
nfs,samba

(SAN存储区域网)块级别的共享---------是指设备 先格式化才能用。使用光线。最好的,也是最贵的。san ipsan ceph

DAS(直连式存储):直接可以链接,受限与服务器的接口。快。
=====================================================
因为NFS有很多功能,不同的功能需要使用不同的端口。因此NFS无法固定端口。而RPC会记录NFS端口的信息,这样我们就能够通过RPC实现服务端和客户端的RPC来沟通端口信息。

那RPC和NFS之间又是如何之间相互通讯的?

首先当NFS启动后,就会随机的使用一些端口,然后NFS就会向RPC去注册这些端口。RPC就会记录下这些端口。并且RPC会开启111端口,等待客户端RPC的请求,如果客户端有请求,那服务端的RPC就会将记录的NFS端口信息告知客户端。

NFS 重要指数4星
项目名称: 为集群中的 Web Server 配置后端存储

NFS:Network File System 网络文件系统,Unix系统之间共享文件的一种协议
NFS 的客户端主要为Linux

实验环境

实验环境准备两台机器
支持多节点同时挂载以及并发写入
服务端:nfs_server 192.168.94.128
客户端:client 192.168.94.129
centos7(服务端和客户端都关闭防火墙和selinux内核防火墙)

#systemctl stop firewalld

#systemctl disable firewalld    

#setenforce 0

nfc_server操作

[root@nfs_server ~]# yum -y install rpcbind  #安装rpc协议的包
[root@nfs_server ~]# yum -y install nfs-utils #安装nfs服务,提供文件系统
启动服务
[root@nfs_server ~]# systemctl start nfs
[root@nfs_server ~]# systemctl start rpcbind
[root@nfs_server ~]# mkdir /nfs_dir    #创建存储目录
[root@nfs_server ~]# echo "hello" >> /nfs_dir/file.txt   #创建测试文件
[root@nfs_server ~]# vim /etc/exports   #编辑共享文件
/nfs-dir        192.168.94.0/24(rw,no_root_squash,sync)
参数注释:
no_root_squash:不压制root权限
ro:只读
rw:读写
*:表示所有。
sync:同步
image-20191116194232117.png
[root@nfs_server ~]# systemctl restart nfs-server #重启服务。
[root@nfs_server ~]# systemctl enable nfs-server #制作开机启动

client客户端操作

[root@client ~]# yum -y install rpcbind
[root@client ~]# yum -y install nfs-utils
[root@client ~]# mkdir /mnt/nfs    #创建挂载点
[root@client ~]# mount -t nfs 192.168.94.128:/nfs_dir /mnt/nfs/   #挂载
[root@client ~]# df -Th
Filesystem              Type      Size  Used Avail Use% Mounted on
192.168.94.128:/nfs_dir nfs4       18G  1.9G   17G  11% /mnt/nfs
[root@client ~]# ls /mnt/nfs/
file.txt
[root@client ~]# umount /mnt/nfs/   #取消挂载

2、ftp及lftp

FTP Server  重要指数4星
作用:提供文件共享服务,实现上传下载
端口:
21号,建立tcp连接  默认端口
20号:传输数据
一、FTP基础
软件包:            vsftpd
FTP端口:           控制端口 command 21/tcp 
配置文件:          /etc/vsftpd/vsftpd.conf

ftp主动模式

ftp主动模式:客户端开启一个(N>1023)的端口向服务端的21端口,建立连接,同时开启一个N+1,告诉服务端,我监听的是N+1端口,服务端接到请求之后,用自己的20端口连接到客户端的N+1端口,进行传输

21端口建立连接
20端口传输数据

ftp被动模式

ftp被动模式:客户端同时开启两个端口(1024,1025),一个端口(1024)跟服务端的21端口建立连接,并给服务端发送请求。服务端接到请求之后,随机会开启一个端口(1027)并告诉客户端我开启的是1027端口,客户端用另一个端口(1025)与服务端的(1027)端口进行连接,传输数据
二、vsftpd配置*

实验环境

准备两台机器
ftp_server :192.168.94.128
client :192.168.94.129
关闭防火墙和selinux
#systemctl stop firewalld
#systemctl disable firewalld    
#setenforce 0

ftp_server端操作

[root@ftp_server ~]# yum -y install vsftpd
[root@ftp_server ~]# systemctl start vsftpd
FTP默认共享目录:/var/ftp
[root@ftp_server ~]# touch /var/ftp/test.txt  #创建测试文件 
[root@ftp_server ~]# cd /var/ftp/
[root@ftp_server ftp]# ls
pub  test.txt
[root@ftp_server ftp]# chmod 777 pub/   #给上传目录设置权限
[root@ftp_server ftp]# vim /etc/vsftpd/vsftpd.conf  #取消下面两行的注释
image-20191116200432424.png
[root@ftp_server ftp]# systemctl restart vsftpd  #重启服务

配置文件详解

基本配置,例如实现访问控制

anonymous_enable=YES           //是否允许匿名用户登录ftp   YES为允许 NO为拒绝
local_enable=YES                //是否允许本地用户登录(比如alice)
write_enable=YES                //是否允许写(全局)
local_umask=022                 //控制本地用户上传文件的默认权限,umask表示要减掉的权限
anon_umask=022                  //控制匿名用户上传文件的默认权限 

download_enable=YES           //是否允许下载文件

anon_upload_enable=YES   //允许上传文件
anon_mkdir_write_enable=YES   //允许上传目录

anon_max_rate=500000           //匿名用户限速
local_max_rate=80000              //本地用户限速
max_clients=500                      //ftp最大连接数
max_per_ip=2                         //单个IP最大连接数,线程数

local_root=/ftproot                 //指定本地用户访问的家目录
anon_root=/anonroot              //指定匿名用户访问的家目录

服务器关闭被动模式:
#vim  /etc/vsftpd/vsftpd.conf
pasv_enable=NO

client端操作

[root@client ~]# yum -y install lftp  #安装客户端
[root@client ~]# lftp 192.168.94.128
lftp 192.168.94.128:~> ls
drwxrwxrwx    2 0        0               6 Oct 30  2018 pub
-rw-r--r--    1 0        0               0 Jan 26 06:11 test.txt
lftp 192.168.94.128:/> get test.txt    #下载
lftp 192.168.94.128:/> exit
[root@client ~]# ls   #会下载到当前目录
test.txt
[root@client ~]# touch file.txt   #创建测试文件
[root@client ~]# mkdir test_dir   #创建测试目录
[root@client ~]# lftp 192.168.94.128
lftp 192.168.94.128:~> cd pub/
lftp 192.168.94.128:/pub> put file.txt    #上传文件
lftp 192.168.94.128:/pub> mirror -R test_dir/   #上传目录以及目录中的子文件
Total: 1 directory, 0 files, 0 symlinks
lftp 192.168.94.128:/pub> ls
-rw-------    1 14       50              0 Jan 26 06:30 file.txt
drwx------    2 14       50              6 Jan 26 06:31 test_dir
lftp 192.168.94.128:/pub> mirror ./test_dir/ /opt/    #下载目录
Total: 1 directory, 0 files, 0 symlinks
lftp 192.168.94.128:/pub> exit 
[root@client ~]# ls /opt
test_dir

3、DNS域名解析服务

域名解析

域名对应ip
www.baidu.com这个域名--对应IP---183.232.231.174
一个域名可以对应多个ip

本地解析

本地解析:/etc/hosts    默认先使用本地解析
[root@linux_server ~]# vim /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.94.128 www.biubiu.com
表示:com域下面有一个biubiu,biubiu下面有一台叫www的机器。解析速度快。机器少可以不用DNS。

使用DNS服务器解析

域名空间

DNS里面顶层是:      .     表示根域 ( 一共有十三台根服务器)
顶级域名(也叫一级域名) 分类:职能:com域,gov域,.org域(非营利机构),edu域名(教育)   
国家:.cn , us 
二级域名:平时申请的。例如:baidu、jd
三级域名:自己设置。(如果下面还有东西就是三级域名,如果没有就是主机名。)最开头的是主机名称。
完整域名:www.biubiu.com.

dns解析过程

1. 客户端拿到域名先访问/etc/hosts配置文件,如果有本地解析会直接使用,如果没有会去看/etc/resolv.conf :如果有答案会直接给出结果。如果没有会帮助转发。如果缓存服务器都没有给出结果那么会找到根服务器
2. 找根服务器。根服务指定一级域名,一级域名同过二级域名查询
搭建DNS服务器

实验环境

准备两台机器
dns_server:192.168.94.128
解析域名为www.biubiu.com

client:192.168.94.129
dns_server操作

1.安装软件

bind  主包----服务叫named
bind-utils   客户端测试工具(host 、dig 、nslookup)
bind-chroot   chroot环境  禁锢dns服务器的工作目录

[root@dns_server ~]# yum install -y bind-utils
[root@dns_server ~]# yum install -y bind-chroot
[root@dns_server ~]# systemctl start named  #启动服务
[root@dns_server ~]# netstat -lntp | grep named  #查看named的端口
tcp        0      0 127.0.0.1:53            0.0.0.0:*               LISTEN      8515/named          
tcp        0      0 127.0.0.1:953           0.0.0.0:*               LISTEN      8515/named          
tcp6       0      0 ::1:53                  :::*                    LISTEN      8515/named          
tcp6       0      0 ::1:953                 :::*                    LISTEN      8515/named 

2.工作目录:

/etc              存放主配置文件  :指定区域配置文件的位置
/var/named        区域配置文件: 主要用来做解析。 配置ip对应域名。域名对应ip

3.编辑主配置文件:

[root@dns_server ~]# mv /etc/named.conf /etc/named.conf.bak
[root@dns_server ~]# vim /etc/named.conf
options {
directory "/var/named";   #指定目录
};
zone "biubiu.com" IN {  #区域
    type master;  #类型
    file "biubiu.zone";
};
[root@dns_server ~]# ll /etc/named.conf
-rw-r--r--. 1 root root 110 Jan 26 15:00 /etc/named.conf
[root@dns_server ~]# chown named.named /etc/named.conf
新建指定域名的配置文件,加权限

[root@dns_server ~]# cd /var/named/
[root@dns_server named]# vim biubiu.zone
$TTL 86400
@ IN SOA www.biubiu.com. root.biubiu.com (
                                        100000000 
                                        3H
                                        15M
                                        1W
                                        1D)
                                        IN NS www.biubiu.com.
www                                     IN A 192.168.94.128
www.biubiu.com.                         IN A 192.168.94.128
[root@dns_server named]# ll biubiu.zone 
-rw-r--r--. 1 root root 448 Jan 26 15:08 biubiu.zone
[root@dns_server named]# chown named.named *.zone
重启named
[root@linux-server named]# systemctl restart named
参数解释:
$TTL 86400  指的是时间秒,86400s = 一天 缓存时间
@ 表示当前域名
SOA 起始授权记录
IN 表示记录
100000000 序列号主从DNS用到的,每次更新一次主配置文件序列号,从服务器检查自己的序列号,如果序列号不同,则会更新配置文件
3H  更新时间(多久进行一次从主从序列号检查,默认3个小时)
15M  如果更新失败,15分钟再次尝试
1W 如果一直失败,一周之后放弃
1D 缓存时间
NS记录(指定管理某个域的服务器)
A: A记录(正向解析)把域名解析为ip

client端操作

[root@client ~]# vim /etc/resolv.conf
# Generated by NetworkManager
search localdomain
nameserver 192.168.94.128
[root@client ~]# ping www.biubiu.com
PING www.biubiu.com (192.168.94.128) 56(84) bytes of data.
64 bytes from 192.168.94.128 (192.168.94.128): icmp_seq=1 ttl=64 time=0.355 ms
64 bytes from 192.168.94.128 (192.168.94.128): icmp_seq=2 ttl=64 time=0.563 ms
64 bytes from 192.168.94.128 (192.168.94.128): icmp_seq=3 ttl=64 time=0.587 ms
64 bytes from 192.168.94.128 (192.168.94.128): icmp_seq=4 ttl=64 time=0.575 ms
64 bytes from 192.168.94.128 (192.168.94.128): icmp_seq=5 ttl=64 time=0.566 ms
64 bytes from 192.168.94.128 (192.168.94.128): icmp_seq=6 ttl=64 time=0.429 ms
^C
--- www.biubiu.com ping statistics ---
6 packets transmitted, 6 received, 0% packet loss, time 5005ms
rtt min/avg/max/mdev = 0.355/0.512/0.587/0.091 ms

相关文章

网友评论

      本文标题:十三、NFS、FTP、DNS

      本文链接:https://www.haomeiwen.com/subject/qojjthtx.html