一、Centos安装
1、系统配置
系统Centos7.8,系统最小安装即可,语言支持选择中文和英文(美国),安装位置默认自动分区,如图:
2、准备环境
①安装软件包
安装工具包vim、net-tools、lrzsz、bash-completion(bash自动补全)、psmisc(killall命令软件包):
$ sudo yum -y install vim net-tools lrzsz bash-completion psmisc
②关闭防火墙
$ sudo systemctl status firewalld # 查看防火墙状态
$ sudo systemctl stop firewalld # 关闭防火墙
$ sudo systemctl disable firewalld # 关闭开机启动
③关闭selinux
$ sudo vim /etc/selinux/config
把SELINUX的值enforcing 改为disabled,如图:
保持退出重启。
二、安装配置TFTP
1、安装依赖库和服务
安装xinetd、tftp、tftp-server安装命令如下:
$ sudo yum -y install xinetd tftp tftp-server
查看是否安装正常:
$ rpm -qa | gerp xinetd
$ rpm -qa | gerp tftp
配置TFTP
sudo vim /etc/xinetd.d/tftp
server_agrs改为自己准备存放的目录,并修改所设文件夹的权限,disable改为no:
$ sudo chmod 777 /share
重启TFTP服务
$ sudo systemctl restart xinetd.service
$ tftp localhost
在tftpboot文件夹中新建一个测试文件:vim 1.txt
在其他linux 设备上安装 tftp-client :tftp.x86_64
# yum -y install tftp.x86_64
通过命令tftp +服务器IP(192.168.100.97)进入tftp命令模式。
输入help命令,查看tftp支持的命令。
通过命令get 1.txt 就可以将/var/lib/tftpboot下的1.txt文件下载到当前目录下(我当前在/目录下),用ls命令查看当前目录下是否存在1.txt。
三、常见问题
- 如果上传时出现"连接请求失败"的提示,请确保tftp服务的文件存放目录权限设置正确
- 解决办法:chmod 0777 /var/lib/tftpboot
- 文件上传时提示:Error code 1: File not found
- 在/etc/xinetd.d/tftp配置文件中,server_args后加上 -c 选项,方可上传
service tftp
{
socket_type = dgram
protocol = udp
wait = yes
user = root
server = /usr/sbin/in.tftpd
server_args = -s /var/lib/tftpboot -c
disable = no
per_source = 11
cps = 100 2
flags = IPv4
}
- 如客户端无法连接,或包timeout
- 请确认服务器iptables策略开放了UDP的 69 端口,并关闭了selinux服务。 iptables策略开放:
[root@node03 ~]# vim /etc/sysconfig/iptables
# sample configuration for iptables service
# you can edit this manually or use system-config-firewall
# please do not ask us to add additional ports/services to this default configuration
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
-A INPUT -p udp -m state --state NEW -m tcp --dport 69 -j ACCEPT
- 或者执行如下命令:
iptables -A INPUT -p udp --dprot 69 -j ACCEPT