CentOS Linux 7.6 部署FTP教程
原创 Hello DBA Hello DBA 2023-09-24 20:55 发表于江苏 收录于合集#Linux2个
今天给大家介绍下在CentOS 7.6操作系统上部署FTP的过程,有需要的朋友参考。
墨天轮:https://www.modb.pro/u/15854
公众号:Hello DBA
一、前言
FTP是一个用于在网络中传输文件的协议,可用于文件传输、网站管理、文件备份和软件发布等多种用途。
二、安装前准备
1、环境介绍
类目 | 详情 | |
OS | CentOS Linux release 7.6 | |
HOSTNAME | hellodba | |
IP | 192.168.0.52 | |
CPU | 2C | |
Memory | 4G | |
Disk | 80G | / |
4G | /swap | |
30G | /FTP |
2、前期准备
2.1、挂载光驱
[root@hellodba ~]# mount /dev/cdrom /mnt
mount: /dev/sr0 is write-protected, mounting read-only
2.2、配置YUM源
[root@hellodba ~]# cd /etc/yum.repos.d
[root@hellodba yum.repos.d]# mkdir bak
[root@hellodba yum.repos.d]# mv *.repo bak
[root@hellodba yum.repos.d]# vi hellodba.repo
[EL]
name=Linux 7.6 DVD
baseurl=file:///mnt
gpgcheck=0
enabled=1
[root@hellodba yum.repos.d]# yum clean all
Loaded plugins: fastestmirror, langpacks
Cleaning repos: EL
Cleaning up list of fastest mirrors
2.3、关闭SELINUX
[root@hellodba ~]# vi /etc/selinux/config
//将
SELINUX=enforcing
//改为
SELINUX=disabled
[root@hellodba ~]# setenforce 0
[root@hellodba ~]# getenforce
Permissive
2.4、关闭防火墙
//查看防火墙状态
[root@hellodba ~]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
Active: active (running) since Fri 2023-09-01 13:16:41 CST; 9s ago
Docs: man:firewalld(1)
Main PID: 77721 (firewalld)
Tasks: 2
CGroup: /system.slice/firewalld.service
└─77721 /usr/bin/python -Es /usr/sbin/firewalld --nofork --nopid
Sep 01 13:16:41 hellodba systemd[1]: Starting firewalld - dynamic firewall daemon...
Sep 01 13:16:41 hellodba systemd[1]: Started firewalld - dynamic firewall daemon.
//关闭防火墙
[root@hellodba ~]# systemctl stop firewalld
//禁止防火墙开机自动启动
[root@hellodba ~]# systemctl disable firewalld
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
//查看防火墙状态
[root@hellodba ~]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
Active: inactive (dead)
Docs: man:firewalld(1)
Sep 01 13:16:41 hellodba systemd[1]: Starting firewalld - dynamic firewall daemon...
Sep 01 13:16:41 hellodba systemd[1]: Started firewalld - dynamic firewall daemon.
Sep 01 13:17:06 hellodba systemd[1]: Stopping firewalld - dynamic firewall daemon...
Sep 01 13:17:07 hellodba systemd[1]: Stopped firewalld - dynamic firewall daemon.
3、添加用户并限制目录及指定用户访问指定目录
3.1、创建 FTP专用目录
//创建FTP用户访问目录
[root@hellodba ~]# mkdir -p /FTP/data/ceshi
[root@hellodba ~]# chmod -R 775 /FTP/data/ceshi
[root@hellodba ~]# ls -ld /FTP/data/ceshi/
drwxrwxr-x. 2 root root 6 Sep 2 17:44 /FTP/data/ceshi/
3.2、建立FTP用户并指定目录
[root@hellodba ~]# useradd -g root -M -d /FTP/data/ceshi -s /sbin/nologin ceshi
[root@hellodba ~]# passwd ceshi
Changing password for user ceshi.
New password: ceshi
BAD PASSWORD: The password is shorter than 8 characters
Retype new password: ceshi
passwd: all authentication tokens updated successfully.
3.3、修改 /etc/shells
[root@hellodba ~]# vi /etc/shells
/sbin/nologin
--说明 /etc/shells文件的作用:
1) 系统某些服务在运行过程中,会去检查用户使用的shells,而这些shell查询就是借助/etc/shells这个文件。
2) 上面创建的FTP用户解释器为 /sbin/nologin,系统默认的 /etc/shells 文件里没有添加 /sbin/nologin,所以需将 /sbin/nologin 加入到 /etc/shells 文件中,否则FTP用户登录不了FTP服务。
三、安装vsftpd服务
1、通过YUM 安装vsftpd软件
[root@hellodba ~]# yum install -y vsftpd
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package vsftpd.x86_64 0:3.0.2-25.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
==============================================================================================================================================================================================
Package Arch Version Repository Size
==============================================================================================================================================================================================
Installing:
vsftpd x86_64 3.0.2-25.el7 EL 171 k
Transaction Summary
==============================================================================================================================================================================================
Install 1 Package
Total download size: 171 k
Installed size: 353 k
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : vsftpd-3.0.2-25.el7.x86_64 1/1
Verifying : vsftpd-3.0.2-25.el7.x86_64 1/1
Installed:
vsftpd.x86_64 0:3.0.2-25.el7
Complete!
[root@hellodba ~]# yum install -y ftp
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package ftp.x86_64 0:0.17-67.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
==============================================================================================================================================================================================
Package Arch Version Repository Size
==============================================================================================================================================================================================
Installing:
ftp x86_64 0.17-67.el7 EL 61 k
Transaction Summary
==============================================================================================================================================================================================
Install 1 Package
Total download size: 61 k
Installed size: 96 k
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : ftp-0.17-67.el7.x86_64 1/1
Verifying : ftp-0.17-67.el7.x86_64 1/1
Installed:
ftp.x86_64 0:0.17-67.el7
Complete!
2、配置vsftpd服务
[root@hellodba ~]# cd /etc/vsftpd/
[root@hellodba vsftpd]# ll
-rw-------. 1 root root 125 Oct 31 2018 ftpusers
-rw-------. 1 root root 361 Oct 31 2018 user_list
-rw-------. 1 root root 5116 Oct 31 2018 vsftpd.conf
-rwxr--r--. 1 root root 338 Oct 31 2018 vsftpd_conf_migrate.sh
[root@hellodba vsftpd]# cp vsftpd.conf vsftpd.conf_bak
[root@hellodba vsftpd]# vi vsftpd.conf
anonymous_enable=NO
local_enable=YES
write_enable=YES
local_umask=000
dirmessage_enable=YES
xferlog_enable=YES
connect_from_port_20=YES
xferlog_std_format=YES
chroot_list_enable=YES
chroot_list_file=/etc/vsftpd/chroot_list
listen=NO
listen_ipv6=YES
pam_service_name=vsftpd
userlist_enable=YES
tcp_wrappers=YES
allow_writeable_chroot=YES
//创建 chroot_list 文件并添加FTP用户
[root@hellodba vsftpd]# vi chroot_list
ceshi
3、重启FTP服务
[root@hellodba ~]# systemctl restart vsftpd
[root@hellodba ~]# systemctl status vsftpd
● vsftpd.service - Vsftpd ftp daemon
Loaded: loaded (/usr/lib/systemd/system/vsftpd.service; disabled; vendor preset: disabled)
Active: active (running) since Sat 2023-09-02 13:21:31 CST; 12s ago
Process: 19364 ExecStart=/usr/sbin/vsftpd /etc/vsftpd/vsftpd.conf (code=exited, status=0/SUCCESS)
Main PID: 19365 (vsftpd)
Tasks: 1
CGroup: /system.slice/vsftpd.service
└─19365 /usr/sbin/vsftpd /etc/vsftpd/vsftpd.conf
Sep 02 13:21:31 hellodba systemd[1]: Starting Vsftpd ftp daemon...
Sep 02 13:21:31 hellodba systemd[1]: Started Vsftpd ftp daemon.
四、登录测试
[root@hellodba ~]# touch /FTP/data/ceshi/test.log
[root@hellodba ~]# ftp 192.168.0.52
Connected to 192.168.0.52 (192.168.0.52).
220 (vsFTPd 3.0.2)
Name (192.168.0.52:root): ceshi
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> ls
227 Entering Passive Mode (192,168,0,52,55,10).
150 Here comes the directory listing.
-rw-r--r-- 1 0 0 0 Sep 02 10:12 test.log
226 Directory send OK.
ftp> pwd
257 "/"
五、常用命令
// 启动FTP
[root@hellodba ~]# systemctl start vsftpd.service
//设置开机自动启动
[root@hellodba ~]# systemctl enable vsftpd.service
//停止FTP
[root@hellodba ~]# systemctl stop vsftpd.service
//查看FTP状态
[root@hellodba ~]# systemctl status vsftpd
● vsftpd.service - Vsftpd ftp daemon
Loaded: loaded (/usr/lib/systemd/system/vsftpd.service; enabled; vendor preset: disabled)
Active: active (running) since Sat 2023-09-23 19:56:17 CST; 5s ago
Process: 20167 ExecStart=/usr/sbin/vsftpd /etc/vsftpd/vsftpd.conf (code=exited, status=0/SUCCESS)
Main PID: 20168 (vsftpd)
Tasks: 1
CGroup: /system.slice/vsftpd.service
└─20168 /usr/sbin/vsftpd /etc/vsftpd/vsftpd.conf
Sep 23 19:56:17 hellodba systemd[1]: Starting Vsftpd ftp daemon...
Sep 23 19:56:17 hellodba systemd[1]: Started Vsftpd ftp daemon.
//查看FTP端口
[root@hellodba ~]# netstat -antup | grep ftp
tcp6 0 0 :::21 :::* LISTEN 20168/vsftpd
六、写在后面
到此,基于CentOS Linux 7.6 部署FTP部署完毕。由于本人有限的能力和知识储备,如有错误敬请批评指正!
THE END
Hello DBA 一名无人知晓、平凡无奇的DBA。茶余饭后分享一些关于数据库方面的实操与心得。因本人能力和水平有限,定有错误和疏漏之处,敬请批评指正! 3篇原创内容 公众号 收录于合集 #Linux 2个 上一篇SUSE Linux Enterprise Server 12 SP5 终端显示设置 阅读原文 阅读 375 Hello DBA 收藏此内容的人还喜欢 实操指南:一步步教你在Red Hat Linux 7.6文件系统安装Oracle 11g数据库,并解决常见安装问题! Hello DBA 不看的原因
- 内容质量低
- 不看此公众号
- 内容质量低
- 不看此公众号
- 内容质量低
- 不看此公众号
人划线
标签:FTP,service,firewalld,vsftpd,服务器,hellodba,root,搭建 From: https://www.cnblogs.com/cherishthepresent/p/17757609.html