生产环境部署之--Fastdfs 生产环境部署配置

#----------------------------------------------------#
# create by xuekun
# date 2015-10-30 15:30

# 812711277@qq.com

# WebUrl  http://www.bdkyr.com

#----------------------------------------------------#
一、安装libfastcommon-master
wget https://github.com/happyfish100/libfastcommon/archive/master.zip
unzip master.zip
cd libfastcommon-master
./make.sh
./make.sh install
cd ../


二、安装fastdfs
tar zxvf FastDFS_v5.05.tar.gz
cd FastDFS
./make.sh
./make.sh install
cd ../


三、配置
vim /etc/fdfs/tracker.conf
 准备几个空闲的端口,可以使用netstat -an | grep 端口号是否被占用。


根据实际情况修改/etc/fdfs下的配置文件,每个上面都有注释说明,如果需要HTTP,别忘了解开最下面的#include http.conf,要带一个#


#启动tracker: 
/usr/local/bin/fdfs_trackerd start


#启动storage:
vim /etc/fdfs/storage.conf
 /usr/local/bin/fdfs_storaged start,如果出现错误,可以到步骤5修改配置文件时设置的目录的log目录下查看具体错误原因。


8. 到此安装配置完毕


#测试上传
[root@lc-static-33-72 xuekun]# /usr/bin/fdfs_test /etc/fdfs/client.conf upload 15012913446028.jpg 
This is FastDFS client test program v5.05


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.


[2016-08-11 09:30:47] DEBUG - base_path=/tmp/fastdfs, 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.150.33.72, port=23000


group_name=group1, ip_addr=10.150.33.72, port=23000
storage_upload_by_filename
group_name=group1, remote_filename=M00/00/00/CpYhSFer1UeAJyLbAACycbW9l1E559.jpg
source ip address: 10.150.33.72
file timestamp=2016-08-11 09:30:47
file size=45681
file crc32=3049101137
example file url: http://10.150.33.72/group1/M00/00/00/CpYhSFer1UeAJyLbAACycbW9l1E559.jpg
storage_upload_slave_by_filename
group_name=group1, remote_filename=M00/00/00/CpYhSFer1UeAJyLbAACycbW9l1E559_big.jpg
source ip address: 10.150.33.72
file timestamp=2016-08-11 09:30:47
file size=45681
file crc32=3049101137
example file url: http://10.150.33.72/group1/M00/00/00/CpYhSFer1UeAJyLbAACycbW9l1E559_big.jpg






[root@storage-1 xuekun]# /usr/bin/fdfs_test /etc/fdfs/client.conf upload pic.jpg 
This is FastDFS client test program v5.05


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-10-30 17:04:06] DEBUG - base_path=/fastdfs, 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=192.168.15.51, port=23000


group_name=group1, ip_addr=192.168.15.51, port=23000
storage_upload_by_filename
group_name=group1, remote_filename=M00/00/00/wKgPM1Yz20aAatatAAApv6iwavM194.jpg
source ip address: 192.168.15.51
file timestamp=2015-10-30 17:04:06
file size=10687
file crc32=2830134003
example file url: http://192.168.15.51/group1/M00/00/00/wKgPM1Yz20aAatatAAApv6iwavM194.jpg
storage_upload_slave_by_filename
group_name=group1, remote_filename=M00/00/00/wKgPM1Yz20aAatatAAApv6iwavM194_big.jpg
source ip address: 192.168.15.51
file timestamp=2015-10-30 17:04:06
file size=10687
file crc32=2830134003
example file url: http://192.168.15.51/group1/M00/00/00/wKgPM1Yz20aAatatAAApv6iwavM194_big.jpg


#查看原图
[root@storage-1 data]# cd 00/00/
[root@storage-1 00]# ls
wKgPM1Yz20aAatatAAApv6iwavM194_big.jpg    wKgPM1Yz20aAatatAAApv6iwavM194.jpg
wKgPM1Yz20aAatatAAApv6iwavM194_big.jpg-m  wKgPM1Yz20aAatatAAApv6iwavM194.jpg-m
[root@storage-1 00]# ll
total 32
-rw-r--r--. 1 root root 10687 Oct 30 17:04 wKgPM1Yz20aAatatAAApv6iwavM194_big.jpg
-rw-r--r--. 1 root root    49 Oct 30 17:04 wKgPM1Yz20aAatatAAApv6iwavM194_big.jpg-m
-rw-r--r--. 1 root root 10687 Oct 30 17:04 wKgPM1Yz20aAatatAAApv6iwavM194.jpg
-rw-r--r--. 1 root root    49 Oct 30 17:04 wKgPM1Yz20aAatatAAApv6iwavM194.jpg-m




#常用命令
[root@tracket1-1 fdfs]# /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart
waiting for pid [5945] exit ...
starting ...




#上传文件:/usr/bin/fdfs_upload_file  <config_file> <local_filename>


#下载文件:/usr/bin/fdfs_download_file <config_file> <file_id> [local_filename]


#删除文件:/usr/bin/fdfs_delete_file <config_file> <file_id>


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


#关闭:
killall fdfs_trackerd


killall fdfs_storaged



/usr/bin/stop.sh /usr/local/bin/fdfs_trackerd /etc/fdfs/tracker.conf


/usr/bin/stop.sh /usr/local/bin/fdfs_storaged /etc/fdfs/storage.conf


#重启tracker和storage:
/usr/bin/restart.sh /usr/local/bin/fdfs_trackerd /etc/fdfs/tracker.conf
/usr/bin/restart.sh /usr/local/bin/fdfs_storaged /etc/fdfs/storage.conf




FAQ:
首次运行出现错误提示
[2015-10-30 16:34:39] ERROR - file: process_ctrl.c, line: 241, "/home/yuqing/fastdfs" can't be accessed, error info: No such file or directory


解决:
修改vim /etc/fdfs/tracker.conf


# the base path to store data and log files
base_path=/fastdfs










#-----------------------------------------------------------------#
FastDFS+Nginx安装配置笔记
1.系统环境
 
最小化安装的 CentOS 6.2




tracker1:   192.168.68.113
tracker1:   192.168.68.116




storage1:   192.168.68.114
storage1:   192.168.68.115








2.环境准备[所有服务器都需要]




安装EPEL源
rpm -ivh epel-release-6-6.noarch.rpm




安装开发工具和编译nginx所需的开发包




yum groupinstall -y "Development Tools"
yum install -y libevent-devel pcre-devel zlib-devel




3.在tracker上的安装配置




[root@tracker1]# wget http://fastdfs.googlecode.com/files/FastDFS_v3.06.tar.gz
[root@tracker1]# tar xvzf FastDFS_v3.06.tar.gz
[root@tracker1]# cd FastDFS
[root@tracker1]# vi make.sh
    #将找到下面两行,将前边的"#"去掉,目的是安装httpd和fdfs_trackerd/fdfs_storaged服务




    WITH_HTTPD=1
    WITH_LINUX_SERVICE=1




[root@tracker1]# ./make.sh
[root@tracker1]# ./make.sh install
[root@tracker1]# vi /etc/fdfs/tracker.conf
    
    修改/etc/fdfs/tracker.conf,主要修改以下两处,如有其他调整,可参考文档自行调整,默认的配置也可以工作。
  
    # 配置data和log的存放路径,该路径如果不存在,需要自己创建
    base_path=/home/tracker1/fastdfs
    
    # 找到下面这行包含两个"##"号
    ##include http.conf
    # 去掉一个"#"
    #include http.conf




[root@tracker1]# mkdir -p /home/tracker1/fastdfs  








启动tracker服务
[root@tracker1]# service fdfs_trackerd start




确认8080,22122端口已经监听
[root@tracker1]# netstat -ntl
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address               Foreign Address             State
tcp        0      0 0.0.0.0:111                 0.0.0.0:*                   LISTEN
tcp        0      0 0.0.0.0:8080                0.0.0.0:*                   LISTEN
tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN
tcp        0      0 0.0.0.0:45372               0.0.0.0:*                   LISTEN
tcp        0      0 0.0.0.0:22122               0.0.0.0:*                   LISTEN
tcp        0      0 :::111                      :::*                        LISTEN
tcp        0      0 :::22                       :::*                        LISTEN
tcp        0      0 :::45032                    :::*                        LISTEN








4.在storage上的安装配置
下载FastDFS,Nginx和fastdfs-nginx-module
[root@storage1]# wget http://fastdfs.googlecode.com/files/FastDFS_v3.06.tar.gz
[root@storage1]# wget http://fastdfs.googlecode.com/files/fastdfs-nginx-module_v1.10.tar.gz
[root@storage1]# wget http://nginx.org/download/nginx-1.0.11.tar.gz




安装FastDFS =>安装方法与tracker1上相同。








安装nginx和fastdfs-nginx-module
[root@storage1]# tar xvzf nginx-1.0.11.tar.gz
[root@storage1]# tar xvzf fastdfs-nginx-module_v1.10.tar.gz
[root@storage1]# cd nginx-1.0.11
[root@storage1]# ./configure --prefix=/usr/local/nginx --add-module=/home/fastdfs-nginx-module/src
[root@storage1]# make
[root@storage1]# make install




[root@storage1]# vi /etc/fdfs/storage.conf
    修改/etc/fdfs/storage.conf,主要修改以下几处,如有其他调整,可参考文档自行调整,默认的配置也可以工作。
    




    # HTTP settings
    # 关闭内置的web server
    http.disabled=true
    
    # the port of the web server on this storage server
    # web server的端口改成80
    http.server_port=80
    
    # the name of the group this storage server belongs to
    # 此台storage1所属的服务器组名,同组内storage数据完全相同
    group_name=group1
    
    # the base path to store data and log files
    # 放置data和log的目录
    base_path=/home/storage1/fastdfs
   
    # store_path#, based 0, if store_path0 not exists, it's value is base_path
    # the paths must be exist
    # 放置文件的目录
    store_path0=/home/storage1/fastdfs
    
    # tracker_server can ocur more than once, and tracker_server format is
    # "host:port", host can be hostname or ip address
    # tracker server的ip和端口,此处可以写多个tracker server,每行一个
    tracker_server=192.168.68.113:22122
    tracker_server=192.168.68.116:22122




[root@storage1]# cp /home/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs/
[root@storage1]# vi /etc/fdfs/mod_fastdfs.conf
 
    # the base path to store log files
    # 放置log的目录
    base_path=/home/storage1/fastdfs




    # FastDFS tracker_server can ocur more than once, and tracker_server format is
    # "host:port", host can be hostname or ip address
    # tracker1的ip和端口,此处可以写多个tracker server,每行一个
    tracker_server=192.168.68.113:22122
    tracker_server=192.168.68.116:22122
    
    # the group name of storage server
    # 此台storage server所属的服务器组名
    group_name=group1
 
    # if uri including group name
    # default value is false
    # 在URL中包含group名称
    url_have_group_name = true
    
    # store_path#, based 0, if store_path0 not exists, it's value is base_path
    # the paths must be exist
    # 放置文件的目录
    store_path0=/home/storage1/fastdfs
    
[root@storage1]# mkdir -p /home/storage1/fastdfs








在nginx的server配置段中增加M00的location声明
[root@storage1]# vi /usr/local/nginx/conf/nginx.conf
    location /group1/M00 {
            root /home/storage1/fastdfs/data;
            ngx_fastdfs_module;
    }




创建M00目录的软连接
[root@storage1]# ln -s /home/storage1/fastdfs/data  /home/storage1/fastdfs/data/M00




启动storage服务
[root@storage1]# service fdfs_storaged start




启动nginx,启动之前,要确定fdfs_trackerd服务已启动且相关防火墙端口已开放
[root@storage1]# /usr/local/nginx/sbin/nginx




确认80,23000端口已经监听
[root@storage1]# netstat -ntl
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address               Foreign Address             State
tcp        0      0 0.0.0.0:111                 0.0.0.0:*                   LISTEN
tcp        0      0 0.0.0.0:80                  0.0.0.0:*                   LISTEN
tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN
tcp        0      0 0.0.0.0:23000               0.0.0.0:*                   LISTEN
tcp        0      0 0.0.0.0:34169               0.0.0.0:*                   LISTEN
tcp        0      0 :::111                      :::*                        LISTEN
tcp        0      0 :::22                       :::*                        LISTEN
tcp        0      0 :::60001                    :::*                        LISTEN
















5.在tracker上的操作[作为client测试]




[root@tracker1]# /etc/fdfs/client.conf




    # the base path to store log files
    base_path=/tmp
    
    # tracker_server can ocur more than once, and tracker_server format is
    #  "host:port", host can be hostname or ip address
    tracker_server=192.168.68.113:22122
    tracker_server=192.168.68.116:22122
    
创建一个用于测试的文件test.txt
[root@tracker1]# vi test.txt
输入内容: hello,this is my first fastdfs test




保存。使用自带的fdfs_test上传文件测试




[root@tracker1]# /usr/local/bin/fdfs_test /etc/fdfs/client.conf upload test.txt
This is FastDFS client test program v3.06




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-06-13 17:58:25] INFO - base_path=/tmp, connect_timeout=30, network_timeout=60, tracker_server_count=2, 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.68.114, port=23000




group_name=group1, ip_addr=192.168.68.114, port=23000
storage_upload_by_filename
group_name=group1, remote_filename=M00/00/00/wKhEck_YZEHqsZRSAAAAJdWuY6w607.txt
source ip address: 192.168.68.114
file timestamp=2012-06-13 17:58:25
file size=37
file crc32=3584975788
file url: http://192.168.68.113:8080/group1/M00/00/00/wKhEck_YZEHqsZRSAAAAJdWuY6w607.txt
storage_upload_slave_by_filename
group_name=group1, remote_filename=M00/00/00/wKhEck_YZEHqsZRSAAAAJdWuY6w607_big.txt
source ip address: 192.168.68.114
file timestamp=2012-06-13 17:58:25
file size=37
file crc32=3584975788
file url: http://192.168.68.113:8080/group1/M00/00/00/wKhEck_YZEHqsZRSAAAAJdWuY6w607_big.txt








6.使用浏览器打开上传的文件
http://192.168.68.113:8080/group1/M00/00/00/wKhEck_YZEHqsZRSAAAAJdWuY6w607_big.txt


如果看到文件内容,说明配置成功!
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值