FastDFS服务器部署 | Eddie'Blog
FastDFS服务器部署

FastDFS服务器部署

eddie 571 2020-09-21

目录

一、环境准备 (All Server)

官方文档:https://github.com/happyfish100/fastdfs/wiki

系统准备

需要两台服务器或者是虚拟机

类型系统
trackercentos 7.x
storagecentos 7.x

编译环境

yum install git gcc gcc-c++ make automake autoconf libtool pcre pcre-devel zlib zlib-devel openssl-devel wget vim -y

安装包

[root@localhost ~]# mkdir -p /home/software

[root@localhost software]# unzip FastDFS.zip 

[root@localhost conf]# ls -la /home/software/
total 3956
drwxr-xr-x.  4 root root     202 Sep 15 16:00 .
drwxr-xr-x.  4 root root      38 Sep 15 15:53 ..
-rw-r--r--.  1 root root  800157 Apr  3 22:05 fastdfs-6.04.tar.gz
-rw-r--r--.  1 root root   19952 Apr  3 22:05 fastdfs-nginx-module-1.22.tar.gz
-rw-r--r--.  1 root root  164704 Apr  3 22:05 libfastcommon-1.0.42.tar.gz
-rw-r--r--.  1 root root 1032630 Apr  3 22:05 nginx-1.16.1.tar.gz

链接:https://pan.baidu.com/s/1_NNy7GgjYk8ld301yh1Cug
提取码:dh9o

解压与编译

  1. 安装libfastcommon
tar -zxvf libfastcommon-1.0.42.tar.gz
cd libfastcommon-1.0.42/
./make.sh && ./make.sh install
  1. 安装FastDFS
tar -zxvf fastdfs-6.04.tar.gz
cd fastdfs-6.04/
./make.sh && ./make.sh install
cd /usr/bin/
ls fdfs_*   

#配置文件准备
cp /home/software/fastdfs-6.04/conf/* /etc/fdfs/
ls -la /etc/fdfs/

二、配置 tracker 服务 (2-4)

2.1 递归创建目录
mkdir -p /usr/local/fastdfs/tracker

2.2 修改base_path路径
vim /etc/fdfs/tracker.conf

[root@localhost fdfs]# cat /etc/fdfs/tracker.conf | grep -n 'base_path'
23:#base_path=/home/yuqing/fastdfs
24:base_path=/usr/local/fastdfs/tracker

2.3 启动服务
/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf

2.4
[root@localhost fdfs]# ps -ef | grep tracker
root      7785     1  0 19:49 ?        00:00:00 /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf
root      7793  6908  0 19:49 pts/0    00:00:00 grep --color=auto tracker

三、配置 storage 服务 (2-5)

3.1 查看与新建文件夹
ls -la /etc/fdfs/
mkdir -p /usr/local/fastdfs/storage

3.2 修改配置文件
vim /etc/fdfs/storage.conf

group_name=group1  -->  group_name=eddie  (之后会显示)

store_path0=/home/yuqing/fastdfs  --> store_path0=/usr/local/fastdfs/storage

base_path=/home/yuqing/fastdfs --> base_path=/usr/local/fastdfs/storage

有两个 tracker_server,屏蔽其中一个,修改剩余那个为tracker的ip地址
tracker_server=192.168.209.122:22122  --> tracker_server=192.168.8.246:22122

按需修改端扣, 默认8888
http.server_port=8888

3.3 启动服务
/usr/bin/fdfs_storaged /etc/fdfs/storage.conf

3.4 查看进程
ps -ef | grep storage

先启动 tracker 后启动 storage, 不然会出现 storage 发送心跳到 tracker

四、测试上传

4.1 查看与新建文件夹
ls -la /etc/fdfs/
mkdir -p /usr/local/fastdfs/storage/client

4.2 修改client配置
vim /etc/fdfs/client.conf

base_path=/home/yuqing/fastdfs  -->  base_path=/usr/local/fastdfs/storage/client

有两个 tracker_server,屏蔽其中一个,修改剩余那个为tracker的ip地址
tracker_server=192.168.0.197:22122 --> tracker_server=192.168.8.246:22122


4.3 随便找图片测试上传 (其中返回的地址是不能访问,需要配合Nginx)
/usr/bin/fdfs_test /etc/fdfs/client.conf upload eddie.jpg

查看图片位置

upload 之后会出现:
example file url: http://192.168.8.247/eddie/M00/00/00/wKgI919huMGANH5_AAAkLGQjp8o200_big.jpg

通过地址到/00/00/查找图片存储地方
ls -la  /usr/local/fastdfs/storage/data/00/00/

错误

errno: 113, error info: No route to host
关闭防火墙或者打开端口

五、配置nginx-fastdf文件

5.1 解压
tar -zxvf fastdfs-nginx-module-1.22.tar.gz

5.2 修改路径
vim /home/software/fastdfs-nginx-module-1.22/src/config 

ngx_module_incs="/usr/local/include"
CORE_INCS="$CORE_INCS /usr/local/include"
修改成:
ngx_module_incs="/usr/include"
CORE_INCS="$CORE_INCS /usr/include"

5.3 拷贝配置 (Nginx联调所使用)
cp mod_fastdfs.conf /etc/fdfs/
ls -la /etc/fdfs

六、安装Nginx

6.1 解压与安装
tar -zxvf nginx-1.16.1.tar.gz 

cd nginx-1.16.1/

mkdir -p /var/tmp/nginx
mkdir -p /var/temp/nginx/client

./configure \
--prefix=/usr/local/nginx \
--pid-path=/var/run/nginx/nginx.pid \
--lock-path=/var/log/nginx/nginx.lock \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--with-http_gzip_static_module \
--http-client-body-temp-path=/var/temp/nginx/client \
--http-proxy-temp-path=/var/temp/nginx/proxy \
--http-fastcgi-temp-path=/var/temp/nginx/fastcgi \
--http-uwsgi-temp-path=/var/temp/nginx/uwsgi \
--http-scgi-temp-path=/var/temp/nginx/scgi \
--add-module=/home/software/fastdfs-nginx-module-1.22/src

make
make install

/usr/local/nginx/sbin/nginx -V

---

6.2 创建文件夹
mkdir -p /usr/local/fastdfs/tmp

6.3 修改 mod_fastdfs.conf
vim /etc/fdfs/mod_fastdfs.conf

#base_path=/tmp
base_path=/usr/local/fastdfs/tmp

#tracker_server=tracker:22122
tracker_server=192.168.8.246:22122

#group_name=group1
group_name=eddie

#url_have_group_name = false
url_have_group_name = true

#store_path0=/home/yuqing/fastdfs
store_path0=/usr/local/fastdfs/storage

6.4 修改 nginx.conf

vim /usr/local/nginx/conf/nginx.conf

# 查看配置是否正常
/usr/local/nginx/sbin/nginx -t 

# 启动
/usr/local/nginx/sbin/nginx

# 重启
/usr/local/nginx/sbin/./nginx -s reload

6.5 浏览器查看图片
复制之前上传的图片名称
ls -la  /usr/local/fastdfs/storage/data/00/00/

http://192.168.8.247:8888/eddie/M00/00/00/wKgI919huMGANH5_AAAkLGQjp8o200.jpg

nginx.conf

worker_processes  1;

events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;

    sendfile        on;

    keepalive_timeout  65;

    server {
        listen       8888;
        server_name  localhost;

        location /eddie/M00 {
           ngx_fastdfs_module;
        }
    }
}