CentOS Linux 7.6 部署FTP教程
今天给大家介绍下在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 /mntmount: /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 DVDbaseurl=file:///mntgpgcheck=0enabled=1[root@hellodba yum.repos.d]# yum clean allLoaded plugins: fastestmirror, langpacksCleaning repos: ELCleaning up list of fastest mirrors
2.3、关闭SELINUX
[root@hellodba ~]# vi /etc/selinux/config//将SELINUX=enforcing//改为SELINUX=disabled[root@hellodba ~]# setenforce 0[root@hellodba ~]# getenforcePermissive
2.4、关闭防火墙
//查看防火墙状态[root@hellodba ~]# systemctl status firewalld● firewalld.service - firewalld - dynamic firewall daemonLoaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)Active: active (running) since Fri 2023-09-01 13:16:41 CST; 9s agoDocs: man:firewalld(1)Main PID: 77721 (firewalld)Tasks: 2CGroup: /system.slice/firewalld.service└─77721 /usr/bin/python -Es /usr/sbin/firewalld --nofork --nopidSep 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 firewalldRemoved 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 daemonLoaded: 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 ceshiChanging password for user ceshi.New password: ceshiBAD PASSWORD: The password is shorter than 8 charactersRetype new password: ceshipasswd: 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 vsftpdLoaded plugins: fastestmirror, langpacksLoading mirror speeds from cached hostfileResolving Dependencies--> Running transaction check---> Package vsftpd.x86_64 0:3.0.2-25.el7 will be installed--> Finished Dependency ResolutionDependencies Resolved==============================================================================================================================================================================================Package Arch Version Repository Size==============================================================================================================================================================================================Installing:vsftpd x86_64 3.0.2-25.el7 EL 171 kTransaction Summary==============================================================================================================================================================================================Install 1 PackageTotal download size: 171 kInstalled size: 353 kDownloading packages:Running transaction checkRunning transaction testTransaction test succeededRunning transactionInstalling : vsftpd-3.0.2-25.el7.x86_64 1/1Verifying : vsftpd-3.0.2-25.el7.x86_64 1/1Installed:vsftpd.x86_64 0:3.0.2-25.el7Complete![root@hellodba ~]# yum install -y ftpLoaded plugins: fastestmirror, langpacksLoading mirror speeds from cached hostfileResolving Dependencies--> Running transaction check---> Package ftp.x86_64 0:0.17-67.el7 will be installed--> Finished Dependency ResolutionDependencies Resolved==============================================================================================================================================================================================Package Arch Version Repository Size==============================================================================================================================================================================================Installing:ftp x86_64 0.17-67.el7 EL 61 kTransaction Summary==============================================================================================================================================================================================Install 1 PackageTotal download size: 61 kInstalled size: 96 kDownloading packages:Running transaction checkRunning transaction testTransaction test succeededRunning transactionInstalling : ftp-0.17-67.el7.x86_64 1/1Verifying : ftp-0.17-67.el7.x86_64 1/1Installed:ftp.x86_64 0:0.17-67.el7Complete!
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.confanonymous_enable=NOlocal_enable=YESwrite_enable=YESlocal_umask=000dirmessage_enable=YESxferlog_enable=YESconnect_from_port_20=YESxferlog_std_format=YESchroot_list_enable=YESchroot_list_file=/etc/vsftpd/chroot_listlisten=NOlisten_ipv6=YESpam_service_name=vsftpduserlist_enable=YEStcp_wrappers=YESallow_writeable_chroot=YES//创建 chroot_list 文件并添加FTP用户[root@hellodba vsftpd]# vi chroot_listceshi
3、重启FTP服务
[root@hellodba ~]# systemctl restart vsftpd[root@hellodba ~]# systemctl status vsftpd● vsftpd.service - Vsftpd ftp daemonLoaded: loaded (/usr/lib/systemd/system/vsftpd.service; disabled; vendor preset: disabled)Active: active (running) since Sat 2023-09-02 13:21:31 CST; 12s agoProcess: 19364 ExecStart=/usr/sbin/vsftpd /etc/vsftpd/vsftpd.conf (code=exited, status=0/SUCCESS)Main PID: 19365 (vsftpd)Tasks: 1CGroup: /system.slice/vsftpd.service└─19365 /usr/sbin/vsftpd /etc/vsftpd/vsftpd.confSep 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.52Connected to 192.168.0.52 (192.168.0.52).220 (vsFTPd 3.0.2)Name (192.168.0.52:root): ceshi331 Please specify the password.Password:230 Login successful.Remote system type is UNIX.Using binary mode to transfer files.ftp> ls227 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.log226 Directory send OK.ftp> pwd257 "/"
五、常用命令
// 启动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 daemonLoaded: loaded (/usr/lib/systemd/system/vsftpd.service; enabled; vendor preset: disabled)Active: active (running) since Sat 2023-09-23 19:56:17 CST; 5s agoProcess: 20167 ExecStart=/usr/sbin/vsftpd /etc/vsftpd/vsftpd.conf (code=exited, status=0/SUCCESS)Main PID: 20168 (vsftpd)Tasks: 1CGroup: /system.slice/vsftpd.service└─20168 /usr/sbin/vsftpd /etc/vsftpd/vsftpd.confSep 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 ftptcp6 0 0 :::21 :::* LISTEN 20168/vsftpd
六、写在后面
到此,基于CentOS Linux 7.6 部署FTP部署完毕。由于本人有限的能力和知识储备,如有错误敬请批评指正!
THE END
Hello DBA
一名无人知晓、平凡无奇的DBA。茶余饭后分享一些关于数据库方面的实操与心得。因本人能力和水平有限,定有错误和疏漏之处,敬请批评指正!
公众号
关注后可发消息