fastdfs

单点部署

# 安装依赖
[root@nfs ~]#  yum install -y gcc gcc-c++
[root@nfs ~]#  yum -y install libevent

# 安装libfastcommon
[root@nfs ~]# wget https://github.com/happyfish100/libfastcommon/archive/refs/tags/V1.0.39.tar.gz

# 解压
[root@nfs ~]# tar xf V1.0.39.tar.gz

# 编译安装
[root@nfs ~]# cd libfastcommon-1.0.39
[root@nfs libfastcommon-1.0.39]# ./make.sh && ./make.sh install

# 安装FastDFS
[root@nfs libfastcommon-1.0.39]# wget https://github.com/happyfish100/fastdfs/archive/refs/tags/V5.12.tar.gz

# 解压
[root@nfs libfastcommon-1.0.39]# tar xf V5.12.tar.gz

# 编译安装
[root@nfs libfastcommon-1.0.39]#  cd fastdfs-5.12
[root@nfs fastdfs-5.12]#  ./make.sh && ./make.sh install

# 准备配置文件
[root@nfs fastdfs-5.12]# cd /etc/fdfs
[root@nfs fdfs]# cp client.conf.sample client.conf
[root@nfs fdfs]# cp storage.conf.sample storage.conf
[root@nfs fdfs]# cp tracker.conf.sample tracker.conf

# 创建fastdfs目录
[root@nfs fdfs]# mkdir -p /fastdfs/{tracker,storage,client}

# tracker配置
[root@nfs fdfs]# vim /etc/fdfs/tracker.conf
base_path=/fastdfs/tracker

# storage配置
[root@nfs fdfs]# vim /etc/fdfs/storage.conf
base_path=/fastdfs/storage
store_path0=/fastdfs/storage
tracker_server=10.0.0.31:22122

# client配置
[root@nfs fdfs]# vim /etc/fdfs/client.conf
base_path=/fastdfs/client
tracker_server=10.0.0.31:22122

# 启动tracker跟踪器
[root@nfs fdfs]# fdfs_trackerd /etc/fdfs/tracker.conf

# 启动storage存储节点
[root@nfs fdfs]# fdfs_storaged /etc/fdfs/storage.conf

# 客户端测试
[root@nfs fdfs]# fdfs_monitor /etc/fdfs/client.conf

# 上传图片
[root@nfs fastdfs]# fdfs_upload_file /etc/fdfs/client.conf 202306281709442.jpg 
group1/M00/00/00/CgAAH2UkAkuAfvWQAAICm4Eb-IU343.jpg

# 查看
[root@nfs fastdfs]# ll /fastdfs/storage/data/00/00
total 132
-rw-r--r-- 1 root root 131739 Oct  9 21:38 CgAAH2UkAkuAfvWQAAICm4Eb-IU343.jpg

# 安装nginx
[root@nfs fastdfs]# yum install -y nginx

# 编辑nginx配置文件(删除nginx本身页面)
[root@nfs fastdfs]# vim /etc/nginx/conf.d/www.conf
server {
        listen 80;
        server_name _;

        location /group1/M00{
                alias /fastdfs/storage/data;
        }
}

# 启动nginx
[root@web01 ~]# systemctl start nginx

# 访问网页http://10.0.0.31/group1/M00/00/00/CgAAH2UkAkuAfvWQAAICm4Eb-IU343.jpg

image-20231009214338404

集群部署

环境准备

主机名 IP地址 角色
web01 10.0.0.7 Tracker、Client
web02 10.0.0.8 Storage
lb02 10.0.0.6 Storage

所有节点操作

# 安装依赖
[root@web01 ~]# yum install -y gcc gcc-c++
[root@web01 ~]# yum -y install libevent

# 安装libfastcommon
[root@web01 ~]# wgethttps://github.com/happyfish100/libfastcommon/archive/refs/tags/V1.0.39.tar.gz

# 解压
[root@web01 ~]# tar xf V1.0.39.tar.gz

# 编译安装
[root@web01 ~]# cd libfastcommon-1.0.39
[root@web01 libfastcommon-1.0.39]# ./make.sh && ./make.sh install

# 安装FastDFS
[root@web01 ~]# wget https://github.com/happyfish100/fastdfs/archive/refs/tags/V5.12.tar.gz

# 解压
[root@web01 ~]# tar xf V5.12.tar.gz

# 编译安装
[root@web01 ~]# cd fastdfs-5.12
[root@web01 fastdfs-5.12]# ./make.sh && ./make.sh install

# 准备配置文件
[root@web01 ~]# cd /etc/fdfs
[root@web01 fdfs]# cp client.conf.sample client.conf
[root@web01 fdfs]# cp storage.conf.sample storage.conf
[root@web01 fdfs]# cp tracker.conf.sample tracker.conf

Tracker节点信息配置(只需在tracker节点执行即可)

# 创建tracker工作目录(此目录用于保存tracker 的data和log)
[root@web01 fdfs]# mkdir -p /fastdfs_tracker

# 配置tracker
[root@web01 fdfs]# vim /etc/fdfs/tracker.conf
base_path=/fastdfs_tracker

# 启动Tracker
[root@web01 fdfs]# fdfs_trackerd /etc/fdfs/tracker.conf

# 配置client
[root@web01 fdfs]# vim client.conf
base_path=/fastdfs_tracker
tracker_server=10.0.0.7:22122

# 启动clinet
[root@web01 fdfs]# fdfs_monitor /etc/fdfs/client.conf

Storage配置(只需在storage节点执行即可)

# 建立存储目录
[root@web02 fdfs]# mkdir /fastdfs_storage
[root@web02 fdfs]# mkdir /fastdfs_storage_data
[root@lb02 fdfs]# mkdir /fastdfs_storage
[root@lb02 fdfs]# mkdir /fastdfs_storage_data

# 修改存储节点配置文件
[root@web02 fdfs]# vim /etc/fdfs/storage.conf
base_path=/fastdfs_storage
store_path0=/fastdfs_storage_data
tracker_server=10.0.0.71:22122
[root@lb02 fdfs]# vim /etc/fdfs/storage.conf
base_path=/fastdfs_storage
store_path0=/fastdfs_storage_data
tracker_server=10.0.0.71:22122

# 启动
[root@web02 fdfs]# fdfs_storaged /etc/fdfs/storage.conf
[root@lb01 fdfs]# fdfs_storaged /etc/fdfs/storage.conf

client

# 配置client
[root@web01 fdfs]# vim client.conf
base_path=/fastdfs_tracker
tracker_server=10.0.0.7:22122

# 启动clinet
[root@web01 fdfs]# fdfs_monitor /etc/fdfs/client.conf

# 上传图片
[root@web01 ~]# fdfs_upload_file /etc/fdfs/client.conf 1.jpg

nginx配置(Storage节点配置)

# 查看图片
[root@web02 fdfs]# ll /fastdfs_storage_data/data/00/00
total 44
-rw-r--r-- 1 root root 41409 Oct 9 18:26 CgAABmUj1WuASVMqAAChwfi33QI038.jpg
[root@lb02 fdfs]# ll /fastdfs_storage_data/data/00/00
total 44
-rw-r--r-- 1 root root 41409 Oct 9 18:26 CgAABmUj1WuASVMqAAChwfi33QI038.jpg

# 安装nginx
[root@web02 fdfs]# yum install -y nginx
[root@lb02 fdfs]# yum install -y nginx

# 删除nginx.conf内nginx本身页面

# 编辑nginx配置文件
[root@web02 fdfs]# vim /etc/nginx/conf.d/www.conf
server {
listen 80;
server_name _;
location /group1/M00{
alias /fastdfs_storage_data/data;
}
}

[root@lb02 fdfs]# vim /etc/nginx/conf.d/www.conf
server {
listen 80;
server_name _;
location /group1/M00{
alias /fastdfs_storage_data/data;
}
}

# 启动nginx
[root@web02 fdfs]# systemctl start nginx
[root@lb02 fdfs]# systemctl start nginx

# 浏览器访问
http://10.0.0.6/group1/M00/00/00/CgAABmUj1WuASVMqAAChwfi33QI038.jpg
http://10.0.0.8/group1/M00/00/00/CgAABmUj1WuASVMqAAChwfi33QI038.jpg