FastDFS安装配置,fastdfs

FastDFS安装配置,fastdfs


FastDFS

FastDFS为互联网量身定制,充分考虑了冗余备份、负载均衡、线性扩容等机制,并注重高可用、高性能等指标,使用FastDFS很容易搭建一套高性能的文件服务器集群提供文件上传、下载等服务。

1.所需要的安装包

2.安装服务器(关闭服务器防火墙service iptables stop    setenforce 0)

192.168.241.137------------------------>tracker服务器

192.168.241.138------------------------>storage服务器(group1)

192.168.241.139------------------------>storage服务器(group1)

   

3.tracker安装

yum -y install gcc-c++ (安装编译工具)
yum -y install libevent (FastDFS依赖libevent库)
mv libfastcommonV1.0.7.tar.gz /usr/local (将libfastcommon放到/usr/local目录下)
cd /usr/local
tar -zxvf libfastcommonV1.0.7.tar.gz (解压libfastcommon)
cd libfastcommon-1.0.7/
./make.sh (编译libfastcommon)
./make.sh install (安装libfastcommon)
cp /usr/lib64/libfastcommon.so /usr/lib (注意:libfastcommon安装好后会自动将库文件拷贝至/usr/lib64下,由于FastDFS程序引用usr/lib目录所以需要将/usr/lib64下的库文件拷贝至/usr/lib下)
mv FastDFS_v5.05.tar.gz /usr/local/ (将FastDFS安装包放到/usr/local目录下)
cd /usr/local
tar -zxvf FastDFS_v5.05.tar.gz (解压FastDFS安装包)
cd FastDFS
./make.sh (编译FastDFS)
./make.sh install (安装FastDFS)
cp /usr/local/FastDFS/conf/http.conf /etc/fdfs/ (将http.conf拷贝到/etc/fdfs目录下)
cp /usr/local/FastDFS/conf/mime.types /etc/fdfs/ (将mime.types拷贝到/etc/fdfs目录下)
cd /etc/fdfs/ (进入FastDFS配置文件目录)
cp tracker.conf.sample tracker.conf (拷贝一份新的tracker配置文件)
mkdir -p /home/FastDFS (创建FastDFS工作目录)
vim tracker.conf (配置配置文件,# HTTP port on this tracker server http.server_port=8080 # the tracker server port port=22122 这里的端口没有配置使用默认端口)
base_path=/home/FastDFS
/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart (启动tracker服务器)

 

扫描二维码关注公众号,回复: 149810 查看本文章

4.storage安装

yum -y install gcc-c++ (安装编译工具)
yum -y install libevent (FastDFS依赖libevent库)
mv libfastcommonV1.0.7.tar.gz /usr/local (将libfastcommon放到/usr/local目录下)
cd /usr/local
tar -zxvf libfastcommonV1.0.7.tar.gz (解压libfastcommon)
cd libfastcommon-1.0.7/
./make.sh (编译libfastcommon)
./make.sh install (安装libfastcommon)
cp /usr/lib64/libfastcommon.so /usr/lib (注意:libfastcommon安装好后会自动将库文件拷贝至/usr/lib64下,由于FastDFS程序引用usr/lib目录所以需要将/usr/lib64下的库文件拷贝至/usr/lib下)
mv FastDFS_v5.05.tar.gz /usr/local/ (将FastDFS安装包放到/usr/local目录下)
cd /usr/local
tar -zxvf FastDFS_v5.05.tar.gz (解压FastDFS安装包)
cd FastDFS
./make.sh (编译FastDFS)
./make.sh install (安装FastDFS)
cp /usr/local/FastDFS/conf/http.conf /etc/fdfs/ (将http.conf拷贝到/etc/fdfs目录下)
cp /usr/local/FastDFS/conf/mime.types /etc/fdfs/ (将mime.types拷贝到/etc/fdfs目录下)
cd /etc/fdfs/ (进入FastDFS配置文件目录)
cp storage.conf.sample storage.conf (拷贝一份新的tracker配置文件)
vim storage.conf(# the port of the web server on this storage server http.server_port=8888 默认,根据需要设置)
group_name=group1 (组名)
base_path=/home/FastDFS (基础目录)
store_path0=/home/FastDFS/fdfs_storage (存储目录)
tracker_server=192.168.101.3:22122 (tracker服务器)
mkdir -p /home/FastDFS (创建FastDFS工作目录)
mkdir -p /home/FastDFS/fdfs_storage (存储目录)
/usr/bin/fdfs_storaged /etc/fdfs/storage.conf restart (启动storage服务器)

 

5.上传图片测试(tracker服务器)

cd /etc/fdfs/
cp client.conf.sample client.conf (FastDFS安装成功可通过/usr/bin/fdfs_test测试上传、下载等操作)
vim client.conf (修改配置文件)
base_path=/home/FastDFS
tracker_server=192.168.241.137:22122

 

使用格式:/usr/bin/fdfs_test  客户端配置文件地址   upload   上传文件

比如将/home下的图片上传到FastDFS中:  /usr/bin/fdfs_test   /etc/fdfs/client.conf   upload /home/567.png  tracker服务器显示日志:   storage服务器:

 

6.FastDFS和nginx整合

tracker服务器装nginx实现负载均衡,nginx服务器装nginx实现http下载

为了体现出负载均衡效果,将192.168.241.138配置为group1;192.168.241.139配置为group2

6.1在tracker上装nginx

yum install -y pcre pcre-devel (依赖)
yum install -y zlib zlib-devel (依赖)
yum install -y openssl openssl-devel (依赖)
mv nginx-1.8.0.tar.gz /usr/local (将nginx安装包放到/usr/local/目录下)
cd /usr/local
tar -zxvf nginx-1.8.0.tar.gz (解压nginx安装包)
mkdir -p /var/temp/nginx (创建nginx临时文件目录)
cd /usr/local/nginx-1.8.0

(配置nginx prefix,指定安装目录,指定的是nginx的安装目录  上边将临时文件目录指定为/var/temp/nginx,需要在/var下创建temp及nginx目录)
./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     make (编译)   make install (安装)  

 

cd /usr/local/nginx/conf/ (打开nginx配置文件)
vim nginx.conf (编辑nginx配置文件)

 

 upstream storage_server_group1{
        server 192.168.241.138:8888 weight=10;

    }

    upstream storage_server_group2{
        server 192.168.241.139:8888 weight=10;

    }

    server {
        listen 8080;
        server_name ccc.test.com;
        location /group1{
                proxy_redirect off;
                proxy_set_header Host $host;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_pass http://storage_server_group1;
        }
        location /group2{
                proxy_redirect off;
                proxy_set_header Host $host;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_pass http://storage_server_group2;
        }

    }

 

 

6.2storage上装nginx

yum install -y pcre pcre-devel (依赖)
yum install -y zlib zlib-devel (依赖)
yum install -y openssl openssl-devel (依赖)
mv fastdfs-nginx-module_v1.16.tar.gz /usr/local (将fastdfs和nginx整合包放到/usr/local下)
mv nginx-1.8.0.tar.gz /usr/local (将nginx安装包放在/usr/local下)
tar -zxvf fastdfs-nginx-module_v1.16.tar.gz (解压整合包)
cd fastdfs-nginx-module/src/ (打开配置文件夹)
vim config 

 

修改config文件将/usr/local/路径改为/usr/

cp /usr/local/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs/ (将整合配置文件放在fastdfs配置文件夹下)
vi /etc/fdfs/mod_FastDFS.conf (修改配置文件)
base_path=/home/FastDFS
tracker_server=192.168.101.3:22122
url_have_group_name=true #url中包含group名称
store_path0=/home/FastDFS/fdfs_storage   #指定文件存储路径
cp /usr/lib64/libfdfsclient.so /usr/lib/
mkdir -p /var/temp/nginx/client (创建nginx/client目录)
 

 

nginx安装
tar -zxvf nginx-1.8.0.tar.gz 
cd nginx-1.8.0
./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=/usr/local/fastdfs-nginx-module/src       make
  make install
   cd /usr/local/nginx/conf/ (打开nginx配置文件)
  vim nginx.conf (编辑nginx配置文件)

 

 server {
                listen       8888;
                server_name  192.168.241.138;

                location /group1/M00/{
                        root /home/FastDFS/fdfs_storage/data;
                        ngx_fastdfs_module;
                }
        }

 

说明: server_name指定本机ip location /group1/M00/:group1为nginx 服务FastDFS的分组名称,M00是FastDFS自动生成编号,对应store_path0=/home/FastDFS/fdfs_storage,如果FastDFS定义store_path1,这里就是M01

猜你喜欢

转载自blog.csdn.net/ganwei793089452/article/details/79695174
今日推荐