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

2017-05-16  本文已影响0人  Nil_Woo

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
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  #停止
# 分组
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根据服务器的存储情况来分配的)
# 下载
git clone https://github.com/happyfish100/fastdfs-nginx-module.git
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
cd /root/fastdfs-5.10/conf
cp http.conf mime.types /etc/fdfs/
ln -s /root/fastdfs/data /root/fastdfs/data/M00
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;
        }
    }
}
/usr/local/nginx/sbin/nginx -s reload
http://node5:8888/group2/M00/00/00/wKgCEFkNnLmAUVpHAAaiLuryqxs.tar.gz
# 下载
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
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
/usr/loacl/nginx/sbin/nginx -s reload
上一篇下一篇

猜你喜欢

热点阅读