分布式环境搭建2--安装FastDFS集群

2、安装FastDFS

  • 下载
wget https://github.com/happyfish100/libfastcommon/archive/V1.0.35.tar.gz
wget https://github.com/happyfish100/fastdfs/archive/V5.10.tar.gz
  • 安装
yum install -y libevent gcc perl

tar -xvzf V1.0.35.tar.gz
tar -xvzf V5.10.tar.gz

cd /libfastcommon-1.0.35
./make.sh
./make.sh install

cd ../fastdfs-5.10
./make.sh
./make.sh install
  • 配置tracker(node1、node2)
cd /etc/fdfs
cp tracker.conf.sample tracker.conf

vi tracker.conf
base_path=/root/fastdfs  # 存储日志和数据的根目录,如果没有需要手动创建该目录

mkdir /root/fastdfs

# 设置开机启动
chkconfig fdfs_trackerd on

/etc/init.d/fdfs_trackerd start #启动
/etc/init.d/fdfs_trackerd stop  #停止
  • 配置storage
# 分组
group1 (node3、node4)
group2 (node5、node6)
cd /etc/fdfs
cp storage.conf.sample storage.conf

vi /etc/fdfs/storage.conf
# 修改的内容如下:
group_name=group1                   # 组名(第一组为group1,第二组为group2,依次类推...)
base_path=/root/fastdfs             # 数据和日志文件存储根目录
store_path0=/root/fastdfs           #第一个存储目录,第二个存储目录起名为:store_path1=xxx,其它存储目录名依次类推...
store_path_count=1                  # 存储路径个数,需要和store_path个数匹配
tracker_server=node1:22122          # tracker服务器IP和端口
tracker_server=node2:22122          # tracker服务器IP和端口

mkdir /root/fastdfs

# 设置开机启动
chkconfig fdfs_storaged on

/etc/init.d/fdfs_storaged start #启动
/etc/init.d/fdfs_storaged stop  #停止

# 所有存储节点都启动之后,可以在任一存储节点上使用如下命令查看集群的状态信息:
fdfs_monitor /etc/fdfs/storage.conf
  • 文件上传测试
# 修改tracker服务器client.conf配置文件
cp /etc/fdfs/client.conf.sample /etc/fdfs/client.conf
vi /etc/fdfs/client.conf
base_path=/root/fastdfs
tracker_server=node1:22122
tracker_server=node2:22122

# 执行文件上传命令
/usr/bin/fdfs_upload_file /etc/fdfs/client.conf /usr/local/src/FastDFS_v5.05.tar.gz

# 返回以下ID号,说明文件上传成功: 
group1/M00/00/00/wKgBh1Xtr9-AeTfWAAVFOL7FJU4.tar.gz 
group2/M00/00/00/wKgBiVXtsDmAe3kjAAVFOL7FJU4.tar.gz 
(从返回的ID号中也可以看出,同一个文件分别存储在两个组内group1和group2,但也有可能在同一组中,具体策略是由FastDFS根据服务器的存储情况来分配的)
  • 在存储节点安装Nginx和fastdfs-nginx-module模块
# 下载
git clone https://github.com/happyfish100/fastdfs-nginx-module.git
  • 复制 fastdfs-nginx-module 源码中的配置文件到/etc/fdfs 目录,并修改
cp /usr/local/src/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs/
vi /etc/fdfs/mod_fastdfs.conf
# 修改如下
connect_timeout=10
base_path=/tmp
tracker_server=node1:22122
tracker_server=node2:22122
group_name=group1                       # 第一组group1、第二组group2
url_have_group_name=true
store_path0=/root/fastdfs
group_count=2
[group1]
group_name=group1
storage_server_port=23000
store_path_count=1
store_path0=/root/fastdfs
[group2]
group_name=group2
storage_server_port=23000
store_path_count=1
store_path0=/root/fastdfs
  • 复制FastDFS源文件目录中HTTP相关的配置文件到/etc/fdfs目录
cd /root/fastdfs-5.10/conf
cp http.conf mime.types /etc/fdfs/
  • 创建数据存放目录的软链接
ln -s /root/fastdfs/data /root/fastdfs/data/M00
  • 配置fastdfs-nginx-module(Nginx简洁版样例)
shell> vi /opt/nginx/conf/nginx.conf

# 修改如下

user root;
http {

    server {
        listen       8888; #与/etc/fdfs/storage.conf 中的 http.server_port=8888 相对应

        # FastDFS 文件访问配置(fastdfs-nginx-module模块)
        location ~/group([0-9])/M00 {
            ngx_fastdfs_module;
        }
    }
}
  • 重启 Nginx
/usr/local/nginx/sbin/nginx -s reload
  • 通过浏览器访问测试时上传的文件
http://node5:8888/group2/M00/00/00/wKgCEFkNnLmAUVpHAAaiLuryqxs.tar.gz
  • 在tracker节点安装Nginx和ngx_cache_purge模块
# 下载
wget https://github.com/FRiCKLE/ngx_cache_purge/archive/2.3.tar.gz
# 解压
tar -zxvf ngx_cache_purge-2.3.tar.gz
# 进入nginx目录
cd nginx-1.12.0
# 配置编译选项
./configure --prefix=/usr/local/nginx --sbin-path=/usr/local/nginx/sbin/nginx --conf-path=/usr/local/nginx/conf/nginx.conf --pid-path=/usr/local/nginx/logs/nginx.pid --with-http_ssl_module --with-http_stub_status_module --with-http_gzip_static_module --add-module=/root/ngx_cache_purge-2.3/
# 编译和安装
make && make install
  • 配置nginx.conf文件
user  root; #root防止404错误
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;

    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_temp_path /root/fastdfs/cache/nginx/proxy_cache/tmp;
    proxy_cache_path /root/fastdfs/cache/nginx/proxy_cache levels=1:2 keys_zone=http-cache:200m inactive=1d max_size=30g;

    #设置 group1 的服务器
    upstream fdfs_group1 {
         server node3:8888 weight=1 max_fails=2 fail_timeout=30s;
         server node4:8888 weight=1 max_fails=2 fail_timeout=30s;
    }

    #设置 group2 的服务器
    upstream fdfs_group2 {
         server node5:8888 weight=1 max_fails=2 fail_timeout=30s;
         server node6:8888 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 / {
            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;
        }

        #设置 group 的负载均衡参数
        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;
        }

        #设置清除缓存的访问权限
        location ~/purge(/.*) {
            allow 127.0.0.1;
            deny all;
            proxy_cache_purge http-cache $1$is_args$args;
        }

        # 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;
    #    }
    #}

}
  • 建立缓存目录
mkdir -p /root/fastdfs/cache/nginx/proxy_cache/tmp
  • 重启nginx
/usr/loacl/nginx/sbin/nginx -s reload
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 158,117评论 4 360
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 66,963评论 1 290
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 107,897评论 0 240
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 43,805评论 0 203
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 52,208评论 3 286
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 40,535评论 1 216
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 31,797评论 2 311
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,493评论 0 197
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 34,215评论 1 241
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,477评论 2 244
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 31,988评论 1 258
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,325评论 2 252
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 32,971评论 3 235
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 26,055评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,807评论 0 194
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 35,544评论 2 271
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 35,455评论 2 266

推荐阅读更多精彩内容