针对 CentOS 7的环境,这是 FastDFS 的部署步骤:
安装所需的依赖
在安装 FastDFS 之前,确保已经安装了以下软件包:
sudo yum update -y
sudo yum install -y gcc make git
安装 libfastcommon
tar -zxvf libfastcommonV1.0.7.tar.gz
cd libfastcommon-1.0.7/
./make.sh
sudo ./make.sh install
安装 FastDFS
tar -zxvf FastDFS_v5.05.tar.gz
cd FastDFS/
./make.sh
sudo ./make.sh install
配置 FastDFS
修改 Tracker 的配置:
cp /etc/fdfs/tracker.conf.sample /etc/fdfs/tracker.conf
在 /etc/fdfs/tracker.conf 里面,主要修改以下内容:
base_path=/data/fastdfs/tracker
http.server_port=80
确保 base_path 所指的目录存在并有适当的权限。
修改 Storage 的配置:
cp /etc/fdfs/storage.conf.sample /etc/fdfs/storage.conf
在 /etc/fdfs/storage.conf 里面,主要修改以下内容:
base_path=/data/fastdfs/storage
store_path0=/data/fastdfs/storage_data
tracker_server=[YOUR_SERVER_IP]:22122
http.server_port=80
同样,确保目录存在并有适当的权限。注意这里YOUR_SERVER_IP不可以写127.0.0.1
启动 FastDFS
启动 Tracker:
sudo fdfs_trackerd /etc/fdfs/tracker.conf
启动 Storage:
sudo fdfs_storaged /etc/fdfs/storage.conf
设置开机自启
当然可以,你可以使用 rc.local 来执行开机启动命令。在 CentOS 7 中,rc.local 仍然存在,但默认可能不是可执行的。以下是将你的命令添加到 rc.local 并确保它在开机时执行的步骤:
/etc/rc.d/rc.local 文件:sudo nano /etc/rc.d/rc.local
sudo fdfs_trackerd /etc/fdfs/tracker.conf
sudo fdfs_storaged /etc/fdfs/storage.conf
保存并退出编辑器。
确保 rc.local 是可执行的:
sudo chmod +x /etc/rc.d/rc.local
rc-local 服务(如果你还没有这样做的话):sudo systemctl start rc-local
sudo systemctl enable rc-local
这样,每次你的系统启动时,rc.local 将会被执行,从而也会运行你添加的命令。
不过,要注意的是,使用 rc.local 的方式比使用 systemd 的服务管理方式要简单得多,但它不提供像 systemd 那样的管理功能(例如查看服务状态、重启服务等)。在现代的 Linux 发行版中,更推荐使用 systemd 来管理和配置服务。
完成以上步骤后,FastDFS 应该已经成功部署在您的 CentOS 7.8 服务器上,并设置为开机自启动。当然,实际部署中,还可能需要进行一些额外的网络或防火墙配置,确保 FastDFS 服务可以被外部访问。
验证:
在成功部署 FastDFS 后,您可以通过以下方式进行测试和简单使用:
查看进程状态
使用以下命令来查看 tracker 和 storage 的进程状态:
ps aux | grep fdfs
如果进程正在运行,您应该能看到 fdfs_trackerd 和 fdfs_storaged 相关的进程。
测试文件上传
FastDFS 提供了一些命令行工具来帮助您进行测试。您可以使用 fdfs_test 命令来测试文件上传。
首先,创建一个客户端配置文件:
cp /etc/fdfs/client.conf.sample /etc/fdfs/client.conf
编辑 /etc/fdfs/client.conf 文件,修改以下内容:
base_path=/data/fastdfs/client
tracker_server=[YOUR_SERVER_IP]:22122
确保 base_path 所指的目录存在并有适当的权限。
使用 fdfs_test 命令上传文件:
fdfs_test /etc/fdfs/client.conf upload your_test_file.txt
如果一切正常,命令会返回文件的存储路径和其他相关信息。
其他常用命令
上传文件:
fdfs_upload_file /etc/fdfs/client.conf your_file.txt
下载文件:
fdfs_download_file /etc/fdfs/client.conf your_file_remote_path local_save_path
删除文件:
fdfs_delete_file /etc/fdfs/client.conf your_file_remote_path
获取文件信息:
fdfs_file_info /etc/fdfs/client.conf your_file_remote_path
使用 FastDFS-nginx-module 与 Nginx
为了使得 FastDFS 存储的文件可以通过 HTTP/HTTPS 被外部访问,您可能会需要使用 FastDFS-nginx-module 与 Nginx。安装并配置该模块后,您可以直接使用浏览器或者其他 HTTP 客户端通过 URL 访问存储在 FastDFS 上的文件。
这只是 FastDFS 的简单测试和基本使用。实际应用中,您可能还需要进行进一步的配置和集成。如果您有任何疑问或需要更深入的指导,欢迎询问!
