- 1.安装FastDFS依赖环境
- 2.安装FastDFS依赖包libfastcommon
- 3.安装FastDFS
- 4.将配置文件复制到系统为fdfs预设的目录
- 5.查看安装FastDFS过程中产生的可执行文件
- 6.配置FastDFS
- 7.安装和配置fastdfs-nginx-module
- 8.安装和配置Nginx。
- 9.运行和验证
1.安装FastDFS依赖环境
yum install zlib zlib-devel pcre pcre-devel gcc gcc-c++ openssl openssl-devel libevent libevent-devel perl unzip net-tools wget -y
2.安装FastDFS依赖包libfastcommon
cd /usr/local/src
wget https://github.com/happyfish100/libfastcommon/archive/V1.0.38.tar.gz
tar -zxvf V1.0.38.tar.gz
cd libfastcommon-1.0.38/
./make.sh
./make.sh install
查看libfastcommon是否安装成功
cd /usr/lib && ll libfast*
显示 libfastcommon.so -> /usr/lib64/libfastcommon.so 安装成功
lrwxrwxrwx. 1 root root 27 9月 13 14:04 libfastcommon.so -> /usr/lib64/libfastcommon.so
3.安装FastDFS
cd /usr/local/src
wget https://github.com/happyfish100/fastdfs/archive/V5.11.tar.gz
tar -zxvf V5.11.tar.gz
cd fastdfs-5.11/
./make.sh
./make.sh install
4.将配置文件复制到系统为fdfs预设的目录
cd /usr/local/src/fastdfs-5.11/conf
cp mime.types http.conf /etc/fdfs/
5.查看安装FastDFS过程中产生的可执行文件
ls -la /usr/bin/fdfs*
显示类似如下内容表示安装成功。
-rwxr-xr-x 1 root root 403928 9月 9 13:34 /usr/bin/fdfs_appender_test
-rwxr-xr-x 1 root root 403768 9月 9 13:34 /usr/bin/fdfs_appender_test1
-rwxr-xr-x 1 root root 385752 9月 9 13:34 /usr/bin/fdfs_append_file
-rwxr-xr-x 1 root root 385128 9月 9 13:34 /usr/bin/fdfs_crc32
-rwxr-xr-x 1 root root 385776 9月 9 13:34 /usr/bin/fdfs_delete_file
-rwxr-xr-x 1 root root 386760 9月 9 13:34 /usr/bin/fdfs_download_file
-rwxr-xr-x 1 root root 386000 9月 9 13:34 /usr/bin/fdfs_file_info
-rwxr-xr-x 1 root root 405288 9月 9 13:34 /usr/bin/fdfs_monitor
-rwxr-xr-x 1 root root 1387984 9月 9 13:34 /usr/bin/fdfs_storaged
-rwxr-xr-x 1 root root 409352 9月 9 13:34 /usr/bin/fdfs_test
-rwxr-xr-x 1 root root 408672 9月 9 13:34 /usr/bin/fdfs_test1
-rwxr-xr-x 1 root root 566008 9月 9 13:34 /usr/bin/fdfs_trackerd
-rwxr-xr-x 1 root root 390568 9月 9 13:34 /usr/bin/fdfs_upload_appender
-rwxr-xr-x 1 root root 391944 9月 9 13:34 /usr/bin/fdfs_upload_file
6.配置FastDFS
分别对tracker,storage,client进行配置
a) 创建目录
mkdir /home/fastdfs/tracker -p
mkdir /home/fastdfs/storage -p
b) 配置tracker
cd /etc/fdfs/
cp tracker.conf.sample tracker.conf
vi tracker.conf
将内容修改为“base_path=/home/fastdfs/tracker”和“thread_stack_size = 128KB”,如下面加粗部分所示:
# the base path to store data and log files
base_path=/home/fastdfs/tracker
......
# thread stack size, should >= 64KB
# default value is 64KB
thread_stack_size = 128KB
c) 启动tracker
ln -s /usr/bin/fdfs_trackerd /usr/local/bin
ln -s /usr/bin/stop.sh /usr/local/bin
ln -s /usr/bin/restart.sh /usr/local/bin
service fdfs_trackerd start # 启动
service fdfs_trackerd stop # 停止
service fdfs_trackerd status # 服务状态
d) 配置storage
配置storage。
cd /etc/fdfs/
cp storage.conf.sample storage.conf
vi storage.conf
将内容修改为“base_path=/home/fastdfs/storage”、“store_path0=/home/fastdfs/storage”和“tracker_server=XX.XX.XX.XX:22122”。
说明:
“tracker_server”中的“XX.XX.XX.XX”为本机的虚拟IP地址,可以通过ifconfig命令查询获取。
修改后的内容,如下面加粗部分所示,其中“192.168.1.206”为示例,应根据实际虚拟IP地址填写。
# the base path to store data and log files
base_path=/home/fastdfs/storage
...
# store_path#, based 0, if store_path0 not exists, it's value is base_path
# the paths must be exist
store_path0=/home/fastdfs/storage
#store_path1=/home/yuqing/fastdfs2
.....
# tracker_server can ocur more than once, and tracker_server format is
# "host:port", host can be hostname or ip address
tracker_server=192.168.1.206:22122
e) 启动storage
启动storage。
ln -s /usr/bin/fdfs_storaged /usr/local/bin # 创建软连接
service fdfs_storaged start # 启动
service fdfs_storaged stop # 停止
service fdfs_storaged status # 服务状态
查看storage启动日志。
vi /home/fastdfs/storage/logs/storaged.log
查看最后几行,显示类似如下所示,表示启动成功。
[2019-07-09 17:03:51] INFO - file: tracker_client_thread.c, line: 310, successfully connect to tracker server 192.168.1.206:2
2122, as a tracker client, my ip is 192.168.1.206
[2019-07-09 17:04:21] INFO - file: tracker_client_thread.c, line: 1263, tracker server 192.168.1.206:22122, set tracker leade
r: 192.168.1.206:22122
f) 配置client
cd /etc/fdfs/
cp client.conf.sample client.conf
vi client.conf
将内容修改为“base_path=/home/fastdfs/tracker”和“tracker_server=XX.XX.XX.XX:22122”。
说明:
“tracker_server”中的“XX.XX.XX.XX”为本机的虚拟IP地址,可以通过ifconfig命令查询获取。
修改后的内容,如下面加粗部分所示,其中“192.168.1.206”为示例,应根据实际虚拟IP地址填写。
# the base path to store log files
base_path=/home/fastdfs/tracker
......
# tracker_server can ocur more than once, and tracker_server format is
# "host:port", host can be hostname or ip address
tracker_server=192.168.1.206:22122
7.安装和配置fastdfs-nginx-module
a) 安装fastdfs-nginx-module
cd /usr/local/src
wget https://github.com/happyfish100/fastdfs-nginx-module/archive/V1.20.tar.gz
tar -zxvf V1.20.tar.gz
b) 配置fastdfs-nginx-module的“config”文件
cd /usr/local/src/fastdfs-nginx-module-1.20/src/
vi config
按照如下加粗所示,修改“ngx_module_incs”和“CORE_INCS”。
ngx_addon_name=ngx_http_fastdfs_module
if test -n "${ngx_module_link}"; then
ngx_module_type=HTTP
ngx_module_name=$ngx_addon_name
ngx_module_incs="/usr/include/fastdfs /usr/include/fastcommon/" #ngx_module_incs
ngx_module_libs="-lfastcommon -lfdfsclient"
ngx_module_srcs="$ngx_addon_dir/ngx_http_fastdfs_module.c"
ngx_module_deps=
CFLAGS="$CFLAGS -D_FILE_OFFSET_BITS=64 -DFDFS_OUTPUT_CHUNK_SIZE='256*1024' -DFDFS_MOD_CONF_FILENAME='\"/etc/fdfs/mod_fast
dfs.conf\"'"
. auto/module
else
HTTP_MODULES="$HTTP_MODULES ngx_http_fastdfs_module"
NGX_ADDON_SRCS="$NGX_ADDON_SRCS $ngx_addon_dir/ngx_http_fastdfs_module.c"
CORE_INCS="$CORE_INCS /usr/include/fastdfs /usr/include/fastcommon/" #CORE_INCS
CORE_LIBS="$CORE_LIBS -lfastcommon -lfdfsclient"
CFLAGS="$CFLAGS -D_FILE_OFFSET_BITS=64 -DFDFS_OUTPUT_CHUNK_SIZE='256*1024' -DFDFS_MOD_CONF_FILENAME='\"/etc/fdfs/mod_fast
dfs.conf\"'"
fi
c) 配置fastdfs-nginx-module的“mod_fastdfs.conf”文件
cp /usr/local/src/fastdfs-nginx-module-1.20/src/mod_fastdfs.conf /etc/fdfs/
vi /etc/fdfs/mod_fastdfs.conf
将内容修改为“base_path=/home/fastdfs”、“tracker_server=XX.XX.XX.XX:22122”、“url_have_group_name = true”和“store_path0=/home/fastdfs/storage”。
说明:
“tracker_server”中的“XX.XX.XX.XX”为本机的虚拟IP地址,可以通过ifconfig命令查询获取。
修改后的内容,如下面加粗部分所示,其中“192.168.1.206”为示例,应根据实际虚拟IP地址填写。
the base path to store log files
base_path=/home/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.1.206:22122
......
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/fastdfs/storage
8.安装和配置Nginx。
a) 安装Nginx
cd /usr/local/src/
wget http://nginx.org/download/nginx-1.15.2.tar.gz
tar -zxvf nginx-1.15.2.tar.gz
cd nginx-1.15.2
./configure --prefix=/usr/local/nginx --add-module=/usr/local/src/fastdfs-nginx-module-1.20/src/ --with-http_stub_status_module --with-http_ssl_module
说明:
如果Nginx编译安装时提示“the HTTP gzip module requires the zlib library”,请执行sudo yum install zlib-devel后再执行./configure --prefix=/usr/local/nginx --add-module=/usr/local/src/fastdfs-nginx-module-1.20/src/
make &&make install
b) 配置Nginx
cd /usr/local/nginx/conf/
vi nginx.conf
server {
listen80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location ~/M00{
root /home/fastdfs/storage/data;
ngx_fastdfs_module;
}
location / {
root html;
index index.html index.htm;
}
}
9.运行和验证
a) 启动nginx
cd /usr/local/nginx/sbin/
./nginx
b) 生成测试文件
cd /usr/local/src
touch a.txt
vi a.txt
插入如下内容并保存
kungpeng test fastdfs ok!
c) 生成文件链接
/usr/bin/fdfs_upload_file /etc/fdfs/client.conf a.txt
回显信息如下:
记录返回的信息为“group1/FAST/00/00/wKgBzl0khdiAWJcGAAAAGmbRVtQ604.txt”。
d) 访问文件
在浏览器中输入“http://[ECS IP]:80/group1/M00/00/00/wKgBzl0khdiAWJcGAAAAGmbRVtQ604.txt”可以看到返回的“a.txt”相关信息。