常用指令
FastDFS上传文件,启动tracker,启动storage,启动niinx,开机自启
[root@localhost software]# /usr/bin/fdfs_upload_file /etc/fdfs/client.conf /opt/1.txt
[root@localhost /]# /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart
[root@localhost /]# /usr/local/fastdfs-5.05/storage/fdfs_storaged /etc/fdfs/storage.conf restart
[root@localhost /]# /usr/local/nginx/sbin/nginx
[root@localhost /]# chmod +x /etc/rc.d/rc.local
FastDFS的安装
1.准备工作,首先先下载好软件安装包
[root@localhost fastDFS]# wget https://github.com/happyfish100/libfastcommon/archive/V1.0.7.tar.gz
wget http://jaist.dl.sourceforge.net/project/fastdfs/FastDFS%20Nginx%20Module%20Source%20Code/fastdfs-nginx-module_v1.16.tar.gz
wget https://github.com/happyfish100/fastdfs/archive/V5.05.tar.gz
wget http://nginx.org/download/nginx-1.8.0.tar.gz
wget http://tenet.dl.sourceforge.net/project/pcre/pcre/8.36/pcre-8.36.tar.gz
2.创建好相应的文件夹,用来存放数据或者是日志
2.1. 配置tracker所需的base_path: /home/lang/fastdfs_tracker。
2.2. 配置storage所需的日志目录: /home/lang/fastdfs_storage_info。 用来存储storage之间同步文件等日志的。
2.3. 配置storage所需的存储文件目录:/home/lang/fastdfs_storage_data,用来存储文件。
[root@localhost /]# mkdir -p /home/lang/fastdfs_tracker
[root@localhost /]# mkdir -p /home/lang/fastdfs_storage_info
[root@localhost /]# mkdir -p /home/lang/fastdfs_storage_data
3.开始安装
3.1先安装 V1.0.7.tar.gz
[root@localhost fastDFS]# tar -zxvf V1.0.7.tar.gz -C /usr/local/
[root@localhost fastDFS]# cd /usr/local/libfastcommon-1.0.7/
[root@localhost libfastcommon-1.0.7]# ./make.sh
[root@localhost libfastcommon-1.0.7]# ./make.sh install
libfastcommon.so默认安装在 /usr/lib64/libfastcommon.so
而FastDFS主程序设置的lib目录是/usr/local/lib
3.2安装FastDFS
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
4.配置tracker
[root@localhost fastdfs-5.05]# cd /etc/fdfs/
[root@localhost fdfs]# cp tracker.conf.sample tracker.conf
[root@localhost fdfs]# vim tracker.conf
修改配置文件
disabled=false
bind_addr=192.168.1.100
port=22122
base_path=/home/lang/fastdfs_tracker
http.server_port=8080
启动tracker,查看是否监听22122端口,或者查看相关日志
[root@localhost fdfs]# /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart
[root@localhost fdfs]# netstat -tunlp | grep 22122
tcp 0 0 192.168.1.100:22122 0.0.0.0:* LISTEN 2028/fdfs_trackerd
[root@localhost fdfs]# tail -100f /home/lang/fastdfs_tracker/logs/trackerd.log
设置开机启动,编辑文件
[root@localhost fdfs]# vim /etc/rc.d/rc.local
添加
/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart
5.配置storage
[root@localhost fdfs]# cp storage.conf.sample storage.conf
[root@localhost fdfs]# vim storage.conf
修改配置文件
disabled=false
group_name=group1
port=23000
base_path=/home/lang/fastdfs_storage_info
store_path_count=1
store_path0=/home/lang/fastdfs_storage_data
tracker_server=192.168.1.100:22122
http.server_port=8080
启动storage
[root@localhost fdfs]# /usr/local/fastdfs-5.05/storage/fdfs_storaged /etc/fdfs/storage.conf restart
查看是否启动
[root@localhost fdfs]# netstat -unltp|grep 23000
tcp 0 0 0.0.0.0:23000 0.0.0.0:* LISTEN 2118/fdfs_storaged
[root@localhost fdfs]# tail -100f /home/lang/fastdfs_storage_info/logs/storage.log
如果配置集群,可以查看集群情况
[root@localhost fdfs]# /usr/bin/fdfs_monitor /etc/fdfs/storage.conf
将storage添加至开机启动
[root@localhost fdfs]# vim /etc/rc.d/rc.local
添加
/usr/local/fastdfs-5.05/storage/fdfs_storaged /etc/fdfs/storage.conf restart
7.安装nginx
准备工作,下载好相应的软件包,nginx主要是提供反向代理和负载均衡。
[root@localhost /]# yum install -y gcc yum install -y gcc-c++ yum install -y pcre pcre-devel yum install -y zlib zlib-devel yum install -y openssl openssl-devel
8.给storage配置nginx
8.1创建nginx默认的安装文件夹
[root@localhost /]# mkdir /usr/local/nginx
8.2提前将nginx1.8.0.tar.gz,fastdfs-nginx-module_v1.16.tar.gz和ngx_cache_purge-2.3.tar.gz解压缩
[root@localhost fastDFS]# cp nginx-1.8.0.tar.gz /usr/local/
[root@localhost fastDFS]# cp fastdfs-nginx-module_v1.16.tar.gz /usr/local/
[root@localhost fastDFS]# cp ngx_cache_purge-2.3.tar.gz /usr/local/
[root@localhost fastDFS]# cd /usr/local/
[root@localhost local]# tar -zxvf nginx-1.8.0.tar.gz
[root@localhost local]# tar -zxvf fastdfs-nginx-module_v1.16.tar.gz
[root@localhost local]# tar -zxvf ngx_cache_purge-2.3.tar.gz
8.3进入/usr/local/fastdfs-nginx-module/src,进行编辑
[root@localhost local]# cd /usr/local/fastdfs-nginx-module/src
[root@localhost src]# vim config
CORE_INCS="$CORE_INCS /usr/local/include/fastdfs /usr/local/include/fastcommon/"
改为
CORE_INCS="$CORE_INCS /usr/include/fastdfs /usr/include/fastcommon/"
8.4准备工作做好了进行安装了,首先进入nginx-1.8.0的目录
[root@localhost /]# cd /usr/local/nginx-1.8.0/
[root@localhost nginx-1.8.0]# ./configure --prefix=/usr/local/nginx --with-http_ssl_module --add-module=/usr/local/fastdfs-nginx-module/src --add-module=/usr/local/ngx_cache_purge-2.3
[root@localhost nginx-1.8.0]# make
[root@localhost nginx-1.8.0]# make install
8.5编辑nginx.conf文件
[root@localhost conf]# vim /usr/local/nginx/conf/nginx.conf
在server中添加
location ~/group1/M00{
root /home/lang/fastdfs_storage_data/data;
ngx_fastdfs_module;
}
8,6拷贝fastdfs-5.05/conf/中的http.conf和mime.types文件到/etc/fdfs文件夹下,fastdfs-nginx-module/src/中的mod_fastdfs.conf到/etc/fdfs文件夹下
[root@localhost /]# cd /usr/local/fastdfs-5.05/conf/
[root@localhost conf]# cp http.conf /etc/fdfs/
[root@localhost conf]# cp mime.types /etc/fdfs/
[root@localhost conf]# cd /usr/local/fastdfs-nginx-module/src/
[root@localhost src]# cp mod_fastdfs.conf /etc/fdfs/
8.7编辑mod_fastdfs.conf文件
[root@localhost src]# cd /etc/fdfs/
[root@localhost fdfs]# vim mod_fastdfs.conf
#编辑内容
base_path=/home/lang/fastdfs_storage_info
tracker_server=192.168.1.100:22122
storage_server_port=23000
group_name=group1
url_have_group_name= true
store_path_count=1
store_path0=/home/lang/fastdfs_storage_data
http.need_find_content_type=true
group_count= 1
#末尾增加
[group1]
group_name=group1
storage_server_port=23000
store_path_count=2
store_path0=/home/lang/fastdfs_storage_data
store_path1=/home/lang/fastdfs_storage_data
8.8建立软连接,启动nginx,看是否正常,访问url:192.168.1.100可以看到nginx的欢迎页面。
[root@localhost fdfs]# ln -s /home/lang/fastdfs_storage_data /home/lang/fastdfs_storage_data/M00
[root@localhost fdfs]# /usr/local/nginx/sbin/nginx
9.在tracker中安装nginx
[root@localhost /]# vim /usr/local/nginx/conf/nginx.conf
#修改
listen 8080;
10.配置文件的上传
[root@localhost conf]# cd /etc/fdfs
[root@localhost fdfs]# cp client.conf.sample client.conf
[root@localhost fdfs]# vim client.conf
#修改
base_path=/home/lang/fastdfs_tracker
tracker_server=192.168.1.100:22122
http.tracker_server_port=8080
配置好了之后就能进行文件的上传了
[root@localhost /]# /usr/bin/fdfs_upload_file /etc/fdfs/client.conf /opt/1.txt
group1/M00/00/00/wKgBZFtcK8CADfe8AAB-ADEkOJs416.doc
FastDFS的简介
1.FastDFS是用来干嘛的?
FastDFS可以用来上传文件到我们的服务器中。将文件放到服务器中,提供一个URL,供外部访问。
2.为什么要用FastDFS呢?
我们也可以将文件存入数据库中,MySql中设置该字段为Blob类型,然后文件将会以二进制的形式写入数据库中。