centos7.4安装FastDFS

时间:2019-01-17
本文章向大家介绍centos7.4安装FastDFS,主要包括centos7.4安装FastDFS使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

centos7.4安装FastDFS(单点)

参考:
http://blog.csdn.net/xll233xx/article/details/50619170
https://www.cnblogs.com/jkko123/p/6490744.html
http://blog.51cto.com/xinzong/1834466

1.环境

防火墙加规则允许出入口通过TCP协议的22122端口和23000端口

安装服务

# yum -y groupinstall 'Development Tools'   
# yum -y install wget vim lrzsz
# yum -y install gcc gcc-c++

2.装包

当初的下载路径现在用不了,所以只能靠大家自己去找了,尴尬啊!
建议下载稳定版

# mkdir /fastdfs
# cd /fastdfs/
# rz
# tar zxvf libfastcommon-1.0.36.tar.gz 
# cd libfastcommon-1.0.36
# ./make.sh
# ./make.sh install 
# cd ..
# tar zxvf fastdfs-5.09.tar.gz
# cd fastdfs-5.09
# ./make.sh
# ./make.sh install

3.修改配置文件

# mkdir -p /data/fdfs
# cd /data/fdfs/
# mkdir tracker
# mkdir storage
# mkdir client

配置tracker

# cd /etc/fdfs/
# mv tracker.conf.sample tracker.conf
# cat tracker.conf  
//...  
base_path=/data/fdfs/tracker  
//...  

配置storage

# cd /etc/fdfs  
# mv storage.conf.sample storage.conf  
# cat storage.conf  
//...  
base_path=/data/fdfs/storage #指定日志位置  
store_path0=/data/fdfs/storage #指定数据位置  
tracker_server=192.168.1.120:22122  #指定tracker服务器地址  
//... 

配置client

# cd /etc/fdfs  
# mv client.conf.sample client.conf  
# cat client.conf  
//...  
base_path=/data/fdfs/client  
tracker_server=192.168.1.120:22122  
//...  

4.启动tracker和storage

# /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf   
# /usr/bin/fdfs_storaged /etc/fdfs/storage.conf  

5.检测

# tail -f /data/fdfs/storage/logs/storaged.log   
# tail -f /data/fdfs/tracker/logs/trackerd.log 
# netstat -unltp|grep fdfs
# ps -ef |grep fdfs
# /usr/bin/fdfs_monitor /etc/fdfs/storage.conf

有ip_addr = 192.168.1.120 (iZclvmruey0h1pZ) ACTIVE
字样即可说明storage服务器已经成功登记到了tracker服务器

##############################################
补充:重启可以先

# ps -ef |grep fdfs
# kill -9 +pid

然后

# /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf   
# /usr/bin/fdfs_storaged /etc/fdfs/storage.conf

###################################################

上传

# /usr/bin/fdfs_test /etc/fdfs/client.conf  upload /home/lily/a.txt  

下载

# /usr/bin/fdfs_download_file /etc/fdfs/client.conf group1/M00/00/00/wKiZglauvkmANC2wAAAAPpWmuhI171.txt

删除

# /usr/bin/fdfs_delete_file /etc/fdfs/client.conf group1/M00/00/00/wKiZglauvkmANC2wAAAAPpWmuhI171.txt

##########################################################

6.Nginx安装

(1)环境

# yum -y install pcre-devel openssl openssl-devel

(2)装包

# cd
# cd /fastdfs
# tar zxvf fastdfs-nginx-module_v1.16.tar.gz
# tar zxvf nginx-1.7.8.tar.gz
# tar zxvf pcre-8.41.tar.gz

( 3 ) 安装pcre

# cd pcre-8.41
# ./configure --prefix=/data/pcre
# make && make install

(4)配置fastdfs-nginx-module,修改CORE_INCS和CORE_LIBS

# cd /fastdfs/fastdfs-nginx-module/src
# cat 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/include/fastdfs /usr/include/fastcommon/"
CORE_LIBS="$CORE_LIBS -L/usr/lib -lfastcommon -lfdfsclient"
CFLAGS="$CFLAGS -D_FILE_OFFSET_BITS=64 -DFDFS_OUTPUT_CHUNK_SIZE='256*1024' -DFDFS_MOD_CONF_FILENAME='\"/etc/fdfs/mod_fastdfs.conf\"'"

(5)安装nginx

# cd /fastdfs/nginx-1.7.8
# ./configure --add-module=/fastdfs/fastdfs-nginx-module/src  --prefix=/data/nginx --with-pcre=/fastdfs/pcre-8.41 --user=nobody --group=nobody --with-http_gzip_static_module --with-http_gunzip_module --with-http_ssl_module --with-http_realip_module --with-http_stub_status_module
# make
# make install

配置mod_fastdfs.conf

# cp /fastdfs/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs/
# mkdir /data/ngx
# cat /etc/fdfs/mod_fastdfs.conf
base_path=/data/ngx
tracker_server=192.168.1.120:22122
store_path0=/data/fdfs/storage

添加http.conf,mime.types到/etc/fdfs

# cd /fastdfs/fastdfs-5.09/conf
# cp anti-steal.jpg http.conf mime.types  /etc/fdfs

修改nginx配置文件

# cat /data/nginx/conf/nginx.conf
server {
    listen 80;
    server_name localhost;

    location ~ /group[0-9]/M00 {
        ngx_fastdfs_module;
         }
    location ~ /group[0-9]/M00/(.*).(gif|GIF|jpg|JPG|jpeg|JPEG|png|PNG) {
        ngx_fastdfs_module;
        }
}

启动nginx

# /data/nginx/sbin/nginx

查看nginx日志

# cd /data/nginx/logs
# ll

显示:

# ll
total 224
-rw-r--r-- 1 root root 119127 Jan 26 11:57 access.log
-rw-r--r-- 1 root root  93895 Jan 26 11:57 error.log
-rw-r--r-- 1 root root      5 Jan 24 20:06 nginx.pid

重启nginx

# /data/nginx/sbin/nginx -s reload

7.测试

# echo "12345678" >> /data/1.txt
# fdfs_upload_file /etc/fdfs/client.conf /data/1.txt

显示:group1/M00/00/00/wKgBeFsUuSWAMfefAAAACZ-6mU0103.txt

打开浏览器输入http://192.168.1.120/group1/M00/00/00/wKgBeFsUuSWAMfefAAAACZ-6mU0103.txt,会显示12345678