程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> JAVA編程 >> JAVA綜合教程 >> FastDFS安裝配置,fastdfs

FastDFS安裝配置,fastdfs

編輯:JAVA綜合教程

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服務器)

 

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

 

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved