zoukankan      html  css  js  c++  java
  • centos fastdfs 多服务器 多硬盘 多组 配置详解

    说正文前,先感谢happy_fish100提供的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是单点的,如果出了故障就郁闷了,以前搞过一次多tracker,不过版本比较老了。请参考:fastdfs 多服务器 配置

    三,安装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

  • 相关阅读:
    Python测试开发Tkinter-----(Button--按钮)
    Python测试开发Tkinter------(Frame--框架)
    Python测试开发Tkinter-----(Tkinter--创建顶层窗口及Label)
    python2.7 Scripts环境变量配置 requests bs4 selenium安装方法
    重要知识点:内网系列
    重点知识:系统区分法,响应码,client-ip限制,抓https包的方法
    重点知识:MD5
    01渗透测试基础
    渗透测试之信息收集篇
    sqlmap安装与使用基础
  • 原文地址:https://www.cnblogs.com/hujihon/p/5578851.html
Copyright © 2011-2022 走看看