测试环境安装记录。
要安装的包:
从上面的链接(github)选择要使用的版本下载压缩包。
安装 libfastcommon
1、解压
tar -xvf libfastcommon-1.0.36.tar.gz
2、设置环境变量
设置环境变量,指定要安装到哪个目录(目录根据自己的需要设置)。不设置默认是 /usr/lib 或 /usr/lib64
export DESTDIR=/opt/fastdfs/fastdfs/fastcommon #设置安装路径变量
3、检查环境变量
echo $DESTDIR
/opt/fastdfs/fastdfs/fastcommon
4、进入解压后的目录
cd libfastcommon-1.0.36
5、编译
./make.sh
6、安装
./make.sh install
7、进入前面环境变量指定的目录看下安装结果:
xxxx@dev-testserver:/opt/fastdfs/libfastcommon-1.0.36$ cd /opt/fastdfs/fastdfs/fastcommon
xxxx@dev-testserver:/opt/fastdfs/fastdfs/fastcommon$ ll
total 12
drwxrwxr-x 3 xxxx xxxx 4096 Sep 9 02:36 ./
drwxrwxr-x 3 xxxx xxxx 4096 Sep 9 02:36 ../
drwxrwxr-x 4 xxxx xxxx 4096 Sep 9 02:36 usr/
xxxx@dev-testserver:/opt/fastdfs/fastdfs/fastcommon$ ll usr/
total 16
drwxrwxr-x 4 xxxx xxxx 4096 Sep 9 02:36 ./
drwxrwxr-x 3 xxxx xxxx 4096 Sep 9 02:36 ../
drwxrwxr-x 3 xxxx xxxx 4096 Sep 9 02:36 include/
drwxrwxr-x 2 xxxx xxxx 4096 Sep 9 02:36 lib/
xxxx@dev-testserver:/opt/fastdfs/fastdfs/fastcommon$ ll usr/lib/
total 1956
drwxrwxr-x 2 xxxx xxxx 4096 Sep 9 02:36 ./
drwxrwxr-x 4 xxxx xxxx 4096 Sep 9 02:36 ../
-rwxr-xr-x 1 xxxx xxxx 1991728 Sep 9 02:36 libfastcommon.so*
xxxx@dev-testserver:/opt/fastdfs/fastdfs/fastcommon$ usr/include/
total 12
drwxrwxr-x 3 xxxx xxxx 4096 Sep 9 02:36 ./
drwxrwxr-x 4 xxxx xxxx 4096 Sep 9 02:36 ../
drwxrwxr-x 2 xxxx xxxx 4096 Sep 9 02:36 fastcommon/
安装 libserverframe
要安装比较新版本 fastdfs,就需要装 libserverframe 这个。
github 上的介绍是:
this network service framework library extract from FastDFS
旧版本应该是没有单独把网络服务框架这部分拆出来,所以安装了 libfastcommon 之后直接装 fastdfs 就行(搜到的很多教程是这样的)。但是我装 fastdfs-6.12.1 版本,如果不提前装好 libserverframe 就会报错。
1、解压
tar -zxvf libserverframe-1.2.4.tar.gz
2、设置环境变量
设置环境变量,指定要安装到哪个目录(目录根据自己的需要设置)。
export DESTDIR=/opt/fastdfs/fastdfs/libserverframe #设置安装路径变量
3、检查环境变量
echo $DESTDIR
/opt/fastdfs/fastdfs/libserverframe
4、进入解压后的目录
cd libserverframe-1.2.4
5、在 Makefile.in 中增加 libfastcommon 安装后的动态库和头文件路径
vi src/MakeFile.in
在 INC_PATH 后添加:-I/opt/fastdfs/fastdfs/fastcommon/usr/include
(路径替换成自己前面设置的)
在 LIB_PATH 后添加:-L-L/opt/fastdfs/fastdfs/fastcommon/usr/lib
(路径替换成自己前面设置的)
6、编译
./make.sh
7、安装
./make.sh install
8、查看安装结果:
xxxx@dev-testserver:/opt/fastdfs/libserverframe-1.2.4$ cd /opt/fastdfs/fastdfs/libserverframe
xxxx@dev-testserver:/opt/fastdfs/fastdfs/libserverframe$ ll
total 12
drwxrwxr-x 3 xxxx xxxx 4096 Sep 9 03:02 ./
drwxrwxr-x 7 xxxx xxxx 4096 Sep 9 03:45 ../
drwxrwxr-x 4 xxxx xxxx 4096 Sep 9 03:02 usr/
xxxx@dev-testserver:/opt/fastdfs/fastdfs/libserverframe$ ll usr/
total 16
drwxrwxr-x 4 xxxx xxxx 4096 Sep 9 03:02 ./
drwxrwxr-x 3 xxxx xxxx 4096 Sep 9 03:02 ../
drwxrwxr-x 3 xxxx xxxx 4096 Sep 9 03:02 include/
drwxrwxr-x 2 xxxx xxxx 4096 Sep 9 03:02 lib/
xxxx@dev-testserver:/opt/fastdfs/fastdfs/libserverframe$ ll usr/lib/
total 1012
drwxrwxr-x 2 xxxx xxxx 4096 Sep 9 03:02 ./
drwxrwxr-x 4 xxxx xxxx 4096 Sep 9 03:02 ../
-rwxr-xr-x 1 xxxx xxxx 1024664 Sep 9 03:02 libserverframe.so*
xxxx@dev-testserver:/opt/fastdfs/fastdfs/libserverframe$ ll usr/include/
total 12
drwxrwxr-x 3 xxxx xxxx 4096 Sep 9 03:02 ./
drwxrwxr-x 4 xxxx xxxx 4096 Sep 9 03:02 ../
drwxrwxr-x 3 xxxx xxxx 4096 Sep 9 03:02 sf/
安装 fastdfs
安装
1、解压
tar zxvf fastdfs-6.12.1.tar.gz
2、设置环境变量
export DESTDIR=/opt/fastdfs/fastdfs # 安装目录
3、检查环境变量
echo $DESTDIR
/opt/fastdfs/fastdfs
4、进入解压后的目录
cd fastdfs-6.12.1
5、在 Makefile.in 中增加 libfastcommon 和libserverframe 安装后的动态库和头文件路径
storage/MakeFile.in、client/MakeFile.in、tracker/MakeFile.in 里的 INC_PATH 和 LIB_PATH,添加 libfastcommon、libserverframe 安装后的include和lib目录。
INC_PATH:-I/opt/fastdfs/fastdfs/fastcommon/usr/include/ -I/opt/fastdfs/fastdfs/libserverframe/usr/include
LIB_PATH:-L/opt/fastdfs/fastdfs/fastcommon/usr/lib -L/opt/fastdfs/fastdfs/libserverframe/usr/lib
配置
1、修改tracker配置
新建目录:
mkdir -p /opt/fastdfs/fastdfs/data/Tracker
修改配置文件
cd /opt/fastdfs/fastdfs
vi etc/fdfs/tracker.conf
修改配置参数如下:
base_path=/opt/fastdfs/fastdfs/data/Tracker
http.server_port=9000
2、启动服务
start_tracker.sh
#!/bin/bash
export LD_LIBRARY_PATH=/opt/fastdfs/fastdfs/fastcommon/usr/lib:/opt/fastdfs/fastdfs/libserverframe/usr/lib
nohup /opt/fastdfs/fastdfs/usr/bin/fdfs_trackerd /opt/fastdfs/fastdfs/etc/fdfs/tracker.conf > start_tracker.log 2>&1 &
2、修改client配置
新建目录:
mkdir -p /opt/fastdfs/fastdfs/data/Client
修改配置文件
cd /opt/fastdfs/fastdfs
vi /etc/fdfs/client.conf
修改配置参数如下:
base_path=/opt/fastdfs/fastdfs/data/Client
tracker_server=192.168.1.100:22122
3、修改Storage配置
新建目录:
mkdir -p /opt/fastdfs/fastdfs/data/Storage
cd /opt/fastdfs/fastdfs
vi etc/fdfs/storage.conf
修改配置参数如下:
修改配置参数如下:
base_path=/opt/fastdfs/fastdfs/data/Storage
tracker_server=10.1.4.52:22122
store_path0=/opt/fastdfs/fastdfs/data/Storage
4、启动
start_storage.sh
#!/bin/bash
export LD_LIBRARY_PATH=/opt/fastdfs/fastdfs/fastcommon/usr/lib:/opt/fastdfs/fastdfs/libserverframe/usr/lib
nohup /opt/fastdfs/fastdfs/usr/bin/fdfs_storaged /opt/fastdfs/fastdfs/etc/fdfs/storage.conf > start_storage.log 2>&1 &
测试
1、检查状态
cd /opt/fastdfs/fastdfs
export LD_LIBRARY_PATH=/opt/fastdfs/fastdfs/fastcommon/usr/lib:/opt/fastdfs/fastdfs/libserverframe/usr/lib
./usr/bin/fdfs_monitor etc/fdfs/client.conf
2、测试文件上传
随便创建个文件 test.txt。
cd /opt/fastdfs/fastdfs
export LD_LIBRARY_PATH=/opt/fastdfs/fastdfs/fastcommon/usr/lib:/opt/fastdfs/fastdfs/libserverframe/usr/lib
./usr/bin/fdfs_upload_file etc/fdfs/client.conf /opt/fastdfs/test.txt
返回:
group1/M00/00/00/CjVkuWbeiCOAecJuAAAAE3NyRxc987.txt
服务器实际存放文件的目录是 :
/opt/fastdfs/fastdfs/data/Storage/data/00/00/CjVkuWbeiCOAecJuAAAAE3NyRxc987.txt
可以配置nginx来访问文件。
server {
listen 8888;
server_name localhost;
location /group1/M00 {
alias /opt/fastdfs/fastdfs/data/Storage/data;
}
}
fastdfs也提供了一个nginx模块,可以安装到nginx上。如果有多个 Storage 服务器 a、b、c,上传文件的时候如果tracker上传到了a上,那么b、c同步文件需要一段时间,这段时间访问b、c下载文件会失败,用 fastdfs 提供的 nginx 模块就可以转发请求到 a上。