/注意//所有tracker和storage都要执行以下操作
1.安装编译所需要的依赖包:
yum install make cmake gcc gcc-c++
2.上传安装包到/usr/local/src
cd /usr/local/src
包括:
FastDFS_v5.05.tar.gz
fastdfs-nginx-module_v1.16.tar.gz
libfastcommon-master.zip
nginx-1.10.3.tar.gz
3.安装libfastcomment:
(如果unzip不能用需要安装:yum install zip unzip)
yum install perl(make.sh里面有用到perl,需要安装)
unzip libfastcommon-master.zip
cd libfastcommon-master
4.安装,编译
./make.sh
./make.sh install
建立软连接:
ln -s /usr/lib64/libfastcommon.so /usr/local/lib/libfastcommon.so
ln -s /usr/lib64/libfastcommon.so /usr/lib/libfastcommon.so
ln -s /usr/lib64/libfdfsclient.so /usr/local/lib/libfdfsclient.so
ln -s /usr/lib64/libfdfsclient.so /usr/lib/libfdfsclient.so
5安装fastdfs:
解压:tar -zxvf FastDFS_v5.05.tar.gz
cd FastDFS
6.编译,安装
./make.sh
./make.sh install
可以通过以下命令来查看fdfs相关命令
[root@fastdfs-storage-01 bin]# pwd
/usr/bin
[root@fastdfs-storage-01 bin]# ls | grep fdfs
7.修改/etc/init.d/fdfs_storaged和/etc/init.d/fdfs_trackerd两个脚本
中的/usr/local/bin修改成/usr/bin:
vi /etc/init.d/fdfs_trackerd
使用查找替换命令统一修改:输入冒号,然后底部输入%s+/usr/local/bin+/usr/bin
vi /etc/init.d/fdfs_storaged
使用查找替换命令统一修改:输入冒号,然后底部输入%s+/usr/local/bin+/usr/bin
/注意//配置跟踪器tracker
1.复制样例文件并重命名:
cd /etc/fdfs
cp tracker.conf.sample tracker.conf
编辑:vi /etc/fdfs/tracker.conf
修改以下内容:
disabled=false
port=22122
base_path=/home/fastdfs/tracker
2.创建集成数据目录
mkdir -p /home/fastdfs/tracker
3.打开防火墙22122端口
vi /etc/sysconfig/iptables
加入:
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22122 -j ACCEPT
重启:
service iptables restart
4.启动tracker:
/etc/init.d/fdfs_trackerd start
首次启动成功会在/fastdfs/tracker生产data和logs目录
5.关闭tracker:
/etc/init.d/fdfs_trackerd stop
7.设置fastdfs开机启动
vi /etc/rc.d/rc.local
添加以下内容
## FastDFS Tracker
su - root -c '/etc/init.d/fdfs_trackerd start'
/注意//配置存储器storage
1.复制配置文件:
cd /etc/fdfs
cp storage.conf.sample storage.conf
1.5启动防盗链,修改配置:
vi /etc/fdfs/http.conf
#开启防盗链
http.anti_steal.check_token=true
#防盗链秘钥
http.anti_steal.secret_key=1qaz@WSXFastDFS12345678901qaz@WSX
#每次生成连接的有效时间
http.anti_steal.token_ttl=900
#校验失败访问的图片
http.anti_steal.token_check_fail=/usr/local/src/FastDFS/conf/anti-steal.jpg
2.修改storage.conf配置文件
vi storage.conf
修改以下内容:
disabled=false
port=2300(tracker连接storage使用的端口)
base_path=/home/fastdfs/storage
store_path0=/home/fastdfs/storage
tracker_server=192.168.2.147:22122
http.server_port=8888
3.创建基础数据目录:
mkdir -p /home/fastdfs/storage
4.打开防火墙23000存储器端口
vi /etc/sysconfig/iptables
加入:
-A INPUT -m state --state NEW -m tcp -p tcp --dport 23000 -j ACCEPT
重启:
service iptables restart
5.启动storage:
/etc/init.d/fdfs_storaged start
6.设置开机启动:
vi /etc/rc.d/rc.local
添加以下内容
## FastDFS Storage
/etc/init.d/fdfs_storaged start
/注意//tracker上传文件测试
1.修改tracker服务器中的客户端配置文件:
cd /etc/fdfs
cp client.conf.sample client.conf
vi client.conf
修改:
base_path=/home/fastdfs/tracker
tracker_server=192.168.2.147:22122
2.执行以下命令进行文件上传:
/usr/bin/fdfs_upload_file /etc/fdfs/client.conf /usr/local/src/FastDFS_v5.05.tar.gz
返回:
group1/M00/00/00/wKgA4Fq97xeAHbFoABmxeu5TEcI687.pdf
group1/M00/00/00/wKgA4Vq97yKAav-ZAAAO2rbuGuY185.png
/注意//在storage,tracker上安装nginx(下面现在storage安装)
1.解压:
/usr/local/src
tar -zxvf fastdfs-nginx-module_v1.16.tar.gz
2.进入fastdfs-nginx-module目录,修改配置文件
cd fastdfs-nginx-module/src/
vi config
修改CORE_INCS="$CORE_INCS /usr/local/include/fastdfs /usr/local/include/fastcommon/"
----》》》CORE_INCS="$CORE_INCS /usr/include/fastdfs /usr/include/fastcommon/"
3.安装编译nginx需要的依赖包
yum install gcc gcc-c++ make automake autoconf libtool pcre* zlib openssl openssl-devel
4.上传nginx包:
cd /usr/local/src
tar -zxvf nginx-1.10.3.tar.gz
cd nginx-1.10.3
./configure --add-module=/usr/local/src/fastdfs-nginx-module/src
make && make install
5.复制fastdfs-nginx-module源码中的配置文件到/etc/fdfs目录,并修改:
cp /usr/local/src/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs/
vi /etc/fdfs/mod_fastdfs.conf
修改以下配置:
connect_timeout=10
base_path=/tmp
tracker_server=192.168.2.147:22122
storage_server_port=23000
group_name=group1
url_have_group_name = true
store_path0=/home/fastdfs/storage
6复制FastDFS的部分配置文件到/etc/fdfs目录
cd /usr/local/src/FastDFS/conf/
cp http.conf mime.types /etc/fdfs/
7.在fastdfs/storage文件存储目录下创建软连接,将其连接到实际存放数据的目录
ln -s /home/fastdfs/storage/data/ /home/fastdfs/storage/data/M00
8.配置nginx:
cd /usr/local/nginx/conf
vi nginx.conf
修改:
(1)#user nobody;改成user root;
(2)server节点的listen 80;改成listen 8888;
(3) location / {
root html;
index index.html index.htm;
}
改成
location ~/group([0-9])/M00 {
#alias /home/fastdfs/storage/data;
ngx_fastdfs_module;
}
也可以改成以下,对于txt|doc|pdf|rar|gz|zip|docx|exe|xlsx|ppt|pptx这些文件进行下载,不直接打开
location ~/group([0-9])/M00 {
#alias /home/fastdfs/storage/data;
ngx_fastdfs_module;
if ($request_filename ~* ^.*?\.(txt|doc|pdf|rar|gz|zip|docx|exe|xlsx|ppt|pptx)$){
add_header Content-Disposition attachment;
}
}
(4)打开8888防火墙
vi /etc/sysconfig/iptables
加入:
-A INPUT -m state --state NEW -m tcp -p tcp --dport 8888 -j ACCEPT
重启:
service iptables restart
(5)启动nginx:
/usr/local/nginx/sbin/nginx
9.通过浏览器测试访问测试时上传的文件
http://192.168.2.148:8888/group1/M00/00/00/wKgClFiq8bGAD5McAAVFOL7FJU4.tar.gz
10.nginx重启命令
/usr/local/nginx/sbin/nginx -s reload
11.重启:
/etc/init.d/fdfs_storaged stop
/etc/init.d/fdfs_trackerd stop
/etc/init.d/fdfs_trackerd start
/etc/init.d/fdfs_storaged start
/usr/local/nginx/sbin/nginx -s reload
补充:文件删除命令
/usr/local/bin/fdfs_delete_file /etc/fdfs/client.conf group3/M00/00/00/wKgAUE5yiVK0VEpSACiWWseqpak.tar.gz