下载libfastcommon
、fastdfs
、fastdfs-nginx-module
wget https://github.com/happyfish100/libfastcommon/archive/V1.0.39.tar.gz -SO libfastcommon.tar.gz
wget https://github.com/happyfish100/fastdfs/archive/V5.11.tar.gz -SO fastdfs.tar.gz
wget https://github.com/happyfish100/fastdfs-nginx-module/archive/V1.20.tar.gz -SO fastdfs-nginx-module.tar.gz
# 解压
tar -xf xxx.tar.gz
一、安装 libfastcommon
wget https://github.com/happyfish100/libfastcommon/archive/V1.0.39.tar.gz -SO libfastcommon.tar.gz
[root@iz2zehtpzc0kbyxlwaw9lez fdfs-package]# wget https://github.com/happyfish100/libfastcommon/archive/V1.0.39.tar.gz -SO libfastcommon.tar.gz
-bash: wget: command not found
提示没有安装wget软件包
输入 yum -y install wget命令安装wget软件包
第一次安装不知道为什么会出现上述情况,然后敲击wget命令还是提示
并且重新输入yum -y install wget提示已经安装wget。
遇到上述情况重新卸载安装了一次wget就可以使用了
卸载wget命令 :yum remove wget卸载
安装成功提示。
然后开始下载安装libfastcommon吧
解压
安装
二、安装 fastdfs
./make.sh
./make.sh install
程序在use/bin目录下
配置文件在etc/fdfs目录下
但是etc/fdfs目录下的配置文件不全,并且都是模板,所以需要从fastdfs包中拷贝过来。并修改配置
进入fastdfs解压位置的目录下
cp conf/* /etc/fdfs/
修改配置
vi /etc/fdfs/tracker.conf
# the tracker server port
port=22122
# the base path to store data and log files
base_path=/home/caibh/fdfs
# HTTP port on this tracker server
http.server_port=9270
vi /etc/fdfs/storage.conf
#storage所属的组
# and storage_ids.conf must be configed correctly.
group_name=group1
# the storage server port
port=23000
# the base path to store data and log files
base_path=/home/caibh/fdfs
# store_path#, based 0, if store_path0 not exists, it's value is base_path
# the paths must be exist
store_path0=/home/caibh/fdfs
#store_path1=/home/yuqing/fastdfs2
#tracker服务器,虽然是同一台机器上,但不能写127.0.0.1.这项配置可以出现一次或者多次
# tracker_server can ocur more than once, and tracker_server format is
# "host:port", host can be hostname or ip address
tracker_server=172.24.3.205:22122
#tracker_server=192.168.209.121:22122
# the port of the web server on this storage server
http.server_port=8888
vi /etc/fdfs/client.conf
# the base path to store log files
base_path=/home/caibh/fdfs/client
# tracker_server can ocur more than once, and tracker_server format is
# "host:port", host can be hostname or ip address
tracker_server=172.24.3.205:22122
#HTTP settings
http.tracker_server_port=9270
vi /etc/fdfs/mod_fastdfs.conf
# the base path to store log files
base_path=/tmp
# 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=172.24.3.205: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
# 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/caibh/fdfs
#store_path1=/home/yuqing/fastdfs1
配置过程中有几点需要注意
- 确保配置中用到的目录已经创建了。比如
~/fdfs/client
、~/fdfs/data
、~/fdfs/logs
-
确保各种配置文件之间引用的端口一直。比如:
mod_fastdfs.conf
文件中tracker_server
的端口应该跟tracker.conf
中port
一致;mod_fastdfs.conf
文件中storage_server_port
的端口应该跟跟storage.conf
中port
一致;
-
其他配置或文件虽然不用修改,但是
fastdfs-nginx-module
模块会用到:anti-steal.jpg
http.conf
mime.types
启动tracker和storage
# 启动 fdfs_trackerd /etc/fdfs/tracker.conf start
fdfs_storaged /etc/fdfs/storage.conf start
# 查看日志
tail -n10 ~/fdfs/logs/trackerd.log
tail -n10 ~/fdfs/logs/storaged.log
# 如果日志显示有错误信息,需要根据信息来查找错误原因
用fdfs_test测试上传(进入该图片的目录下upload 上传)
fdfs_test /etc/fdfs/client.conf upload 3600.jpg
example file url: http://172.24.3.205:9270/group1/M00/00/00/rBgDzV7CINaAMGslABIShJMhbpI443_big.jpg
三、安装fastdfs-nginx-module
修改/fastdfs-nginx-module/src/config文件。去掉所有的local
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"
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_fastdfs.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"
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_fastdfs.conf\"'"
fi
拷贝usr/lib64目录下库文件libfdfsclient.so
cp /usr/lib64/libfdfsclient.so /usr/lib
在nginx安装目录下执行如下命令:把module添加nginx中。通过设置安装参数方式添加模块。
./configure --add-module=../fastdfs-nginx-module-1.20/src
注意:我这里nginx-1.12.1和fastdfs-nginx-module在同一级目录,所以这样写
重新安装编译
make && make install
出现如上错误只需修改fastdfs-nginx-module的config文件
进入fastdfs-nginx-module安装目录src下 vi config 改为如下路径
ngx_module_incs="/usr/include/fastdfs /usr/include/fastcommon/"
CORE_INCS="$CORE_INCS /usr/include/fastdfs /usr/include/fastcommon/"
改完之后重新重复./configure --add-module=../fastdfs-nginx-module-1.20/src ,之后再make编译行了
复制 fastdfs-nginx-module 源码中的配置文件到/etc/fdfs 目录, 并修改
cd fastdfs-nginx-module-1.20/src
cp mod_fastdfs.conf /etc/fdfs/
进入/etc/fdfs/修改mod_fastdfs.conf如下配置,其他默认
# 连接超时时间
connect_timeout=10
# Tracker Server
tracker_server=47.93.35.232:22122
# StorageServer 默认端口
storage_server_port=23000
# 如果文件ID的uri中包含/group**,则要设置为true
url_have_group_name = true
# Storage 配置的store_path0路径,必须和storage.conf中的一致
store_path0=/home/caibh/fdfs
# the base path to store log files
base_path=/home/fdfs-package/storage
配置iNginx ,进入/usr/local/nginx/conf目录下修改nginx.conf
注意:无论你在哪解压安装的。必须进这个目录/usr/local/nginx/conf下修改nginx.conf
vim nginx.conf
修改配置,其它的默认
listen 9270; server_name 47.93.35.***; location ~/group([0-9])/M00 { root ~/fdfs/data; ngx_fastdfs_module; }
注意:
location 的配置,如果有多个group则配置location ~/group([0-9])/M00 ,没有则不用配group。
启动nginx
#启动nginx
cd /usr/local/nginx/sbin/
./nginx
直接启动
/usr/local/nginx/sbin/nginx
#设置开机启动
vim /etc/rc.local
/usr/local/nginx/sbin/nginx
# 设置执行权限
chmod 755 rc.local
查看Nginx是否启动
ps -ef | grep nginx
测试上传图片