CentOs7 安装 FastDFS
1. 安装依赖
yum install gcc libevent libevent-devel -y
#进入src目录
cd /usr/local/src
2. 安装 libfastcommon 库
libfastcommon 库是 FastDFS 文件系统运行需要的公共 C 语言函数库
# 下载
wget https://github.com/happyfish100/libfastcommon/archive/refs/tags/V1.0.48.tar.gz
# 解压
tar -zxvf V1.0.48.tar.gz
# 进入目录
cd libfastcommon-1.0.48/
#执行make脚本进行编译
./make.sh
# 执行make install进行安装
./make.sh install
3.安装 FastDFS
#回到src目录下
cd /usr/local/src
#下载
wget https://github.com/happyfish100/fastdfs/archive/refs/tags/V6.07.tar.gz
# 解压
tar -zxvf V6.07.tar.gz
# 进入解压后目录,编译下载
cd fastdfs-6.07/
./make.sh
./make.sh install
4. 调整目录位置
# 进入fastdfs-6.07 conf目录下
cd /usr/local/src/fastdfs-6.07/conf
# 复制文件到 /etc/fdfs
cp http.conf /etc/fdfs/
cp mime.types /etc/fdfs/
#进入 /etc/fdfs 修改配置文件
cd /etc/fdfs/
# 修改tracker.conf文件
cp tracker.conf.sample tracker.conf
vim tracker.conf
#修改内容
base_path=/opt/fastdfs/tracker #配置tracker存储数据的目录
#修改storage.conf文件
cp storage.conf.sample storage.conf
vim storage.conf
#修改内容
base_path= /opt/fastdfs/storage #storage存储数据目录
store_path0= /opt/fastdfs/storage/files #真正存放文件的目录
# 设置为自己虚拟机ip,配置文件中有两个,注释掉一个即可
tracker_server=192.168.xx.xx:22122 #注册当前存储节点的跟踪器地址
#配置文件最下方,该端口需要与之后,配置的nginx一致,storage默认为8888
# 这里改为,同nginx默认一样为80 ,当然也可以把nginx的端口改为8888
http.server_port = 80
#创建上面指定的目录
mkdir -p /opt/fastdfs/tracker
mkdir -p /opt/fastdfs/storage
mkdir -p /opt/fastdfs/storage/files
5. 启动FastDFS(还没完)
#FastDFS服务启动需要启动两个脚本:
#启动FastDFS的tracker服务
#在任意目录下执行:
fdfs_trackerd /etc/fdfs/tracker.conf
#启动FastDFS的storage服务
#在任意目录下执行:
fdfs_storaged /etc/fdfs/storage.conf
查看启动进程
ps -ef | grep fdfs
查看storage是否已经注册到了tracker下
fdfs_monitor /etc/fdfs/storage.conf
首次启动storage后,会在配置的路径下创建存储文件的目录
6.重启与关闭
重启tracker
fdfs_trackerd /etc/fdfs/tracker.conf restart
重启storage
fdfs_storaged /etc/fdfs/storage.conf restart
FastDFS关闭
关闭tracker执行命令
在任意目录下执行:fdfs_trackerd /etc/fdfs/tracker.conf stop
关闭storage执行命令
在任意目录下执行:fdfs_storaged /etc/fdfs/storage.conf stop
或者kill关闭fastdfs,但不建议在线上使用 kill -9 强制关闭,因为可能会导致文件信息不同步问题
7. FastDFS测试
测试之前,需要修改client.conf配置文件,修改两个配置
# 进入/etc/fdfs 目录下
cd /etc/fdfs
#修改配置文件
cp client.conf.sample client.conf
vim client.conf
#修改内容
base_path=/opt/fastdfs/client
#与storage.conf 一样注释掉一个
tracker_server=192.168.xx.xx:22122
#在/opt/fastdfs/目录下创建client
mkdir -p /opt/fastdfs/client
#测试文件上传
fdfs_test /etc/fdfs/client.conf upload /root/aa.txt
#测试文件删除
fdfs_delete_file /etc/fdfs/client.conf group1/要删除的文件路径
8. 下载fastdfs-nginx
#跳转目录
cd /usr/local/src
#下载
wget https://github.com/happyfish100/fastdfs-nginx-module/archive/refs/tags/V1.22.tar.gz
#解压
tar -zxvf V1.22.tar.gz
#装依赖
yum install gcc openssl openssl-devel pcre pcre-devel zlib zlib-devel –y
#跳转到nginx目录下(根据自己目录而定)
#nginx下载 详见 linux下载nginx.md
cd /usr/local/nginx/nginx-1.21.6/
#添加模块(注意路径)
./configure --prefix=/usr/local/nginx --with-http_ssl_module --add-module=/usr/local/src/fastdfs-nginx-module-1.22/src
#编译
make & make install
#复制 出现overwrite 输入y重新即可
cp ./objs/nginx /usr/local/nginx/sbin/
#查看安装情况
/usr/local/nginx/sbin/nginx -V
#将/home/soft/fastdfs-nginx-module-master/src(自己实际存放Nginx扩展模块的目录)目录下的mod_fastdfs.conf文件拷贝到 /etc/fdfs/目录下,这样才能正常启动Nginx
#出现overwrite 输入y重写即可
cp /usr/local/src/fastdfs-nginx-module-1.22/src/mod_fastdfs.conf /etc/fdfs/
#切换目录,修改配置文件
cd /etc/fdfs/
#修改mod_fastdfs.conf配置文件
vim mod_fastdfs.conf
#修改内容
base_path=/opt/fastdfs/nginx_mod
tracker_server=192.168.xx.xx:22122
url_have_group_name = true
store_path0=/opt/fastdfs/storage/files
#在/opt/fastdfs/目录下创建nginx_mod目录
mkdir -p /opt/fastdfs/nginx_mod
#修改Nginx.config:
vim /usr/local/nginx/conf/nginx.conf
#修改内容
location ~ /group[1-9]/M0[0-9] {
ngx_fastdfs_module;
}
9. 启动nginx
#指定配置文件
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
重启或启动FastDFS服务进程 详见 6.重启与关闭
记得放开端口开放端口:23000,80,8080(没有用到的话,可以不放),22122(linux常见指令中有相关操作)
10. 原文nginx配置
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
#上传大小限制
client_max_body_size 5000m;
#下载大小限制
proxy_max_temp_file_size 5000m;
#设置为on表示启动高效传输文件的模式
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root /data/build/;
add_header Cache-Control no-store;
add_header Cache-Control no-cache;
try_files $uri $uri/ /index.html;
index index.html index.htm;
}
location ^~ /static/ {
alias /data/build/static/;
}
location ~ /group[1-9]/M0[0-9] {
ngx_fastdfs_module;
}
#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;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
}