背景:
我们在原来服务器上使用fastdfsV3.02,现在要迁移到新服务器,网上没有相关的文档,折腾了很久,现将迁移过程记录如下,方便其它同学配置和迁移
tracker服务器:192.168.1.246
storage服务器:192.168.1.246
在访问量都不是很大情况下,将tracker和storage都部署在同一台服务器上
一、配置tracker服务器:192.168.1.246
1.下载相关软件
wget http://cloud.github.com/downloads/libevent/libevent/libevent-2.0.14-stable.tar.gz
wget http://fastdfs.googlecode.com/files/FastDFS_v3.02.tar.gz
2、编译安装libevent库
tar -zxvf libevent-2.0.14-stable.tar.gz
cd libevent-2.0.14-stable
./configure --prefix=/usr/local/libevent
make && make install
3、配置,编译安装FastDFS
tar -zxvf FastDFS_v3.02.tar.gz
cd FastDFS
vi make.sh (修改下面几处)
TARGET_PREFIX=/usr/local/fastdfs
TARGET_CONF_PATH=/etc/fdfs
WITH_HTTPD=1
WITH_LINUX_SERVICE=1
./make.sh C_INCLUDE_PATH=/usr/local/libevent/include LIBRARY_PATH=/usr/local/libevent/lib
./make.sh install
ls /etc/fdfs/ (安装成功后会在/etc/fdfs/生成以下文件)
client.conf http.conf mime.types storage.conf tracker.conf
4、修改tracker配置文件
vi /etc/fdfs/tracker.conf
重点关注以下几个配置项,其它一般默认即可
bind_addr= //绑定的IP
port=22122 //监听的端口
base_path=/home/data/fastdfs //存放路径
store_group=group2
reserved_storage_space = 4GB //预留存储空间
http.server_port=8080
#include httpd.conf //原来是有两个#号,去掉一个#号即可
5、修改http.conf
vi /etc/fdfs/http.conf
重点关注以下几个配置项,其它一般默认即可
http.default_content_type = application/octet-stream
http.mime_types_filename=/etc/fdfs/mime.types
http.anti_steal.check_token=false
http.anti_steal.token_ttl=900
http.anti_steal.secret_key=FastDFS1234567890
http.anti_steal.token_check_fail=/usrdata/fastdfs/conf/anti-steal.jpg
6、启动tracker服务
需要注意tracker.conf文件最后一行为#include httpd.conf
(1)添加库文件(以下命令如果不能正确执行,请手动输入)
echo ’/usr/local/libevent/include/’ >> /etc/ld.so.conf
echo ’/usr/local/libevent/lib/’ >> /etc/ld.so.conf
ldconfig
(2)创建basedir
mkdir -p /usrdata/fastdfs
(3)启动tracker服务
/usr/local/fastdfs/bin/fdfs_trackerd /etc/fdfs/tracker.conf
echo $?
启动完成,查看进程:
ps -ef |grep track
在防火墙中增加设置,打开相应的端口:
vi /etc/sysconfig/iptables
-A RH-Firewall-1-INPUT -p tcp -m tcp --dport 22122 -j ACCEPT
-A RH-Firewall-1-INPUT -p tcp -m tcp --dport 8080 -j ACCEPT
?
二、配置storage服务器:192.168.1.246
如果是在另外一台服务器上安装,需要再次安装FastDFS,在同一台服务器上则不用,安装步骤和上面一样,只配置文件不一样。
1、增加storage的存储目录:
mkdir -p /usrdata/storage
2、修改存储结点配置文件
vi /etc/fdfs/storage.conf
重点关注以下几个配置项,其它一般默认即可
group_name=group1
bind_addr=
base_path=/usrdata/storage
store_path_count=1
store_path0=/usrdata/storage
tracker_server=192.168.1.246:22122
http.server_port=8888
#include httpd.conf //原来是有两个#号,去掉一个#号即可
3、修改测试客户端配置文件(用于测试)
vi /etc/fdfs/client.conf
重点关注以下几个配置项,其它一般默认即可
base_path=/usrdata/fastdfs
tracker_server=192.168.1.246:22122
http.tracker_server_port=8080
#include httpd.conf
4、修改http.conf
vi /etc/fdfs/http.conf
重点关注以下几个配置项,其它一般默认即可
http.default_content_type = application/octet-stream
http.mime_types_filename=/etc/fdfs/mime.types
http.anti_steal.check_token=false
http.anti_steal.token_ttl=900
http.anti_steal.secret_key=FastDFS1234567890
http.anti_steal.token_check_fail=/usrdata/fastdfs/conf/anti-steal.jpg
5、启动storage
/usr/local/FastDFS/bin/fdfs_storaged /etc/fdfs/storage.conf
三、测试文件上传
上传文件/home/test/a.jpg用于测试
/usr/local/FastFDS/bin/fdfs_test /etc/fdfs/client.conf upload /home/test/a.jpg
This is FastDFS client test program v3.02
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-07-30 16:29:22] INFO – base_path=/home/data/fastdfs, connect_timeout=30, network_timeout=60, tracker_server_count=1, anti_steal_token=0, anti_steal_secret_key length=0tracker_query_storage_store_list_without_group:
server 1. group_name=group1, ip_addr=192.168.1.246, port=23000 group_name=group1, ip_addr=192.168.1.246, port=23000
storage_upload_by_filename
group_name=group1, remote_filename=M00/00/00/wKh7FFAWReLzPs4sAAEYquSDGwc472.jpg
source ip address: 192.168.1.246.20
file timestamp=2012-07-30 16:29:22
file size=71850
file crc32=3833797383
file url: http://192.168.1.246:8080/group1/M00/00/00/wKh7FFAWReLzPs4sAAEYquSDGwc472.jpg
storage_upload_slave_by_filename
group_name=group1, remote_filename=M00/00/00/wKh7FFAWReLzPs4sAAEYquSDGwc472_big.jpg
source ip address: 192.168.1.246
file timestamp=2012-07-30 16:29:22
file size=71850
file crc32=3833797383
file url: http://192.168.1.246:8080/group1/M00/00/00/wKh7FFAWReLzPs4sAAEYquSDGwc472_big.jpg
四、常见命令:
1、启动:
/usr/local/fastdfs/bin/fdfs_trackerd /etc/fdfs/tracker.conf
/usr/local/fastdfs/bin/fdfs_storaged /etc/fdfs/storage.conf
2、停止:
/usr/local/fastdfs/bin/stop.sh /usr/local/fastdfs/bin/fdfs_trackerd
/usr/local/fastdfs/bin/stop.sh /usr/local/fastdfs/bin/fdfs_storaged
3、重启:
/usr/local/fastdfs/bin/restart.sh /usr/local/fastdfs/bin/fdfs_trackerd
/usr/local/fastdfs/bin/restart.sh /usr/local/fastdfs/bin/fdfs_storaged
五、迁移:
以上是正常的配置及启动,我是要将文件从旧的fastdfs服务器迁移到新的fastdfs文件服务器上来:
1、先将所有storage进程都停止:
/usr/local/fastdfs/bin/stop.sh /usr/local/fastdfs/bin/fdfs_storaged
2、修改storage.conf文件
vi /etc/fdfs/storage.conf
将tracker_server的IP设置成旧服务器IP192.168.1.53
tracker_server=192.168.1.53:22122
3、启动storage进程:
/usr/local/fastdfs/bin/fdfs_storaged /etc/fdfs/storage.conf
此时storage服务器开始同步;
查看同步进程:
在旧tracker服务器执行:
/usr/local/fastdfs/bin/fdfs_monitor /etc/fdfs/storage.conf
可以看到同步进度;
4、同步完成后,在新的fastdfs文件服务器192.168.1.246上停止storage进程:
/usr/local/fastdfs/bin/stop.sh /usr/local/fastdfs/bin/fdfs_storaged
5、修改storage.conf文件,将tracker修改成新的tracker IP
vi /etc/fdfs/storage.conf
tracker_server=192.168.1.246:22122
6、修改.data_init_flag文件:
cd /usrdata/storage/data/
vi .data_init_flag
将sync_src_server配置项留空,其它配置项不变
sync_src_server=
7、启动storage进程
/usr/local/fastdfs/bin/fdfs_storaged /etc/fdfs/storage.conf
查看storage进程状态:
/usr/local/fastdfs/bin/fdfs_monitor /etc/fdfs/storage.conf
完成。