centos fastdfs 多服務器 多硬盤 多組 配置詳解

隨着用戶量的變大,圖片,視頻等的量會不斷的增大,這個時候一個硬盤可能不夠用了,就要加硬盤。硬盤加不了時,就要增加服務器了。同一組服務器,文件服務器的東西是一樣,不同組的服務器,有不同的文件,不同的組之間,共同組建了文件服務器的所有內容。

下面說一下,安裝配置的過程,這裏配置的方法,根開發者提供的方法不一樣,我沒有用到fastdfs-nginx-module,通過配置nginx實現了fastdfs-nginx-module的功能。

 

一,Fastdfs的下載

地址:http://sourceforge.net/projects/fastdfs/files/FastDFS%20Server%20Source%20Code/

二,服務器,以及系統

我用的centos 6.5 x86_64 ,fastdfs v5.01架構如下:

架構圖

這裏的tracker是單點

三,安裝fastdfs和nginx

1,安裝nginx

  1. //安裝,gcc,automake,autoconf等依賴包  
  2. [root@localhost download]$ yum install gettext gettext-devel libXft libXft-devel libXpm libXpm-devel\  
  3.  automake autoconf libXtst-devel gtk+-devel gcc zlib-devel libpng-devel gtk2-devel glib-devel  
  4.   
  5. //安裝FastDFS  
  6. [root@localhost download]# tar zxf FastDFS_v5.01.tar.gz  
  7. [root@localhost download]# cd FastDFS  
  8. [root@localhost download]# ./make.sh  
  9. [root@localhost download]# ./make.sh install  
  10.   
  11. //安裝成功有以下內容  
  12. [root@localhost fdfs]# ll /usr/local/bin/ |grep fdfs  
  13. -rwxr-xr-x 1 root root 522870 7月 4 03:20 fdfs_appender_test  
  14. -rwxr-xr-x 1 root root 522823 7月 4 03:20 fdfs_appender_test1  
  15. -rwxr-xr-x 1 root root 513975 7月 4 03:20 fdfs_append_file  
  16. -rwxr-xr-x 1 root root 513393 7月 4 03:20 fdfs_crc32  
  17. -rwxr-xr-x 1 root root 513927 7月 4 03:20 fdfs_delete_file  
  18. -rwxr-xr-x 1 root root 514329 7月 4 03:20 fdfs_download_file  
  19. -rwxr-xr-x 1 root root 514093 7月 4 03:20 fdfs_file_info  
  20. -rwxr-xr-x 1 root root 525024 7月 4 03:20 fdfs_monitor  
  21. -rwxr-xr-x 1 root root 1179642 7月 4 03:20 fdfs_storaged  
  22. -rwxr-xr-x 1 root root 529805 7月 4 03:20 fdfs_test  
  23. -rwxr-xr-x 1 root root 527726 7月 4 03:20 fdfs_test1  
  24. -rwxr-xr-x 1 root root 655761 7月 4 03:20 fdfs_trackerd  
  25. -rwxr-xr-x 1 root root 514173 7月 4 03:20 fdfs_upload_appender  
  26. -rwxr-xr-x 1 root root 514951 7月 4 03:20 fdfs_upload_file  

2,安裝nginx

  1. [root@localhost fdfs]# yum install nginx  

所有機器的fastdfs和nginx安裝方法都是一樣。

四,配置192.168.10.219服務器

1,配置tracker和storage

  1. [root@localhost fdfs]# vim /etc/fdfs/tracker.conf   
  2.   
  3. port=22122                   #設置tracker的端口號  
  4. base_path=/var/www/fastdfs   #設置tracker的數據文件和日誌目錄(需預先創建)  

如果要調優,參考:http://bbs.chinaunix.net/forum.php?mod=viewthread&tid=1941456

  1. [root@localhost fdfs]# vim /etc/fdfs/storage.conf  
  2.   
  3. group_name=group1                   #組名,根據實際情況修改  
  4. port=23000                          #設置storage的端口號  
  5. base_path=/var/www/fastdfs          #設置storage的日誌目錄(需預先創建)  
  6. store_path_count=1                  #存儲路徑個數,需要和store_path個數匹配  
  7. store_path0=/var/www/fastdfs        #存儲路徑  
  8. tracker_server=192.168.10.219:22122 #tracker服務器的IP地址和端口號  

2,tracker的nginx配置

  1. [root@localhost nginx]# cat /etc/nginx/nginx.conf   #配置主配置文件  
  2. user nginx;  
  3. worker_processes 1;  
  4. events {  
  5.  worker_connections 65535;  #最大鏈接數  
  6.  use epoll;                 #新版本的Linux可使用epoll加快處理性能  
  7. }  
  8. error_log /var/log/nginx/error.log;  
  9. pid /var/run/nginx.pid;  
  10.   
  11. http {  
  12.  server_names_hash_bucket_size 128;  
  13.  client_header_buffer_size 32k;  
  14.  large_client_header_buffers 4 32k;  
  15.  client_max_body_size 300m;  
  16.  sendfile on;  
  17.  tcp_nopush on;  
  18.  proxy_redirect off;  
  19.  proxy_set_header Host $http_host;  
  20.  proxy_set_header X-Real-IP $remote_addr;  
  21.  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;  
  22.  proxy_connect_timeout 90;  
  23.  proxy_send_timeout 90;  
  24.  proxy_read_timeout 90;  
  25.  proxy_buffer_size 16k;  
  26.  proxy_buffers 4 64k;  
  27.  proxy_busy_buffers_size 128k;  
  28.  proxy_temp_file_write_size 128k;  
  29.   
  30.  log_format main '$remote_addr - $remote_user [$time_local] "$request" '  
  31.  '$status $body_bytes_sent "$http_referer" '  
  32.  '"$http_user_agent" "$http_x_forwarded_for"';  
  33.   
  34.  access_log /var/log/nginx/access.log main;  
  35.   
  36.  #設置緩存存儲路徑、存儲方式、分配內存大小、磁盤最大空間、緩存期限  
  37.  proxy_cache_path /var/cache/nginx/proxy_cache levels=1:2 keys_zone=http-cache:500m max_size=10g inactive=30d;  
  38.  proxy_temp_path /var/cache/nginx/proxy_cache/tmp;  
  39.   
  40.  upstream fdfs_group1 { #設置group1的服務器  
  41.  server 192.168.10.209:8080 weight=1 max_fails=2 fail_timeout=30s;  
  42.  server 192.168.10.219:8080 weight=1 max_fails=2 fail_timeout=30s;  
  43.  }  
  44.   
  45.  upstream fdfs_group2 { #設置group2的服務器  
  46.  server 192.168.10.103:10000 weight=1 max_fails=2 fail_timeout=30s;  
  47.  }  
  48.   
  49.  include /etc/nginx/conf.d/*.conf;  
  50. }  
  1. [root@localhost fdfs]# cat /etc/nginx/conf.d/tracker.conf    #配置nginx的tracker  
  2. server {  
  3.  listen 80;                #設置服務器端口  
  4.  server_name 192.168.10.219;  
  5.   
  6.  location /group1/M00 {    #設置group1的負載均衡參數  
  7.  proxy_next_upstream http_502 http_504 error timeout invalid_header;  
  8.  proxy_cache http-cache;  
  9.  proxy_cache_valid 200 304 12h;  
  10.  proxy_cache_key $uri$is_args$args;  
  11.  proxy_pass http://fdfs_group1;  
  12.  expires 30d;  
  13.  }  
  14.   
  15.  location ~* /group2/(M00|M01) { #設置group2的負載均衡參數  
  16.  proxy_next_upstream http_502 http_504 error timeout invalid_header;  
  17.  proxy_cache http-cache;  
  18.  proxy_cache_valid 200 304 12h;  
  19.  proxy_cache_key $uri$is_args$args;  
  20.  proxy_pass http://fdfs_group2;  
  21.  expires 30d;  
  22.  }  
  23. }  
  1. [root@localhost conf.d]# cat /etc/nginx/conf.d/storage.conf   #配置nginx的storage  
  2. server  
  3. {  
  4.  listen 8080;  
  5.  server_name 192.168.10.219;   
  6.   
  7.  location /group1/M00/ {  
  8.  root /var/www/fastdfs/data;  
  9.  rewrite ^/group1/M00/(.*) /$1 break;  
  10.  }   
  11.   
  12. }  

3,啓動tracker,storage和nginx

  1. //啓動  
  2. [root@localhost fdfs]# /usr/local/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart  
  3. [root@localhost fdfs]# /usr/local/bin/fdfs_storaged /etc/fdfs/storage.conf restart  
  4. [root@localhost fdfs]# /etc/init.d/nginx start  

在這裏有一點要注意,就是要先啓動tracker在啓動storage,如果nginx報目錄沒有建,創建一下,在重新啓動

五,配置192.168.10.209服務器

1,配置storage

  1. [root@localhost fdfs]# vim /etc/fdfs/storage.conf  
  2.   
  3. group_name=group1                   #組名,根據實際情況修改  
  4. port=23000                          #設置storage的端口號  
  5. base_path=/var/www/fastdfs          #設置storage的日誌目錄(需預先創建)  
  6. store_path_count=1                  #存儲路徑個數,需要和store_path個數匹配  
  7. store_path0=/var/www/fastdfs        #存儲路徑  
  8. tracker_server=192.168.10.219:22122 #tracker服務器的IP地址和端口號  

2,nginx配置

  1. [root@localhost conf.d]# cat /etc/nginx/conf.d/storage.conf   #配置storage  
  2. server  
  3. {  
  4.  listen 8080;  
  5.  server_name 192.168.10.209;   
  6.   
  7.  location /group1/M00/ {  
  8.  root /var/www/fastdfs/data;  
  9.  rewrite ^/group1/M00/(.*) /$1 break;  
  10.  }   
  11.   
  12. }  

3,啓動

  1. //啓動  
  2. [root@localhost fdfs]# /usr/local/bin/fdfs_storaged /etc/fdfs/storage.conf restart  
  3. [root@localhost fdfs]# /etc/init.d/nginx start  

六,配置192.168.10.103服務器

1,配置storage

  1. [root@localhost fdfs]# vim /etc/fdfs/storage.conf  
  2.   
  3. group_name=group2                   #組名,根據實際情況修改  
  4. port=23000                          #設置storage的端口號  
  5. base_path=/var/www/fastdfs          #設置storage的日誌目錄(需預先創建)  
  6. store_path_count=2                  #存儲路徑個數,需要和store_path個數匹配  
  7. store_path0=/var/www/fastdfs        #存儲路徑  
  8. store_path1=/mnt/usb/fastdfs2       #硬盤2的存儲路徑  
  9. tracker_server=192.168.10.219:22122 #tracker服務器的IP地址和端口號  

在這裏有一點要注意,就是有二塊硬盤,存文件的目錄也有二個

2,配置nginx

  1. [root@localhost conf.d]# cat /etc/nginx/conf.d/storage.conf    #配置storage  
  2. server  
  3. {  
  4.  listen 10000;  
  5.  server_name 192.168.10.103;   
  6.   
  7.  location /group2/M01/ {  
  8.  root /mnt/usb/fastdfs2/data;  
  9.  rewrite ^/group2/M01/(.*) /$1 break;  
  10.  }   
  11.   
  12.  location /group2/M00/ {  
  13.  root /var/www/fastdfs/data;  
  14.  rewrite ^/group2/M00/(.*) /$1 break;  
  15.  }   
  16.   
  17. }  

3,啓動

  1. //啓動  
  2. [root@localhost fdfs]# /usr/local/bin/fdfs_storaged /etc/fdfs/storage.conf restart  
  3. [root@localhost fdfs]# /etc/init.d/nginx start  

到這兒就安裝配置好了,有一點要注意:

就是訪問文件服務器的文件時,地址要用tracker的地址,例如:

http://192.168.10.219/group2/M01/00/00/wKgKZ1PAEquAbLj1AAK4TxGeCvM649.jpg

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章