首页 » Ubuntu » Ubuntu16.04和CentOS7安装FastDFS服务

Ubuntu16.04和CentOS7安装FastDFS服务

原文 http://blog.csdn.net/lynnyq/article/details/79108066

2018-01-20 02:01:35阅读(219)

Ubuntu16.04CentOS7安装FastDFS服务 1.安装依赖 CentOS7
# yum install unzip zip  gcc-c++
nginx模块依赖
# yum -y install pcre pcre-devel
# yum -y install zlib zlib-devel
# yum -y install openssl openssl-devel
Ubuntu16.04
$ sudo apt-get unzip
$ sudo apt-get install libpcre3 libpcre3-dev
$ sudo apt-get install zlib1g  zlib1g-dev
$ sudo apt-get install openssl libssl-dev 
2.下载必要的包
$ mkdir sofware
$ cd software
# FastDFSV5.11源码包
$ wget https://codeload.github.com/happyfish100/fastdfs/tar.gz/V5.11
$ tar -zxvf V5.11
# libfastcommon依赖库源码包
$ wget https://codeload.github.com/happyfish100/libfastcommon/tar.gz/V1.0.36
$ tar -zxvf V1.0.36
# fastdfs-nginx-module模块源码包
$ wget https://codeload.github.com/happyfish100/fastdfs-nginx-module/zip/master
$ unzip master
$ wget http://nginx.org/download/nginx-1.12.2.tar.gz
$ tar -zxvf nginx-1.12.2.tar.gz
3.安装包 编译安装FastDFS
# 安装FastDFS依赖包
$ cd libfastcommon-1.0.36/
$ ./make.sh
$ sudo ./make.sh install
# libfastcommon.so 默认安装到了/usr/lib64/libfastcommon.so,但是FastDFS主程序设置的lib目录是/usr/local/lib,所以此处需要重新设置软链接:
$ sudo ln -s /usr/lib64/libfastcommon.so /usr/local/lib/libfastcommon.so
$ sudo ln -s /usr/lib64/libfdfsclient.so /usr/local/lib/libfdfsclient.so
$ sudo ln -s /usr/lib64/libfdfsclient.so /usr/lib/libfdfsclient.so
# 安装FastDFS
$ cd ..
$ cd fastdfs-5.11/
$ ./make.sh 
$ sudo ./make.sh install
$ cd ..
编译安装nginx
$ sudo mkdir -p /var/tmp/nginx/proxy
$ cd nginx-1.12.2/
$ ./configure --prefix=/usr/local/nginx  --user=nginx --group=nginx --with-http_ssl_module --with-http_flv_module --with-http_gzip_static_module  --with-http_stub_status_module  --add-module=/root/sofware/fastdfs-nginx-module-master/src  --http-client-body-temp-path=/var/tmp/nginx/proxy --http-fastcgi-temp-path=/var/tmp/nginx/fcgi
$ make && sudo make install
$ sudo groupadd -f nginx
$ sudo useradd -g nginx nginx
3.配置包 tracker配置
$ sudo mkdir -p /FastDFS/tracker
$ sudo mkdir -p /FastDFS/storage
$ cd /etc/fdfs/
$ sudo cp client.conf.sample client.conf
$ sudo cp storage.conf.sample storage.conf
$ sudo cp tracker.conf.sample tracker.conf
# 配置tracker
$ sudo vim /etc/fdfs/tracker.conf 
#设置tracker的数据文件和日志目录
base_path=/FastDFS/tracker
# 启动tracker服务
$ sudo /etc/init.d/fdfs_trackerd start
# 查看服务状态
$ sudo netstat -unltp|grep fdfs
tcp        0      0 0.0.0.0:22122           0.0.0.0:*               LISTEN      14628/fdfs_trackerd
服务运行的22122端口正常
storage配置
$ sudo vim /etc/fdfs/storage.conf
#设置storage数据文件和日志目录
base_path=/FastDFS/storage
store_path0=/FastDFS/storage
#存储路径个数,需要和store_path个数匹配
store_path_count=1 
#tracker 服务器的 IP地址和端口号,如果是单机搭建,IP不要写127.0.0.1,否则启动不成功
$ tracker_server=192.168.184.132:22122 
$ sudo /etc/init.d/fdfs_storaged start
$ sudo netstat -unltp|grep fdfs
tcp        0      0 0.0.0.0:23000           0.0.0.0:*               LISTEN      15063/fdfs_storaged
tcp        0      0 0.0.0.0:22122           0.0.0.0:*               LISTEN      14628/fdfs_trackerd
# 查看:storage服务器是否已经登记到 tracker服务器,运行以下命令:
$ sudo /usr/bin/fdfs_monitor /etc/fdfs/storage.conf
测试安装
# 编辑/etc/fdfs/client.conf配置文件
$ sudo vim /etc/fdfs/client.conf
# 修改内容:
base_path=/FastDFS/tracker
tracker_server=192.168.184.132:22122
# 上传文件测试:
$ fdfs_upload_file /etc/fdfs/client.conf /home/ubuntu/1.jpg
# 如果返回类似group1/M00/00/00/rBIK6VcaP0aARXXvAAHrUgHEviQ394.jpg的文件id则说明文件上传成功
配置nginx
# 拷贝配置文件
$ sudo cp/home/ubuntu/software/fastdfs-5.11/conf/http.conf /etc/fdfs/
$ sudo cp /home/ubuntu/software/fastdfs-5.11/conf/mime.types  /etc/fdfs/
$ sudo cp /home/ubuntu/software/fastdfs-nginx-module-master/src/mod_fastdfs.conf /etc/fdfs/
# 编辑mod_fastdfs.conf文件,
$ sudo vim /etc/fdfs/mod_fastdfs.conf
#保存日志目录
base_path=/FastDFS/storage
#tracker服务器的IP地址以及端口号
tracker_server=192.168.184.132:22122 
#文件 url 中是否有 group 名
url_have_group_name = true 
# 存储路径
store_path0=/FastDFS/storage
# 配置nginx
$ cd /usr/local/nginx/conf/
$ sudo vim nginx.conf
# 配置nginx.conf文件,加入一个server配置
server{ 
    listen       9999;
    location ~/group[0-9]/  {
            root /FastDFS/storage/data;
            ngx_fastdfs_module;
    }
}
启动nginx:
$ sudo /usr/local/nginx/sbin/nginx
测试下载
# 上传一个图片
$ fdfs_upload_file /etc/fdfs/client.conf /home/ubuntu/1.jpg
# 返回路径
# group1/M00/00/00/rBIK6VcaP0aARXXvAAHrUgHEviQ394.jpg的文件id则说明文件上传成功
# 在浏览器访问
http://ip:9999/group1/M00/00/00/rBIK6VcaP0aARXXvAAHrUgHEviQ394.jpg

最新发布

CentOS专题

关于本站

5ibc.net旗下博客站精品博文小部分原创、大部分从互联网收集整理。尊重作者版权、传播精品博文,让更多编程爱好者知晓!

小提示

按 Ctrl+D 键,
把本文加入收藏夹