CentOS 6.2 下安装FastDFS
1,安装libevent[*]
wget https:
//github.com/downloads/libevent/libevent/libevent-2.0.20-stable.tar.gz
[*]
将其拷贝到 /usr/local/lib下
[*]
tar xvzf libevent-
2.0
.
20
-stable.tar.gz
[*]
./configure
[*]
make
[*]
make install
[*]
[*]
测试libevent是否安装成功
ls -al /usr/lib | grep libevent
出来一大列东西,就说明安装成功了。
[*]
如果libevent的安装目录为/usr/local/lib下,则还需要建立
libevent-
2.0
.so.
5
到
/usr/lib 的软连接,这样其他程序运行时才能找到libevent库:
[*]
ln -s /usr/local/lib/libevent-
2.0
.so.
5
/usr/lib/libevent-
2.0
.so.
5
[*]
否则会出现
./tracker/fdfs_trackerd: error while loading shared
libraries:
libevent-2.0.so.5: cannot open shared object file: No such file or
directory)
2,安装FastDFS
[*]
wget http:
//fastdfs.googlecode.com/files/FastDFS_v3.11.tar.gz
[*]
将其拷贝到/usr/local下
[*]
tar xvzf FastDFS_v3.
11
.tar.gz
[*]
[*]
修改 make.sh
[*]
#WITH_HTTPD=1 --> WITH_HTTPD =1
[*]
[*]
./make.sh
[*]
./make.sh install
3,启动FastDFS-->tracker
创建目录/opt/fastdfs
[root
@ www.iyunv.com
~]# mkdir /opt/fastdfs
修改tracker.conf配置
[*]
[root
@ www.iyunv.com
~]# vim /etc/fdfs/tracker.conf
[*]
base_path=/home/yuqing/fastdfs -> base_path=/opt/fastdfs
[*]
#
改成你想要的
http
端口,将来
http
下载文件的端口就是它了。
http.server_port=8080
->
http.server_port=8090
[*]
#http
支持
##include http.conf
->
#include
http.conf
[*]
#
默认
4GB
,如果空间不足,建议调小,否则会报
no
free space
的异常,无法正常启动。
reserved_storage_space = 4GB
->
reserved_storage_space = 1GB
[*]
#tracker server
对
storage
server
供服务的端口,使用默认的即可,也可以自定义
port=22122
启动tracker
/usr/local/bin/fdfs_trackerd /etc/fdfs/tracker.conf
进入/opt/fastdfs/
fastdfs_tracker/logs/trackerd.log
查看
tracker
的启动日志,
恭喜你,
tracker
server
已经启动成功!
重启
/usr/local/bin/restart.sh /usr/local/bin/fdfs_trackerd /etc/fdfs/tracker.conf
关闭
/usr/local/bin/stop.sh /usr/local/bin/fdfs_trackerd /etc/fdfs/tracker.conf
4,启动FastDFS-->storage
创建目录/opt/fastdfs
# mkdir /opt/fastdfs
修改storage.conf配置
[*]
[root
@ www.iyunv.com
~]# vim /etc/fdfs/storage.conf
[*]
base_path=/home/yuqing/fastdfs --> /opt/fastdfs
[*]
store_path0=/home/yuqing/fastdfs --> store_path0=/opt/fastdfs
[*]
group_name=group1
[*]
tracker_server=
192.168
.
209.121
:
22122
--> tracker_server=
192.168.217.130
:
22122
[*]
##include http.conf --> #include http.conf
启动storage
/usr/local/bin/fdfs_storaged /etc/fdfs/storage.conf
5,上传测试
修改client.conf
[*]
[root
@ www.iyunv.com
~]# vim /etc/fdfs/client.conf
[*]
vi /etc/fdfs/client.conf
[*]
base_path=/home/yuqing/fastdfs-> base_path=/opt/fastdfs
[*]
tracker_server=
192.168
.
209.121
:
22122
-> tracker_server=
192.168.217.130
:
22122
[*]
##include http.conf ->#include http.conf
[*]
[root
@ www.iyunv.com
~]# /usr/local/bin/fdfs_test /etc/fdfs/client.conf upload FastDFS_v3.
03
.tar.gz //假设当前目录下有
FastDFS_v3.
03
.tar.gz 这个文件,并且上传他 如果没有问题,出现下面一大陀文字
[*]
This is FastDFS client test program v3.
11
[*]
[*]
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.
[*]
[*]
[
2012
-
09
-
12
15
:
43
:
03
] DEBUG - base_path=/opt/fastdfs, connect_timeout=
30
, network_timeout=
60
, tracker_server_count=
1
, anti_steal_token=
0
, anti_steal_secret_key length=
0
[*]
[*]
tracker_query_storage_store_list_without_group:
[*]
server
1
. group_name=group1, ip_addr=
192.168
.
0.11
, port=
23000
[*]
[*]
group_name=group1, ip_addr=
192.168
.
0.11
, port=
23000
[*]
storage_upload_by_filename
[*]
group_name=group1, remote_filename=M00/
00
/
00
/CAAAC1BQPQqy0zXVAAWp7X_1XGc.tar.gz
[*]
source ip address:
192.168
.
0.11
[*]
file timestamp=
2012
-
09
-
12
15
:
43
:
06
[*]
file size=
371181
[*]
file crc32=
2146786407
[*]
file url: http:
//192.168.0.10:8080/group1/M00/00/00/CAAAC1BQPQqy0zXVAAWp7X_1XGc.tar.gz
[*]
storage_upload_slave_by_filename
[*]
group_name=group1, remote_filename=M00/
00
/
00
/CAAAC1BQPQqy0zXVAAWp7X_1XGc_big.tar.gz
[*]
source ip address:
8.0
.
0.11
[*]
file timestamp=
2012
-
09
-
12
15
:
43
:
06
[*]
file size=
371181
[*]
file crc32=
2146786407
[*]
file url: http:
//192.168.0.10:8080/group1/M00/00/00/CAAAC1BQPQqy0zXVAAWp7X_1XGc_big.tar.gz
6,
下载文件
在浏览器中,输入
http:
//192.168.0.10:8080/group1/M00/00/00/CAAAC1BQPQqy0zXVAAWp7X_1XGc_big.tar.gz
,
tracker
server
会自动重定向到存储文件的
storage
server
,文件下载成功。至此,已经成功搭建了
FastDFS
,编写你自己的
client
来进行访问吧;
7,监视器
# fdfs_monitor /etc/fdfs/storage.conf
测试代码
package com.test;
import java.net.InetSocketAddress;
import org.csource.common.NameValuePair;
import org.csource.fastdfs.ClientGlobal;
import org.csource.fastdfs.StorageClient;
import org.csource.fastdfs.StorageServer;
import org.csource.fastdfs.TrackerClient;
import org.csource.fastdfs.TrackerGroup;
import org.csource.fastdfs.TrackerServer;
public class JavaClient {
public JavaClient(){}
public static void doTest(){
try
{
String local_file_name ="/Users/ckwang17/Desktop/DCIM/100NCD90/DSC_0003.JPG";
String conf_filename = "/Users/ckwang17/Student/workspace/fastdfs/src/com/test/fdfs_client.conf";
NameValuePair []pair = {newNameValuePair("1111","222")};
ClientGlobal.init(conf_filename);
TrackerGroup group = new TrackerGroup(
new InetSocketAddress[]{
new InetSocketAddress("192.168.217.130",22122)
});
TrackerClient client = new TrackerClient(group);
TrackerServer ts = client.getConnection();
StorageServer storage = client.getStoreStorage(ts);
//System.out.println(storage.getSocket().);
StorageClient s_client = new StorageClient(ts,storage);
String url [] = s_client.upload_file(local_file_name, "jpg", pair);
storage.close();
for (int i = 0; i < url.length; i++) {
System.out.println(url);
s_client.download_file(url, url, "/Users/ckwang17/Student/workspace/fastdfs/11.jpg");
}
}catch(Exception io){
io.printStackTrace();
}
}
public static void main(String[] args)throws Exception {
doTest();
}
}
页:
[1]