FastDFS安装与操作
1 安装步骤
1.1 用户登录
步骤 1 以root用户登录服务器。
备注:后续软件的安装,无特别说明,默认情况下都是用root用户进行安装操作。
1.2 安装包上传
1.3 依赖库安装
1.3.1 安装gcc
步骤 1
# yum install make cmake gcc gcc-c++
----结束
1.3.2 安装libfastcommon库
可选择本地上传
步骤 1 # wget https://github.com/happyfish100/libfastcommon/archive/V1.0.39.tar.gz
步骤 2 # tar -zxvf libfastcommon-1.0.39.tar.gz
步骤 3 # cd libfastcommon-1.0.39/
步骤 4 # ./make.sh
步骤 5 # ./make.sh install
----结束
1.3.3 安装perl
可选择本地上传
步骤 1 # wget http://www.cpan.org/src/5.0/perl-5.16.1.tar.gz
步骤 2 # tar -xzf perl-5.16.1.tar.gz
步骤 3 # cd perl-5.16.1
步骤 4 # ./Configure -des -Dprefix=/usr/local/perl
步骤 5 # make && make test && make install
步骤 6 # perl -v
----结束
1.4 安装FastDFS
root用户进行安装操作。
1.4.1 解压缩 编译 安装
可选择本地上传
步骤 1 # wget https://github.com/happyfish100/fastdfs/archive/V5.11.tar.gz
步骤 2 # tar -zxvf fastdfs-5.11.tar.gz
步骤 3 # cd fastdfs-5.11/
步骤 4 # ./make.sh
步骤 5 # ./make.sh install
----结束
1.4.2 复制配置文件
Fastdfs默认配置文件安装在 /etc/fdfs 路径下
Fastdfs的命令行工具在/usr/bin下
步骤 1 tracker节点
cp /etc/fdfs/tracker.conf.sample /etc/fdfs/tracker.conf
步骤 2 storage节点
#cp /etc/fdfs/storage.conf.sample /etc/fdfs/storage.conf
步骤 3 客户端文件,测试用
#cp /etc/fdfs/client.conf.sample /etc/fdfs/client.conf
步骤 4 供nginx访问使用
#cp /opt/fastdfs/fastdfs-5.11/conf/http.conf /etc/fdfs/
步骤 5 供nginx访问使用
#cp /opt/fastdfs/fastdfs-5.11/conf/mime.types /etc/fdfs/
----结束
1.5 修改FastDFS配置文件
root用户进行安装操作。
1.5.1 配置Tracker
tracker配置文件参数解释:http://bbs.chinaunix.net/thread-1941456-1-1.html
步骤 1 # vim /etc/fdfs/tracker.conf
步骤 2 #需要修改的内容如下
port=22122 # tracker服务器端口(默认22122,一般不修改)
base_path=/lv_share/fastdfs # 存储日志和数据的根目录
步骤 3 # :qw
----结束
1.5.2 配置Storage
步骤 1 # vim /etc/fdfs/storage.conf
步骤 2 #需要修改的内容如下
port=23000 # storage服务端口(默认23000,一般不修改)
base_path=/lv_share/fastdfs # 数据和日志文件存储根目录
store_path0=/lv_share/fastdfs # 第一个存储目录
tracker_server=xxx.xxx.xxx.xxx:22122 # tracker服务器IP和端口
http.server_port=8888 # http访问文件的端口(默认8888,看情况修改,和nginx中保持一致)
步骤 3 # :qw
----结束
1.5.3 Storage水平扩容
在第二台服务器上同样搭建一套storage ,修改storage.conf配置文件,配置Tracker地址指向第一台服务器 使Tracker管理两台storage集群,实现水平扩容。
1.5.4 配置Client
步骤 1 # vim /etc/fdfs/client.conf
步骤 2 #需要修改的内容如下
base_path=/lv_share/fastdfs
# tracker服务器IP和端口#
tracker_server=xxx.xxx.xxx.xxx:22122
步骤 3 # :qw
----结束
1.6 开启服务
1.6.1 启动Tracker服务
步骤 1 # /etc/init.d/fdfs_trackerd start
1.6.2 启动Storage服务
步骤 1 # /etc/init.d/fdfs_storaged start
1.6.3 常用命令
查看进程:# ps -ef | grep fdfs
停止Storage服务:# /etc/init.d/fdfs_storaged stop
停止Tracker服务:# /etc/init.d/fdfs_trackerd stop
1.6.4 验证
#fdfs_monitor /etc/fdfs/storage.conf list
----结束
1.6.5 验证文件上传
出错server: 192.168.1.208:22122, response status 2 != 0
解决:
pkill -9 fdfs
/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf
/usr/bin/fdfs_storaged /etc/fdfs/storage.conf
步骤 1 # fdfs_upload_file /etc/fdfs/client.conf ./xx.tar.gz
#保存后测试,返回ID表示成功 如:group1/M00/00/00/xx.tar.gz
1.6.6 验证文件下载
步骤 1 # fdfs_test /etc/fdfs/client.conf download group1 /M00/00/00/xx.tar.gz
1.7 安装Nginx
Nginx安装参考文档
1.8 安装fastdfs-nginx-module插件
1.8.1 下载 编译
可选择本地上传
步骤 1 # wget https://github.com/happyfish100/fastdfs-nginx-module/archive/V1.20.tar.gz
步骤 2 #cp /opt/fastdfs/fastdfs-nginx-module-1.20/src/mod_fastdfs.conf /etc/fdfs
步骤 3 ./configure --prefix=/usr/share/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/var/lib/nginx/tmp/client_body --http-proxy-temp-path=/var/lib/nginx/tmp/proxy --http-fastcgi-temp-path=/var/lib/nginx/tmp/fastcgi --http-uwsgi-temp-path=/var/lib/nginx/tmp/uwsgi --http-scgi-temp-path=/var/lib/nginx/tmp/scgi --pid-path=/run/nginx.pid --lock-path=/run/lock/subsys/nginx --user=nginx --group=nginx --with-file-aio --with-ipv6 --with-http_auth_request_module --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module=dynamic --with-http_image_filter_module=dynamic --with-http_geoip_module=dynamic --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_slice_module --with-http_stub_status_module --with-http_perl_module=dynamic --with-mail=dynamic --with-mail_ssl_module --with-pcre --with-pcre-jit --with-stream=dynamic --with-stream_ssl_module --with-google_perftools_module --with-debug --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -m64 -mtune=generic' --with-ld-opt='-Wl,-z,relro -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -Wl,-E' --add-module=/opt/fastdfs/fastdfs-nginx-module-1.20/src/
步骤 4 # make
步骤 5 #cp objs/nginx /usr/sbin/nginx
步骤 6 #systemctl enable nginx
步骤 7 #systemctl restart nginx
----结束
1.8.2 修改配置
步骤 1 # vim /etc/fdfs/mod_fastdfs.conf
步骤 2 #需要修改的内容如下
tracker_server=xxx.xxx.xxx.xxx:22122 # tracker服务器IP和端口
url_have_group_name=true
base_path=/lv_share/fastdfs # 存储日志和数据的根目录
store_path0=/lv_share/fastdfs # 存储日志和数据的根目录
----结束
1.8.3 修改nginx配置
步骤 1 #vim /etc/nginx/nginx.conf
步骤 2 #需要修改的内容如下
worker_processes 8;
server {
listen 8888;
server_name localhost xx.xxx.xx.xxx;
#charset koi8-r;
#access_log logs/host.access.log main;
location ~*/group[0-9]/ {
root /lv_share/fastdfs;
ngx_fastdfs_module;
}
location / {
root html;
index index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
----结束
1.8.4 重启nginx
步骤 1 /usr/local/nginx/sbin/nginx –s reload
1.8.5 Nginx验证
#测试下载,用外部浏览器访问刚才已传过的文件,引用返回的ID
http://xxx.xxx.xx.xxx:8888/group1/M00/00/00/wKixkV2J5Q-AbqJcAAAFUsTxALA287.log
#弹出下载则目前nginx已经OK
1.9 R&S
运维注意:我们在使用FastDFS的时候,需要正常关机,不要使用kill -9强杀FastDFS进程,不然会在文件上传时出现丢数据的情况。