隨着用戶量的變大,圖片,視頻等的量會不斷的增大,這個時候一個硬盤可能不夠用了,就要加硬盤。硬盤加不了時,就要增加服務器了。同一組服務器,文件服務器的東西是一樣,不同組的服務器,有不同的文件,不同的組之間,共同組建了文件服務器的所有內容。
下面說一下,安裝配置的過程,這裏配置的方法,根開發者提供的方法不一樣,我沒有用到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
- //安裝,gcc,automake,autoconf等依賴包
- [root@localhost download]$ yum install gettext gettext-devel libXft libXft-devel libXpm libXpm-devel\
- automake autoconf libXtst-devel gtk+-devel gcc zlib-devel libpng-devel gtk2-devel glib-devel
- //安裝FastDFS
- [root@localhost download]# tar zxf FastDFS_v5.01.tar.gz
- [root@localhost download]# cd FastDFS
- [root@localhost download]# ./make.sh
- [root@localhost download]# ./make.sh install
- //安裝成功有以下內容
- [root@localhost fdfs]# ll /usr/local/bin/ |grep fdfs
- -rwxr-xr-x 1 root root 522870 7月 4 03:20 fdfs_appender_test
- -rwxr-xr-x 1 root root 522823 7月 4 03:20 fdfs_appender_test1
- -rwxr-xr-x 1 root root 513975 7月 4 03:20 fdfs_append_file
- -rwxr-xr-x 1 root root 513393 7月 4 03:20 fdfs_crc32
- -rwxr-xr-x 1 root root 513927 7月 4 03:20 fdfs_delete_file
- -rwxr-xr-x 1 root root 514329 7月 4 03:20 fdfs_download_file
- -rwxr-xr-x 1 root root 514093 7月 4 03:20 fdfs_file_info
- -rwxr-xr-x 1 root root 525024 7月 4 03:20 fdfs_monitor
- -rwxr-xr-x 1 root root 1179642 7月 4 03:20 fdfs_storaged
- -rwxr-xr-x 1 root root 529805 7月 4 03:20 fdfs_test
- -rwxr-xr-x 1 root root 527726 7月 4 03:20 fdfs_test1
- -rwxr-xr-x 1 root root 655761 7月 4 03:20 fdfs_trackerd
- -rwxr-xr-x 1 root root 514173 7月 4 03:20 fdfs_upload_appender
- -rwxr-xr-x 1 root root 514951 7月 4 03:20 fdfs_upload_file
2,安裝nginx
- [root@localhost fdfs]# yum install nginx
所有機器的fastdfs和nginx安裝方法都是一樣。
四,配置192.168.10.219服務器
1,配置tracker和storage
- [root@localhost fdfs]# vim /etc/fdfs/tracker.conf
- port=22122 #設置tracker的端口號
- base_path=/var/www/fastdfs #設置tracker的數據文件和日誌目錄(需預先創建)
如果要調優,參考:http://bbs.chinaunix.net/forum.php?mod=viewthread&tid=1941456
- [root@localhost fdfs]# vim /etc/fdfs/storage.conf
- group_name=group1 #組名,根據實際情況修改
- port=23000 #設置storage的端口號
- base_path=/var/www/fastdfs #設置storage的日誌目錄(需預先創建)
- store_path_count=1 #存儲路徑個數,需要和store_path個數匹配
- store_path0=/var/www/fastdfs #存儲路徑
- tracker_server=192.168.10.219:22122 #tracker服務器的IP地址和端口號
2,tracker的nginx配置
- [root@localhost nginx]# cat /etc/nginx/nginx.conf #配置主配置文件
- user nginx;
- worker_processes 1;
- events {
- worker_connections 65535; #最大鏈接數
- use epoll; #新版本的Linux可使用epoll加快處理性能
- }
- error_log /var/log/nginx/error.log;
- pid /var/run/nginx.pid;
- http {
- server_names_hash_bucket_size 128;
- client_header_buffer_size 32k;
- large_client_header_buffers 4 32k;
- client_max_body_size 300m;
- sendfile on;
- tcp_nopush on;
- proxy_redirect off;
- proxy_set_header Host $http_host;
- proxy_set_header X-Real-IP $remote_addr;
- proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
- proxy_connect_timeout 90;
- proxy_send_timeout 90;
- proxy_read_timeout 90;
- proxy_buffer_size 16k;
- proxy_buffers 4 64k;
- proxy_busy_buffers_size 128k;
- proxy_temp_file_write_size 128k;
- log_format main '$remote_addr - $remote_user [$time_local] "$request" '
- '$status $body_bytes_sent "$http_referer" '
- '"$http_user_agent" "$http_x_forwarded_for"';
- access_log /var/log/nginx/access.log main;
- #設置緩存存儲路徑、存儲方式、分配內存大小、磁盤最大空間、緩存期限
- proxy_cache_path /var/cache/nginx/proxy_cache levels=1:2 keys_zone=http-cache:500m max_size=10g inactive=30d;
- proxy_temp_path /var/cache/nginx/proxy_cache/tmp;
- upstream fdfs_group1 { #設置group1的服務器
- server 192.168.10.209:8080 weight=1 max_fails=2 fail_timeout=30s;
- server 192.168.10.219:8080 weight=1 max_fails=2 fail_timeout=30s;
- }
- upstream fdfs_group2 { #設置group2的服務器
- server 192.168.10.103:10000 weight=1 max_fails=2 fail_timeout=30s;
- }
- include /etc/nginx/conf.d/*.conf;
- }
- [root@localhost fdfs]# cat /etc/nginx/conf.d/tracker.conf #配置nginx的tracker
- server {
- listen 80; #設置服務器端口
- server_name 192.168.10.219;
- location /group1/M00 { #設置group1的負載均衡參數
- proxy_next_upstream http_502 http_504 error timeout invalid_header;
- proxy_cache http-cache;
- proxy_cache_valid 200 304 12h;
- proxy_cache_key $uri$is_args$args;
- proxy_pass http://fdfs_group1;
- expires 30d;
- }
- location ~* /group2/(M00|M01) { #設置group2的負載均衡參數
- proxy_next_upstream http_502 http_504 error timeout invalid_header;
- proxy_cache http-cache;
- proxy_cache_valid 200 304 12h;
- proxy_cache_key $uri$is_args$args;
- proxy_pass http://fdfs_group2;
- expires 30d;
- }
- }
- [root@localhost conf.d]# cat /etc/nginx/conf.d/storage.conf #配置nginx的storage
- server
- {
- listen 8080;
- server_name 192.168.10.219;
- location /group1/M00/ {
- root /var/www/fastdfs/data;
- rewrite ^/group1/M00/(.*) /$1 break;
- }
- }
3,啓動tracker,storage和nginx
- //啓動
- [root@localhost fdfs]# /usr/local/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart
- [root@localhost fdfs]# /usr/local/bin/fdfs_storaged /etc/fdfs/storage.conf restart
- [root@localhost fdfs]# /etc/init.d/nginx start
在這裏有一點要注意,就是要先啓動tracker在啓動storage,如果nginx報目錄沒有建,創建一下,在重新啓動
五,配置192.168.10.209服務器
1,配置storage
- [root@localhost fdfs]# vim /etc/fdfs/storage.conf
- group_name=group1 #組名,根據實際情況修改
- port=23000 #設置storage的端口號
- base_path=/var/www/fastdfs #設置storage的日誌目錄(需預先創建)
- store_path_count=1 #存儲路徑個數,需要和store_path個數匹配
- store_path0=/var/www/fastdfs #存儲路徑
- tracker_server=192.168.10.219:22122 #tracker服務器的IP地址和端口號
2,nginx配置
- [root@localhost conf.d]# cat /etc/nginx/conf.d/storage.conf #配置storage
- server
- {
- listen 8080;
- server_name 192.168.10.209;
- location /group1/M00/ {
- root /var/www/fastdfs/data;
- rewrite ^/group1/M00/(.*) /$1 break;
- }
- }
3,啓動
- //啓動
- [root@localhost fdfs]# /usr/local/bin/fdfs_storaged /etc/fdfs/storage.conf restart
- [root@localhost fdfs]# /etc/init.d/nginx start
六,配置192.168.10.103服務器
1,配置storage
- [root@localhost fdfs]# vim /etc/fdfs/storage.conf
- group_name=group2 #組名,根據實際情況修改
- port=23000 #設置storage的端口號
- base_path=/var/www/fastdfs #設置storage的日誌目錄(需預先創建)
- store_path_count=2 #存儲路徑個數,需要和store_path個數匹配
- store_path0=/var/www/fastdfs #存儲路徑
- store_path1=/mnt/usb/fastdfs2 #硬盤2的存儲路徑
- tracker_server=192.168.10.219:22122 #tracker服務器的IP地址和端口號
在這裏有一點要注意,就是有二塊硬盤,存文件的目錄也有二個
2,配置nginx
- [root@localhost conf.d]# cat /etc/nginx/conf.d/storage.conf #配置storage
- server
- {
- listen 10000;
- server_name 192.168.10.103;
- location /group2/M01/ {
- root /mnt/usb/fastdfs2/data;
- rewrite ^/group2/M01/(.*) /$1 break;
- }
- location /group2/M00/ {
- root /var/www/fastdfs/data;
- rewrite ^/group2/M00/(.*) /$1 break;
- }
- }
3,啓動
- //啓動
- [root@localhost fdfs]# /usr/local/bin/fdfs_storaged /etc/fdfs/storage.conf restart
- [root@localhost fdfs]# /etc/init.d/nginx start
到這兒就安裝配置好了,有一點要注意:
就是訪問文件服務器的文件時,地址要用tracker的地址,例如:
http://192.168.10.219/group2/M01/00/00/wKgKZ1PAEquAbLj1AAK4TxGeCvM649.jpg