Linux安装FastDFS集群部署
过程问题:
make: gcc:命令未找到
yum -y install gcc
一、环境和版本:
Linux环境:CentOS 7.6
libfastcommon版本:1.0.39
FastDFS版本:V5.11
fastdfs-nginx-module版本:V1.2
nginx版本:1.12.2
yum -y install pcre pcre-devel yum install -y zlib-devel mkdir -p /opt/fastdfs /data/fastdfs/tracker /data/fastdfs/storage /data/fastdfs/client /data/fastdfs/file
为下一步下载源码做准备
cd /opt/fastdfs
(2)安装libfastcommon
wget https://github.com/happyfish100/libfastcommon/archive/V1.0.39.tar.gz tar -zxvf V1.0.39.tar.gz cd libfastcommon-1.0.39/ ./make.sh ./make.sh install
(3)安装FastDFS(在两台服务器上
)cd /opt/fastdfs wget https://github.com/happyfish100/fastdfs/archive/V5.11.tar.gz tar -zxvf V5.11.tar.gz \cd fastdfs-5.11/ ./make.sh ./make.sh install
配置文件准备
cp /etc/fdfs/tracker.conf.sample /etc/fdfs/tracker.conf #tracker节点 cp /etc/fdfs/storage.conf.sample /etc/fdfs/storage.conf #storage节点 cp /etc/fdfs/client.conf.sample /etc/fdfs/client.conf #客户端文件,测试用 cp /opt/fastdfs/fastdfs-5.11/conf/http.conf /etc/fdfs/ #供nginx访问使用 cp /opt/fastdfs/fastdfs-5.11/conf/mime.types /etc/fdfs/ #供nginx访问使用
(4)tracker server配置:
vim /etc/fdfs/tracker.conf
需要修改的内容如下 port=22122 # tracker服务器端口(默认22122,一般不修改) base_path=/data/fastdfs/tracker # 存储日志和数据的根目录
启动服务
service fdfs_trackerd start
查看服务状态, 查看服务是否启动,端口是否打开
netstat -tulnp
(5)storage server配置:
vim /etc/fdfs/storage.conf
需要修改的内容如下
port=23000 # storage服务端口(默认23000,一般不修改) base_path=/data/fastdfs/storage # 数据和日志文件存储根目录 store_path0=/data/fastdfs/file # 第一个存储目录 tracker_server=172.18.183.5:22122 # tracker服务器IP和端口 tracker_server=172.18.183.8:22122 # tracker服务器IP和端口 http.server_port=8888 # http访问文件的端口(默认8888,看情况修改,和nginx中保持一致)
启动服务
service fdfs_storaged start
查看服务是否启动,端口是否打开
netstat -tulnp firewall-cmd --permanent --add-port=22122/tcp firewall-cmd --permanent --add-port=23000/tcp firewall-cmd --reload
查看日志
journalctl -xe
查看集群状态
fdfs_monitor /etc/fdfs/storage.conf list
storage server有7个状态,如下: FDFS_STORAGE_STATUS_INIT :初始化,尚未得到同步已有数据的源服务器 FDFS_STORAGE_STATUS_WAIT_SYNC :等待同步,已得到同步已有数据的源服务器 FDFS_STORAGE_STATUS_SYNCING :同步中 FDFS_STORAGE_STATUS_DELETED :已删除,该服务器从本组中摘除(注:本状态的功能尚未实现) FDFS_STORAGE_STATUS_OFFLINE :离线 FDFS_STORAGE_STATUS_ONLINE :在线,尚不能提供服务 FDFS_STORAGE_STATUS_ACTIVE :在线,可以提供服务 当storage server的状态为 FDFS_STORAGE_STATUS_ONLINE 时,当该storage server向tracker server发起一次heart beat时,tracker server将其状态更改为 FDFS_STORAGE_STATUS_ACTIVE
(6)Client配置:
vim /etc/fdfs/client.conf
需要修改的内容如下
base_path=/data/fastdfs/client tracker_server=172.18.183.5:22122 # tracker服务器IP和端口 tracker_server=172.18.183.8:22122 # tracker服务器IP和端口
保存后测试,随便上传一张图片到服务器,然后在该目录下执行以下命令返回ID表示成功
fdfs_upload_file /etc/fdfs/client.conf halo.jpg
返回值如下
group1/M00/00/00/rBK3BV58iTKABs-cABYoCsMn6JA740.jpg
#下载nginx module cd /opt/fastdfs/ wget https://github.com/happyfish100/fastdfs-nginx-module/archive/V1.20.tar.gz tar -zxvf V1.20.tar.gz cp /opt/fastdfs/fastdfs-nginx-module-1.20/src/mod_fastdfs.conf /etc/fdfs #编辑 fastdfs-n/ginx-module-1.20/src/config 文件 vim /opt/fastdfs/fastdfs-nginx-module-1.20/src/config
ngx_addon_name=ngx_http_fastdfs_module if test -n "${ngx_module_link}"; then ngx_module_type=HTTP ngx_module_name=$ngx_addon_name ngx_module_incs="/usr/local/include/fastdfs /usr/include/fastcommon" ngx_module_libs="-lfastcommon -lfdfsclient" ngx_module_srcs="$ngx_addon_dir/ngx_http_fastdfs_module.c" ngx_module_deps= CFLAGS="$CFLAGS -D_FILE_OFFSET_BITS=64 -DFDFS_OUTPUT_CHUNK_SIZE='256*1024' - DFDFS_MOD_CONF_FILENAME='\"/etc/fdfs/mod_fastdfs.conf\"'" . auto/module else HTTP_MODULES="$HTTP_MODULES ngx_http_fastdfs_module" NGX_ADDON_SRCS="$NGX_ADDON_SRCS $ngx_addon_dir/ngx_http_fastdfs_module.c" CORE_INCS="$CORE_INCS /usr/local/include/fastdfs /usr/include/fastcommon" CORE_LIBS="$CORE_LIBS -lfastcommon -lfdfsclient" CFLAGS="$CFLAGS -D_FILE_OFFSET_BITS=64 -DFDFS_OUTPUT_CHUNK_SIZE='256*1024' -DFDFS_MOD_CONF_FILENAME='\"/etc/fdfs/mod_fastdfs.conf\"'" fi
安装nginx,并且添加nginx module
cd /opt/fastdfs/ wget http://nginx.org/download/nginx-1.12.2.tar.gz tar -zxvf nginx-1.12.2.tar.gz cd nginx-1.12.2/ ./configure --prefix=/usr/local/nginx --add-module=/opt/fastdfs/fastdfs-nginx-module-1.20/src make && make install
配置nginx访问
vim /etc/fdfs/mod_fastdfs.conf
connect_timeout=10 base_path=/data/fastdfs/file tracker_server=172.18.183.5:22122 # tracker服务器IP和端口 tracker_server=172.18.183.8:22122 #tracker服务器IP2和端口 group_name=group1 #当前服务器的group名 url_have_group_name=true #url中包含group名称 store_path0=/data/fastdfs/file #存储路径
配置nginx.config
vim /usr/local/nginx/conf/nginx.conf
worker_processes 4; worker_cpu_affinity 1000 0100 0010 0001; error_log logs/error.log; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; server { listen 8888; server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; location ~/group([0-9])/M00 { ngx_fastdfs_module; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } }
测试下载,用外部浏览器访问刚才已传过的文件。
http://172.18.183.5:8888/group1/M00/00/00/rBK3BV58iTKABs-cABYoCsMn6JA740.jpg http://172.18.183.8:8888/group1/M00/00/00/rBK3BV58iTKABs-cABYoCsMn6JA740.jpg