FastDFS安装配置

FastDFS

FastDFS为互联网量身定制,充分考虑了冗余备份、负载均衡、线性扩容等机制,并注重高可用、高性能等指标,使用FastDFS很容易搭建一套高性能的文件服务器集群提供文件上传、下载等服务。

1.所需要的安装包

2.安装服务器(关闭服务器防火墙service iptables stop    setenforce 0)

192.168.241.137------------------------>tracker服务器

192.168.241.138------------------------>storage服务器(group1)

192.168.241.139------------------------>storage服务器(group1)

   

3.tracker安装

yum -y install gcc-c++ (安装编译工具)
yum -y install libevent (FastDFS依赖libevent库)
mv libfastcommonV1.0.7.tar.gz /usr/local (将libfastcommon放到/usr/local目录下)
cd /usr/local
tar -zxvf libfastcommonV1.0.7.tar.gz (解压libfastcommon)
cd libfastcommon-1.0.7/
./make.sh (编译libfastcommon)
./make.sh install (安装libfastcommon)
cp /usr/lib64/libfastcommon.so /usr/lib (注意:libfastcommon安装好后会自动将库文件拷贝至/usr/lib64下,由于FastDFS程序引用usr/lib目录所以需要将/usr/lib64下的库文件拷贝至/usr/lib下)
mv FastDFS_v5.05.tar.gz /usr/local/ (将FastDFS安装包放到/usr/local目录下)
cd /usr/local
tar -zxvf FastDFS_v5.05.tar.gz (解压FastDFS安装包)
cd FastDFS
./make.sh (编译FastDFS)
./make.sh install (安装FastDFS)
cp /usr/local/FastDFS/conf/http.conf /etc/fdfs/ (将http.conf拷贝到/etc/fdfs目录下)
cp /usr/local/FastDFS/conf/mime.types /etc/fdfs/ (将mime.types拷贝到/etc/fdfs目录下)
cd /etc/fdfs/ (进入FastDFS配置文件目录)
cp tracker.conf.sample tracker.conf (拷贝一份新的tracker配置文件)
mkdir -p /home/FastDFS (创建FastDFS工作目录)
vim tracker.conf (配置配置文件,# HTTP port on this tracker server http.server_port=8080 # the tracker server port port=22122 这里的端口没有配置使用默认端口)
base_path=/home/FastDFS
/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart (启动tracker服务器)

 开机启动tracker

vim /etc/rc.local
/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart

 查看日志

tail -f /home/FastDFS/logs/trackerd.log 

 使用fdfs_monitor命令查看Storage是否已登记到Tracker

/usr/bin/fdfs_monitor /etc/fdfs/client.conf

 

4.storage安装

yum -y install gcc-c++ (安装编译工具)
yum -y install libevent (FastDFS依赖libevent库)
mv libfastcommonV1.0.7.tar.gz /usr/local (将libfastcommon放到/usr/local目录下)
cd /usr/local
tar -zxvf libfastcommonV1.0.7.tar.gz (解压libfastcommon)
cd libfastcommon-1.0.7/
./make.sh (编译libfastcommon)
./make.sh install (安装libfastcommon)
cp /usr/lib64/libfastcommon.so /usr/lib (注意:libfastcommon安装好后会自动将库文件拷贝至/usr/lib64下,由于FastDFS程序引用usr/lib目录所以需要将/usr/lib64下的库文件拷贝至/usr/lib下)
mv FastDFS_v5.05.tar.gz /usr/local/ (将FastDFS安装包放到/usr/local目录下)
cd /usr/local
tar -zxvf FastDFS_v5.05.tar.gz (解压FastDFS安装包)
cd FastDFS
./make.sh (编译FastDFS)
./make.sh install (安装FastDFS)
cp /usr/local/FastDFS/conf/http.conf /etc/fdfs/ (将http.conf拷贝到/etc/fdfs目录下)
cp /usr/local/FastDFS/conf/mime.types /etc/fdfs/ (将mime.types拷贝到/etc/fdfs目录下)
cd /etc/fdfs/ (进入FastDFS配置文件目录)
cp storage.conf.sample storage.conf (拷贝一份新的storage配置文件)
vim storage.conf(# the port of the web server on this storage server http.server_port=8888 默认,根据需要设置)
group_name=group1 (组名)
base_path=/home/FastDFS (基础目录)
store_path0=/home/FastDFS/fdfs_storage (存储目录)
tracker_server=192.168.101.3:22122 (tracker服务器)
mkdir -p /home/FastDFS (创建FastDFS工作目录)
mkdir -p /home/FastDFS/fdfs_storage (存储目录)
/usr/bin/fdfs_storaged /etc/fdfs/storage.conf restart (启动storage服务器)

 设置开机启动

vim /etc/rc.local
/usr/bin/fdfs_storaged /etc/fdfs/storage.conf restart

查看日志

tail -f /home/FastDFS/logs/storaged.log

使用fdfs_monitor命令查看Storage是否已登记到Tracker

/usr/bin/fdfs_monitor /etc/fdfs/storage.conf

 注意标红的地方(storage服务器和tracker服务器连接需要时间)

Group 2:
group name = group2
disk total space = 17846 MB
disk free space = 14096 MB
trunk free space = 0 MB
storage server count = 3
active server count = 3
storage server port = 23000
storage HTTP port = 8888
store path count = 1
subdir count per path = 256
current write server index = 0
current trunk file id = 0

        Storage 1:
                id = 192.168.241.138
                ip_addr = 192.168.241.138 (localhost)  ACTIVE
                ...
        Storage 2:
                id = 192.168.241.139
                ip_addr = 192.168.241.139 (localhost)  ACTIVE
                ...

 

5.上传图片测试(tracker服务器)

cd /etc/fdfs/
cp client.conf.sample client.conf (FastDFS安装成功可通过/usr/bin/fdfs_test测试上传、下载等操作)
vim client.conf (修改配置文件)
base_path=/home/FastDFS
tracker_server=192.168.241.137:22122

 

使用格式:/usr/bin/fdfs_test  客户端配置文件地址   upload   上传文件

比如将/home下的图片上传到FastDFS中:
/usr/bin/fdfs_test /etc/fdfs/client.conf upload /home/567.png
tracker服务器显示日志:
storage服务器:

 或者使用:/usr/bin/fdfs_upload_file /etc/fdfs/client.conf /home/567.png

当配置有多个group的时候,存储在哪个group下,根据/etc/fdfs/tracker.conf配置文件配置决定


 

 

6.FastDFS和nginx整合

 

tracker服务器装nginx实现负载均衡(这里的负载值是负载相同group内不同storage服务器/上传tracker根据自己的策略选择group,同group不同storage同步数据/下载要指定group,所以负载只是负载相同group的不同ip)

storage服务器装nginx实现http下载

为了体现出负载均衡效果,将192.168.241.138配置为group1;192.168.241.139配置为group2

在tracker上装nginx

yum install -y pcre pcre-devel (依赖)
yum install -y zlib zlib-devel (依赖)
yum install -y openssl openssl-devel (依赖)
mv nginx-1.8.0.tar.gz /usr/local (将nginx安装包放到/usr/local/目录下)
cd /usr/local
tar -zxvf nginx-1.8.0.tar.gz (解压nginx安装包)
mkdir -p /var/temp/nginx (创建nginx临时文件目录)
cd /usr/local/nginx-1.8.0

(配置nginx prefix,指定安装目录,指定的是nginx的安装目录 上边将临时文件目录指定为/var/temp/nginx,需要在/var下创建temp及nginx目录)
./configure \
--prefix=/usr/local/nginx \
--pid-path=/var/run/nginx/nginx.pid \
--lock-path=/var/lock/nginx.lock \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--with-http_gzip_static_module \
--http-client-body-temp-path=/var/temp/nginx/client \
--http-proxy-temp-path=/var/temp/nginx/proxy \
--http-fastcgi-temp-path=/var/temp/nginx/fastcgi \
--http-uwsgi-temp-path=/var/temp/nginx/uwsgi \
--http-scgi-temp-path=/var/temp/nginx/scgi
 
  make (编译)
  make install (安装)
 

 

cd /usr/local/nginx/conf/ (打开nginx配置文件)
vim nginx.conf (编辑nginx配置文件)

 

 upstream storage_server_group1{
        server 192.168.241.138:8888 weight=10;
     server 192.168.241.139:8888 weight=10;
    }

   

    server {
        listen 8080;
        server_name ccc.test.com;
        location /group1{
                proxy_redirect off;
                proxy_set_header Host $host;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_pass http://storage_server_group1;
        }
       

    }

 

 

storage上装nginx

yum install -y pcre pcre-devel (依赖)
yum install -y zlib zlib-devel (依赖)
yum install -y openssl openssl-devel (依赖)
mv fastdfs-nginx-module_v1.16.tar.gz /usr/local (将fastdfs和nginx整合包放到/usr/local下)
mv nginx-1.8.0.tar.gz /usr/local (将nginx安装包放在/usr/local下)
tar -zxvf fastdfs-nginx-module_v1.16.tar.gz (解压整合包)
cd fastdfs-nginx-module/src/ (打开配置文件夹)
vim config

 

修改config文件将/usr/local/路径改为/usr/

cp /usr/local/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs/ (将整合配置文件放在fastdfs配置文件夹下)
vi /etc/fdfs/mod_FastDFS.conf (修改配置文件)
base_path=/home/FastDFS
tracker_server=192.168.101.3:22122
url_have_group_name=true (url中包含group名称)
group_name=group1 (当前服务器的group名)

store_path0=/home/FastDFS/fdfs_storage   (指定文件存储路径)
cp /usr/lib64/libfdfsclient.so /usr/lib/
mkdir -p /var/temp/nginx/client (创建nginx/client目录)

 

nginx安装
tar -zxvf nginx-1.8.0.tar.gz
cd nginx-1.8.0
./configure \
--prefix=/usr/local/nginx \
--pid-path=/var/run/nginx/nginx.pid \
--lock-path=/var/lock/nginx.lock \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--with-http_gzip_static_module \
--http-client-body-temp-path=/var/temp/nginx/client \
--http-proxy-temp-path=/var/temp/nginx/proxy \
--http-fastcgi-temp-path=/var/temp/nginx/fastcgi \
--http-uwsgi-temp-path=/var/temp/nginx/uwsgi \
--http-scgi-temp-path=/var/temp/nginx/scgi \
--add-module=/usr/local/fastdfs-nginx-module/src
 
  make
  make install
  cd /usr/local/nginx/conf/ (打开nginx配置文件)
  vim nginx.conf (编辑nginx配置文件)

 

 server {
                listen       8888;
                server_name  192.168.241.138;

                location /group1/M00/{
                        root /home/FastDFS/fdfs_storage/data;
                        ngx_fastdfs_module;
                }
        }

 

说明:
server_name指定本机ip
location /group1/M00/:group1为nginx 服务FastDFS的分组名称,M00是FastDFS自动生成编号,对应store_path0=/home/FastDFS/fdfs_storage,如果FastDFS定义store_path1,这里就是M01

 

测试

通过tracker负载均衡后访问

通过storage直接访问


 

 

FASTDFS的STORAGE SERVER的状态问题

STORAGE SERVER的状态通常有七种:

# FDFS_STORAGE_STATUS:INIT      :初始化,尚未得到同步已有数据的源服务器

# FDFS_STORAGE_STATUS:WAIT_SYNC :等待同步,已得到同步已有数据的源服务器

# FDFS_STORAGE_STATUS:SYNCING   :同步中

# FDFS_STORAGE_STATUS:DELETED   :已删除,该服务器从本组中摘除

# FDFS_STORAGE_STATUS:OFFLINE   :离线

# FDFS_STORAGE_STATUS:ONLINE    :在线,尚不能提供服务

# FDFS_STORAGE_STATUS:ACTIVE    :在线,可以提供服务


正常状态必须是ACTIVE,如果运行以下命令:

fdfs_monitor /etc/fdfs/client.conf

 

发现有以下状态的服务器:

Storage 4:
        ip_addr = 10.120.151.114  WAIT_SYNC

 

经过各种重启都不解决问题,只好先删除,再加入:

#从集群中删除
fdfs_monitor /etc/fdfs/client.conf delete group1 10.120.151.114

#在114服务器中,删除数据文件夹
rm -rf /home/storage1/fastdfs/data

#重启114节点
fdfs_storaged /etc/fdfs/storage.conf restart

 

重新查状态

fdfs_monitor /etc/fdfs/client.conf

 


状态变正常了。

 

posted @ 2016-09-05 14:03  woms  阅读(627)  评论(0编辑  收藏  举报