FastDFS集群-安装说明
一、简介
FastDFS服务端有两个角色:跟踪器(tracker)和存储节点(storage)。跟踪器主要做调度工作,在访问上起负载均衡的作用。
2.2、FastDFS系统结构图
3.2、编译环境:
yum install git gcc gcc-c++ make automake autoconf libtool pcre pcre-devel zlib zlib-devel openssl-devel wget vim -y
4.1、修改tracker配置文件
vim /etc/fdfs/tracker.conf
# 修改的内容如下:
disabled=false # 启用配置文件
port=22122 # tracker服务器端口(默认22122)
base_path=/home/dfs # 存储日志和数据的根目录
store_lookup=0 # 轮询方式上传
4.2、启动tracker服务器
cp /usr/local/src/fastdfs/init.d/fdfs_storaged
chmod +x /etc/rc.d/init.d/fdfs_trackerd
/etc/init.d/fdfs_trackerd start
或者
systemctl start fdfs_trackerd
或者
fdfs_trackerd /etc/fdfs/tracker.conf start
初次启动,会在/data/fastdfs/tracker目录下生成logs、data两个目录。
drwxr-xr-x 2 root root 178 May 3 22:34 data
drwxr-xr-x 2 root root 26 May 2 18:57 logs
检查FastDFS Tracker Server是否启动成功:
ps aux | grep fdfs_trackerd
4.3、tracker server的关闭命令
/etc/init.d/fdfs_trackerd stop
或者
systemctl stop fdfs_trackerd
或者
fdfs_trackerd /etc/fdfs/tracker.conf stop
4.4、设置tracker server开机启动
chkconfig fdfs_trackerd on
配置文件准备:cp /etc/fdfs/storage.conf.sample /etc/fdfs/storage.conf
4.5、192.168.56.11、192.168.56.12修改storage配置文件
vim /etc/fdfs/storage.conf
# 修改的内容如下:
disabled=false # 启用配置文件
port=23000 # storage的端口号,同一个组的 storage 端口号必须相同
group_name=group1
base_path=/home/dfs # 存储日志和数据的根目录
store_path0=/home/dfs # 第一个存储目录
store_path_count=1 #存储路径个数,需要和store_path个数匹配
tracker_server=192.168.56.40:22122 # tracker服务器的IP地址和端口
tracker_server=192.168.56.45:22122 # 多个tracker直接添加多条配置
配置group_name
不同分组配置不同group_name,第一组为group1, 第二组为group2
4.6、192.168.56.13、192.168.56.14修改storage配置文件
vim /etc/fdfs/storage.conf
# 修改的内容如下:
disabled=false # 启用配置文件
port=23000 # storage的端口号,同一个组的 storage 端口号必须相同
group_name=group2
base_path=/home/dfs # 存储日志和数据的根目录
store_path0=/home/dfs # 第一个存储目录
store_path_count=1 #存储路径个数,需要和store_path个数匹配
tracker_server=192.168.56.40:22122 # tracker服务器的IP地址和端口
tracker_server=192.168.56.45:22122 # 多个tracker直接添加多条配置
4.7、启动storage服务器
/etc/init.d/fdfs_storaged start
或者
systemctl start fdfs_storaged
或者
fdfs_storaged /etc/fdfs/tracker.conf start
初次启动,会在/home/dfs目录下生成logs、data两个目录。
drwxr-xr-x 259 root root 8192 May 3 23:06 data
drwxr-xr-x 2 root root 26 May 2 19:12 logs
检查FastDFS Tracker Server是否启动成功:
ps aux | grep fdfs_storaged
所有 Storage 节点都启动之后,可以在任一 Storage 节点上使用如下命令查看集群信息:
/usr/bin/fdfs_monitor /etc/fdfs/storage.conf
部分截图信息
user nobody;
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 8888;
server_name localhost;
location ~/group[1-2]/M00
{
ngx_fastdfs_module;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html { root html;
}
}
}
user root;
worker_processes 1;
events {
worker_connections 1024;
use epoll;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
tcp_nopush on;
keepalive_timeout 65;
upstream fdfs_group1 {
server 192.168.56.11:8888 weight=1 max_fails=2 fail_timeout=30s;
server 192.168.56.12:8888 weight=1 max_fails=2 fail_timeout=30s;
}
upstream fdfs_group2 {
server 192.168.56.13:8888 weight=1 max_fails=2 fail_timeout=30s;
server 192.168.56.14:8888 weight=1 max_fails=2 fail_timeout=30s;
}
server {
listen 8000;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
#设置 group 的负载均衡参数
location /group1/M00 {
proxy_pass http://fdfs_group2;
}
location /group2/M00 {
proxy_pass http://fdfs_group2;
}
}
}
7.3、启动Nginx
user root;
worker_processes 1;
events {
worker_connections 1024;
use epoll;
}
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;
sendfile on;
tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server_names_hash_bucket_size 128;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
client_max_body_size 300m;
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;
proxy_cache_path /tmp/cache/nginx/proxy_cache levels=1:2 keys_zone=http-cache:200m max_size=1g inactive=30d;
proxy_temp_path /tmp/cache/nginx/proxy_cache/tmp;
upstream fdfs_group1 {
server 192.168.56.40:8000 weight=1 max_fails=2 fail_timeout=30s;
server 192.168.56.45:8000 weight=1 max_fails=2 fail_timeout=30s;
}
upstream fdfs_group2 {
server 192.168.56.40:8000 weight=1 max_fails=2 fail_timeout=30s;
server 192.168.56.45:8000 weight=1 max_fails=2 fail_timeout=30s;
}
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location /group1/M00 {
proxy_next_upstream http_502 http_504 error timeout invalid_header;
proxy_cache http-cache;
proxy_cache_valid 200 304 12h;
proxy_cache_key $uri$is_args$args;
proxy_pass http://fdfs_group1;
expires 30d;
}
location /group2/M00 {
proxy_next_upstream http_502 http_504 error timeout invalid_header;
proxy_cache http-cache;
proxy_cache_valid 200 304 12h;
proxy_cache_key $uri$is_args$args;
proxy_pass http://fdfs_group2;
expires 30d;
}
#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;
}
}
}