Ubuntu下安装并配置FastDFS

711 阅读2分钟

参考文章:www.linuxdiyf.com/linux/27518…

第一步:安装下载和编译必要的工具以及进入root用户

# 安装git
sudo apt-get install git

# 安装make和gcc
sudo apt-get install gcc make -y

# 设置root用户密码
sudo passwd(接下来要输入设置的密码)

# 创建之后包下载的路径并进入
mkdir /software
cd /software

第二步:克隆libfastcommon库并安装

# 克隆libfastcommon到本地
git clone https://github.com/happyfish100/libfastcommon.git  

# 进入libfastcommon目录,依次执行脚本:
cd /software/libfastcommon目录
./make.sh  
./make.sh install

第三步:设置环境变量和软连接

# 在32位ubuntu中,libfastcommon会安装在/usr/lib 中,64位系统则安装在 /usr/lib64 中。依次执行以下命令:(根据自己的操作系统选择路径)

export LD_LIBRARY_PATH=/usr/lib/  

ln -s /usr/lib/libfastcommon.so /usr/local/lib/libfastcommon.so

第四步:下载、解压并安装FastDFS

FastDFS的Github下载地址为:github.com/happyfish10… 有可能使用wget下载github中的压缩包的时候出现403错误,需要执行如下命令解决问题:

  $ git config --global --unset http.proxy
  $ git config --global --unset https.proxy
# 下载最新版本到/software目录下,当前最新版本为6.8
wget https://github.com/happyfish100/fastdfs/archive/refs/tags/V6.08.tar.gz

# 解压并进入
tar -zxvf V6.08.tar.gz
cd fastdfs-6.08

# 安装
./make.sh
./make.sh install

第五步:修改配置文件

在默认安装路径 /etc/fdfs 下,有四个配置文件:

client.conf storage.conf  storage_ids.conf  tracker.conf

我们还需要将/software/fastdfs-6.08/conf目录中的http.conf配置文件拷贝到/etc/fdfs目录下

cp /software/fastdfs-6.08/conf/http.conf /etc/fdfs

因此/etc/fdfs目录下一共存在5个配置文件:

client.conf  http.conf  storage.conf  storage_ids.conf  tracker.conf

**修改tracker.conf 文件

修改 tracker.conf 文件中的日志存放路径 和 tracker server HTTP端口号:

# the base path to store data and log files  
base_path=/home/ubuntu/fastdfs/log  

注意,这个路径是根据实际情况自定义的,文件路径需要安装者手动创建,否则后续步骤会报“路径不存在”的错误,下同。

如果HTTP端口号冲突则修改:

# HTTP port on this tracker server  
http.server_port=8090

接下来修改 storage.conf 文件

group_name=group1  

store_path0=/home/ubuntu/fastdfs/storage0  

base_path=/home/buntu/fastdfs/log  

tracker_server=192.168.64.3:22122  (当前主机的ip)

http.server_port=8888  

配置文件里有详细注释说明,这里不再赘述每个参数的作用。

继续修改 client.conf 文件

base_path=/home/ubuntu/fastdfs/log  

tracker_server=192.168.64.3:22122  

http.tracker_server_port=8888  

#include http.conf  
注意,#include http.conf 这句,原配置文件中有2个#,删掉一个。

修改storage_ids.conf

100001   group0  192.168.64.3

修改 http.conf 文件 http.conf 文件在解压目录的conf目录下,里面有个默认图片路径,愿意改就改了吧。

http.anti_steal.token_check_fail=/home/fastdfs/anti-steal.jpg

第六步:启动服务

依次执行(前提是要先创建配置文件中自定义的路径)

mkdir -p ~/fastdfs/storage0 
mkdir -p ~/fastdfs/log
/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf  
/usr/bin/fdfs_storaged /etc/fdfs/storage.conf

第七步:测试上传文件

首先准备一张图片文件,例如:/home/ubuntu/qq.jpg 将这张图片上传至FastDFS,执行:

fdfs_test /etc/fdfs/client.conf upload /home/software/qq.jpg