四、在storage上安裝配置nginx
以下操作是在 storage1 10.10.10.120 上操作
1.安裝nginx
上傳 fastdfs-nginx-module_v1.16.tar.gz nginx-1.4.7.tar.gz pcre-8.36.tar.gz zlib-1.2.8.tar.gz 到storage服務器上的/usr/local/src 目錄下
[root@server1 src]# rz
rz waiting to receive.
Starting zmodem transfer. Press Ctrl+C to cancel.
Transferring fastdfs-nginx-module_v1.16.tar.gz...
100% 17 KB 17 KB/sec 00:00:01 0 Errors
Transferring nginx-1.4.7.tar.gz...
100% 751 KB 751 KB/sec 00:00:01 0 Errors
Transferring pcre-8.36.tar.gz...
100% 1962 KB 1962 KB/sec 00:00:01 0 Errors
Transferring zlib-1.2.8.tar.gz...
100% 557 KB 557 KB/sec 00:00:01 0 Errors
解壓各個文件,然后編譯安裝nginx
[root@server1 src]# tar xf nginx-1.4.7.tar.gz
[root@server1 src]# tar xf pcre-8.36.tar.gz
[root@server1 src]# tar xf zlib-1.2.8.tar.gz
[root@server1 src]# tar xf fastdfs-nginx-module_v1.16.tar.gz
[root@server1 src]# cd nginx-1.4.7
[root@server1 nginx-1.4.7]# ls
auto CHANGES CHANGES.ru conf configure contrib html LICENSE man README src
[root@server1 nginx-1.4.7]# ./configure --prefix=/usr/local/nginx --add-module=/usr/local/src/fastdfs-nginx-module/src --with-pcre=/usr/local/src/pcre-8.36 --with-zlib=/usr/local/src/zlib-1.2.8
出現以下錯誤:
cc -c -pipe -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g -D_FILE_OFFSET_BITS=64 -DFDFS_OUTPUT_CHUNK_SIZE='256*1024' -DFDFS_MOD_CONF_FILENAME='"/etc/fdfs/mod_fastdfs.conf"' -I src/core -I src/event -I src/event/modules -I src/os/unix -I /usr/local/include/fastdfs -I /usr/local/include/fastcommon/ -I /usr/local/src/pcre-8.36 -I /usr/local/src/zlib-1.2.8 -I objs -I src/http -I src/http/modules -I src/mail \
-o objs/addon/src/ngx_http_fastdfs_module.o \
/usr/local/src/fastdfs-nginx-module/src/ngx_http_fastdfs_module.c
在包含自 /usr/local/src/fastdfs-nginx-module/src/ngx_http_fastdfs_module.c:6 的文件中:
/usr/local/src/fastdfs-nginx-module/src/common.c:21:25: 錯誤:fdfs_define.h:沒有那個文件或目錄
/usr/local/src/fastdfs-nginx-module/src/common.c:22:20: 錯誤:logger.h:沒有那個文件或目錄
/usr/local/src/fastdfs-nginx-module/src/common.c:23:25: 錯誤:shared_func.h:沒有那個文件或目錄
/usr/local/src/fastdfs-nginx-module/src/common.c:24:25: 錯誤:fdfs_global.h:沒有那個文件或目錄
/usr/local/src/fastdfs-nginx-module/src/common.c:25:21: 錯誤:sockopt.h:沒有那個文件或目錄
/usr/local/src/fastdfs-nginx-module/src/common.c:26:23: 錯誤:http_func.h:沒有那個文件或目錄
/usr/local/src/fastdfs-nginx-module/src/common.c:27:30: 錯誤:fdfs_http_shared.h:沒有那個文件或目錄
/usr/local/src/fastdfs-nginx-module/src/common.c:28:25: 錯誤:fdfs_client.h:沒有那個文件或目錄
/usr/local/src/fastdfs-nginx-module/src/common.c:29:27: 錯誤:local_ip_func.h:沒有那個文件或目錄
/usr/local/src/fastdfs-nginx-module/src/common.c:30:30: 錯誤:fdfs_shared_func.h:沒有那個文件或目錄
/usr/local/src/fastdfs-nginx-module/src/common.c:31:26: 錯誤:trunk_shared.h:沒有那個文件或目錄
以上的這個錯誤是由于沒找到 頭文件導致的,找了找原因,在編譯fastdf模塊的時候會找這個地方/usr/local/include尋找fastdfs主程序的fastcommon和fastdfs這2個目錄下的頭文件,但是在編譯安裝的fastdfs主程序的時候,卻把這2個目錄放到了/usr/include下面了,于是復制這2個目錄到/usr/local/include下
[root@server1 src]# cp -rf /usr/include/fast* /usr/local/include/
[root@server1 src]# ls /usr/local/include/
fastcommon fastdfs
[root@server1 src]#
于是再次編譯
[root@server1 src]# cd nginx-1.4.7
[root@server1 nginx-1.4.7]# ./configure --prefix=/usr/local/nginx --add-module=/usr/local/src/fastdfs-nginx-module/src --with-pcre=/usr/local/src/pcre-8.36 --with-zlib=/usr/local/src/zlib-1.2.8
[root@server1 nginx-1.4.7]# make && make install
這次終于編譯安裝通過。
2.準備啟動腳本
編輯 /etc/init.d/nginx,如下內容:
#!/bin/bash
# nginx Startup script for the Nginx HTTP Server
# it is v.1.4.7 version.
# chkconfig: - 85 15
# description: Nginx is a high-performance web and proxy server.
# It has a lot of features, but it's not for everyone.
# processname: nginx
# pidfile: /usr/local/nginx/logs/nginx.pid
# config: /usr/local/nginx/conf/nginx.conf
nginxd=/usr/local/nginx/sbin/nginx
nginx_config=/usr/local/nginx/conf/nginx.conf
nginx_pid=/usr/local/nginx/logs/nginx.pid
nginx_lock=/var/lock/subsys/nginx
RETVAL=0
prog="nginx"
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0
[ -x $nginxd ] || exit 0
# Start nginx daemons functions.
start() {
nginx_is_run=`ps -ef | egrep 'nginx:\s*(worker|master)\s*process' | wc -l`
if [ ${nginx_is_run} -gt 0 ];then
echo "nginx already running...."
exit 1
fi
echo -n $"Starting $prog: "
daemon $nginxd -c ${nginx_config}
RETVAL=$?
echo
[ $RETVAL = 0 ] && touch ${nginx_lock}
return $RETVAL
}
# Stop nginx daemons functions.
stop() {
echo -n $"Stopping $prog: "
killproc $nginxd
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f ${nginx_lock} ${nginx_pid}
}
# Reload nginx config file
reload() {
echo -n $"Reloading $prog: "
#kill -HUP `cat ${nginx_pid}`
killproc $nginxd -HUP
RETVAL=$?
echo
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
reload)
reload
;;
restart)
stop
start
;;
status)
status $prog
RETVAL=$?
;;
*)
echo $"Usage: $prog {start|stop|restart|reload|status|help}"
exit 1
esac
3.將 FastDFS 的 nginx 插件模塊的配置文件
copy 到 FastDFS 配置文件目錄
[root@server1 src]# cp fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs/
4.修改nginx配置文件
① 修改nginx的監聽端口
將 server 段中的 listen 端口號改為 8080:
[root@server1 nginx]# vim /usr/local/nginx/conf/nginx.conf
listen 8080;
② 在 server 段中添加fastdfs的配置
這里的group[1-3] 可以匹配 group1,group2,group3,當然group也可以是其他的名字
location ~ /group[1-3]/M00 {
root /data/fastdfs/storage/data;
ngx_fastdfs_module;
}
/data/fastdfs/storage/data 這個是指向 真正存儲文件的地方,該目錄下有這些個二級目錄
[root@server1 src]# cd /data/fastdfs/storage/data/
[root@server1 data]# ll
總用量 1036
drwxr-xr-x 258 root root 4096 10月 28 14:42 00
drwxr-xr-x 258 root root 4096 10月 28 14:42 01
drwxr-xr-x 258 root root 4096 10月 28 14:42 02
drwxr-xr-x 258 root root 4096 10月 28 14:42 03
drwxr-xr-x 258 root root 4096 10月 28 14:42 04
drwxr-xr-x 258 root root 4096 10月 28 14:42 05
drwxr-xr-x 258 root root 4096 10月 28 14:42 06
drwxr-xr-x 258 root root 4096 10月 28 14:42 07
drwxr-xr-x 258 root root 4096 10月 28 14:42 08
drwxr-xr-x 258 root root 4096 10月 28 14:42 09
drwxr-xr-x 258 root root 4096 10月 28 14:42 0A
drwxr-xr-x 258 root root 4096 10月 28 14:42 0B
drwxr-xr-x 258 root root 4096 10月 28 14:42 0C
drwxr-xr-x 258 root root 4096 10月 28 14:42 0D
drwxr-xr-x 258 root root 4096 10月 28 14:42 0E
drwxr-xr-x 258 root root 4096 10月 28 14:42 0F
drwxr-xr-x 258 root root 4096 10月 28 14:42 10
5.修改 fastdfs的nginx模塊的配置文件 mod_fastdfs.conf
一般只需改動以下幾個參數即可:
base_path=/data/fastdfs/storage #保存日志目錄
tracker_server=10.10.10.124:22122 #tracker 服務器的 IP 地址以及端口號
storage_server_port=23000 #storage 服務器的端口號
group_name=group1 #當前服務器的 group 名
url_have_group_name = true #文件 url 中是否有 group 名
store_path_count=1 #存儲路徑個數,需要和 store_path 個數匹配
store_path0=/data/fastdfs/storage #存儲路徑
http.need_find_content_type=true # 從文件 擴展 名查 找 文件 類型 ( nginx 時 為true)
group_count = 1 #設置組的個數
然后在末尾添加分組信息,目前只有一個分組,就只寫一個
[group1]
group_name=group1
storage_server_port=23000
store_path_count=1
store_path0=/data/fastdfs/storage
6.建立 M00 至存儲目錄的符號連接
[root@server1 fdfs]# ln -s /data/fastdfs/storage/data /data/fastdfs/storage/data/M00
[root@server1 fdfs]# ll /data/fastdfs/storage/data/M00
lrwxrwxrwx 1 root root 26 10月 29 11:22 /data/fastdfs/storage/data/M00 -> /data/fastdfs/storage/data
至此nginx和FastDFS 插件模塊設置完成
7.啟動nginx
[root@server1 nginx]# chmod u+x /etc/init.d/nginx
[root@server1 nginx]# chkconfig --add nginx
[root@server1 nginx]# chkconfig nginx on
[root@server1 nginx]# service nginx start
正在啟動 nginx: [確定]
[root@server1 nginx]# service nginx status
nginx (pid 26500) 正在運行...
查看nginx的日志 錯誤日志logs/error.log 看是否有問題
[2014-10-29 14:35:29] INFO - local_host_ip_count: 2, 127.0.0.1 10.10.10.120
[2014-10-29 14:35:29] INFO - fastdfs apache / nginx module v1.15, response_mode=proxy, base_path=/tmp, url_have_group_name=1, group_count=1, connect_timeout=2, network_timeout=30, tracker_server_count=1, if_alias_prefix=, local_host_ip_count=2, anti_steal_token=0, token_ttl=0s, anti_steal_secret_key length=0, token_check_fail content_type=, token_check_fail buff length=0, load_fdfs_parameters_from_tracker=1, storage_sync_file_max_delay=86400s, use_storage_id=0, storage server id count=0, flv_support=1, flv_extension=flv
[2014-10-29 14:35:29] INFO - group 1. group_name=group1, storage_server_port=23000, path_count=1, store_path0=/data/fastdfs/storage
也可以訪問 http://10.10.10.120:8080
看到沒什么錯誤,至此在storage1上安裝配置nginx結束。
再在storage2上以相同的步驟來安裝nginx。
五、安裝nginx反向代理及緩存服務器
以下操作在 10.10.10.123 上操作
1.安裝nginx
將所需的軟件包上傳至服務器/usr/local/src下
[root@fastdfs-nginx ~]# cd /usr/local/src/
[root@fastdfs-nginx src]# ls
[root@fastdfs-nginx src]# rz
rz waiting to receive.
Starting zmodem transfer. Press Ctrl+C to cancel.
Transferring nginx-1.4.7.tar.gz...
100% 751 KB 751 KB/sec 00:00:01 0 Errors
Transferring ngx_cache_purge-2.1.tar.gz...
100% 10 KB 10 KB/sec 00:00:01 0 Errors
Transferring pcre-8.36.tar.gz...
100% 1962 KB 1962 KB/sec 00:00:01 0 Errors
Transferring zlib-1.2.8.tar.gz...
100% 557 KB 557 KB/sec 00:00:01 0 Errors
解壓各個軟件包
[root@fastdfs-nginx src]# tar xf nginx-1.4.7.tar.gz
[root@fastdfs-nginx src]# tar xf ngx_cache_purge-2.1.tar.gz
[root@fastdfs-nginx src]# tar xf pcre-8.36.tar.gz
[root@fastdfs-nginx src]# tar xf zlib-1.2.8.tar.gz
[root@fastdfs-nginx src]# cd nginx-1.4.7
編譯安裝nginx
[root@fastdfs-nginx nginx-1.4.7]# ./configure --prefix=/usr/local/nginx --add-module=/usr/local/src/ngx_cache_purge-2.1 --with-pcre=/usr/local/src/pcre-8.36/ --with-zlib=/usr/local/src/zlib-1.2.8
checking for OS
+ Linux 2.6.32-431.el6.x86_64 x86_64
checking for C compiler ... found
+ using GNU C compiler
+ gcc version: 4.4.7 20120313 (Red Hat 4.4.7-4) (GCC)
checking for gcc -pipe switch ... found
checking for gcc builtin atomic operations ... found
checking for C99 variadic macros ... found
checking for gcc variadic macros ... found
checking for unistd.h ... found
checking for inttypes.h ... found
...
Configuration summary
+ using PCRE library: /usr/local/src/pcre-8.36/
+ OpenSSL library is not used
+ md5: using system crypto library
+ sha1: using system crypto library
+ using zlib library: /usr/local/src/zlib-1.2.8
nginx path prefix: "/usr/local/nginx"
nginx binary file: "/usr/local/nginx/sbin/nginx"
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"
[root@fastdfs-nginx nginx-1.4.7]# make && make install
至此 nginx 以及 nginx cache purge 插件模塊安裝完成。
2.配置
準備nginx的啟動腳本,內容同上面的storage安裝時的腳本,并加入到系統的服務,開機啟動
創建nginx的緩存目錄
[root@fastdfs-nginx nginx]# mkdir -pv /var/cache/nginx/proxy_cache/tmp
mkdir: 已創建目錄 "/var/cache/nginx"
mkdir: 已創建目錄 "/var/cache/nginx/proxy_cache"
mkdir: 已創建目錄 "/var/cache/nginx/proxy_cache/tmp"
增加系統打開文件數的限制
[root@fastdfs-nginx nginx]# ulimit -SHn 102400
[root@fastdfs-nginx nginx]# echo "ulimit -SHn 102400" >> /etc/rc.local
編輯 vim /usr/local/nginx/conf/nginx.conf 文件修改以下內容:
user nobody;
worker_processes 1;
error_log logs/error.log info;
pid logs/nginx.pid;
events {
worker_connections 65535;
use epoll;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
tcp_nopush on;
keepalive_timeout 65;
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 /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;
#設置 group1 的服務器
upstream fdfs_group1 {
server 10.10.10.120:8080 weight=1 max_fails=2 fail_timeout=30s;
server 10.10.10.122:8080 weight=1 max_fails=2 fail_timeout=30s;
}
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
server {
listen 80;
server_name localhost;
access_log logs/host.access.log main;
#設置 group1 的反向代理參數
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 ~ /purge(/.*) {
allow 127.0.0.1;
allow 10.10.10.0/24;
deny all;
proxy_cache_purge http-cache $1$is_args$args;
}
}
}
使用 /usr/local/nginx/sbin/nginx -t 來測試配置文件語法的正確性
[root@fastdfs-nginx nginx]# ./sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
3.啟動nginx
[root@fastdfs-nginx nginx]# service nginx start
正在啟動 nginx: [確定]
查看監聽的端口
[root@fastdfs-nginx conf]# netstat -antp | grep nginx
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 20526/nginx
[root@fastdfs-nginx conf]#
六、測試上傳文件
以下操作在tracker服務器(10.10.10.124)上進行
1.創建client 使用的日志目錄
[root@tracker tracker]# mkdir -pv /data/fastdfs/client
mkdir: 已創建目錄 "/data/fastdfs/client"
2. 修改客戶端的配置文件/etc/fdfs/client.conf
修改以下參數即可:
base_path=/data/fastdfs/client #日志存放路徑
tracker_server=10.10.10.124:22122 #tracker 服務器 IP 地址和端口號
http.tracker_server_port=8080 #tracker 服務器的 http 端口號 ,這一項感覺沒什么用處,tracker都沒有啟用http服務
3.上傳一個圖片
[root@tracker ~]# fdfs_upload_file /etc/fdfs/client.conf 1.jpg
group1/M00/00/00/CgoKeFRQqaaASsgNAAEgRqu1UiU712.jpg
[root@tracker ~]#
得到了一個如上的一個地址 group1/M00/00/00/CgoKeFRQqaaASsgNAAEgRqu1UiU712.jpg
可以使用fdfs_file_info 來查看上傳文件的信息
[root@tracker ~]# fdfs_file_info /etc/fdfs/client.conf group1/M00/00/00/CgoKeFRQqaaASsgNAAEgRqu1UiU712.jpg
source storage id: 0
source ip address: 10.10.10.120
file create timestamp: 2014-10-29 16:47:34
file size: 73798
file crc32: 2880786981 (0xABB55225)
這個信息里面可以看到 這個文件上傳的時候 首先上傳到了10.10.10.120這臺服務器,文件的創建時間、文件的大小
4.使用瀏覽器訪問一下該地址
完整的URL是這樣的http://10.10.10.123/group1/M00/00/00/CgoKeFRQqaaASsgNAAEgRqu1UiU712.jpg
10.10.10.123 就是nginx反向代理緩存服務器
成功訪問到圖片
查看一下nginx的訪問日志,可以看到狀態碼是 200OK.
[root@fastdfs-nginx ~]# tail -1 /usr/local/nginx/logs/host.access.log
10.10.10.46 - - [29/Oct/2014:16:48:43 +0800] "GET /group1/M00/00/00/CgoKeFRQqaaASsgNAAEgRqu1UiU712.jpg HTTP/1.1" 200 73798 "-" "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/537.36" "-"
[root@fastdfs-nginx ~]#
查看nginx的緩存目錄,看是否已經緩存成功
[root@fastdfs-nginx ~]# ll -R /var/cache/nginx/proxy_cache/
/var/cache/nginx/proxy_cache/:
總用量 8
drwx------. 3 nobody nobody 4096 10月 29 16:47 e
drwxr-xr-x. 2 nobody root 4096 10月 29 16:47 tmp
/var/cache/nginx/proxy_cache/e:
總用量 4
drwx------. 2 nobody nobody 4096 10月 29 16:47 a8
/var/cache/nginx/proxy_cache/e/a8:
總用量 76
-rw-------. 1 nobody nobody 74110 10月 29 16:47 54408edb44f74ab4da965506f54a6a8e 在此已經緩存成功
/var/cache/nginx/proxy_cache/tmp:
總用量 0
[root@fastdfs-nginx ~]#
5. 清除緩存
若要清除該圖片的緩存,可以在文件 URL 之前加上 purge 即可,如下圖
http://10.10.10.123/purge/group1/M00/00/00/CgoKeFRQqaaASsgNAAEgRqu1UiU712.jpg
6. 配置瀏覽器端查看是否命中緩存
可以使用Chrome瀏覽器的開發工具,查看響應的頭部信息來查看是否命中緩存,要啟用此功能,修改nginx的主配置文件如下:
在location /group1/M00 段增加這2個行
add_header X-Via $server_addr;
add_header X-Cache-Status $upstream_cache_status;
最終效果
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;
add_header X-Via $server_addr;
add_header X-Cache-Status $upstream_cache_status;
}
重啟nginx
[root@fastdfs-nginx ~]# service nginx restart
停止 nginx: [確定]
正在啟動 nginx: [確定]
[root@fastdfs-nginx ~]#
清空chrome瀏覽器的緩存,清除那張圖片在nginx中的緩存
第一次訪問
顯示MISS,代表緩存中沒有
第二次 ctrl+F5 強制刷新訪問
已經顯示HIT,代表已經命中緩存
至此 FastDFS + nginx 反向代理緩存搭建完畢。
七、優化部分
1、Tracker優化
1) max_connections=10000或更大響應參數增大內存消耗增加該參數需修改單一進程同時可打開文件數量(* soft nofile 65536 * hard nofile 65536)的限制后生效。
2) work_threads=12 cpu數量此處設置cpu核心數量
3) thread_stack_size=256
測試配置如下
work_threads=12
thread_stack_size=256
max_connections=65535
2、Storage優化
work_threads= work_threads + 1 + (disk_reader_threads + disk_writer_threads) * store_path_count= 15
disk_rw_separated:磁盤讀寫是否分離
disk_reader_threads:單個磁盤讀線程數
disk_writer_threads:單個磁盤寫線程數
如果磁盤讀寫混合,單個磁盤讀寫線程數為讀線程數和寫線程數之后
對于單盤掛載方式,磁盤讀寫線程分別設置為1即可
如果磁盤做了RAID,那么需要酌情加大讀寫線程數,這樣才能最大程度地發揮磁盤性能
buff_size=512增大提升磁盤IO的另外一個技巧,一次盡可能多寫入或多讀取。也就是說,將程序的讀寫buffer設置得盡可能大一些。例如日志或者redo log的寫入,不是每次調用都直接寫磁盤,而是先緩存到內存中,等buffer滿了再寫入磁盤,也可以定時寫入磁盤。
測試配置如下
thread_stack_size=512KB
disk_reader_threads = 4
disk_writer_threads = 4
buff_size=512
max_connections=65535
accept_threads=10
work_threads=16a
以上配置壓力測試上傳并發2w 事務平均響應時間0.46秒,4w事務平均響應時間2.2秒。
八、FastDFS使用流程
1.上傳文件
FastDFS 提供了多種方式上傳文件:
使用 fdfs_upload_file 上傳
使用 C 語言客戶端接口上傳
使用 PHP 客戶端接口上傳
使用 Java 客戶端接口上傳
使用 Python 客戶端接口上傳
使用.NET 客戶端接口上傳
根據具體情況選擇使用。上傳均支持斷點續傳。
如果Java的客戶端,在API的配置文件中配置 tracker服務器,如果有多個tracker服務器,就配置多臺
WEB-INF/classes/fdfs_client.conf
connect_timeout = 2
network_timeout = 30
charset = UTF-8
http.tracker_http_port = 8080
http.anti_steal_token = no
http.secret_key = FastDFS1234567890
tracker_server =192.168.10.27:22122
tracker_server = 192.168.10.28:22122
2.下載文件
使用 fdfs_download_file 通過 tracker 服務器下載
使用 nginx 通過 http 方式直接從 storage 下載(支持斷點續傳,作者推薦)
3.監視服務器資源
使用 fdfs_monitor 查看 tracker 和所有 group 的運行情況
[root@tracker ~]# fdfs_monitor /etc/fdfs/client.conf
[2014-10-31 14:09:20] DEBUG - base_path=/data/fastdfs/client, connect_timeout=30, network_timeout=60, tracker_server_count=1, 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=1, server_index=0
tracker server is 10.10.10.124:22122
group count: 1
Group 1:
group name = group1
disk total space = 14020 MB
disk free space = 10224 MB
trunk free space = 0 MB
storage server count = 2
active server count = 2
storage server port = 23000
storage HTTP port = 8080
store path count = 1
subdir count per path = 256
current write server index = 1
current trunk file id = 0
Storage 1:
id = 10.10.10.120
ip_addr = 10.10.10.120 ACTIVE
http domain =
version = 5.04
join time = 2014-10-28 14:42:43
up time = 2014-10-29 14:14:44
total storage = 14020 MB
....
Storage 2:
id = 10.10.10.122
ip_addr = 10.10.10.122 ACTIVE
http domain =
version = 5.04
join time = 2014-10-28 15:53:51
up time = 2014-10-28 15:53:51
total storage = 14020 MB
....
4.其他功能
使用 fdfs_crc32 獲取文件 CRC
使用 fdfs_delete_file 刪除文件
使用 fdfs_file_info 查看文件屬性信息
2017-11-16 Boy