fastdfs集群部署
准备工作:
fastdfs-5.10.tar.gz
https://github.com/happyfish100/fastdfs/archive/V5.10.tar.gz
fastdfs-nginx-module_v1.16.tar.gz
https://nchc.dl.sourceforge.net/project/fastdfs/FastDFS%20Nginx%20Module%20Source%20Code/fastdfs-nginx-module_v1.16.tar.gz
libevent-2.0.22-stable.tar.gz
https://github.com/libevent/libevent/archive/release-2.0.22-stable.tar.gz
libfastcommon.zip 下载地址
https://github.com/happyfish100/libfastcommon/archive/V1.0.35.tar.gz
nginx-1.13.2.tar.gz
http://nginx.org/download/nginx-1.13.2.tar.gz
pcre-8.40.tar.gz
https://nchc.dl.sourceforge.net/project/pcre/pcre/8.40/pcre-8.40.tar.gz
安装:libfastcommon
解压libfastcommon
unzip libfastcommon.zip
安装 libfastcommon
cd libfastcommon/
./make.sh
./make.sh install
添加软链接
ln -s /usr/lib64/libfastcommon.so /usr/local/lib/libfastcommon.so
安装:libevent
解压libevent
tar -zxvf libevent-2.0.22-stable.tar.gz
安装 libevent
cd libevent/
./configure --prefix=/usr/local/
make clean
make && make install
添加软链接
ln -s /usr/local/lib/libevent-2.0.so.5 /usr/lib/libevent-2.0.so.5
ln -s /usr/local/lib/libevent-2.0.so.5 /usr/lib64/libevent-2.0.so.5
安装:pcre
解压pcre到指定目录
tar -zxvf pcre-8.40.tar.gz
安装:fastdfs
解压fastdfs
tar -zxvf fastdfs-5.10.tar.gz
安装 fastdfs
cd fastdfs-5.10/
./make.sh
./make.sh install
文件存储目录
mkdir -p /var/fastdfs/tracker
mkdir -p /var/fastdfs/storage
mkdir -p /var/fastdfs/client
修改配置文件
cd /etc/fdfs/
#查看目录下文件是否齐全,应该有client.conf http.conf mime.types storage.conf tracker.conf 5个文件,如果没有,libevent 安装有问题
vim /etc/fdfs/tracker.conf #编辑tracker配置文件
disabled=false #启用配置文件
bind_addr= #解析主机地址,空则解析所有主机
port=22122 #tracker服务端口
connect_timeout=30 #连接超时时间30S
network_timeout=60 #网络超时时间60S
base_path=/var/fastdfs/tracker #tracker基础数据存储路径及日志存放路径
max_connections=256 #最大并发连接数
work_threads=4 #工作线程数,最好和cpu核数保持一致
store_lookup=0 #选择上传文件模式 0代表group轮询 1指定特定group 2选择空间最大的group
#store_group= #上传文件组,如果模式为1,则必须设置成核特定group一致的组名
store_server=0 #选择存储服务器上传文件 0代表轮询,1根据通过IP第的顺序 2通过优先级
store_path=0 #选择哪块存储盘上传文件 0代表轮询,2代表优先最大存储空间盘(路径)
download_server=0 #选择哪台存储服务器下载文件0代表轮询,1代表当前文件上传的源服务器
reserved_storage_space = 10% #系统保留存储空间10%
vim /etc/fdfs/storage.conf #编辑存储配置文件
group_name=group1 #存储组名
client_bind=true #当连接其他服务器时解析该主机地址
port=23000 #storage端口 23000
base_path=/var/fastdfs/storage #基础存储数据和日志文件
store_path0=/usr/share/fastdfs/storage #group 所占用的目录或硬盘,有几个写几个
tracker_server=172.18.4.217:22122 #指定tracker1服务器
tracker_server=172.18.4.218:22122 #指定tracker2服务器
vim /etc/fdfs/client.conf
base_path=/var/fastdfs/client #基础数据和日志文件
tracker_server=fastfds01:22122 #tracker1服务器
tracker_server=fastfds02:22122 #tracker2服务器
安装:fastdfs-nginx-module
解压fastdfs-nginx-module
tar -zxvf fastdfs-nginx-module_v1.16.tar.gz
配置 fastdfs-nginx-module
cp mod_fastdfs.conf /etc/fdfs/
#将mod_fastdfs.conf 拷贝到fdfs下进行配置
文件存储目录
mkdir -p /var/fastdfs/tracker
mkdir -p /var/fastdfs/storage
mkdir -p /var/fastdfs/client
修改配置文件
vim /etc/fdfs/mod_fastdfs.conf #编辑tracker配置文件
base_path=/var/fastdfs/storage #修改成和storage 存放路径一致
tracker_server=fastdfs01:22122 #配置成tracker server 地址和端口
url_have_group_name = true #url 中是否包组名
store_path0=/var/fastdfs/storage #文件存放路径,与storage 一致
group_count = 0 #0代表单组,非零代表多组,一般设置几就为几组
group_count = 1
group_name=group1
storage_server_port=23000
store_path_count=1
store_path0=/var/fastdfs/storage
安装:nginx
解压nginx
tar -zxvf nginx-1.13.2.tar.gz
安装 nginx
cd nginx-1.13.2
./configure --prefix=/usr/local/nginx --with-pcre=/usr/local/pcre-8.12 --add-module=/usr/local/fastdfs-nginx-module/src
make #编译错误 出现make[1]: * [objs/addon/src/ngx_http_fastdfs_module.o] Error 1
vi /usr/local/fastdfs-nginx-module/src/config
去掉local
CORE_INCS="$CORE_INCS /usr/local/fastdfs/include/fastdfs /usr/local/fastdfs/include/fastcommon/"
CORE_LIBS="$CORE_LIBS -L/usr/lib -lfastcommon -lfdfsclient"
make install
修改配置文件
vim /usr/local/nginx/nginx.conf #编辑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;
use epoll;
}
error_log /usr/local/nginx/logs/error.log;
pid /usr/local/nginx/logs/nginx.pid;
http {
server_names_hash_bucket_size 128;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
client_max_body_size 300m;
sendfile on;
tcp_nopush on;
proxy_redirect off;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffer_size 16k;
proxy_buffers 4 64k;
proxy_busy_buffers_size 128k;
proxy_temp_file_write_size 128k;
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 /usr/local/nginx/logs/access.log main;
upstream fdfs_group1 {
server rocketmq01:8080 weight=1 max_fails=2 fail_timeout=30s;
}
upstream fdfs_group2 {
server rocketmq02:8080 weight=1 max_fails=2 fail_timeout=30s;
}
include /usr/local/nginx/conf.d/*.conf;
}
vim /usr/local/nginx/conf.d/storage.conf #编辑storage配置文件
server {
listen 8080;
server_name rocketmq01;
location ~ /group01/M00 {
root /var/fastdfs/storage/data;
index index.html index.htm;
ngx_fastdfs_module;
}
}
vim /usr/local/nginx/conf.d/tracker.conf #编辑tracker配置文件
server {
listen 80;
server_name rocketmq01;
location ~ /group01/M00 {
proxy_next_upstream http_502 http_504 error timeout invalid_header;
proxy_pass http://fdfs_group1;
expires 30d;
}
location ~ /group02/M00 {
proxy_next_upstream http_502 http_504 error timeout invalid_header;
proxy_pass http://fdfs_group2;
expires 30d;
}
}
启动 nginx
cd nginx
./sbin/nginx -c conf/nginx.conf
#启动错误 出现http.conf找不到
拷贝fastdfs/conf下面的http.conf与mime.types到/etc/fdfs/目录
重新启动
添加数据链接
ln -s /var/fastdfs/storage/data /var/fastdfs/storage/data/M00
命令:
#tracker 命定
/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf start/stop/restart
#storage命定
/usr/bin/fdfs_storaged /etc/fdfs/storage.conf start/stop/restart
测试:
/usr/bin/fdfs_test /etc/fdfs/client.conf upload /opt/1.txt
#返回结果中会把上传完成的url 打印出来,看三个上传的url group是否轮询变化,如果停掉fastdfs01 的tracker 返回url是不是地址变成fastdfs02,如都成功则 复制URL在浏览器中打开看是否正常