FastDFS安装与部署

yne7 9年前

(一)下载依赖库libevent(不管解压在哪里必须安装在/usr目录下,否则FastDFS找不到)
wget https://github.com/downloads/libevent/libevent/libevent-1.4.14b-stable.tar.gz
tar zvxf libevent-1.4.14b-stable.tar.gz
./configure --prefix=/usr
make clean;
make
make install

(二)下载FastDFS安装包及nginx依赖组件
FastDFS官方论坛:http://www.csource.org
下载1:http://sourceforge.net/projects/fastdfs/files/
下载2:https://code.google.com/p/fastdfs/downloads/list

所需要下载的压缩包有:
FastDFS源代码:FastDFS_v5.01.tar.gz
nginx服务器源代码:nginx-1.4.7.tar.gz
nginx扩展插件源代码:fastdfs-nginx-module_v1.15.tar.gz
nginx缓存插件源代码:ngx_cache_purge-2.1.tar.gz
nginx依赖的pcre库源代码:pcre-8.34.tar.gz
nginx依赖的zlib库源代码:zlib-1.2.8.tar.gz
nginx依赖的openssl库源代码:openssl-fips-2.0.9.tar.gz

--关闭防火墙
service iptables stop

(三)安装
cp FastDFS_v5.01.tar.gz /usr/local/src/
cd /usr/local/src/
tar -zxvf FastDFS_v5.01.tar.gz
cd FastDFS
./make.sh
./make.sh install

备注:
(1)./make.sh期间安装错误,可能缺少依赖的软件包,安装后重新执行./make.sh
(2)安装的
源文件目录在:/usr/local/src/
可执行文件目录在:/usr/local/bin
所有配置文件目录在:/etc/fdfs(该目录下会产生tracker.conf、storage.conf及client.conf)

至此FastDFS安装成功....



(四)配置及启动Tracker Server
vim /etc/fdfs/tracker.conf
--修改文件:
disabled=false #启用配置文件(这个暂时不知道怎么处理先不改)
port=22122 #设置tracker的端口号
base_path=/fdfs/tracker #设置tracker的数据文件和日志目录(需预先创建) 
http.server_port=8090 #设置http端口号
#include http.conf

注意上面那个是1个#,默认是2个#,去掉1个就行

--开启端口
iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 22122 -j ACCEPT
--将防火墙规则保存到/etc/sysconfig/iptables(若iptables不存在则手动创建并授权)
/etc/init.d/iptables save
--启动tracker,确认启动是否成功
/usr/local/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart
--查看是否对应端口22122是否开始监听
netstat -unltp | grep fdfs
--查看tracker的日志是否有错误
cat /fdfs/tracker/logs/trackerd.log
--设置开机自动启动
vim /etc/rc.d/rc.local
添加:/usr/local/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart



(五)配置及启动Storage Server
vim /etc/fdfs/storage.conf
--修改文件:
group_name=group1 #组名,根据实际情况修改
port=23000 #设置storage的端口号
base_path=/fdfs/storage #设置storage的日志目录(需预先创建)
store_path_count=1 #存储路径个数,需要和store_path个数匹配
store_path0=/fdfs/storage #存储路径
tracker_server=192.168.1.103:22122 #tracker服务器的IP地址和端口号(若tracker是单独服务器则ip另写)
http.server_port=8888 #设置http端口号
#include http.conf

--开启端口
iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 23000 -j ACCEPT
--将防火墙规则保存到/etc/sysconfig/iptables(若iptables不存在则手动创建并授权)
/etc/init.d/iptables save
--启动tracker,确认启动是否成功
/usr/local/bin/fdfs_storaged /etc/fdfs/storage.conf restart
--查看是否对应端口23000是否开始监听
netstat -unltp | grep fdfs
--查看tracker的日志是否有错误
cat /fdfs/storage/logs/storaged.log
--设置开机自动启动
vim /etc/rc.d/rc.local
添加:/usr/local/bin/fdfs_storaged /etc/fdfs/storage.conf restart

--启动成功后,运行fdfs_monitor查看storage服务器是否已经登记到tracker服务器。前几行看到tracker的ip即正常
/usr/local/bin/fdfs_monitor /etc/fdfs/storage.conf

至此,非nginx的FastDFS文件系统已安装完成

(六)验证FastDFS上传下载(上传下载可省端client配置可省略)
vim /etc/fdfs/client.conf
--修改client.conf
base_path=/fdfs/client
tracker_server=192.168.1.103:22122
http.tracker_server_port=8090 #设置tracker端口号

--上传
fdfs_test /etc/fdfs/client.conf upload /data/monk.jpg
http://192.168.1.103:8090/group1/M00/00/00/OlPQG1Db6jWAFmbTAAADqdgNsks5096460_big.jpg
--删除
fdfs_test /etc/fdfs/client.conf delete group1 M00/00/00/OlPQG1Db6jWAFmbTAAADqdgNsks5096460_big.jpg

http://192.168.1.103:8090/group1/M00/00/00/wKgBZ1UX8tGACWOJAACdM6nw92I711_big.jpg





(七)FastDFS和nginx整合
(1)nginx安装扩展插件
cp fastdfs-nginx-module_v1.15.tar.gz /usr/local/src
tar -zxvf fastdfs-nginx-module_v1.15.tar.gz
cd /usr/local/src
cd nginx-1.4.7
./configure --prefix=/usr/local/nginx --add-module=/usr/local/src/fastdfs-nginx-module/src --with-pcre=/usr/local/src/pcre-8.34/ --with-zlib=/usr/local/src/zlib-1.2.8
make
make install

--复制扩展插件配置文件到/etc/fdfs
cp /usr/local/src/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs/



(2)配置mod_fastdfs.conf
vim /etc/fdfs/mod_fastdfs.conf
--修改文件:
base_path=/fdfs/storage #保存日志目录
tracker_server=192.168.1.103:22122 #tracker服务器的IP地址以及端口号
storage_server_port=23000 #storage服务器的端口号
group_name=group1 #当前服务器的group名
url_have_group_name = true #文件url中是否有group名
store_path_count=1 #存储路径个数,需要和store_path个数匹配
store_path0=/fdfs/storage #存储路径
http.need_find_content_type=true #从文件扩展名查找文件类型(nginx时为true)
group_count = 1 #设置组的个数

--建立软连接
ln -s /fdfs/storage/data /fdfs/storage/data/M00



(3)配置nginx.conf
vim /usr/local/nginx/conf/nginx.conf
--修改文件:
server {
listen 8888;
location / {
root html;
index index.html index.htm;
}
location /group1/M00 {
root /fdfs/storage/data;
ngx_fastdfs_module;
}
}

--重启tracker
/usr/local/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart
--重启storage
/usr/local/bin/fdfs_storaged /etc/fdfs/storage.conf restart
--重启nginx
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
/usr/local/nginx/sbin/nginx -s reload

--查看启动日志:
cat /fdfs/tracker/logs/trackerd.log
cat /fdfs/storage/logs/storaged.log
cat /usr/local/nginx/logs/error.log

--访问nginx
http://192.168.1.103:8888/



--查看端口使用情况:
netstat -lnp --tcp

tcp 0 0 0.0.0.0:23000 0.0.0.0: LISTEN 1761/fdfs_storaged
tcp 0 0 0.0.0.0:8888 0.0.0.0:
LISTEN 1718/nginx
tcp 0 0 0.0.0.0:8090 0.0.0.0: LISTEN 1809/fdfs_trackerd
tcp 0 0 0.0.0.0:22122 0.0.0.0:
LISTEN 1809/fdfs_trackerd

默认的8888端口本来是storage的,现在被nginx替代



(8)上传下载
--上传前确保/etc/fdfs/client.conf正确配置
base_path=/fdfs/tracker                    #日志存放路径
tracker_server=192.168.1.103:22122         #tracker服务器IP地址和端口号
http.tracker_server_port=8090              #tracker服务器的http端口号

--使用/usr/local/bin/fdfs_upload_file上传一个文件,程序会自动返回文件的URL
/usr/local/bin/fdfs_upload_file /etc/fdfs/client.conf /data/8.jpg

--返回:
group1/M00/00/00/wKgBZ1UX_7WAQTFPAACdM6nw92I838.jpg

--浏览器访问:
http://192.168.1.103:8888/group1/M00/00/00/wKgBZ1UX_7WAQTFPAACdM6nw92I838.jpg

--查看nginx的access.log日志,可以看到访问返回200成功

tail -n 10 -f /usr/local/nginx/logs/access.log

http://nonfu.me/p/4843.html