🎈 作者:Linux猿
🎈 简介:CSDN博客专家🏆,华为云享专家🏆,Linux、C/C++、云计算、物联网、面试、刷题、算法尽管咨询我,关注我,有问题私聊!
🎈 欢迎小伙伴们点赞👍、收藏⭐、留言💬
目录
本篇文章介绍安装 FastDFS 的过程。
一、安装环境
本文是安装在虚拟机里的 CentOS 7.9,如下所示。
[node@k8s-node-1 ~]$ cat /etc/centos-release
CentOS Linux release 7.9.2009 (Core)
[node@k8s-node-1 ~]$
二、准备工作
2.1 安装 git
执行如下命令安装 git,用于克隆 FastDFS 仓库。
[node@k8s-node-1 ~]$ sudo yum install git -y
2.2 安装 gcc 和 g++
用于编译源码,执行如下命令。
[node@k8s-node-1 ~]$ sudo yum install gcc gcc-c++ -y
2.3 安装 perl
安装 perl,用于编译源码,执行如下命令。
[node@k8s-node-1 ~]$ sudo yum install perl -y
三、安装 FastDFS
3.1 安装 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
3.2 安装 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
4.1 修改 tracker.conf 配置文件
修改配置文件 /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
4.2 修改 storage.conf 配置文件
主要修改 3 处,两处是路径修改,另外一处是 tracker_server 的 IP 修改,注销原来的两个 tracker_server,添加一个新的 tracker_server,IP 是本机 IP,如下所示。
# 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
4.3 修改 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
执行如下命令查看进程是否启动成功。
[node@k8s-node-1 ~]$ ps -ef | grep fdfs
node 52002 1 0 22:57 ? 00:00:00 /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart
node 52111 1 4 22:57 ? 00:00:03 /usr/bin/fdfs_storaged /etc/fdfs/storage.conf restart
验证是否可以上传文件,执行如下命令上传文件 /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
根据返回信息显示,上传文件存储的路径是 /home/node/fastdfs/data/00/00,其中 /00/00 是从返回信息中获取,查看目录下的信息是否有上传的文件。
[node@k8s-node-1 00]$ ls
wKjnl2Se7qOAeXeIAACE7hQ7S5c46158_big.h wKjnl2Se7qOAeXeIAACE7hQ7S5c46158.h
wKjnl2Se7qOAeXeIAACE7hQ7S5c46158_big.h-m wKjnl2Se7qOAeXeIAACE7hQ7S5c46158.h-m
FastDFS 安装成功。
参考链接: