1- 系统部署

本贴最后更新于 1165 天前,其中的信息可能已经天翻地覆

1 系统安装过程

1.1 运维自动化发展历程及技术应用

clipboard.png

1.2 系统安装过程

  • 加载 boot loader
  • 加载启动安装菜单
  • 加载内核和 initrd 文件
  • 加载根系统
  • 运行 anaconda 的安装向导

1.2.1 Linux 安装光盘的安装相关文件

在系统光盘的 isolinux 目录下有和安装相关的文件

  • boot.cat: 相当于 grub 的第一阶段
  • isolinux.bin:光盘引导程序,在 mkisofs 的选项中需要明确给出文件路径,这个文件属于 SYSLINUX 项目
  • isolinux.cfg:启动菜单的配置文件,当光盘启动后(即运行 isolinux.bin),会自动去找 isolinux.cfg 文件
  • vesamenu.c32:是光盘启动后的启动菜单图形界面,也属于 SYSLINUX 项目,menu.c32 提供纯文本的菜单
  • memtest: 内 存 检 测 程 序
  • splash.png:光盘启动菜单界面的背景图
  • vmlinuz: 是 内 核 映 像
  • initrd.img:ramfs 文件

1.2.2 安装菜单的内核参数

安装光盘的启动菜单配置文件:isolinux/isolinux.cfg 中设置相关的内核加载参数,实现不同的安装过程 isolinux.cfg 文件中每个安装对应菜单选项:

  • 加载内核:isolinuz/vmlinuz
  • 向内核传递参数:append initrd=initrd.img 参数设置

1.2.2.1 指定内核参数方法

  • 在启动菜单界面,选中一项安装方法,按 tab 键,在后面增加参数
  • 在启动菜单界面,任意选中一项安装方法,按 ESC 键:boot: linux 参数设置

1.2.2.2 常见的内核参数:

  • text:默认启动 GUI 安装接口,可以指定文本方式的安装界面
  • rescue:进入救援模式
  • inst.repo=path:指定安装源文件的路径,可以是以下格式

Centos 6

DVD drive repo=cdrom :device 
Hard Drive repo=hd:device/path 
HTTP Server repo=http://host/path 
HTTPS Server repo=https://host/path 
FTP Server repo=ftp://username:password@host/path 
NFS Server repo=nfs:server:/path 
ISO images on an NFS Server repo=nfsiso:server:/path

Centos 7 以上版本

Any CD/DVD drive   inst.repo=cdrom
Hard Drive inst.repo=hd:device:/path
HTTP Server inst.repo=http://host/path
HTTPS Server inst.repo=https://host/path
FTP Server inst.repo=ftp://username:password@host/path
NFS Server inst.repo=nfs:[options:]server:/path
  • askmethod:选择安装源文件的获取方法,提供了光盘,本地硬盘,NFS,FTP,HTTP 多种安装源,此项 Centos7 以后已废弃
  • ks=path:指定自动安装应答文件路径
initrd=initrd.img inst.ks=http://10.0.0.8/ksdir/centos8.cfg
  • ip=:指定地址信息
ip=method,method #可以为dhcp
ip=interface:method #指定特定接口
ip=ip::gateway:netmask:hostname:interface:none   #静态IP

1.2.3 anaconda 安装向导

anaconda 是 Linux 系统安装程序,可以提供俩种风格的安装界面

  • gui:图形窗口
  • tui: 基于图形库 curses 的文本窗口

1.2.3.1 anaconda 工作过程

  • 安装过程使用的语言

  • 键盘类型

  • 时区和时间

  • 安装源文件路径

  • 选定要安装的程序包

  • 安装目标存储设备及分区设置 Basic Storage:本地磁盘

    • 特殊设备:iSCSI
  • KDUMP 功能

  • 设定主机名和配置网络接口

  • 安全策略

  • 管理员密码

  • 创建一个普通用户

anaconda 的配置方式:

  • 交互式配置方式
  • 通过读取事先给定的配置文件自动完成配置,加内核参数:ks=/path 实现指明 kickstart 文件的位置,各种路径格式如下:
DVD drive: ks=cdrom:/PATH/TO/KICKSTART_FILE
Hard drive: ks=hd:device:/directory/KICKSTART_FILE
HTTP server: ks=http://host:port/path/to/KICKSTART_FILE
FTP server: ks=ftp://host:port/path/to/KICKSTART_FILE
HTTPS server: ks=https://host:port/path/to/KICKSTART_FILE
NFS server:ks=nfs:host:/path/to/KICKSTART_FILE

范例:用 boot 光盘启动利用网络源安装

[16:21:59 root@centos7 ~]#yum install -y httpd
[16:19:53 root@centos7 ~]#mkdir -p /var/www/html/centos/{7,8}/x86_64
[16:21:04 root@centos7 ~]#systemctl enable --now httpd.service
[16:22:07 root@centos7 ~]#mount /dev/sr0 /var/www/html/centos/8/x86_64/

创建新的虚拟机,关联 CentOS-8.3.2011-x86_64-boot.iso 文件到光驱,配置如下
clipboard.png

光盘启动,先启用网卡,指定安装源

注意:Centos7 只有一个 yum 源就指到镜像根目录就可以了 Centos8 有俩个源分别是 AppStream 和 BaseOS 需要指定到这俩个目录下

clipboard.png

设置完毕后安装
clipboard.png

2 自动安装的应答文件

实现自动安装前,需要制作对应的安装应答文件,称为 kickstart 文件,用于保存安装过程需要指定的选 项。

2.1 kickstart 文件使用过程

  1. Create a Kickstart file.
  2. Make the Kickstart file available on removable media, a hard drive or a network location.
  3. Create boot media, which will be used to begin the installation.
  4. Make the installation source available.
  5. Start the Kickstart installation.

2.2 kickstart 文件的格式

2.2.1 Kickstart 文件格式官方说明

https://access.redhat.com/documentation/enus/red_hat_enterprise_linux/6/html/installation_guide/s1-kickstart2-options

2.2.2 kickstart 文件格式说明

kickstart 文件主要包括三个部分:命令段,程序包段,脚本段

  • 命令段:指明各种安装前配置,如键盘类型等

    • 命令段中的常见命令:
    • keyboard: 设定键盘类型
    • lang: 语言类型
    • zerombr:清除 mbr
    • clearpart:清除分区
    • part: 创建分区
    • rootpw: 指明 root 的密码
    • timezone: 时区
    • text: 文本安装界面
    • network:指定网络设置
    • firewall:设置防火墙设置
    • selinux:设置 selinux 设置
    • reboot:安装完自动重启
    • user:安装完成后为系统创建新用户
    • url:指明安装源
  • 程序包段:指明要安装的程序包组或程序包,不安装的程序包等

    • %packages
    • @^environment group: 指定环境包组,如:@^minimal-environment
    • @group_name
    • package
    • -package
    • %end
  • 脚本段:

    • %pre: 安装前脚本
    • %post: 安装后脚本

注意:

  • Centos 8,7,6 不同版本的 kickstart 文件格式不尽相同,不可混用
  • %addon, %packages, %onerror, %pre 、 %post 必须以 %end 结束,否则安装失败

范例:Centos8 的最小化安装 kickstart 文件

#version=RHEL8
ignoredisk --only-use=sda
Partition clearing information
Use graphical install
text
zerombr
reboot
clearpart --all --initlabel
selinux --disabled
firewall --disabled
Use CDROM installation media
url --url="http://192.168.10.71/centos/8/x86_64"
Keyboard layouts
keyboard --vckeymap=us --xlayouts='us'
System language
lang en_US.UTF-8
Network information
bootloader --append="net.ifnames=0" --location=mbr --boot-drive=sda
network  --bootproto=dhcp --device=eth0 --ipv6=auto --activate
network  --hostname=localhost.localdomain
Root password
rootpw --iscrypted $6$q76Q7kMy.HLaa0Jc$pN1iBqDhYaNZNqLxV.8Qz8QwxgRYB3NXt7/1ikn4buFXhI8GrYUj3hzYhN5Bdw5LzmmZAbXEg9KNx8cC67J73.
Run the Setup Agent on first boot
firstboot --enable
Do not configure the X Window System
skipx
System services
services --disabled="chronyd"
System timezone
timezone Asia/Shanghai --isUtc --nontp
#Disk partitioning information
part /boot --fstype="ext4" --ondisk=sda --size=1024
part /     --fstype="xfs" --ondisk=sda --size=10240
%packages
@^minimal-environment
vim
tree
wget
curl
%end
%addon com_redhat_kdump --disable --reserve-mb='auto'
%end
%anaconda
pwpolicy root --minlen=6 --minquality=1 --notstrict --nochanges --notempty
pwpolicy user --minlen=6 --minquality=1 --notstrict --nochanges --emptyok
pwpolicy luks --minlen=6 --minquality=1 --notstrict --nochanges --notempty
%end
%post
mkdir /root/.ssh -m 700 
cat > /root/.ssh/authorized_keys <<EOF
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDLHJojzR16nNVt7F8Zyn7Mw+Wxffshj093eiswWK45HPo/WtV4AORBka5iYHOFaA9Dp7wxNTLiPVgX3ud47U8OwEEHxJmyXbP8kIH/xOZGovMd3XukF7jUUNwQJJkYUnsInypHxs95bD0png2OgR2oq31FtccTAQ7mUFr5AiW0FsI9ue2sJQVdEEM+kB674mRbZK0bv75Ezh7IvrprbXzgRhY5IBQdRxHDyarRnaNs7MRS+bhZ2K+Zon5vi9ZxQO+9wXWSskCzEzMpVaKwuOXGnfd2y5PPUQ7KDOPN8usF9r+fkE1h8T6TgDAp24ERUEWX4bDQPcXjQKZt4YHofzXh root@centos7
EOF
chmod 600 /root/.ssh/authorized_keys
%end

范例:Centos7 的最小化安装 kickstart 文件

#platform=x86, AMD64, or Intel EM64T
#version=DEVEL
Install OS instead of upgrade
install
Keyboard layouts
keyboard 'us'
Root password
rootpw --iscrypted $1$NxU3dKmV$fRJv0NpyNJv6sQSK2SEh//
System language
lang en_US
System authorization information
auth  --useshadow  --passalgo=sha512
Use text mode install
text
SELinux configuration
selinux --disabled
Do not configure the X Window System
skipx
Firewall configuration
firewall --disabled
Network information
network  --bootproto=dhcp --device=eth0
Reboot after installation
reboot
System timezone
timezone Asia/Shanghai
Use network installation
url --url="http://192.168.10.71/centos/7/x86_64"
System bootloader configuration
bootloader --append="net.ifnames=0" --location=mbr
Clear the Master Boot Record
zerombr
Partition clearing information
clearpart --all --initlabel
Disk partitioning information
part /boot --fstype="ext4" --size=1000
part / --fstype="xfs" --size=10000
%post
mkdir /root/.ssh -m 700
cat > /root/.ssh/authorized_keys <<EOF
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDLHJojzR16nNVt7F8Zyn7Mw+Wxffshj093eiswWK45HPo/WtV4AORBka5iYHOFaA9Dp7wxNTLiPVgX3ud47U8OwEEHxJmyXbP8kIH/xOZGovMd3XukF7jUUNwQJJkYUnsInypHxs95bD0png2OgR2oq31FtccTAQ7mUFr5AiW0FsI9ue2sJQVdEEM+kB674mRbZK0bv75Ezh7IvrprbXzgRhY5IBQdRxHDyarRnaNs7MRS+bhZ2K+Zon5vi9ZxQO+9wXWSskCzEzMpVaKwuOXGnfd2y5PPUQ7KDOPN8usF9r+fkE1h8T6TgDAp24ERUEWX4bDQPcXjQKZt4YHofzXh root@centos7
EOF
chmod 600 /root/.ssh/authorized_keys
%end
%packages
@development
@mail-server
%end

范例:Centos6 的最小化安装 kickstart 文件

#platform=x86, AMD64, or Intel EM64T
#version=DEVEL
Install OS instead of upgrade
install
Keyboard layouts
keyboard 'us'
Root password
rootpw --iscrypted $1$NxU3dKmV$fRJv0NpyNJv6sQSK2SEh//
System language
lang en_US.UTF-8
System authorization information
auth  --useshadow  --passalgo=sha512
Use text mode install
text
SELinux configuration
selinux --disabled
Do not configure the X Window System
authconfig --enableshadow --passalgo=sha512
Firewall configuration
firewall --disabled
Network information
network --onboot yes  --bootproto=dhcp --device=eth0 --noipv6
Reboot after installation
reboot
System timezone
timezone Asia/Shanghai
Use network installation
url --url="http://192.168.10.71/centos/6/x86_64"
System bootloader configuration
bootloader --append="crashkernel=auto rhgb quiet" --location=mbr --driveorder=sda
Clear the Master Boot Record
zerombr
Partition clearing information
clearpart --all --initlabel
Disk partitioning information
part /boot --fstype="ext4" --size=1000
part / --fstype="ext4" --size=10000
%post
mkdir /root/.ssh -m 700
cat > /root/.ssh/authorized_keys <<EOF
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDLHJojzR16nNVt7F8Zyn7Mw+Wxffshj093eiswWK45HPo/WtV4AORBka5iYHOFaA9Dp7wxNTLiPVgX3ud47U8OwEEHxJmyXbP8kIH/xOZGovMd3XukF7jUUNwQJJkYUnsInypHxs95bD0png2OgR2oq31FtccTAQ7mUFr5AiW0FsI9ue2sJQVdEEM+kB674mRbZK0bv75Ezh7IvrprbXzgRhY5IBQdRxHDyarRnaNs7MRS+bhZ2K+Zon5vi9ZxQO+9wXWSskCzEzMpVaKwuOXGnfd2y5PPUQ7KDOPN8usF9r+fkE1h8T6TgDAp24ERUEWX4bDQPcXjQKZt4YHofzXh root@centos7
EOF
chmod 600 /root/.ssh/authorized_keys
%end
%packages
@development
@mail-server
%end

2.3 kickstart 文件创建

创建 kickstart 文件的方式

  • 可使用创建工具:system-config-kickstart ,注意:此方法 CentOS 8 不再支持
  • 依据某模板修改并生成新配置,CentOS 安装完后,会自动参考当前系统的安装过程,生成一个 kickstart 文件 /root/anaconda-ks.cfg

检查 ks 文件的语法错误:

使用 ksvalidator 工具可以检查 kickstart 的文件格式是否有语法错误,来自于 pykickstart 包

格式:

ksvalidator /PATH/TO/KICKSTART_FILE

范例:使用 system-config-kickstart 生成 kickstart` 配置文件

1.Basic Configuration
clipboard.png

2.Installation Method
ipimage002.jpeg

3.Boot Loader Options

clipboard.png

4.Partition In

clipboard.png

5.Network Configuration

clipboard.png

6. Authentication

clipboard.png

7.Firewall Configuration

clipboard.png

8.Display Configuration

clipboard.png

9. Package Selection

clipboard.png

如果包安装的界面不出现可选的包信息,那么需要修改yum仓库配置文件
[root@centos ~]#vim /etc/yum.repos.d/***.repo
[development]
#把原来"[]"内的内容改成development,其它不变

10.pre-Installation script

安装前脚本

11.post-Installation script

安装后脚本

3 制作引导光盘和 U 盘

可以将定制安装光盘,并结合 kickstart 实现基于光盘启动的半自动化安装

实现过程

[20:25:58 root@centos7 myiso]#mkdir -pv /data/myiso/
[20:30:32 root@centos7 myiso]#cp -r /var/www/html/centos/8/x86_64/isolinux /data/myiso/
[20:31:12 root@centos7 myiso]#tree /data/myiso/
/data/myiso/
└── isolinux
├── boot.cat
├── boot.msg
├── grub.conf
├── initrd.img
├── isolinux.bin
├── isolinux.cfg
├── ldlinux.c32
├── libcom32.c32
├── libutil.c32
├── memtest
├── splash.png
├── TRANS.TBL
├── vesamenu.c32
└── vmlinuz

1 directory, 14 files
[20:31:20 root@centos7 myiso]#vim /data/myiso/isolinux/isolinux.cfg
#方法1应答放在ISO文件中
label linux
menu label ^Install CentOS Linux 8
kernel vmlinuz
append initrd=initrd.img ks=cdrom:/myks.cfg

#方法2:应答放在http服务器中
label linux
menu label ^Install CentOS Linux 8
kernel vmlinuz
append initrd=initrd.img ks=http://192.168.10.71/ks/ks-centos8.cfg
label rescue
menu label ^Rescue a CentOS Linux system
kernel vmlinuz
append initrd=initrd.img inst.repo=http://192.168.10.71/centos/8/x86_64/ rescue quiet

[20:36:08 root@centos7 myiso]#yum install mkisofs
[20:36:35 root@centos7 myiso]#mkisofs -R -J -T -v --no-emul-boot --boot-load-size 4 --boot-info-table -V "CentOS 8.0 x86_64 boot" -b isolinux/isolinux.bin -c isolinux/boot.cat -o /root/boot.iso /data/myiso/
注意:以上相对路径都是相对于光盘的根,和工作目录无关

mkisofs 选项说明
clipboard.png

4 实现 DHCP 服务

主机获取网络配置可以通过俩种方式:

  • 静态指定
  • 动态获取:
    • bootp:boot protocol MAC 与 IP 一一静态对应
    • dhcp:增强的 bootp,支持静态和动态

4.1 DHCP 工作原理

DHCP:Dynamic Host Configuration Protocol,动态主机配置协议

UDP 协议,C/S 模式,dhcp server:67/udp,dhcpv4c client:68/udp,dhcpv6 client:546/udp

主要用途:

  • 用于内部网络和网络服务提供商自动分配 IP 地址给用户
  • 用于内部网络管理员作为对所有电脑集中管理的手段
  • 自动化安装系统
  • 解决 IPv4 资源不足问题

DHCP 共有八种报文
clipboard.png

  • DHCP DISCOVER:客户端到服务器
  • DHCP OFFER:服务器到客户端
  • DHCP REQUEST:客户端到服务器
  • DHCP ACK:服务器到客户端
  • DHCP NAK:服务器到客户端,通知用户无法分配合适的 IP 地址
  • DHCP DECLINE:客户端到服务器,指示地址已被使用
  • DHCP RELEASE:客户端到服务器,放弃网络地址和取消剩余的租约时间
  • DHCP INFORM:客户端到服务器,客户端如果需要从 DHCP 服务器端获取更为详细的配置信息,则发送 Inform 报文向服务器进行请求,极少用到

DHCP 服务续租

  • 50% :租赁时间达到 50% 时来续租,刚向 DHCP 服务器发向新的 DHCPREQUEST 请求。如果 dhcp 服务没有拒绝的理由,则回应 DHCPACK 信息。当 DHCP 客户端收到该应答信息后,就重新开始新的租用周期
  • 87.5%:如果之前 DHCP Server 没有回应续租请求,等到租约期的 7/8 时,主机会再发送一次广播请求

同网段多 DHCP 服务器

  • DHCP 服务必须基于本地
  • 先到先得的原则

跨网段

  • RFC 1542 Compliant Routers
  • dhcp relay agent: 中继代理

相关协议

  • arp
  • rarp

租期:

  • 长租期:IP 相对稳定,网络资源消耗较少,但是浪费 IP 资源
  • 短租期:IP 相对不稳定,网络资源消耗较多,但是 IP 资源可以充分利用,可以实现较少 IP 为较多的主机服务

4.2 DHCP 实现

注意:实现 DHCP 服务前,先将网络已有 DHCP 服务,如:mware 中的 DHCP 关闭,访止冲突

DHCP 服务的实现软件:

  • dhcp(CentOS 7 之前版本) 或 dhcp-server(CentOS 8 中的包名)
  • dnsmasq:小型服务软件,可以提供 dhcp 和 dns 功能

4.2.1 DHCP 相关文件组成

dhcp 或 dhcp-server 包文件组成

  • /usr/sbin/dhcpd dhcp 服务主程序
  • /etc/dhcp/dhcpd.conf dhcp 服务配置文件
  • /usr/share/doc/dhcp-server/dhcpd.conf.example #dhcp 服务配置范例文件
  • /usr/lib/systemd/system/dhcpd.service #dhcp 服务 service 文件
  • /var/lib/dhcpd/dhcpd.leases 地址分配记录

dhcp-client 客户端包

  • /usr/sbin/dhclient #客户端程序
  • /var/lib/dhclient #自动获取的 IP 信息

windows 工具

  • ipconfig /release #释放 DHCP 获取的 IP,重新申请 IP
  • ipconfig/renew #刷新租约,续约

4.2.2 DHCP 服务器配置文件

帮助参考:man 5 dhcpd.conf

/etc/dhcp/dhcpd.conf 格式

全局配置
subnet {
...
}
host {
}

检查语法命令:service dhcpd configtest (CentOS 6 之前版本支持)

范例:dhcpd.conf

[15:46:13 root@centos7 ~]#cat /etc/dhcp/dhcpd.conf
#

# DHCP Server Configuration file.

# see /usr/share/doc/dhcp*/dhcpd.conf.example

# see dhcpd.conf(5) man page

#
option domain-name "zhang.org";             #为客户端指明DNS名字
option domain-name-servers 180.76.76.76,223.6.6.6;  #为客户端指明DNS服务器IP地址
default-lease-time 600;     #指定缺省租赁的时间的长度,单位是秒
max-lease-time 7200;       #指定最大租赁的时间长度,单位是秒
log-facility local7;
subnet 192.168.10.0 netmask 255.255.255.0 {
range 192.168.10.230 192.168.10.240;      #地址池
option routers 192.168.10.2;              #默认网关
next-server 192.168.10.71;
filename "pxelinux.0";
}
host testclient {                               下面这个表示这个地址跟主机是绑定的
hardware ethernet 00:0c:29:a0:fc:7d;
fixed-address 192.168.10.111;
default-lease-time 86400;
max-lease-time 864000;
option routers 192.168.10.2;
option domain-name-servers 114.114.114.114,8.8.8.8 ;
option domain-name "zhang.net";
}

DHCP 配置文件其它配置选项:

  • next-server:提供引导文件的服务器 IP 地址
  • filename: 指明引导文件名称
subnet 192.168.10.0 netmask 255.255.255.0 {
range 192.168.10.230 192.168.10.240;      #地址池
option routers 192.168.10.2;              #默认网关
next-server 192.168.10.71;                #TFTP服务器地址
filename "pxelinux.0";                    #bootloader启动文件的名称
}

范例:dhcp 客户端申请地址的过程

[root@localhost ~]# dhclient -d
Internet Systems Consortium DHCP Client 4.1.1-P1
Copyright 2004-2010 Internet Systems Consortium.
All rights reserved.
For info, please visit https://www.isc.org/software/dhcp/

Listening on LPF/eth0/00:0c:29:a0:fc:7d
Sending on   LPF/eth0/00:0c:29:a0:fc:7d
Sending on   Socket/fallback
DHCPDISCOVER on eth0 to 255.255.255.255 port 67 interval 8 (xid=0x1c4b1bad)
DHCPOFFER from 192.168.10.71
DHCPREQUEST on eth0 to 255.255.255.255 port 67 (xid=0x1c4b1bad)
DHCPACK from 192.168.10.71 (xid=0x1c4b1bad)
bound to 192.168.10.111 -- renewal in 34688 seconds.

#DHCP客户端日志
[root@localhost ~]# cat /var/lib/dhclient/dhclient.leases
lease {
interface "eth0";
fixed-address 192.168.10.111;
option subnet-mask 255.255.255.0;
option routers 192.168.10.2;
option dhcp-lease-time 86400;
option dhcp-message-type 5;
option domain-name-servers 114.114.114.114,8.8.8.8;
option dhcp-server-identifier 192.168.10.71;
option domain-name "zhang.net";
renew 0 2021/01/17 17:43:55;
rebind 1 2021/01/18 05:05:45;
expire 1 2021/01/18 08:05:45;
}
#服务器的日志
[16:02:28 root@centos7 ~]#cat /var/lib/dhcpd/dhcpd.leases

范例:DHCP服务器给指定主机分配固定IP

[16:08:10 root@centos7 ~]#vim /etc/dhcp/dhcpd.conf
host test {
hardware ethernet 00:0c:29:a0:fc:7d;
fixed-address 192.168.10.111;
}

5 实现 TFTP 服务

5.1 TFTP 介绍

TFTP:Trivial File Transfer Protocol ,是一种用于传输文件的简单高级协议,是文件传输协议(FTP) 的简化版本。用来传输比文件传输协议(FTP)更易于使用但功能较少的文件

TFTP 和 FTP 的区别

  1. 安全性区别

FTP 支持登录安全,具有适当的身份验证和加密协议,在建立连接期间需要与 FTP 身份验证通信

TFTP 是一种开放协议,缺乏安全性,没有加密机制,与 TFTP 通信时不需要认证

  1. 传输层协议的区别

FTP 使用 TCP 作为传输层协议,TFTP 使用 UDP 作为传输层协议

  1. 使用端口的区别

FTP 使用 2 个端口:TCP 端口 21,是个侦听端口;TCP 端口 20 或更高 TCP 端口 1024 以上用于源连接

TFTP 仅使用一个具有停止和等待模式的端口:端口:69/udp

  1. RFC 的区别

FTP 是基于 RFC 959 文档,带有其他 RFC 涵盖安全措施;TFTP 基于 RFC 1350 文档

  1. 执行命令的区别

FTP 有许多可以执行的命令(get,put,ls,dir,lcd)并且可以列出目录等

TFTP 只有 5 个指令可以执行(rrq,wrq,data,ack,error)

5.2 安装和使用 TFTP

安装包:

  • tftp-server #服务器包
  • tftp #客户端包

范例:安装并使用 tftp 下载文件

#安装tftp包
[16:11:05 root@centos7 ~]#yum install tftp-server.x86_64
[16:15:03 root@centos7 ~]#rpm -ql tftp-server
/etc/xinetd.d/tftp
/usr/lib/systemd/system/tftp.service    #tftp service文件
/usr/lib/systemd/system/tftp.socket     #tftp socket文件
/usr/sbin/in.tftpd                      #tftp主程序
/usr/share/doc/tftp-server-5.2
/usr/share/doc/tftp-server-5.2/CHANGES
/usr/share/doc/tftp-server-5.2/README
/usr/share/doc/tftp-server-5.2/README.security
/usr/share/man/man8/in.tftpd.8.gz
/usr/share/man/man8/tftpd.8.gz
/var/lib/tftpboot                      #TFTP服务数据目录
#启动服务
[16:17:14 root@centos7 ~]#systemctl start tftp.socket
[16:20:17 root@centos7 ~]#ss -nulp | grep systemd
UNCONN     0      0         [::]:69                    [::]:*                   users:(("systemd",pid=1,fd=40))

#准备测试文件
[16:20:26 root@centos7 ~]#cp /etc/fstab /var/lib/tftpboot/f1.txt
[16:20:57 root@centos7 ~]#mkdir /var/lib/tftpboot/dir
[16:21:12 root@centos7 ~]#cp /etc/passwd /var/lib/tftpboot/dir/f2.txt

#安装tftp客户端包
[16:22:29 root@centos7 ~]#tftp 192.168.10.71
tftp> help
tftp-hpa 5.2
Commands may be abbreviated.  Commands are:

connect 	connect to remote tftp
mode    	set file transfer mode
put     	send file
get     	receive file
quit    	exit tftp
verbose 	toggle verbose mode
trace   	toggle packet tracing
literal 	toggle literal mode, ignore ':' in file name
status  	show current status
binary  	set mode to octet
ascii   	set mode to netascii
rexmt   	set per-packet transmission timeout
timeout 	set total retransmission timeout
?       	print help information
help    	print help information
tftp> get f1.txt
tftp> get dir/f2.txt
tftp> quit
[16:23:45 root@centos7 ~]#ls
boot.iso  f1.txt  f2.txt  ks-centos6.cfg  ks-centos8.cfg  ks.cfg  swap.img
  • 运维

    互联网运维工作,以服务为中心,以稳定、安全、高效为三个基本点,确保公司的互联网业务能够 7×24 小时为用户提供高质量的服务。

    148 引用 • 257 回帖 • 2 关注

相关帖子

欢迎来到这里!

我们正在构建一个小众社区,大家在这里相互信任,以平等 • 自由 • 奔放的价值观进行分享交流。最终,希望大家能够找到与自己志同道合的伙伴,共同成长。

注册 关于
请输入回帖内容 ...