配置过程:
修改storage.conf配置文件:
vim storage.conf
disabled=false
port=23000
base_path=/fastdfs/storager
tracker_server=192.168.216.132:22122 tracker_server=192.168.216.133:22122 tracker_server=192.168.216.134:22122
修改 client.conf配置文件;
vim /etc/fdfs/client.conf # 修改以下配置,其它保持默认
base_path=/home/fastdfs/tracker
tracker_server=192.168.216.132:22122
tracker_server=192.168.216.133:22122
tracker_server=192.168.216.134:22122
修改mod_fastdfs.conf 配置文件:
[root@localhost fdfs]# more /etc/fdfs/mod_fastdfs.conf #include http.conf # Tracker 服务器IP和端口修改 # # url 中是否包含 group 名称,改为 true,包含 group url_have_group_name = true # # 配置 Storage 信息,修改 store_path0 的信息 group_name=group1 base_path=/fastdfs/storager [group1] storage_server_port=23000 store_path_count=1 store_path0=/fastdfs/storager tracker_server=192.168.216.132:22122 tracker_server=192.168.216.133:22122 tracker_server=192.168.216.134:22122
安装nginx:
安装依赖包 yum install -y gcc gcc-c++ make automake autoconf libtool pcre pcre-devel zlib zlib-devel openssl openssl-devel wget http://labs.frickle.com/files/ngx_cache_purge-2.3.tar.gz tar xf ngx_cache_purge-2.3.tar.gz cd nginx-1.6.3/ ./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-http_stub_status_module --with-pcre --with-http_realip_module --add-module=/usr/local/ngx_cache_purge-2.3 make && make install
配置nginx负载均衡和缓存:
[root@localhost conf]# more nginx.conf user root; worker_processes 1; #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; #pid logs/nginx.pid; events { worker_connections 1024; use epoll; } http { include mime.types; default_type application/octet-stream; #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 logs/access.log main; sendfile on; tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; #gzip on; #设置缓存 server_names_hash_bucket_size 128; client_header_buffer_size 32k; large_client_header_buffers 4 32k; client_max_body_size 300m; 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; #设置缓存存储路径、存储方式、分配内存大小、磁盘最大空间、缓存期限 proxy_cache_path /data/fastdfs/cache/nginx/proxy_cache levels=1:2 keys_zone=http-cache:200m max_size=1g inactive=30d; proxy_temp_path /data/fastdfs/cache/nginx/proxy_cache/tmp; #设置 group1 的服务器 upstream fdfs_group1 { server 192.168.216.132:80 weight=1 max_fails=2 fail_timeout=30s; server 192.168.216.133:80 weight=1 max_fails=2 fail_timeout=30s; server 192.168.216.134:80 weight=1 max_fails=2 fail_timeout=30s; } #设置 group2 的服务器 #upstream fdfs_group2 { # server 192.168.0.125:8888 weight=1 max_fails=2 fail_timeout=30s; # server 192.168.0.126:8888 weight=1 max_fails=2 fail_timeout=30s; #} server { listen 8000; server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; #设置 group 的负载均衡参数 location /group1/M00 { 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 { # 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; #} #设置清除缓存的访问权限 location ~/purge(/.*) { allow 127.0.0.1; allow 192.168.0.0/24; deny all; proxy_cache_purge http-cache $1$is_args$args; } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } }
/usr/bin/fdfs_monitor /etc/fdfs/storage.conf: 查看fastdfs集群状态:
[root@localhost fdfs]# /usr/bin/fdfs_monitor /etc/fdfs/storage.conf [2021-03-18 02:21:26] DEBUG - base_path=/fastdfs/storager, connect_timeout=30, network_timeout=60, tracker_server_count=3, anti_steal_token=0, anti_steal_secret_key length=0, use_connection_pool=0, g_connection_pool_max_idle_time=3600s, use_storage_id=0, storage server id count: 0 server_count=3, server_index=0 tracker server is 192.168.216.132:22122 group count: 1 Group 1: group name = group1 disk total space = 46907 MB disk free space = 29405 MB trunk free space = 0 MB storage server count = 1 active server count = 1 storage server port = 23000 storage HTTP port = 8888 store path count = 1 subdir count per path = 256 current write server index = 0 current trunk file id = 0 Storage 1: id = 192.168.216.132 ip_addr = 192.168.216.132 (localhost.localdomain) ACTIVE http domain = version = 5.08 join time = 2021-02-22 00:17:16 up time = 2021-02-22 01:07:49 total storage = 46907 MB free storage = 29405 MB upload priority = 10 store_path_count = 1 subdir_count_per_path = 256 storage_port = 23000 storage_http_port = 8888 current_write_path = 0 source storage id = if_trunk_server = 0 connection.alloc_count = 256 connection.current_count = 0 connection.max_count = 1 total_upload_count = 5 success_upload_count = 5 total_append_count = 0 success_append_count = 0 total_modify_count = 0 success_modify_count = 0 total_truncate_count = 0 success_truncate_count = 0 total_set_meta_count = 0 success_set_meta_count = 0 total_delete_count = 0 success_delete_count = 0 total_download_count = 0 success_download_count = 0 total_get_meta_count = 0 success_get_meta_count = 0 total_create_link_count = 0 success_create_link_count = 0 total_delete_link_count = 0 success_delete_link_count = 0 total_upload_bytes = 445173 success_upload_bytes = 445173 total_append_bytes = 0 success_append_bytes = 0 total_modify_bytes = 0 success_modify_bytes = 0 stotal_download_bytes = 0 success_download_bytes = 0 total_sync_in_bytes = 0 success_sync_in_bytes = 0 total_sync_out_bytes = 0 success_sync_out_bytes = 0 total_file_open_count = 5 success_file_open_count = 5 total_file_read_count = 0 success_file_read_count = 0 total_file_write_count = 5 success_file_write_count = 5 last_heart_beat_time = 2021-03-18 02:20:58 last_source_update = 2021-03-18 01:53:16 last_sync_update = 1969-12-31 16:00:00 last_synced_timestamp = 1969-12-31 16:00:00 [root@localhost fdfs]#
测试: