Fastdfs 安装教程

Fastdfs 安装教程

一、准备工作

安装git sudo yum install git -y
安装gcc g++ sudo yum install gcc gcc-c++ -y
安装 perl sudo yum install perl -y

二、 安装FastDFS

安装 libfastcommon
创建 installFastDFS 目录用于存储 FastDFS 需要编译的源码,进入目录,从远程仓库下载源码,执行如下命令。

[node@k8s-node-1 ~]$ mkdir installFastDFS
[node@k8s-node-1 ~]$ cd installFastDFS/
[node@k8s-node-1 installFastDFS]$ ls
[node@k8s-node-1 installFastDFS]$ git clone https://gitee.com/fastdfs100/libfastcommon.git
正克隆到 'libfastcommon'...
remote: Enumerating objects: 4872, done.
remote: Counting objects: 100% (693/693), done.
remote: Compressing objects: 100% (692/692), done.
remote: Total 4872 (delta 481), reused 0 (delta 0), pack-reused 4179
接收对象中: 100% (4872/4872), 1.72 MiB | 482.00 KiB/s, done.
处理 delta 中: 100% (3689/3689), done.
[node@k8s-node-1 installFastDFS]$

进入 libfastcommon 目录,切换版本为 V1.0.43,执行命令如下所示。

[node@k8s-node-1 installFastDFS]$ cd libfastcommon/
[node@k8s-node-1 libfastcommon]$ ls
debian  doc  HISTORY  INSTALL  libfastcommon.spec  LICENSE  make.sh  php-fastcommon  README  src
[node@k8s-node-1 libfastcommon]$ git checkout V1.0.43
Note: checking out 'V1.0.43'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:

  git checkout -b new_branch_name

HEAD 目前位于 c8c7566... upgrade version to 1.43
[node@k8s-node-1 libfastcommon]$

编译安装源码,执行如下命令。

[node@k8s-node-1 libfastcommon]$ ./make.sh clean && ./make.sh && sudo ./make.sh install

安装 FastDFS
在目录 ~/installFastDFS 下,执行命令下载源码。

[node@k8s-node-1 installFastDFS]$ git clone https://gitee.com/fastdfs100/fastdfs.git

进入 fastdfs 目录,切换到执行版本,执行命令如下。

[node@k8s-node-1 installFastDFS]$ cd fastdfs/
[node@k8s-node-1 fastdfs]$ git checkout V6.06

编译源码,执行命令如下。

[node@k8s-node-1 fastdfs]$ ./make.sh clean && ./make.sh && sudo ./make.sh install
四 修改配置文件

将 fastdfs 目录下的配置文件拷贝到 /etc/fdfs 目录下,执行命令如下。

[node@k8s-node-1 fastdfs]$ sudo ./setup.sh /etc/fdfs

修改配置文件 /etc/fdfs/tracker.conf, 执行命令如下所示

[node@k8s-node-1 fastdfs]$ sudo vim /etc/fdfs/tracker.conf

修改 base_path 如下所示,node 为当前操作的用户名。 如果文件夹没有的话,就手动创建下 并不一定要用户名之类的,只要相关配置文件路径正确就行

base_path = /home/node/fastdfs

创建 fastdfs 目录,执行命令如下所示。

[node@k8s-node-1 ~]$ mkdir ~/fastdfs

修改 storage.conf 配置文件
主要修改 3 处,两处是路径修改,另外一处是 tracker_server 的 IP 修改,注销原来的两个 tracker_server,添加一个新的 tracker_server,IP 是本机 IP,如下所示。 用户名为node为例

# tracker_server can ocur more than once for multi tracker servers.
# the value format of tracker_server is "HOST:PORT",
#   the HOST can be hostname or ip address,
#   and the HOST can be dual IPs or hostnames seperated by comma,
#   the dual IPS must be an inner (intranet) IP and an outer (extranet) IP,
#   or two different types of inner (intranet) IPs.
#   for example: 192.168.2.100,122.244.141.46:22122
#   another eg.: 192.168.1.10,172.17.4.21:22122

tracker_server = 192.168.231.152:22122 # 修改 1 : 192.168.231.152 是本机 IP
#tracker_server = 192.168.209.121:22122
#tracker_server = 192.168.209.122:22122


# the base path to store data and log files
# NOTE: the binlog files maybe are large, make sure
#       the base path has enough disk space,
#       eg. the disk free space should > 50GB
base_path = /home/node/fastdfs   # 修改 2 : 修改 yuqing 为 node

store_path0 = /home/node/fastdfs # 修改 3 : 修改 yuqing 为 node

修改 client.conf 配置文件
主要修改两处,第一处是修改 yuqing 为 node,第二处是先注释已有的两个 tracker_server,然后新加一行 tracker_server,其中 IP 为本机 IP。修改如下所示

[node@k8s-node-1 ~]$ sudo vim /etc/fdfs/client.conf

# the base path to store log files
base_path = /home/node/fastdfs   # 修改 1 : 修改 yuqing 为 node


# tracker_server can ocur more than once for multi tracker servers.
# the value format of tracker_server is "HOST:PORT",
#   the HOST can be hostname or ip address,
#   and the HOST can be dual IPs or hostnames seperated by comma,
#   the dual IPS must be an inner (intranet) IP and an outer (extranet) IP,
#   or two different types of inner (intranet) IPs.
#   for example: 192.168.2.100,122.244.141.46:22122
#   another eg.: 192.168.1.10,172.17.4.21:22122

tracker_server = 192.168.231.152:22122   # 修改 2 : 修改 tracker_server IP 为本机 IP
#tracker_server = 192.168.0.196:22122
#tracker_server = 192.168.0.197:22122
五、启动 tracker、storage 服务器和监控程序

执行如下命令。

[node@k8s-node-1 ~]$ /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart
[node@k8s-node-1 ~]$ /usr/bin/fdfs_storaged /etc/fdfs/storage.conf restart
[node@k8s-node-1 ~]$ /usr/bin/fdfs_monitor /etc/fdfs/client.conf

执行如下命令查看进程是否启动成功。

[root@hecs-270948 fdfs]# ps aux|grep fdfs

验证是否可以上传文件,执行如下命令上传文件 /usr/include/stdlib.h。

[node@k8s-node-1 ~]$ /usr/bin/fdfs_test /etc/fdfs/client.conf upload /usr/include/stdlib.h

记录返回的 group 和 filename 的值,如下所示。

group_name=group1, remote_filename=M00/00/00/wKjnl2Se7qOAeXeIAACE7hQ7S5c46158.h

如果上传不成功的话,看一下端口号有开放吗 端口号 23000 22122
一个是 tracker 服务器的 22122 端口,另一个是 storage 服务器的 23000 端口。

FastDFS 安装成功
但是安装成功后,浏览器却无法访问想要访问的话,需要以下操作

安装 FastDFS-Nginx 模块

  1. FastDFS-Nginx 模块下载到/usr/local/src下
cd /usr/local
git clone https://gitee.com/fastdfs100/fastdfs-nginx-module.git
克隆完成之后,进入该模块源码目录中,执行以下命令,切换到版本 V1.22:
cd fastdfs-nginx-module

宝塔安装完,在/www/server/nginx/src下重新编译nginx
cd /www/server/nginx/src

a. nginx -V 获取到之前的编译参数,兼容以前的nginx

--user=www --group=www --prefix=/www/server/nginx --add-module=/www/server/nginx/src/ngx_devel_kit --add-module=/www/server/nginx/src/lua_nginx_module --add-module=/www/server/nginx/src/ngx_cache_purge --add-module=/www/server/nginx/src/nginx-sticky-module --with-openssl=/www/server/nginx/src/openssl --with-pcre=pcre-8.43 --with-http_v2_module --with-stream --with-stream_ssl_module --with-stream_ssl_preread_module --with-http_stub_status_module --with-http_ssl_module --with-http_image_filter_module --with-http_gzip_static_module --with-http_gunzip_module --with-ipv6 --with-http_sub_module --with-http_flv_module --with-http_addition_module --with-http_realip_module --with-http_mp4_module --add-module=/www/server/nginx/src/ngx_http_substitutions_filter_module-master --with-ld-opt=-Wl,-E --with-cc-opt=-Wno-error --with-ld-opt=-ljemalloc --with-http_dav_module --add-module=/www/server/nginx/src/nginx-dav-ext-module

b. 添加fastdfs模块编译

./configure --user=www --group=www --prefix=/www/server/nginx --add-module=/www/server/nginx/src/ngx_devel_kit --add-module=/www/server/nginx/src/lua_nginx_module --add-module=/www/server/nginx/src/ngx_cache_purge --add-module=/www/server/nginx/src/nginx-sticky-module --with-openssl=/www/server/nginx/src/openssl --with-pcre=pcre-8.43 --with-http_v2_module --with-stream --with-stream_ssl_module --with-stream_ssl_preread_module --with-http_stub_status_module --with-http_ssl_module --with-http_image_filter_module --with-http_gzip_static_module --with-http_gunzip_module --with-ipv6 --with-http_sub_module --with-http_flv_module --with-http_addition_module --with-http_realip_module --with-http_mp4_module --add-module=/www/server/nginx/src/ngx_http_substitutions_filter_module-master --with-ld-opt=-Wl,-E --with-cc-opt=-Wno-error --with-ld-opt=-ljemalloc --with-http_dav_module --add-module=/www/server/nginx/src/nginx-dav-ext-module --add-module=/usr/local/src/fastdfs-nginx-module/src

make

c. 将objs/nginx拷贝到/www/server/nginx/sbin目录下

cp objs/nginx /www/server/nginx/sbin

新增 配置文件 为了防止端口冲突,可以自定义端口,但要记得开放

server {
        listen 9888;
        server_name localhost;
        #如果自己修改组名了,这块配自己修改的组名
        location ~/group([0-9])/M00 {
                ngx_fastdfs_module;
        }
}

修改 mod_fastdfs.conf 配置文件
将 /usr/local/fastdfs-nginx-module/src/mod_fastdfs.conf 配置文件复制到 /etc/fdfs 目录中。

然后编辑 /etc/fdfs/mod_fastdfs.conf 文件

base_path=/home/root/fastdfs

# FastDFS tracker_server can ocur more than once, and tracker_server format is
#  "host:port", host can be hostname or ip address
# valid only when load_fdfs_parameters_from_tracker is true
tracker_server=192.168.88.173:22122

# the port of the local storage server
# the default value is 23000
storage_server_port=23000

# the group name of the local storage server
group_name=group1

# if the url / uri including the group name
# set to false when uri like /M00/00/00/xxx
# set to true when uri like ${group_name}/M00/00/00/xxx, such as group1/M00/xxx
# default value is false
url_have_group_name = true

# store_path#, based 0, if store_path0 not exists, it's value is base_path
# the paths must be exist
# must same as storage.conf
store_path0=/home/node/fastdfs
#store_path1=/home/node/fastdfs1

主要修改五个点,第一个是 tracker 服务器的地址;第二个是 storage 服务器的端口;第三个是 group_name,这个和 storage.conf 配置文件中的保持一致;第四个是 url_have_group_name;第五个是 store_path0 文件存储路径。 base_path也要改下

启动nginx 就可以了

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值