FDFS V4.06安装部署

1.系统环境说明

部署环境ubuntu 12.0.4 server 32or 64位,本文以64部署做说明。

最小安装,除openssh-server服务外不安装任何服务,我们的clienttrackerserverstorageserver 用同一台,iP 192.168.0.22  是最小系统

2.分区设置

根据部署的服务要求选择合理的分区,根据公司现有生产环境的分区划分这里做一下分区。

/boot      200M

/                    1G

Swap            2倍内存

/www            剩余空间,数据,部署程序,log,备份主要存放地。

3.初始化部署环境

sudo apt-get update

sudo apt-get upgrade

sudo apt-get dist-upgrade


安装编译环境

sudoapt-get install build-essential    #配置编译器和库文件

sudodpkg-reconfigure tzdata  或者sudotzselect

然后在crontab设置服务器时间同步,比如每天凌晨115分同步一次网络时钟

15      1      *       *       *      /usr/sbin/ntpdate 210.72.145.44;/sbin/hwclock -w > /dev/null2>&1 &

4.安装libevent

下载并安装

#cd/usr/src

wgethttps://github.com/downloads/libevent/libevent/libevent-1.4.14b-stable.tar.gz

$sudosu –

#tarzxvf libevent-1.4.14b-stable.tar.gz

#cd libevent-1.4.14b-stable

#/configure--prefix=/usr

#make && make install

5.安装FastDFS

这里我们选择的FDFS新版本,这里的FASTDFS 本身没有了http server的功能。

5.1

#cd /usr/src

#wget http://fastdfs.googlecode.com/files/FastDFS_v4.06.tar.gz

#tar zxvf  FastDFS_v4.06.tar.gz

#cd FastDFS/

由于一些库文件的存放位置,和编译脚本中的不一致,需要根据系统的实际情况进行调整。

#Vim make.sh

查找:

if[ -f /usr/lib/libpthread.so ] || [ -f /usr/local/lib/libpthread.so ] || [ -f/lib64/libpthread.so ] || [ -f /usr/lib64/libpthread

.so] || [ -f /usr/lib/libpthread.a ] || [ -f /usr/local/lib/libpthread.a ] || [ -

f/lib64/libpthread.a ] || [ -f /usr/lib64/libpthread.a ] ;


替换成:(以你服务器的实际路径为准)

if [ -f/usr/lib/libpthread.so ] || [ -f /usr/local/lib/libpthread.so ] || [ -f/lib64/libpthread.so ] || [ -f /usr/lib64/libpthread

.so ] || [ -f/usr/lib/x86_64-linux-gnu/libpthread.so ] || [ -f /usr/lib/libpthread.a ] || [-f /usr/local/lib/libpthread.a ] || [ -

f/lib64/libpthread.a ] || [ -f /usr/lib64/libpthread.a ] || [ -f /usr/lib/x86_64-linux-gnu/libpthread.a];

保存退出


#Vim /usr/src/FastDFS/client/fdfs_link_library.sh.in(64 bit 需要修改)


查找:

ln -fs $TARGET_LIB/libfastcommon.so.1/usr/lib64/libfastcommon.so

ln -fs $TARGET_LIB/libfdfsclient.so.1/usr/lib64/libfdfsclient.so


替换成:


ln -fs$TARGET_LIB/libfastcommon.so.1 /usr/lib/x86_64-linux-gnu/libfastcommon.so

ln -fs$TARGET_LIB/libfdfsclient.so.1 /usr/lib/x86_64-linux-gnu/libfdfsclient.so

保存退出

# sudo./make.sh

sudo./make.sh install

#cp init.d/* /etc/init.d/


注:如果报perl: warning: Setting locale failed.

perl: warning:Please check that your locale settings:

LANGUAGE =(unset),

LC_ALL =(unset),

LANG ="en_US.UTF-8"

are supported and installed on your system.

perl: warning:Falling back to the standard locale ("C").

locale: Cannotset LC_CTYPE to default locale: No such file or directory

locale: Cannotset LC_MESSAGES to default locale: No such file or directory

locale: Cannotset LC_ALL to default locale: No such file or directory


错,需要设置

vim/root/.bashrc

export LC_ALL=C

保存退出

#source/root/.bashrc

6.配置tracker server

安装完成后,在默认/etc/fdfs下

#vimtracker.conf

port=22122

base_path=/www/geebook_tracker

保存退出

#mkdir/www/geebook_tracker

#/etc/init.d/fdfs_trackerdstart  

检查tracker server

#netstat–antpul |grep 22122 或者lsof –i:22122


tcp        0     0 0.0.0.0:22122          0.0.0.0:*               LISTEN      23275/fdfs_trackerd

7.配置及启动Storage Server

#/www/geebook_storage

#vim/etc/fdfs/storage.conf

# port=23000

base_path=/www/geebook_storage

#base_path,指定datalog所在目录,根目录必须存在,子目录会自动创建

store_path0=/www/geebook_storage

#文件的存储位置,在一台Storage Server上可以指定多个存储位置

group_name=group1

tracker_server=192.168.0.22:22122  #tracker_server ip

保存退出

启动storage server


#/etc/init.d/fdfs_storaged  start

#netstat–antpul |grep 23000 或者lsof –i:23000 查看进程。

可以查看相关日志排错

#tail–f /www/geebook_storage/logs/storaged.log

验证验证上传下载

首先配置好客户端

#mkdirwww/geebook_client

#vim/etc/fdfs/client.conf

base_path=/www/geebook_client

tracker_server=192.168.0.22:22122

保存设置


测试上传

fdfs_test /etc/fdfs/client.confupload /etc/fstab

Thisis FastDFS client test program v4.06


Copyright(C) 2008, Happy Fish / YuQing


FastDFSmay be copied only under the terms of the GNU General

PublicLicense V3, which may be found in the FastDFS source kit.

Pleasevisit the FastDFS Home Page http://www.csource.org/

formore detail.


[2013-06-0315:45:41] DEBUG - base_path=/www/geebook_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 idcount: 0


tracker_query_storage_store_list_without_group:

       server 1. group_name=, ip_addr=192.168.0.22,port=23000


group_name=group1,ip_addr=192.168.0.22, port=23000

storage_upload_by_filename

group_name=group1,remote_filename=M00/00/00/AQEBjFGsSaWAOjeUAAAD9M32Tdg9524157

sourceip address: 192.168.0.22

filetimestamp=2013-06-03 15:45:41

filesize=1012

filecrc32=3455471064

fileurl: http://192.168.0.22/group1/M00/00/00/AQEBjFGsSaWAOjeUAAAD9M32Tdg9524157

storage_upload_slave_by_filename

group_name=group1,remote_filename=M00/00/00/AQEBjFGsSaWAOjeUAAAD9M32Tdg9524157_big

sourceip address: 192.168.0.22

filetimestamp=2013-06-03 15:45:42

filesize=1012

filecrc32=3455471064

fileurl: http://192.168.0.22/group1/M00/00/00/AQEBjFGsSaWAOjeUAAAD9M32Tdg9524157_big

下载

#cd/usr/src

查看

#fdfs_file_info/etc/fdfs/client.conf group1/M00/00/00/AQEBjFGsSaWAOjeUAAAD9M32Tdg9524157_big


sourcestorage id: 0

sourceip address: 192.168.0.22

filecreate timestamp: 2013-06-03 15:45:42

filesize: 1012

filecrc32: 3455471064 (0xCDF64DD8)

#fdfs_download_file/etc/fdfs/client.conf group1/M00/00/00/AQEBjFGsSaWAOjeUAAAD9M32Tdg9524157_big

-rw-r--r--1 root root  1012 Jun  3 15:59AQEBjFGsSaWAOjeUAAAD9M32Tdg9524157_big

删除

fdfs_delete_file/etc/fdfs/client.conf group1/M00/00/00/AQEBjFGsSaWAOjeUAAAD9M32Tdg9524157_big


8.Fdfs Nginx  的整合

8.1因为FastDFS默认自带的http服务器性能不好,所以一般建议用外置的apache或者nginx来解决http下载,以应付大并发的情况.

#cd  /usr/src/

#wgethttp://fastdfs-nginx-module.googlecode.com/files/fastdfs-nginx-module_v1.15.tar.gz

#wget http://nginx.org/download/nginx-1.3.9.tar.gz

#tar zxvf fastdfs-nginx-module_v1.15.tar.gz

#tarzxvf nginx-1.3.9.tar.gz

# apt-getinstall libssl-dev zlib1g-dev libpcre3-dev

#cd nginx-1.3.9/

#./configure--prefix=/usr/local/nginx --with-http_gzip_static_module--add-module=/usr/src/fastdfs-nginx-module/src/        

#make && make install

8.2 修改相关配置文件

修改nginx扩展模块的配置文件

#cd../usr/src/fastdfs-nginx-module/src

#cpmod_fastdfs.conf /etc/fdfs/


#vim/etc/fdfs/mod_fastdfs.conf


base_path=/www/logs

#存放log的路径


tracker_server=192.168.0.22:22122

#指定tracker服务器及端口


url_have_group_name= true

#这个很重要,在URL中包含group名称


store_path0=/www/geebook_storage

#存储文件的路径


storage_server_port=23000

#storage的配置端口保持一致


保存后退出


M00的链接

sudo ln -s/www/geebook_storage/data /www/geebook_storage/data/M00


修改nginx的配置文件

#Vim vim/usr/local/nginx/conf/nginx.conf

server{

       listen       8888



       location / {

           root   /www/geebook_storage/data;

           index  index.html index.htm;

       }


       location /group1/M00 {

       root /www/geebook_storage/data;

           ngx_fastdfs_module;

       }

}

保存退出

#cp/usr/local/nginx/sbin/nginx /etc/init.d/nginx

#/etc/init.d/nginx–t

ngx_http_fastdfs_setpid=23580

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

检查配置文件语法

#/etc/init.d/nginx     ##启动nginx

检查端口

#netstat–antpul |grep tcp

tcp        0     0 0.0.0.0:22122          0.0.0.0:*               LISTEN      23275/fdfs_trackerd

tcp        0     0 0.0.0.0:80             0.0.0.0:*               LISTEN      22917/nginx    

tcp        0     0 0.0.0.0:22             0.0.0.0:*               LISTEN      2117/sshd      

tcp        0     0 0.0.0.0:23000          0.0.0.0:*               LISTEN      23325/fdfs_storaged

tcp        0     0 0.0.0.0:8888           0.0.0.0:*               LISTEN      22917/nginx    

tcp        0     0 192.168.0.22:22122         192.168.0.22:48515         ESTABLISHED 23275/fdfs_trackerd

tcp        0     0 192.168.0.22:22           1.1.1.24:1558          ESTABLISHED 16381/sshd: geeboo

tcp        0     0 192.168.0.22:48515         192.168.0.22:22122         ESTABLISHED 23325/fdfs_storaged

tcp6       0     0 :::22                  :::*                    LISTEN      2117/sshd

测试上传和下载


#fdfs_test/etc/fdfs/client.conf upload /etc/fstab

#cd/usr/src

#wgethttp://192.168.0.22:8888/group1/M00/00/00/AQEBjFGsVESARdlrAAAD9M32Tdg0763076_big

--2013-06-0316:32:40--  http://192.168.0.22:8888/group1/M00/00/00/AQEBjFGsVESARdlrAAAD9M32Tdg0763076_big

Connectingto 192.168.0.22:8888... connected.

HTTPrequest sent, awaiting response... 200 OK

Length:1012

Savingto: `AQEBjFGsVESARdlrAAAD9M32Tdg0763076_big'


100%[======================================================================================>]1,012       --.-K/s   in 0s    


2013-06-0316:32:40 (309 MB/s) - `AQEBjFGsVESARdlrAAAD9M32Tdg0763076_big' saved[1012/1012]

9.添加新的tracker server  Storage Server同步设置

sudovi /etc/fdfs/storage.conf


修改以下内容


sync_start_time=0:00

sync_end_time=23:59

#设置允许同步时间,设置的时候考虑避开业务高峰时段


tracker_server=:192.168.1.216:22122

tracker_server=192.168.1.217:22122

#这里我们举例192.168.1.216是原tracker_server192.168.1.217是本身的tracker_server,只要添加原来的tracker_server就行,实际配置中,ip地址按实际需求来配置


保存后退出




如何查看并删除无效的storage server

#dfs_monitor/etc/fdfs/client.conf 可以查看当前group信息,以及一些统计信息。

再使用fdfs_monitor来删除。命令行如下:

fdfs_monitordelete

例如:

fdfs_monitor/etc/fdfs/client.conf delete group1 192.168.0.100