libfastcommon:FastDFS分离出的一些公用函数包
FastDFS:FastFDS本体
fastdfs-nginx-module:FastFDS和nignx的关联模块
nginx:发布访问服务
二、安装
0.将安装包上传至/home/software/fastdfs
1.安装基础环境
yum install -y gcc gcc-c++
yum -y install libevent
2.安装libfastcommon函数库
解压: tar -zxvf libfastcommon-1.0.42.tar.gz
进入到libfastcommon文件夹:./make.sh
./make.sh install
3.安装fastdfs主程序文件
解压:tar -zxvf fastdfs-6.04.tar.gz
进入fastdfs目录:./make.sh
./make.sh install
4.确保文件夹存在
/usr/bin:包含了可执行文件
/etc/fdfs:包含了配置文件
5.拷贝配置文件 cp /home/software/FastDFS/fastdfs-6.04/conf/* /etc/fdfs/
三、配置tracker
1.配置tracker配置文件
cd /etc/fdfs
vim tracker.conf
2.修改基础路径
base_path=/usr/local/fastdfs/tracker
mkdir /usr/local/fastdfs/tracker
3.启动tracker服务
/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf
4.查看进程 ps -ef|grep tracker
5.停止tracker
/usr/bin/stop.sh /etc/fdfs/tracker.conf
四、配置storage
1.配置storage配置文件
cd /etc/fdfs
vim storage.conf
#修改组名
group_name=imooc
# 修改storage的工作空间
base_path=/usr/local/fastdfs/storage
# 修改storage的存储空间
store_path0=/usr/local/fastdfs/storage
# 修改tracker的地址和端口号,用于心跳
tracker_server=192.168.1.153:22122
# 后续结合nginx的一个对外服务端口号
http.server_port=8888
2.创建目录 mkdir /usr/local/fastdfs/storage -p
3.启动storage(前提:必须先启动tracker) /usr/bin/fdfs_storaged /etc/fdfs/storage.conf
4.查看进程: ps -ef|grep storage
五、测试图片上传
0.创建/usr/local/fastdfs/client后,配置/etc/fdfs/client.conf
base_path=/usr/local/fastdfs/client
tracker_server=192.168.1.153:22122
1.上传测试图片至/home/logo.png
2.确保先启动tracker,再启动storage
/usr/bin/fdfs_test /etc/fdfs/client.conf upload /home/logo.png
六、配置Nginx FastDFS实现文件服务器(按步骤来配置)
fastdfs安装好以后是无法通过http访问的,这个时候就需要借助nginx,所以需要安装fastdfs第三方模块到nginx中,就能使用了。
注:nginx需要和storage在同一个节点
1.安装nginx插件
解压nginx的fastdfs压缩包:tar -zxvf fastdfs-nginx-module-1.22.tar.gz
复制配置文件:cp mod_fastdfs.conf /etc/fdfs
修改/fastdfs-nginx-modules/src/config文件,主要是修改路径,把local删除,因为fastdfs安装的时候我们没有修改路径
2.安装nginx,详情参考https://www.jianshu.com/p/65b48c4a6606
其中配置模块,增加fastdfs插件
./configure --prefix=/usr/local/nginx --pid-path=/var/run/nginx/nginx.pid --lock-path=/var/lock/nginx.lock --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --with-http_gzip_static_module --http-client-body-temp-path=/var/temp/nginx/client --http-proxy-temp-path=/var/temp/nginx/proxy --http-fastcgi-temp-path=/var/temp/nginx/fastcgi --http-uwsgi-temp-path=/var/temp/nginx/uwsgi --http-scgi-temp-path=/var/temp/nginx/scgi --add-module=/home/software/fastdfs/fastdfs-nginx-module-1.22/src
修改nginx.conf,添加如下虚拟机
3.修改mod_fastdfs.conf配置文件
创建文件夹: mkdir /usr/local/fastdfs/tmp
4.启动nginx
5.访问 Ip+代理转发端口+storage存储组名
http://192.168.31.221:8888/imooc/M00/00/00/wKgf3V-eChSAdlnFAALdsLCF3uA337.JPG
在Linux系统中进行FastDFS软件的安装配置,方法的过程中是很复杂的,所以如果不是专业的电脑高手可能是没有办法整理出来,所以为了方便网友们更好的了解这个软件的安装,一下就是详细的过程,大家一起来看看吧!第一步:安装FastDFS 1.解压 FastDFS_v4.07.tar.gz ==>FastDFS 2. cd FastDFS ==>vim make.sh 修改以下内容 TARGET_PREFIX=/usr/local/fdfs TARGET_CONF_PATH=/usr/local/fdfs/conf mkdir -p /usr/local/fdfs mkdir -p /usr/local/fdfs/conf 修改 if [ "$uname" = "Linux" ]then if [ "$WITH_LINUX_SERVICE" = "1" ]then if [ ! -d $TARGET_CONF_PATH ]then mkdir -p $TARGET_CONF_PATH cp -f conf/tracker.conf $TARGET_CONF_PATH cp -f conf/storage.conf $TARGET_CONF_PATH cp -f conf/client.conf $TARGET_CONF_PATH cp -f conf/http.conf $TARGET_CONF_PATH cp -f conf/mime.types $TARGET_CONF_PATH fi cp -f init.d/fdfs_trackerd /etc/rc.d/init.d/ cp -f init.d/fdfs_storaged /etc/rc.d/init.d/ /sbin/chkconfig --add fdfs_trackerd /sbin/chkconfig --add fdfs_storaged fi fi 第二步:安装libevent-2.0.19-stable.tar.gz 1.解压 libevent-2.0.19-stable.tar.gz==>libevent-2.0.19-stable 2.进入libevent-2.0.19-stable 安装 ./configure --prefix=/usr/local/libevent make make install 3. 添加软连接 ln -s /usr/local/libevent/lib/libevent-2.0.so.5 /usr/lib/libevent-2.0.so.5 ln -s /usr/local/libevent/lib/libevent-2.0.so.5 /usr/lib64/libevent-2.0.so.5 ln -s /usr/local/libevent/lib/libevent-2.0.so.5 /lib64/libevent-2.0.so.5 ln -s /usr/local/libevent/lib/libevent-2.0.so.5 /lib/libevent-2.0.so.5 ln -s /usr/local/libevent/lib/libevent-2.0.so.5 /usr/local/lib64/libevent-2.0.so.5 ln -s /usr/local/libevent/lib/libevent-2.0.so.5 /usr/local/lib/libevent-2.0.so.5 第三步:安装FastDFS ./make.sh C_INCLUDE_PATH=/usr/local/libevent/include LIBRARY_PATH=/usr/local/libevent/lib ./make.sh install 第四步:如果/usr/local/fastdfs/conf没有fdfs_trackerd和fdfs_storaged这两个文件,就从 /FastDFS/tracker 和FastDFS/storage/目录下复制过去 第五步:修改配置 mkdir -p /home/softinstall/data/tracker 1. 修改 tracker.conf base_path=/home/softinstall/data/tracker bind_addr=192.168.9.169 1.1 修改storage_ids.conf 100001 group1 192.168.9.169 2. 启动tracker ./fdfs_trackerd ../conf/tracker.conf 查看22122端口是否启动起来 第六步:配置storage mkdir -p /home/softinstall/data/store mkdir -p /home/softinstall/data/store/store0 mkdir -p /home/softinstall/data/store/store1 mkdir -p /home/softinstall/data/store/store2 1.修改storage.conf base_path=/home/softinstall/data/store store_path_count=3 store_path0=/home/softinstall/data/store/store0 store_path1=/home/softinstall/data/store/store1 store_path2=/home/softinstall/data/store/store2 tracker_server=192.168.9.169:22122 #限6*6=36个目录 默认256*256 subdir_count_per_path=6 2. 启动storage ./fdfs_storaged ../conf/storage.conf 查看23000端口是否启动 第七步:安装nginx+fastdfs模块 1. 安装pcre-8.32 进入pcre-8.32 ./configure make make install 安装如果有问题缺省某些包,可以执行: yum groupinstall "Development Tools" 第八步:解压fastdfs-nginx-module_v1.15.tar.gz和 nginx-1.4.2.tar.gz 1.进入 fastdfs-nginx-module_v1.15/src vim fastdfs-nginx-module_v1.15/src/config 修改成以下内容 ngx_addon_name=ngx_http_fastdfs_module 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/local/fdfs/include/fastdfs /usr/local/fdfs/include/fastcommon/" CORE_LIBS="$CORE_LIBS -L/usr/local/fdfs/lib -lfastcommon -lfdfsclient" CFLAGS="$CFLAGS -D_FILE_OFFSET_BITS=64 -DFDFS_OUTPUT_CHUNK_SIZE='256*1024' -DFDFS_MOD_CONF_FILENAME='\"/usr/local/fdfs/conf/mod_fastdfs.conf\"'" 2. 安装 进入nginx-1.4.2目录 ./configure --prefix=/home/softinstall/nginx/nginx-fastdfs-install --with-pcre=/home/softinstall/nginx/pcre-8.32 --add-module=/home/softinstall/nginx/fastdfs-nginx-module/src 安装中如果有问题 可以执行安装以下包:yum -y install gcc gcc-c++ zlib-devel openssl-devel 3.配置nginx.conf 进入nginx-fastdfs-install/conf vim nginx.conf 配置以下内容 location /M00 { root /home/softinstall/data/store/store0/datangx_fastdfs_module} location /M01 { root /home/softinstall/data/store/store1/datangx_fastdfs_module} location /M02 { root /home/softinstall/data/store/store2/datangx_fastdfs_module} 4.配置mod_fastdfs.conf mkdir -p /home/softinstall/data/nginx_mod 进入 /usr/local/fdfs/conf目录 vim mod_fastdfs.conf base_path=/home/softinstall/data/nginx_mod tracker_server=192.168.9.169:22122 store_path_count=3 store_path0=/home/softinstall/data/store/store0 store_path1=/home/softinstall/data/store/store1 store_path2=/home/softinstall/data/store/store2 5. 启动nginx 进入 /home/softinstall/nginx/nginx-fastdfs-install/sbin ./nginx 如果启动找不到 error while loading shared libraries: libfdfsclient.so: cannot open shared object file: No such file or directory error while loading shared libraries: libfastcommon.so: cannot open shared object file: No such file or directory 请使用以下软连接 ln -s /usr/local/fdfs/lib/libfastcommon.so /usr/lib/libfastcommon.so ln -s /usr/local/fdfs/lib/libfastcommon.so /usr/lib64/libfastcommon.so ln -s /usr/local/fdfs/lib/libfdfsclient.so /usr/lib64/libfdfsclient.so ln -s /usr/local/fdfs/lib/libfdfsclient.so /usr/lib/libfdfsclient.so ==========================fastDHT================================ 【第一步:】安装 Berkley DB 【1.】 tar -zxvf db-4.7.25.tar.gz 进入 db-4.7.25/build_unix ../dist/configure --prefix=/usr 【第二步:】安装FastDHT mkdir -p /usr/local/fdht mkdir -p /usr/local/fdht/conf 1. tar -zxvf FastDHT_v1.23.tar.gz 进入 FastDHT_v1.23 vim make.sh 修改 TARGET_PREFIX=/usr/local/fdht TARGET_CONF_PATH=/usr/local/fdht/conf if [ "$1" = "install" ]then cd .. cp -f restart.sh $TARGET_PREFIX/bin cp -f stop.sh $TARGET_PREFIX/bin if [ "$uname" = "Linux" ]then if [ "$WITH_LINUX_SERVICE" = "1" ]then if [ ! -d $TARGET_CONF_PATH ]then mkdir -p $TARGET_CONF_PATH cp -f conf/fdhtd.conf $TARGET_CONF_PATH cp -f conf/fdht_servers.conf $TARGET_CONF_PATH cp -f conf/fdht_client.conf $TARGET_CONF_PATH fi cp -f init.d/fdhtd /etc/rc.d/init.d/ /sbin/chkconfig --add fdhtd fi fi fi 【2.】 安装 ./make.sh ------------------------------------------------------------------------------ 如果出现 global.h:18:19: error: event.h: No such file or directory 进入/home/softinstall/fastdfs/libevent-2.0.19-stable然后执行 ./configure --prefix=/usr make make install --------------------------------------------------------------------------------- ./make.sh install 【3.】 配置fdht 【3.1】 vim /usr/local/fdht/conf/fdhtd.conf port=11411 bash_path=/home/softinstall/data/fastdht cache_size = 32MB store_sub_keys=true use_storage_id=true #include /usr/local/fdht/conf/fdht_servers.conf (本行前有#表示打开,如果想关闭此选项,则应该为##开头) 【3.2】 vim /usr/local/fdht/conf/fdht_server.conf group_count = 1 group0 = 192.168.9.165:11411 【3.3】 vim /usr/local/fdht/conf/fdht_client.conf keep_alive=1 (本选项关联 storaged.conf文件) base_path=/home/softinstall/data/fastdht #include /usr/local/fdht/conf/fdht_servers.conf 【3.4】 配置FastDFS 的 storaged.conf文件 vi storaged.conf (默认位置: /usr/local/fdfs/conf/storaged.conf) check_file_duplicate=1 本配置项解释: 是否检测上传文件已经存在。如果已经存在,则不存在文件内容,建立一个索引链接以节省磁盘空间 key_namespace=FastDFS 本配置项解释: 当上个参数设定为1时 , 在FastDHT中的命名空间 keep_alive=1 本配置项解释: 长连接配置选项,如果为0则为短连接 1为长连接 #include /usr/local/fdht/conf/fdht_servers.conf 本配置项解释: 可以通过 #include filename 方式来加载 FastDHT servers 的配置 【3.5】 ===========================总体启动流程====================================== 启动tracker/usr/local/fdfs/bin/fdfs_trackerd /usr/local/fdfs/conf/tracker.conf 停止tracker/usr/local/fdfs/bin/stop.sh /usr/local/fdfs/conf/tracker.conf 启动storage /usr/local/fdfs/bin/fdfs_storaged /usr/local/fdfs/conf/storage.conf 停止storage /usr/local/fdfs/bin/stop.sh /usr/local/fdfs/conf/storage.conf 启动nginx/home/softinstall/nginx/nginx-fastdfs-install/sbin/nginx 启动 /usr/local/fdht/bin/fdhtd /usr/local/fdht/conf/fdhtd.conf 停止 /usr/local/fdht/bin/stop.sh /usr/local/fdht/conf/fdhtd.conf 测试 是否有错误: /usr/local/fdht/bin/fdht_test /usr/local/fdht/conf/fdht_client.conf =================================================================项目中使用了FastDFS作为文件系统,这里记录一下它的安装和配置过程
由于是测试环境,所以只提供了一台服务器,后续软件的安装和配置都在这台服务器上完成
1、安装fastdfs公共库libfastcommon,注意fastdfs和libfastcommon的安装目录,后面安装fastdfs-nginx-module时需要进行相关配置
2、安装fastdfs
3、配置Tracker
注意一下存放数据和日志的目录,启动后需要查看日志信息
4、启动Tracker
5、查看日志
为了确保Tracker启动成功,我们可以在刚在配置的日志目录中查看日志信息
出现上述信息表示Tracker已启动成功
6、遇到的问题
Tracker启动后,如果改了Tracker的配置文件想要重新启动,执行启动命令后发现日志中报错
这是因为此时Tracker已经启动了,再执行启动命令就会报错地址已被使用,此时可以执行restart命令进行重启
或者
安装步骤在上面Tracker的安装中已经做好了,直接配置即可
1、配置Storage
注意tracker的地址配置是否正确,否则启动时会报错
2、启动Storage
3、查看日志
出现上述信息表示Storage已启动成功
4、遇到的问题
Storage启动后,如果改了Storage的配置文件想要重新启动,执行启动命令后发现日志中报错
这是因为此时Storage已经启动了,再执行启动命令就会报错地址已被使用,此时可以执行restart命令进行重启
或者
之前阿里云ESC实例迁移,导致服务器内网ip地址发生了改变,重启Storage时日志报错
这是由于Storage配置文件中tracker_server的ip地址还是旧地址,所以会出现连接超时的问题,将配置文件中的地址改成新的地址重启Storage
1、配置fastdfs-nginx-module所需的配置文件,包括mod_fastdfs.conf,http.conf,mime.types
注意tracker_server地址,否则启动后会报错
2、安装配置
注意CORE_INCS和CFLAGS两项的配置
1、建立nginx用户
2、安装配置
3、更改nginx目录权限
4、配置文件nginx.conf
提供一个最简单的配置方式供参考,由于项目中nginx还做了其他处理,配置文件比较复杂,这里就不贴出来了
5、启动nginx
两种方式
或者
使用过程中有其他问题多查看日志报错情况,或者查阅 Nginx 跳转fastdfs存储图片地址报错问题分析过程汇总 ,详细原理讲解和测试查阅下面的参考文档
参考: 分布式文件系统FastDFS实践
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)