web访问 FastDFS 方法思路
生活随笔
收集整理的這篇文章主要介紹了
web访问 FastDFS 方法思路
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
? ? ? ?由于余老師在 V4.05 以后的版本就把內(nèi)置 HTTP服務(wù)去掉了,所以就算這篇你測試上傳成功了,你也訪問不了。 推薦大家結(jié)合 Nginx 使用 fastdfs-nginx-module 模塊,
搭建好fastdfs 系統(tǒng)后 就可以搭建web訪問功能了。
大體思路有以下兩種
1.直接安裝nginx關(guān)于fastdfs集合的擴(kuò)展模塊 ?fastdfs-nginx-module ?
? ? 或者直接安裝apache關(guān)于fastdfs集合的擴(kuò)展模塊 ?fastdfs-apache-module ? ? ?fastdfs-nginx-module 的作用:
? ? ? ?在每一臺(tái)storage上部署Nginx及?fastdfs-nginx-module擴(kuò)展模塊,如果當(dāng)前storage節(jié)點(diǎn)找不到文件時(shí)
會(huì)向源storage主機(jī)發(fā)起redirect或proxy動(dòng)作 2.安裝web軟件后,通過配置nginx實(shí)現(xiàn)了fastdfs-nginx-module的功能
第一種(推薦).
下載nginx ?和 ? 插件fastdfs-nginx-module-master.zip ? 這兩個(gè)軟件 (如果nginx已經(jīng)安裝好了,需要重新編譯一遍,編譯時(shí)把插件裝上)
(如果nginx使用yum安裝的,需要下載yum相同版本安裝包,重新編譯)
這里從頭開始安裝: 解壓: # tar -zxvf nginx-1.13.5.tar.gz
# unzip fastdfs-nginx-module-master.zip?
安裝nginx和fastdfs插件:
?./configure --prefix=/usr/local/nginx ?--add-module=/home/packages/fastdfs-nginx-module-master/src
連續(xù)報(bào)錯(cuò): 報(bào)錯(cuò):?the HTTP rewrite module requires the PCRE library.……
解決:yum install pcre-devel.x86_64 報(bào)錯(cuò):?the HTTP gzip module requires the zlib library.……
解決:yum install zlib-devel.x86_64
編譯成功:
adding module in /home/packages/fastdfs-nginx-module-master/src ?+ ngx_http_fastdfs_module was configured
Configuration summary ? + using system PCRE library ? + OpenSSL library is not used ? + using system zlib library
? nginx path prefix: "/usr/local/nginx" ? nginx binary file: "/usr/local/nginx/sbin/nginx" ? nginx modules path: "/usr/local/nginx/modules" ? nginx configuration prefix: "/usr/local/nginx/conf" ? nginx configuration file: "/usr/local/nginx/conf/nginx.conf" ? nginx pid file: "/usr/local/nginx/logs/nginx.pid" ? nginx error log file: "/usr/local/nginx/logs/error.log" ? nginx http access log file: "/usr/local/nginx/logs/access.log" ? nginx http client request body temporary files: "client_body_temp" ? nginx http proxy temporary files: "proxy_temp" ? nginx http fastcgi temporary files: "fastcgi_temp" ? nginx http uwsgi temporary files: "uwsgi_temp" ? nginx http scgi temporary files: "scgi_temp"
繼續(xù)安裝: # make # make install
進(jìn)入nginx安裝目錄,修改其配置文件: # cd /usr/local/nginx/conf # vi nginx.conf 增加以下內(nèi)容:
?location /M00 { ? ? ? ? ? ? root /home/yuqing/fastdfs/data; ? ? ? ? ? ? ngx_fastdfs_module; ? ? ? ? }
新建一個(gè)軟連接: # ln -s /home/yuqing/fastdfs/data ?/home/yuqing/fastdfs/data/M00
復(fù)制并修改mod_fastdfs.conf文件: # cp mod_fastdfs.conf /etc/fdfs/ # vi /etc/fdfs/mod_fastdfs.conf 修改了這里: tracker_server=10.0.0.42:22122
(復(fù)制這兩個(gè)文件到fdfs配置文件,要不無法訪問nginx) (# cp /home/fastdfs-5.11/conf/http.conf /etc/fdfs/)
(# cp /home/fastdfs-5.11/conf/mime.types /etc/fdfs/)
重啟nginx:
# /usr/local/nginx/sbin/nginx -s stop;
# /usr/local/nginx/sbin/nginx
報(bào)錯(cuò):瀏覽器無法訪問
查看nginx錯(cuò)誤日志 如下 ?ERROR - file: ini_file_reader.c, line: 631, include file "http.conf" not exists, line: "#include http.conf" ?ERROR - file: /home/packages/fastdfs-nginx-module-master/src/common.c, line: 163, load conf file "/etc/fdfs/mod_fastdfs.conf" fail, ret code: 2 解決:# cp /home/fastdfs-5.11/conf/http.conf /etc/fdfs/
?ERROR - file: shared_func.c, line: 968, file /etc/fdfs/mime.types not exist 解決:# cp /home/fastdfs-5.11/conf/mime.types /etc/fdfs/
訪問nginx 成功
下面看一下?mod_fastdfs.conf文件: # connect timeout in seconds # default value is 30s connect_timeout=2 連接超時(shí)時(shí)間
# network recv and send timeout in seconds # default value is 30s network_timeout=30 發(fā)送接受數(shù)據(jù) 超時(shí)時(shí)間
# the base path to store log files base_path=/tmp 日志文件 位置
# if load FastDFS parameters from tracker server # since V1.12 # default value is false load_fdfs_parameters_from_tracker=true 是否從 tracket服務(wù)器讀取信息
如果不從tracket服務(wù)器讀取信息,以下三個(gè)參數(shù)生效 # storage sync file max delay seconds # same as tracker.conf # valid only when load_fdfs_parameters_from_tracker is false # since V1.12 # default value is 86400 seconds (one day) storage_sync_file_max_delay = 86400 ? ? ? 當(dāng)load_fdfs_parameters_from_tracker設(shè)置為false時(shí),本參數(shù)生效 同步文件最大延遲時(shí)間,與tracker.conf文件中參數(shù)相同
默認(rèn)是一天
# if use storage ID instead of IP address # same as tracker.conf # valid only when load_fdfs_parameters_from_tracker is false # default value is false # since V1.13 use_storage_id = false ? ? 是否使用storage_id?
# specify storage ids filename, can use relative or absolute path # same as tracker.conf # valid only when load_fdfs_parameters_from_tracker is false # since V1.13 storage_ids_filename = storage_ids.conf
? ? ?storage_id的位置
# FastDFS tracker_server can ocur more than once, and tracker_server format is # ?"host:port", host can be hostname or ip address # valid only when load_fdfs_parameters_from_tracker is true tracker_server=10.0.0.42:22122 從tracket服務(wù)器讀取信息,這個(gè)參數(shù)生效 tracket服務(wù)器地址、端口
# the port of the local storage server # the default value is 23000 storage_server_port=23000 ? ? 本storage server監(jiān)聽端口
# the group name of the local storage server group_name=group1 ? ? ? group組名
# if the url / uri including the group name # set to false when uri like /M00/00/00/xxx # set to true when uri like ${group_name}/M00/00/00/xxx, such as group1/M00/xxx # default value is false url_have_group_name = false url鏈接中是否包含 組名 類似?/M00/00/00/xxx 和group1/M00/00/00/xxx 如果選擇true 即包含組名,需要修改nginx配置文件
將??location /M00 ? ?改為 ? ??location /group1/M00?
# path(disk or mount point) count, default value is 1 # must same as storage.conf store_path_count=1 ? ? ? 存儲(chǔ)路徑數(shù)量,必須和?storage.conf文件一致
# store_path#, based 0, if store_path0 not exists, it's value is base_path # the paths must be exist # must same as storage.conf store_path0=/home/yuqing/fastdfs #store_path1=/home/yuqing/fastdfs1 ? ? ?存儲(chǔ)路徑地址、必須和?storage.conf文件一致
# standard log level as syslog, case insensitive, value list: ### emerg for emergency ### alert ### crit for critical ### error ### warn for warning ### notice ### info ### debug log_level=info ? ? 日志級別
# set the log filename, such as /usr/local/apache2/logs/mod_fastdfs.log # empty for output to stderr (apache and nginx error_log file) log_filename= ? ? ?設(shè)置日志的名稱,為空則記錄到 http服務(wù)的錯(cuò)誤日志里
# response mode when the file not exist in the local file system ## proxy: get the content from other storage server, then send to client ## redirect: redirect to the original storage server (HTTP Header is Location) response_mode=proxy 當(dāng)文件在本地不存在時(shí)怎樣回應(yīng)
# use "#include" directive to include HTTP config file # NOTE: #include is an include directive, do NOT remove the # before include #include http.conf ? ?使用#include指令 包含http配置文件 ? ? 注意:#include ?這是一個(gè)包含指令,不要?jiǎng)h除 include前面的 #
# if support flv # default value is false # since v1.15 flv_support = true ? ?是否支持flv文件,默認(rèn)不支持
# flv file extension name # default value is flv # since v1.15 flv_extension = flv ? ? flv文件的擴(kuò)展名,默認(rèn)是flv
# set the group count # set to none zero to support multi-group on this storage server # set to 0 ?for single group only # groups settings section as [group1], [group2], ..., [groupN] # default value is 0 # since v1.14 group_count = 0 設(shè)置組的數(shù)量
設(shè)置沒有0 ,支持多個(gè)group組在這個(gè)存儲(chǔ)服務(wù)器上 設(shè)置0 為只有一個(gè)組 如果服務(wù)器上多個(gè)組,組的設(shè)置 就像這樣?[group1], [group2], ..., [groupN] 默認(rèn)是0,一組
# group settings for group #1 # since v1.14 # when support multi-group on this storage server, uncomment following section #[group1] #group_name=group1 #storage_server_port=23000 #store_path_count=2 #store_path0=/home/yuqing/fastdfs #store_path1=/home/yuqing/fastdfs1 ? ?組1的設(shè)置 ? ?若本存儲(chǔ)服務(wù)器支持多組,取消下面的注釋
# group settings for group #2 # since v1.14 # when support multi-group, uncomment following section as neccessary #[group2] #group_name=group2 #storage_server_port=23000 #store_path_count=1 #store_path0=/home/yuqing/fastdfs 組2的設(shè)置 若本存儲(chǔ)服務(wù)器支持多組,取消下面的注釋
二、直接使用 web訪問 這個(gè)比較簡單,只需要把web根目錄指定到 fastdfs的存儲(chǔ)目錄就可以了
三、web訪問fastdfs 的幾種思路
3.1 ?只使用 組名
適用于圖片量大、group組多、每個(gè)group組都有備份 訪問地址類似于 ? picture.xxx.com/groupx/M00/……jpg 只需要一個(gè)域名;
上傳圖片后 將返回的值 直接+域名 ?保存為圖片名 :picture.xxx.com/groupx/M00/……jpg 前端使用一個(gè)nginx做反向代理+負(fù)載均衡 ?配置如下: upstream group1{ ? ?server group1_storage1:80;
? ?server group1_storage2:80;
} upstream group2{ ? ?server group2_storage1:80;
? ?server group2_storage2:80;
}
location /group1/M00{ proxy_pass http://group1; } location /group2/M00{ proxy_pass http://group2; }
注意:group1 和 group2 中 機(jī)器要正確配置 nginx.conf ?storage.conf 和 mod_fastdfs.conf 文件 nginx.conf中
?location /group1/M00 { ? ? ? ? ? ? root /home/yuqing/fastdfs/data; ? ? ? ? ? ? ngx_fastdfs_module; ? ? ? ? }
?特別注意 ?mod_fastdfs.conf文件中 ?這兩項(xiàng) 組名、url是否包含group名
group_name=
url_have_group_name =
3.2 只使用 域名 (已部署生產(chǎn)環(huán)境)
適用于圖片較少,每個(gè)group組都是單機(jī)跑,沒有備份的情況 訪問地址類似于 ? picturex.xxx.com/M00/……jpg 需要多個(gè)域名;
上傳圖片后 將返回的值分開后 結(jié)合域名 生成圖片名 ??picturex.xxx.com/M00/……jpg 前端使用一個(gè)nginx做反向代理 ?配置如下: upstream group1{ ? ?server group1_storage1:80;
} upstream group2{ server group2_storage1:80;
}
location /group1/M00{ proxy_pass http://group1; } location /group2/M00{ proxy_pass http://group2; }
注意:group1 和 group2 中 機(jī)器要正確配置 nginx.conf ?storage.conf
由于每組沒有備份, mod_fastdfs.conf 也不用安裝了 nginx.conf中
location /group1/M00 { root /home/yuqing/fastdfs/data; }
3.3 域名和組名同時(shí)使用 ? 適用于圖片量大、業(yè)務(wù)量多、group組多、每個(gè)group組都有備份 訪問地址類似于 ? picturex.xxx.com/groupx/M00/……jpg 只需要一個(gè)域名;
上傳圖片后 將返回的值+改動(dòng)域名 ?保存為圖片名 :picturex.xxx.com/groupx/M00/……jpg 使用多個(gè)域名對應(yīng)一個(gè)nginx ?做反向代理+負(fù)載均衡 ?配置如下: ? upstream group1{ server group1_storage1:80;
? ?server group1_storage2:80;
} upstream group2{ server group2_storage1:80;
? ?server group2_storage2:80;
}
server {
? ? ? ? listen ? ? ? 80;
? ? ? ? server_name ?picture1.xxx.com;
? ? ? ?…… location /group1/M00{ proxy_pass http://group1; } location /group2/M00{ proxy_pass http://group2; } }
server {
? ? ? ? listen ? ? ? 80;
? ? ? ? server_name ?picture2.xxx.com;
? ? ? ?……
} 注意:group1 和 group2 中 機(jī)器要正確配置 nginx.conf ?storage.conf 和?mod_fastdfs.conf 文件 nginx.conf中
location /group1/M00 { root /home/yuqing/fastdfs/data; ?ngx_fastdfs_module; }
?特別注意 ?mod_fastdfs.conf文件中 ?這兩項(xiàng) 組名、url是否包含group名
group_name=
url_have_group_name =
搭建好fastdfs 系統(tǒng)后 就可以搭建web訪問功能了。
大體思路有以下兩種
1.直接安裝nginx關(guān)于fastdfs集合的擴(kuò)展模塊 ?fastdfs-nginx-module ?
? ? 或者直接安裝apache關(guān)于fastdfs集合的擴(kuò)展模塊 ?fastdfs-apache-module ? ? ?fastdfs-nginx-module 的作用:
? ? ? ?在每一臺(tái)storage上部署Nginx及?fastdfs-nginx-module擴(kuò)展模塊,如果當(dāng)前storage節(jié)點(diǎn)找不到文件時(shí)
會(huì)向源storage主機(jī)發(fā)起redirect或proxy動(dòng)作 2.安裝web軟件后,通過配置nginx實(shí)現(xiàn)了fastdfs-nginx-module的功能
第一種(推薦).
下載nginx ?和 ? 插件fastdfs-nginx-module-master.zip ? 這兩個(gè)軟件 (如果nginx已經(jīng)安裝好了,需要重新編譯一遍,編譯時(shí)把插件裝上)
(如果nginx使用yum安裝的,需要下載yum相同版本安裝包,重新編譯)
這里從頭開始安裝: 解壓: # tar -zxvf nginx-1.13.5.tar.gz
# unzip fastdfs-nginx-module-master.zip?
安裝nginx和fastdfs插件:
?./configure --prefix=/usr/local/nginx ?--add-module=/home/packages/fastdfs-nginx-module-master/src
連續(xù)報(bào)錯(cuò): 報(bào)錯(cuò):?the HTTP rewrite module requires the PCRE library.……
解決:yum install pcre-devel.x86_64 報(bào)錯(cuò):?the HTTP gzip module requires the zlib library.……
解決:yum install zlib-devel.x86_64
編譯成功:
adding module in /home/packages/fastdfs-nginx-module-master/src ?+ ngx_http_fastdfs_module was configured
Configuration summary ? + using system PCRE library ? + OpenSSL library is not used ? + using system zlib library
? nginx path prefix: "/usr/local/nginx" ? nginx binary file: "/usr/local/nginx/sbin/nginx" ? nginx modules path: "/usr/local/nginx/modules" ? nginx configuration prefix: "/usr/local/nginx/conf" ? nginx configuration file: "/usr/local/nginx/conf/nginx.conf" ? nginx pid file: "/usr/local/nginx/logs/nginx.pid" ? nginx error log file: "/usr/local/nginx/logs/error.log" ? nginx http access log file: "/usr/local/nginx/logs/access.log" ? nginx http client request body temporary files: "client_body_temp" ? nginx http proxy temporary files: "proxy_temp" ? nginx http fastcgi temporary files: "fastcgi_temp" ? nginx http uwsgi temporary files: "uwsgi_temp" ? nginx http scgi temporary files: "scgi_temp"
繼續(xù)安裝: # make # make install
進(jìn)入nginx安裝目錄,修改其配置文件: # cd /usr/local/nginx/conf # vi nginx.conf 增加以下內(nèi)容:
?location /M00 { ? ? ? ? ? ? root /home/yuqing/fastdfs/data; ? ? ? ? ? ? ngx_fastdfs_module; ? ? ? ? }
新建一個(gè)軟連接: # ln -s /home/yuqing/fastdfs/data ?/home/yuqing/fastdfs/data/M00
復(fù)制并修改mod_fastdfs.conf文件: # cp mod_fastdfs.conf /etc/fdfs/ # vi /etc/fdfs/mod_fastdfs.conf 修改了這里: tracker_server=10.0.0.42:22122
(復(fù)制這兩個(gè)文件到fdfs配置文件,要不無法訪問nginx) (# cp /home/fastdfs-5.11/conf/http.conf /etc/fdfs/)
(# cp /home/fastdfs-5.11/conf/mime.types /etc/fdfs/)
重啟nginx:
# /usr/local/nginx/sbin/nginx -s stop;
# /usr/local/nginx/sbin/nginx
報(bào)錯(cuò):瀏覽器無法訪問
查看nginx錯(cuò)誤日志 如下 ?ERROR - file: ini_file_reader.c, line: 631, include file "http.conf" not exists, line: "#include http.conf" ?ERROR - file: /home/packages/fastdfs-nginx-module-master/src/common.c, line: 163, load conf file "/etc/fdfs/mod_fastdfs.conf" fail, ret code: 2 解決:# cp /home/fastdfs-5.11/conf/http.conf /etc/fdfs/
?ERROR - file: shared_func.c, line: 968, file /etc/fdfs/mime.types not exist 解決:# cp /home/fastdfs-5.11/conf/mime.types /etc/fdfs/
訪問nginx 成功
下面看一下?mod_fastdfs.conf文件: # connect timeout in seconds # default value is 30s connect_timeout=2 連接超時(shí)時(shí)間
# network recv and send timeout in seconds # default value is 30s network_timeout=30 發(fā)送接受數(shù)據(jù) 超時(shí)時(shí)間
# the base path to store log files base_path=/tmp 日志文件 位置
# if load FastDFS parameters from tracker server # since V1.12 # default value is false load_fdfs_parameters_from_tracker=true 是否從 tracket服務(wù)器讀取信息
如果不從tracket服務(wù)器讀取信息,以下三個(gè)參數(shù)生效 # storage sync file max delay seconds # same as tracker.conf # valid only when load_fdfs_parameters_from_tracker is false # since V1.12 # default value is 86400 seconds (one day) storage_sync_file_max_delay = 86400 ? ? ? 當(dāng)load_fdfs_parameters_from_tracker設(shè)置為false時(shí),本參數(shù)生效 同步文件最大延遲時(shí)間,與tracker.conf文件中參數(shù)相同
默認(rèn)是一天
# if use storage ID instead of IP address # same as tracker.conf # valid only when load_fdfs_parameters_from_tracker is false # default value is false # since V1.13 use_storage_id = false ? ? 是否使用storage_id?
# specify storage ids filename, can use relative or absolute path # same as tracker.conf # valid only when load_fdfs_parameters_from_tracker is false # since V1.13 storage_ids_filename = storage_ids.conf
? ? ?storage_id的位置
# FastDFS tracker_server can ocur more than once, and tracker_server format is # ?"host:port", host can be hostname or ip address # valid only when load_fdfs_parameters_from_tracker is true tracker_server=10.0.0.42:22122 從tracket服務(wù)器讀取信息,這個(gè)參數(shù)生效 tracket服務(wù)器地址、端口
# the port of the local storage server # the default value is 23000 storage_server_port=23000 ? ? 本storage server監(jiān)聽端口
# the group name of the local storage server group_name=group1 ? ? ? group組名
# if the url / uri including the group name # set to false when uri like /M00/00/00/xxx # set to true when uri like ${group_name}/M00/00/00/xxx, such as group1/M00/xxx # default value is false url_have_group_name = false url鏈接中是否包含 組名 類似?/M00/00/00/xxx 和group1/M00/00/00/xxx 如果選擇true 即包含組名,需要修改nginx配置文件
將??location /M00 ? ?改為 ? ??location /group1/M00?
# path(disk or mount point) count, default value is 1 # must same as storage.conf store_path_count=1 ? ? ? 存儲(chǔ)路徑數(shù)量,必須和?storage.conf文件一致
# store_path#, based 0, if store_path0 not exists, it's value is base_path # the paths must be exist # must same as storage.conf store_path0=/home/yuqing/fastdfs #store_path1=/home/yuqing/fastdfs1 ? ? ?存儲(chǔ)路徑地址、必須和?storage.conf文件一致
# standard log level as syslog, case insensitive, value list: ### emerg for emergency ### alert ### crit for critical ### error ### warn for warning ### notice ### info ### debug log_level=info ? ? 日志級別
# set the log filename, such as /usr/local/apache2/logs/mod_fastdfs.log # empty for output to stderr (apache and nginx error_log file) log_filename= ? ? ?設(shè)置日志的名稱,為空則記錄到 http服務(wù)的錯(cuò)誤日志里
# response mode when the file not exist in the local file system ## proxy: get the content from other storage server, then send to client ## redirect: redirect to the original storage server (HTTP Header is Location) response_mode=proxy 當(dāng)文件在本地不存在時(shí)怎樣回應(yīng)
- proxy 代理,從其它存儲(chǔ)服務(wù)器獲取內(nèi)容,然后發(fā)送給客戶
- redirect ?重定向原始存儲(chǔ)服務(wù)器的http頭
# use "#include" directive to include HTTP config file # NOTE: #include is an include directive, do NOT remove the # before include #include http.conf ? ?使用#include指令 包含http配置文件 ? ? 注意:#include ?這是一個(gè)包含指令,不要?jiǎng)h除 include前面的 #
# if support flv # default value is false # since v1.15 flv_support = true ? ?是否支持flv文件,默認(rèn)不支持
# flv file extension name # default value is flv # since v1.15 flv_extension = flv ? ? flv文件的擴(kuò)展名,默認(rèn)是flv
# set the group count # set to none zero to support multi-group on this storage server # set to 0 ?for single group only # groups settings section as [group1], [group2], ..., [groupN] # default value is 0 # since v1.14 group_count = 0 設(shè)置組的數(shù)量
設(shè)置沒有0 ,支持多個(gè)group組在這個(gè)存儲(chǔ)服務(wù)器上 設(shè)置0 為只有一個(gè)組 如果服務(wù)器上多個(gè)組,組的設(shè)置 就像這樣?[group1], [group2], ..., [groupN] 默認(rèn)是0,一組
# group settings for group #1 # since v1.14 # when support multi-group on this storage server, uncomment following section #[group1] #group_name=group1 #storage_server_port=23000 #store_path_count=2 #store_path0=/home/yuqing/fastdfs #store_path1=/home/yuqing/fastdfs1 ? ?組1的設(shè)置 ? ?若本存儲(chǔ)服務(wù)器支持多組,取消下面的注釋
# group settings for group #2 # since v1.14 # when support multi-group, uncomment following section as neccessary #[group2] #group_name=group2 #storage_server_port=23000 #store_path_count=1 #store_path0=/home/yuqing/fastdfs 組2的設(shè)置 若本存儲(chǔ)服務(wù)器支持多組,取消下面的注釋
二、直接使用 web訪問 這個(gè)比較簡單,只需要把web根目錄指定到 fastdfs的存儲(chǔ)目錄就可以了
三、web訪問fastdfs 的幾種思路
3.1 ?只使用 組名
適用于圖片量大、group組多、每個(gè)group組都有備份 訪問地址類似于 ? picture.xxx.com/groupx/M00/……jpg 只需要一個(gè)域名;
上傳圖片后 將返回的值 直接+域名 ?保存為圖片名 :picture.xxx.com/groupx/M00/……jpg 前端使用一個(gè)nginx做反向代理+負(fù)載均衡 ?配置如下: upstream group1{ ? ?server group1_storage1:80;
? ?server group1_storage2:80;
} upstream group2{ ? ?server group2_storage1:80;
? ?server group2_storage2:80;
}
location /group1/M00{ proxy_pass http://group1; } location /group2/M00{ proxy_pass http://group2; }
注意:group1 和 group2 中 機(jī)器要正確配置 nginx.conf ?storage.conf 和 mod_fastdfs.conf 文件 nginx.conf中
?location /group1/M00 { ? ? ? ? ? ? root /home/yuqing/fastdfs/data; ? ? ? ? ? ? ngx_fastdfs_module; ? ? ? ? }
?特別注意 ?mod_fastdfs.conf文件中 ?這兩項(xiàng) 組名、url是否包含group名
group_name=
url_have_group_name =
3.2 只使用 域名 (已部署生產(chǎn)環(huán)境)
適用于圖片較少,每個(gè)group組都是單機(jī)跑,沒有備份的情況 訪問地址類似于 ? picturex.xxx.com/M00/……jpg 需要多個(gè)域名;
上傳圖片后 將返回的值分開后 結(jié)合域名 生成圖片名 ??picturex.xxx.com/M00/……jpg 前端使用一個(gè)nginx做反向代理 ?配置如下: upstream group1{ ? ?server group1_storage1:80;
} upstream group2{ server group2_storage1:80;
}
location /group1/M00{ proxy_pass http://group1; } location /group2/M00{ proxy_pass http://group2; }
注意:group1 和 group2 中 機(jī)器要正確配置 nginx.conf ?storage.conf
由于每組沒有備份, mod_fastdfs.conf 也不用安裝了 nginx.conf中
location /group1/M00 { root /home/yuqing/fastdfs/data; }
3.3 域名和組名同時(shí)使用 ? 適用于圖片量大、業(yè)務(wù)量多、group組多、每個(gè)group組都有備份 訪問地址類似于 ? picturex.xxx.com/groupx/M00/……jpg 只需要一個(gè)域名;
上傳圖片后 將返回的值+改動(dòng)域名 ?保存為圖片名 :picturex.xxx.com/groupx/M00/……jpg 使用多個(gè)域名對應(yīng)一個(gè)nginx ?做反向代理+負(fù)載均衡 ?配置如下: ? upstream group1{ server group1_storage1:80;
? ?server group1_storage2:80;
} upstream group2{ server group2_storage1:80;
? ?server group2_storage2:80;
}
server {
? ? ? ? listen ? ? ? 80;
? ? ? ? server_name ?picture1.xxx.com;
? ? ? ?…… location /group1/M00{ proxy_pass http://group1; } location /group2/M00{ proxy_pass http://group2; } }
server {
? ? ? ? listen ? ? ? 80;
? ? ? ? server_name ?picture2.xxx.com;
? ? ? ?……
} 注意:group1 和 group2 中 機(jī)器要正確配置 nginx.conf ?storage.conf 和?mod_fastdfs.conf 文件 nginx.conf中
location /group1/M00 { root /home/yuqing/fastdfs/data; ?ngx_fastdfs_module; }
?特別注意 ?mod_fastdfs.conf文件中 ?這兩項(xiàng) 組名、url是否包含group名
group_name=
url_have_group_name =
?
轉(zhuǎn)載于:https://www.cnblogs.com/centos2017/p/7896726.html
總結(jié)
以上是生活随笔為你收集整理的web访问 FastDFS 方法思路的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: node经验总结(一)
- 下一篇: canvas学习笔记(下篇) -- ca