我的博客已迁移到xdoujiang.com请去那边和我交流
FastDFS是一个开源的轻量级应用级的分布式文件存储服务,它对文件进行管理,功能包括:
文件存储、文件同步、文件访问(文件上传、文件下载)等解决了大容量存储和负载均衡的问题。
特别适合以文件为载体的在线服务,如相册网站、视频网站等等。
FastDFS有三个角色:跟踪服务器(tracker server)、存储服务器(storage server)和客户端(client)。
1)跟踪服务器:主要做调度工作 起负载均衡的作用
2)存储服务器:存储节点存储文件 完成文件管理的所有功能:存储、同步和提供存取接口
3)客户端:可以使用fdfs_upload_file、c、php、java、python、.net等api接口
使用TCP/IP协议与跟踪器服务器或存储节点进行数据交互
一、基础环境
1、角色、ip、版本、内核、fastdfs、fastdfs-nginx-module、nginx
serverA 10.1.10.117 3.2.0-4-amd64 7.8 tracker nginx
serverB 10.1.10.185 3.2.0-4-amd64 7.8 storage fastdfs-nginx-module nginx group1
serverC 10.1.10.194 3.2.0-4-amd64 7.8 storage fastdfs-nginx-module nginx group1
client 10.1.10.117
fastdfs版本5.05
fastdfs-nginx-module版本1.15
nginx版本1.4.7
libfastcommon版本1.3
2、安装基础包
apt-get -y install git wget gcc make libpcre3-dev libpcre3 libssl-dev zlib1g-dev
axel libc6-dev libc-bin curl
二、在serverA上安装fastdfs的tracker角色
1、git方式下载
git clone https://github.com/happyfish100/libfastcommon.git libfastcommon
git clone https://github.com/happyfish100/fastdfs.git fastdfs
2、编译安装
1)cd libfastcommon
bash make.sh
bash make.sh install
2)cd fastdfs
bash make.sh
bash make.sh install
3、查看相应命令具体在哪里
ll /usr/bin/fdfs*
-rwxr-xr-x 1 root root 349008 Aug 21 14:12 /usr/bin/fdfs_appender_test
-rwxr-xr-x 1 root root 348193 Aug 21 14:12 /usr/bin/fdfs_appender_test1
-rwxr-xr-x 1 root root 333057 Aug 21 14:12 /usr/bin/fdfs_append_file
-rwxr-xr-x 1 root root 333109 Aug 21 14:12 /usr/bin/fdfs_crc32
-rwxr-xr-x 1 root root 333164 Aug 21 14:12 /usr/bin/fdfs_delete_file
-rwxr-xr-x 1 root root 334435 Aug 21 14:12 /usr/bin/fdfs_download_file
-rwxr-xr-x 1 root root 333737 Aug 21 14:12 /usr/bin/fdfs_file_info
-rwxr-xr-x 1 root root 351638 Aug 21 14:12 /usr/bin/fdfs_monitor
-rwxr-xr-x 1 root root 1211424 Aug 21 14:12 /usr/bin/fdfs_storaged
-rwxr-xr-x 1 root root 358392 Aug 21 14:12 /usr/bin/fdfs_test
-rwxr-xr-x 1 root root 357073 Aug 21 14:12 /usr/bin/fdfs_test1
-rwxr-xr-x 1 root root 491214 Aug 21 14:12 /usr/bin/fdfs_trackerd
-rwxr-xr-x 1 root root 334835 Aug 21 14:12 /usr/bin/fdfs_upload_appender
-rwxr-xr-x 1 root root 336773 Aug 21 14:12 /usr/bin/fdfs_upload_file
4、创建数据目录
mkdir -p /opt/fastdfs/tracker
5、创建组和用户
groupadd fastdfs
useradd -s /bin/bash -d /opt/fastdfs/ -g fastdfs fastdfs
6、修改相关目录权限
chown -R fastdfs.fastdfs /opt/fastdfs
7、修改配置
1)备份配置
cp /etc/fdfs/tracker.conf.sample /etc/fdfs/tracker.conf
2)修改配置/etc/fdfs/tracker.conf(serverA)
sed -i 's/bind_addr=.*/bind_addr=10.1.10.117/' /etc/fdfs/tracker.conf
sed -i 's!base_path=.*!base_path=/opt/fastdfs/tracker/!g' /etc/fdfs/tracker.conf
sed -i 's!run_by_group=.*!run_by_group=fastdfs!g' /etc/fdfs/tracker.conf
sed -i 's!run_by_user=.*!run_by_user=fastdfs!g' /etc/fdfs/tracker.conf
8、启动服务tracker
1)使用ldd命令检查相应支持模块
ldd /usr/bin/fdfs_trackerd
linux-vdso.so.1 => (0x00007ffd4abb3000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f5dd7c48000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f5dd7a44000)
libfastcommon.so => not found
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f5dd76b8000)
/lib64/ld-linux-x86-64.so.2 (0x00007f5dd7e6a000)
PS:查看到libfastcommon.so => not found 目前不找到
2)先找下libfastcommon.so这个文件在哪里
find / -name "libfastcommon.so"
/root/libfastcommon/src/libfastcommon.so
/usr/lib64/libfastcommon.so
2)加载libfastcommon.so
echo "/usr/lib64" > /etc/ld.so.conf.d/libfastcommon.conf
ldconfig
3)再次查看下
ldd /usr/bin/fdfs_trackerd
linux-vdso.so.1 => (0x00007ffebedd2000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f3732ddb000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f3732bd7000)
libfastcommon.so => /usr/lib64/libfastcommon.so (0x00007f37329ae000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f3732623000)
/lib64/ld-linux-x86-64.so.2 (0x00007f3732ffd000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f37323a1000)
PS:都OK了
4)启动tracker服务
fdfs_trackerd /etc/fdfs/tracker.conf
9、查看端口和进程tracker
1)查看端口tracker
netstat -tupnl|grep trackerd
tcp 0 0 10.1.10.117:22122 0.0.0.0:* LISTEN 11461/fdfs_trackerd
2)查看进程tracker
ps -ef |grep track
root 11461 1 0 17:32 ? 00:00:00 fdfs_trackerd /etc/fdfs/tracker.conf
10、查看日志
1)查看trackerd日志
cat /opt/fastdfs/tracker/logs/trackerd.log
[2015-08-27 14:51:15] INFO - FastDFS v5.07, base_path=/opt/fastdfs/tracker, run_by_group=fastdfs, run_by_user=fastdfs, connect_timeout=30s, network_timeout=60s, port=22122, bind_addr=10.1.10.117, max_connections=256, accept_threads=1, work_threads=4, store_lookup=2, store_group=, store_server=0, store_path=0, reserved_storage_space=10.00%, download_server=0, allow_ip_count=-1, sync_log_buff_interval=10s, check_active_interval=120s, thread_stack_size=64 KB, storage_ip_changed_auto_adjust=1, storage_sync_file_max_delay=86400s, storage_sync_file_max_time=300s, use_trunk_file=0, slot_min_size=256, slot_max_size=16 MB, trunk_file_size=64 MB, trunk_create_file_advance=0, trunk_create_file_time_base=02:00, trunk_create_file_interval=86400, trunk_create_file_space_threshold=20 GB, trunk_init_check_occupying=0, trunk_init_reload_from_binlog=0, trunk_compress_binlog_min_interval=0, use_storage_id=0, id_type_in_filename=ip, storage_id_count=0, rotate_error_log=0, error_log_rotate_time=00:00, rotate_error_log_size=0, log_file_keep_days=0, store_slave_file_use_link=0, use_connection_pool=0, g_connection_pool_max_idle_time=3600s
[2015-08-27 14:51:15] INFO - local_host_ip_count: 2, 127.0.0.1 10.1.10.117
11、设置开机启动
echo "/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf" >> /etc/rc.local
三、 分别在serverB和C上安装fastdfs的storage角色和nginx和fastdfs-nginx-module模块
1、git方式下载
git clone https://github.com/happyfish100/libfastcommon.git libfastcommon
git clone https://github.com/happyfish100/fastdfs.git fastdfs
git clone https://github.com/happyfish100/fastdfs-nginx-module fastdfs-nginx-module
2、编译安装(serverB和serverC)
1)cd libfastcommon
bash make.sh
bash make.sh install
2)cd fastdfs
bash make.sh
bash make.sh install
3、创建数据目录(serverB和serverC)
mkdir -p /opt/fastdfs/storage
4、创建组和用户(serverB和serverC)
groupadd fastdfs
useradd -s /bin/bash -d /opt/fastdfs/ -g fastdfs fastdfs
5、修改相关目录权限(serverB和serverC)
chown -R fastdfs.fastdfs /opt/fastdfs
6、修改配置/etc/fdfs/storage.conf(serverB和serverC)
1)备份配置
cp /etc/fdfs/storage.conf.sample /etc/fdfs/storage.conf
2)修改配置/etc/fdfs/storage.conf
sed -i 's/bind_addr=.*/bind_addr=10.1.10.185/' /etc/fdfs/storage.conf
sed -i 's!base_path=.*!base_path=/opt/fastdfs/storage/!g' /etc/fdfs/storage.conf
sed -i 's!store_path0=.*!store_path0=/opt/fastdfs/storage/!g' /etc/fdfs/storage.conf
sed -i 's!tracker_server=.*!tracker_server=10.1.10.117:22122!g' /etc/fdfs/storage.conf
sed -i 's!run_by_group=.*!run_by_group=fastdfs!g' /etc/fdfs/storage.conf
sed -i 's!run_by_user=.*!run_by_user=fastdfs!g' /etc/fdfs/storage.conf
sed -i 's!http.server_port=.*!http.server_port=80!g' /etc/fdfs/storage.conf
PS:这里bind_addr的IP如果是serverB那么就是10.1.10.185
这里bind_addr的IP如果是serverC那么就是10.1.10.194
7、加载libfastcommon.so(serverB和serverC)
echo "/usr/lib64" > /etc/ld.so.conf.d/libfastcommon.conf
ldconfig
8、启动storage服务(serverB和serverC)
fdfs_storaged /etc/fdfs/storage.conf
9、查看端口和进程storage(serverB和serverC)
1)查看端口storage
netstat -tupnl|grep storage
tcp 0 0 10.1.10.194:23000 0.0.0.0:* 、 LISTEN 9665/fdfs_storaged
2)查看进程storage
ps -ef |grep storage
fastdfs 9665 1 3 17:48 ? 00:00:02 fdfs_storaged /etc/fdfs/storage.conf
10、查看日志(serverB和serverC)
1)查看storage日志
cat /opt/fastdfs/storage/logs/storaged.log
[2015-08-31 13:58:39] INFO - FastDFS v5.07, base_path=/opt/fastdfs/storage, store_path_count=1, subdir_count_per_path=256, group_name=group1, run_by_group=fastdfs, run_by_user=fastdfs, connect_timeout=30s, network_timeout=60s, port=23000, bind_addr=10.1.10.194, client_bind=1, max_connections=256, accept_threads=1, work_threads=4, disk_rw_separated=1, disk_reader_threads=1, disk_writer_threads=1, buff_size=256KB, heart_beat_interval=30s, stat_report_interval=60s, tracker_server_count=1, sync_wait_msec=50ms, sync_interval=0ms, sync_start_time=00:00, sync_end_time=23:59, write_mark_file_freq=500, allow_ip_count=-1, file_distribute_path_mode=0, file_distribute_rotate_count=100, fsync_after_written_bytes=0, sync_log_buff_interval=10s, sync_binlog_buff_interval=10s, sync_stat_file_interval=300s, thread_stack_size=512 KB, upload_priority=10, if_alias_prefix=, check_file_duplicate=0, file_signature_method=hash, FDHT group count=0, FDHT server count=0, FDHT key_namespace=, FDHT keep_alive=0, HTTP server port=80, domain name=, use_access_log=0, rotate_access_log=0, access_log_rotate_time=00:00, rotate_error_log=0, error_log_rotate_time=00:00, rotate_access_log_size=0, rotate_error_log_size=0, log_file_keep_days=0, file_sync_skip_invalid_record=0, use_connection_pool=0, g_connection_pool_max_idle_time=3600s
data path: /opt/fastdfs/storage//data, mkdir sub dir...
data path: /opt/fastdfs/storage//data, mkdir sub dir done.
[2015-08-31 13:59:02] INFO - file: storage_param_getter.c, line: 191, use_storage_id=0, id_type_in_filename=ip, storage_ip_changed_auto_adjust=1, store_path=0, reserved_storage_space=10.00%, use_trunk_file=0, slot_min_size=256, slot_max_size=16 MB, trunk_file_size=64 MB, trunk_create_file_advance=0, trunk_create_file_time_base=02:00, trunk_create_file_interval=86400, trunk_create_file_space_threshold=20 GB, trunk_init_check_occupying=0, trunk_init_reload_from_binlog=0, trunk_compress_binlog_min_interval=0, store_slave_file_use_link=0
[2015-08-31 13:59:02] INFO - file: storage_func.c, line: 254, tracker_client_ip: 10.1.10.194, my_server_id_str: 10.1.10.194, g_server_id_in_filename: -1039531766
[2015-08-31 13:59:02] INFO - local_host_ip_count: 2, 127.0.0.1 10.1.10.194
[2015-08-31 13:59:04] ERROR - file: tracker_client_thread.c, line: 277, connect to tracker server 10.1.10.117:22122 fail, errno: 4, error info: Interrupted system call
[2015-08-31 13:59:04] INFO - file: tracker_client_thread.c, line: 310, successfully connect to tracker server 10.1.10.117:22122, continuous fail count: 1, as a tracker client, my ip is 10.1.10.194
[2015-08-31 13:59:04] INFO - file: tracker_client_thread.c, line: 1235, tracker server 10.1.10.117:22122, set tracker leader: 10.1.10.117:22122
[2015-08-31 13:59:04] INFO - file: storage_sync.c, line: 2698, successfully connect to storage server 10.1.10.185:23000
11、使用fdfs_monitor命令查看集群信息(serverB和serverC)
fdfs_monitor /etc/fdfs/storage.conf
[2015-08-31 14:01:54] DEBUG - base_path=/opt/fastdfs/storage, 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.1.10.117:22122
group count: 1
Group 1:
group name = group1
disk total space = 37251 MB
disk free space = 34926 MB
trunk free space = 0 MB
storage server count = 2
active server count = 2
storage server port = 23000
storage HTTP port = 80
store path count = 1
subdir count per path = 256
Storage 1:
id = 10.1.10.185
ip_addr = 10.1.10.185 ACTIVE
http domain =
version = 5.07
join time = 2015-08-31 13:58:36
up time = 2015-08-31 13:58:36
total storage = 37251 MB
free storage = 34926 MB
upload priority = 10
store_path_count = 1
subdir_count_per_path = 256
storage_port = 23000
storage_http_port = 80
source storage id =
connection.alloc_count = 256
connection.current_count = 1
connection.max_count = 1
last_heart_beat_time = 2015-08-31 14:01:29
last_source_update = 1970-01-01 08:00:00
last_sync_update = 1970-01-01 08:00:00
last_synced_timestamp = 1970-01-01 08:00:00
Storage 2:
id = 10.1.10.194
ip_addr = 10.1.10.194 ACTIVE
http domain =
version = 5.07
join time = 2015-08-31 13:58:39
up time = 2015-08-31 13:58:39
total storage = 37251 MB
free storage = 34926 MB
upload priority = 10
store_path_count = 1
subdir_count_per_path = 256
storage_port = 23000
storage_http_port = 80
source storage id = 10.1.10.185
connection.alloc_count = 256
connection.current_count = 1
connection.max_count = 1
last_heart_beat_time = 2015-08-31 14:01:33
last_source_update = 1970-01-01 08:00:00
last_sync_update = 1970-01-01 08:00:00
last_synced_timestamp = 1970-01-01 08:00:00
12、设置开机启动(serverB和serverC)
echo "/usr/bin/fdfs_storaged /etc/fdfs/storage.conf" >> /etc/rc.local
13、安装nginx及fastdfs-nginx-module(nginx提供http服务及
fastdfs-nginx-module解决同步问题)(serverB和serverC)
1)建立nginx用户(serverB和serverC)
groupadd nginx
useradd nginx -g nginx -s /bin/false
2)下载nginx(serverB和serverC)
axel -n 10 http://nginx.org/download/nginx-1.4.7.tar.gz
3)解压(serverB和serverC)
tar zxvf nginx-1.4.7.tar.gz && cd nginx-1.4.7
4)编译三部曲(serverB和serverC)
./configure --prefix=/opt/nginx --user=nginx --group=nginx --with-http_ssl_module --add-module=/root/fastdfs-nginx-module/src
make && make install
5)为了方便 弄个软链接(serverB和serverC)
ln -s /opt/nginx/sbin/nginx /usr/local/sbin/nginx
6)备份配置(serverB和serverC)
cp /opt/nginx/conf/nginx.conf /opt/nginx/conf/nginx.conf.bak
cp /root/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs/
cp /root/fastdfs/conf/http.conf /etc/fdfs
cp /root/fastdfs/conf/mime.types /etc/fdfs
7)修改配置/opt/nginx/conf/nginx.conf(serverB和serverC)
diff /opt/nginx/conf/nginx.conf /opt/nginx/conf/nginx.conf.bak
3d2
< user nginx;
37,40c36,38
< listen 10.1.10.194:80;
< server_name 10.1.10.194;
< access_log /opt/nginx/logs/10.1.10.194.access.log;
< error_log /opt/nginx/logs/10.1.10.194.error.log;
---
> listen 80;
> server_name localhost;
>
45,47c43,45
< location /group1/M00 {
< root /opt/fastdfs/storage/data;
< ngx_fastdfs_module;
---
> location / {
> root html;
> index index.html index.htm;
8)修改配置/etc/fdfs/mod_fastdfs.conf(serverB和serverC)
sed -i 's!base_path=.*!base_path=/opt/fastdfs/storage/!g' /etc/fdfs/mod_fastdfs.conf
sed -i 's!store_path0=.*!store_path0=/opt/fastdfs/storage/!g' /etc/fdfs/mod_fastdfs.conf
sed -i 's!tracker_server=.*!tracker_server=10.1.10.117:22122!g' /etc/fdfs/mod_fastdfs.conf
sed -i 's!url_have_group_name =.*!url_have_group_name = true!g' /etc/fdfs/mod_fastdfs.conf
9)启动服务nginx(serverB和serverC)
nginx
ngx_http_fastdfs_set pid=12058
10)查看端口进程nginx(serverB和serverC)
netstat -tupnl |grep nginx
tcp 0 0 10.1.10.194:80 0.0.0.0:* LISTEN 12059/nginx: master
ps -ef |grep nginx(serverB和serverC)
root 12059 1 0 19:01 ? 00:00:00 nginx: master process nginx
11)查看日志(serverB和serverC)
cat /opt/nginx/logs/error.log
ngx_http_fastdfs_process_init pid=14667
[2015-08-28 03:46:32] INFO - local_host_ip_count: 2, 127.0.0.1 10.1.10.194
[2015-08-28 03:46:32] INFO - fastdfs apache / nginx module v1.15, response_mode=proxy, base_path=/opt/fastdfs/storage, url_have_group_name=1, group_name=group1, storage_server_port=23000, path_count=1, store_path0=/home/yuqing/fastdfs, 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
12)设置开机启动(serverB和serverC)
echo "/usr/local/sbin/nginx" >> /etc/rc.local
13)访问nginx(serverB和serverC)
curl 10.1.10.185:80
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>
PS:有看到页面信息 说明配置都OK了
四、相关命令说明
fdfs_monitor #查看集群情况
fdfs_crc32 #获取文件CRC
fdfs_delete_file #删除文件
fdfs_file_info #查看文件属性信息
fdfs_download_file #下载文件
fdfs_upload_file #上传文件
fdfs_storaged #启storage服务
fdfs_trackerd #启tracker服务
五、测试
1、在tracker上的操作[作为client测试]
1)备份配置
cp /etc/fdfs/client.conf.sample /etc/fdfs/client.conf
2)修改配置
diff /etc/fdfs/client.conf.sample /etc/fdfs/client.conf
10c10
< base_path=/home/yuqing/fastdfs
---
> base_path=/tmp
14c14
< tracker_server=192.168.0.197:22122
---
> tracker_server=10.1.10.117:22122
2、上传文件测试
root@10.1.10.117:~# fdfs_test /etc/fdfs/client.conf upload Chrysanthemum.jpg
This is FastDFS client test program v5.07
Copyright (C) 2008, Happy Fish / YuQing
FastDFS may be copied only under the terms of the GNU General
Public License V3, which may be found in the FastDFS source kit.
Please visit the FastDFS Home Page http://www.csource.org/
for more detail.
[2015-08-31 15:04:52] DEBUG - base_path=/tmp, 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
tracker_query_storage_store_list_without_group:
server 1. group_name=, ip_addr=10.1.10.185, port=23000
server 2. group_name=, ip_addr=10.1.10.194, port=23000
group_name=group1, ip_addr=10.1.10.194, port=23000
storage_upload_by_filename
group_name=group1, remote_filename=M00/00/00/CgEKwlXj_JSAHsHYAA1rIuRd3Es813.jpg
source ip address: 10.1.10.194
file timestamp=2015-08-31 15:04:52
file size=879394
file crc32=3831356491
example file url: http://10.1.10.194/group1/M00/00/00/CgEKwlXj_JSAHsHYAA1rIuRd3Es813.jpg
storage_upload_slave_by_filename
group_name=group1, remote_filename=M00/00/00/CgEKwlXj_JSAHsHYAA1rIuRd3Es813_big.jpg
source ip address: 10.1.10.194
file timestamp=2015-08-31 15:04:52
file size=879394
file crc32=3831356491
example file url: http://10.1.10.194/group1/M00/00/00/CgEKwlXj_JSAHsHYAA1rIuRd3Es813_big.jpg
root@10.1.10.117:~# fdfs_test /etc/fdfs/client.conf upload Desert.jpg
This is FastDFS client test program v5.07
Copyright (C) 2008, Happy Fish / YuQing
FastDFS may be copied only under the terms of the GNU General
Public License V3, which may be found in the FastDFS source kit.
Please visit the FastDFS Home Page http://www.csource.org/
for more detail.
[2015-08-31 15:04:59] DEBUG - base_path=/tmp, 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
tracker_query_storage_store_list_without_group:
server 1. group_name=, ip_addr=10.1.10.185, port=23000
server 2. group_name=, ip_addr=10.1.10.194, port=23000
group_name=group1, ip_addr=10.1.10.185, port=23000
storage_upload_by_filename
group_name=group1, remote_filename=M00/00/00/CgEKuVXj_JuAbUQnAAzodQCbVVc191.jpg
source ip address: 10.1.10.185
file timestamp=2015-08-31 15:04:59
file size=845941
file crc32=10179927
example file url: http://10.1.10.185/group1/M00/00/00/CgEKuVXj_JuAbUQnAAzodQCbVVc191.jpg
storage_upload_slave_by_filename
group_name=group1, remote_filename=M00/00/00/CgEKuVXj_JuAbUQnAAzodQCbVVc191_big.jpg
source ip address: 10.1.10.185
file timestamp=2015-08-31 15:04:59
file size=845941
file crc32=10179927
example file url: http://10.1.10.185/group1/M00/00/00/CgEKuVXj_JuAbUQnAAzodQCbVVc191_big.jpg
3、windows上访问地址测试效果
![11111.png 分布式文件存储fastdfs_fastdfs nginx](http://s2.51cto.com/wyfs02/M02/72/79/wKiom1XkUHXgp6frAA2Jx6c9CAQ268.jpg?x-oss-process=image/resize,m_fixed,w_1184)
![22222.png 分布式文件存储fastdfs_fastdfs nginx_02](http://s2.51cto.com/wyfs02/M00/72/76/wKioL1XkUpbxud-QAA2RDkCxy_Q656.jpg?x-oss-process=image/resize,m_fixed,w_1184)
六、在ServerA上安装nginx(前端提供负载均衡)并进行测试
1、建立nginx用户
groupadd nginx
useradd nginx -g nginx -s /bin/false
2、下载nginx
axel -n 10 http://nginx.org/download/nginx-1.4.7.tar.gz
3、解压
tar zxvf nginx-1.4.7.tar.gz && cd nginx-1.4.7
4、编译三部曲
./configure --prefix=/opt/nginx --user=nginx --group=nginx --with-http_ssl_module
make && make install
5、为了方便 弄个软链接
ln -s /opt/nginx/sbin/nginx /usr/local/sbin/nginx
6、备份配置
cp /opt/nginx/conf/nginx.conf /opt/nginx/conf/nginx.conf.bak
7、修改配置
diff /opt/nginx/conf/nginx.conf /opt/nginx/conf/nginx.conf.bak
3d2
< user nginx;
35,38c34
< upstream group1{
< server 10.1.10.185:80;
< server 10.1.10.194:80;
< }
---
>
40,41c36,37
< listen 10.1.10.117:80;
< server_name 10.1.10.117;
---
> listen 80;
> server_name localhost;
47c43
< location /group1/M00 {
---
> location / {
50d45
< proxy_pass http://group1;
8、启动服务
nginx
9、设置开机启动
echo "/usr/local/sbin/nginx" >> /etc/rc.local
10、查看端口和进程
ps -ef |grep nginx
root 14627 1 0 15:09 ? 00:00:00 nginx: master process nginx
nginx 14628 14627 0 15:09 ? 00:00:00 nginx: worker process
netstat -tupnl |grep nginx
tcp 0 0 10.1.10.117:80 0.0.0.0:* LISTEN 16986/nginx: master
11、再次上传图片测试
root@10.1.10.117:~# fdfs_test /etc/fdfs/client.conf upload Tulips.jpg
This is FastDFS client test program v5.07
Copyright (C) 2008, Happy Fish / YuQing
FastDFS may be copied only under the terms of the GNU General
Public License V3, which may be found in the FastDFS source kit.
Please visit the FastDFS Home Page http://www.csource.org/
for more detail.
[2015-08-31 16:02:17] DEBUG - base_path=/tmp, 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
tracker_query_storage_store_list_without_group:
server 1. group_name=, ip_addr=10.1.10.185, port=23000
server 2. group_name=, ip_addr=10.1.10.194, port=23000
group_name=group1, ip_addr=10.1.10.185, port=23000
storage_upload_by_filename
group_name=group1, remote_filename=M00/00/00/CgEKuVXkCgmAfHn_AAl5WLU-YRY278.jpg
source ip address: 10.1.10.185
file timestamp=2015-08-31 16:02:17
file size=620888
file crc32=3040764182
example file url: http://10.1.10.185/group1/M00/00/00/CgEKuVXkCgmAfHn_AAl5WLU-YRY278.jpg
storage_upload_slave_by_filename
group_name=group1, remote_filename=M00/00/00/CgEKuVXkCgmAfHn_AAl5WLU-YRY278_big.jpg
source ip address: 10.1.10.185
file timestamp=2015-08-31 16:02:17
file size=620888
file crc32=3040764182
example file url: http://10.1.10.185/group1/M00/00/00/CgEKuVXkCgmAfHn_AAl5WLU-YRY278_big.jpg
![33333.png 分布式文件存储fastdfs_fastdfs nginx_03](http://s2.51cto.com/wyfs02/M00/72/79/wKiom1XkUJeDOw_gAAuwNkaSKtI421.jpg?x-oss-process=image/resize,m_fixed,w_1184)
七、参考文章
http://www.simlinux.com/books/FastDFS.pdf