当前位置:   article > 正文

fastdfs单双节点搭建

fastdfs 2节点

下载包:

链接:https://pan.baidu.com/s/1vGlTYVyJpH1kMpVM49KqRQ
提取码:ng3t

都放到/usr/local/src

A:安装前准备:

yum -y install libevent pop* openssl* gcc gcc-c++

安装libfastcommon-1.0.7.tar.gz

tar -zxvf libfastcommon-1.0.7.tar.gz

cd libfastcommon-1.0.7

./make.sh

./make.sh install

注意:libfastcommon安装好后会自动将库文件拷贝至/usr/lib64下,由于FastDFS程序引用usr/lib目录所以需要将/usr/lib64下的库文件拷贝至/usr/lib下。

要拷贝的文件如下:

cp /usr/lib64/libfastcommon.so /usr/lib/

 

B:fastdfs编译配置:

tar -zxvf FastDFS_v5.05.tar.gz

cd FastDFS

./make.sh 

./make.sh install
cp -ar conf/* /etc/fdfs/

cd /etc/fdfs/

配置tracker:

cp tracker.conf.sample tracker.conf

vim tracker.conf修改配置文件:

base_path=/home/yuqing/FastDFS改为base_path=/home/fdfs/tracker-data

配置http端口:

http.server_port=8080

启动tracker:

mkdir -p /home/fdfs/tracker-data

/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart

可以在/home/fdfs/tracker-data/logs下面查看启动日志

配置storage:

mkdir -p /home/fdfs/storage-data

mkdir -p /home/fdfs/pic   #存放图片的地方

vim storage.conf

base_path=/home/yuqing/FastDFS改为:base_path=/home/fdfs/storage-data

store_path0=/home/yuqing/FastDFS改为:store_path0=/home/fdfs/pic

#如果有多个挂载磁盘则定义多个store_path,如下

#store_path1=.....

#store_path2=......

tracker_server=10.6.11.103:22122   #自己的服务器内网ip+22122

http.server_port=8080

启动storage:

/usr/bin/fdfs_storaged /etc/fdfs/storage.conf restart

 

 

集群的话新机器都要搞一遍上面的操作  配置文件里需要添加多个tracker_server

tracker_server=10.6.11.103:22122

tracker_server=10.6.11.104:22122

其他配置不变

 

C:测试图片上传:

fdfs_test /etc/fdfs/client.conf upload /etc/fdfs/anti-steal.jpg

This is FastDFS client test program v5.05

Copyright (C) 2008, Happy Fish / YuQing

FastDFS may be copied only under the terms of the GNU General
Public License V3, which may be found in the FastDFS source kit.
Please visit the FastDFS Home Page http://www.csource.org/ 
for more detail.

[2019-05-30 17:24:12] DEBUG - base_path=/home/fdfs/pic, connect_timeout=30, network_timeout=60, tracker_server_count=1, anti_steal_token=0, anti_steal_secret_key length=0, use_connection_pool
=0, g_connection_pool_max_idle_time=3600s, use_storage_id=0, storage server id count: 0
tracker_query_storage_store_list_without_group: 
    server 1. group_name=, ip_addr=10.6.11.103, port=23000

group_name=group1, ip_addr=10.6.11.103, port=23000
storage_upload_by_filename
group_name=group1, remote_filename=M00/00/00/CgYLZ1zvoTyAb3LwAABdrZgsqUU328.jpg
source ip address: 10.6.11.103
file timestamp=2019-05-30 17:24:12
file size=23981
file crc32=2553063749
example file url: http://10.6.11.103:8080/group1/M00/00/00/CgYLZ1zvoTyAb3LwAABdrZgsqUU328.jpg
storage_upload_slave_by_filename
group_name=group1, remote_filename=M00/00/00/CgYLZ1zvoTyAb3LwAABdrZgsqUU328_big.jpg
source ip address: 10.6.11.103
file timestamp=2019-05-30 17:24:12
file size=23981
file crc32=2553063749
example file url: http://10.6.11.103:8080/group1/M00/00/00/CgYLZ1zvoTyAb3LwAABdrZgsqUU328_big.jpg
View Code

D:安装nginx展示图片:

tar -zxvf fastdfs-nginx-module_v1.16.tar.gz

cd fastdfs-nginx-module/src

cp mod_fastdfs.conf /etc/fdfs/

vim /etc/fdfs/mod_fastdfs.conf 

# connect timeout in seconds
# default value is 30s
connect_timeout=2

# network recv and send timeout in seconds
# default value is 30s
network_timeout=30

# the base path to store log files
base_path=/home/fdfs  #需要改

# if load FastDFS parameters from tracker server
# since V1.12
# default value is false
load_fdfs_parameters_from_tracker=true

# storage sync file max delay seconds
# same as tracker.conf
# valid only when load_fdfs_parameters_from_tracker is false
# since V1.12
# default value is 86400 seconds (one day)
storage_sync_file_max_delay = 86400

# if use storage ID instead of IP address
# same as tracker.conf
# valid only when load_fdfs_parameters_from_tracker is false
# default value is false
# since V1.13
use_storage_id = false

# specify storage ids filename, can use relative or absolute path
# same as tracker.conf
# valid only when load_fdfs_parameters_from_tracker is false
# since V1.13
storage_ids_filename = storage_ids.conf

# FastDFS tracker_server can ocur more than once, and tracker_server format is
#  "host:port", host can be hostname or ip address
# valid only when load_fdfs_parameters_from_tracker is true
tracker_server=10.6.11.103:22122  #需要改

# the port of the local storage server
# the default value is 23000
storage_server_port=23000

# the group name of the local storage server
group_name=group1

# if the url / uri including the group name
# set to false when uri like /M00/00/00/xxx
# set to true when uri like ${group_name}/M00/00/00/xxx, such as group1/M00/xxx
# default value is false
url_have_group_name = true  #需要改 重要

# path(disk or mount point) count, default value is 1
# must same as storage.conf
store_path_count=1

# store_path#, based 0, if store_path0 not exists, it's value is base_path
# the paths must be exist
# must same as storage.conf
#store_path0=/home/yuqing/fastdfs
#store_path1=/home/yuqing/fastdfs1
store_path0=/home/fdfs/pic   #需要改

# standard log level as syslog, case insensitive, value list:
### emerg for emergency
### alert
### crit for critical
### error
### warn for warning
### notice
### info
### debug
log_level=info

# set the log filename, such as /usr/local/apache2/logs/mod_fastdfs.log
# empty for output to stderr (apache and nginx error_log file)
log_filename=

# response mode when the file not exist in the local file system
## proxy: get the content from other storage server, then send to client
## redirect: redirect to the original storage server (HTTP Header is Location)
response_mode=proxy

# the NIC alias prefix, such as eth in Linux, you can see it by ifconfig -a
# multi aliases split by comma. empty value means auto set by OS type
# this paramter used to get all ip address of the local host
# default values is empty
if_alias_prefix=

# use "#include" directive to include HTTP config file
# NOTE: #include is an include directive, do NOT remove the # before include
#include http.conf


# if support flv
# default value is false
# since v1.15
flv_support = true

# flv file extension name
# default value is flv
# since v1.15
flv_extension = flv


# set the group count
# set to none zero to support multi-group
# set to 0  for single group only
# groups settings section as [group1], [group2], ..., [groupN]
# default value is 0
# since v1.14
group_count = 0

# group settings for group #1
# since v1.14
# when support multi-group, uncomment following section
#[group1]
#group_name=group1
#storage_server_port=23000
#store_path_count=2
#store_path0=/home/yuqing/fastdfs
#store_path1=/home/yuqing/fastdfs1

# group settings for group #2
# since v1.14
# when support multi-group, uncomment following section as neccessary
#[group2]
#group_name=group2
#storage_server_port=23000
#store_path_count=1
#store_path0=/home/yuqing/fastdfs
####下面需要增加
[group1]
group_name=group1
storage_server_port=23000
store_path_count=1
store_path0= /home/fdfs/pic/
View Code

ln -s /home/fdfs/pic/data/ /home/fdfs/pic/data/M00

pcre和zlib需要编译一下

./configure

make &&make install

openssl直接解压就行

tar -zxvf ngx_cache_purge-2.3.tar.gz

tar -zxvf fastdfs-nginx-module_v1.16.tar.gz

cd fastdfs-nginx-module/src

修改config

将CORE_INCS="$CORE_INCS /usr/local/include/fastdfs /usr/local/include/fastcommon/" 这一行替换为:

CORE_INCS="$CORE_INCS /usr/include/fastdfs /usr/include/fastcommon/"

tar -zxvf nginx-1.9.3.tar.gz && cd nginx-1.9.3

./configure  --prefix=/usr/local/nginx --with-http_ssl_module --add-module=/usr/local/src/fastdfs-nginx-module/src --add-module=/usr/local/src/ngx_cache_purge-2.3 --with-pcre=/usr/local/src/pcre-8.37 --with-zlib=/usr/local/src/zlib-1.2.8 --with-openssl=/usr/local/src/openssl-1.0.2j --with-stream

make && make install

nginx.conf配置文件如下:

user  xhdf;
worker_processes  16;
error_log  logs/error.log  info;
pid             logs/nginx.pid;
events {
  worker_connections  65535;
  use epoll;
}
http {
  access_log off;
  server_tokens off;
  include          mime.types;
  default_type  application/octet-stream;
  sendfile              on;
  tcp_nopush     on;
  keepalive_timeout  65;
  server_names_hash_bucket_size 128;
  client_header_buffer_size 32k;
  large_client_header_buffers 4 32k;
  client_max_body_size 3m;
  access_log  logs/access.log;
  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  /var/cache/nginx/proxy_cache  levels=1:2
  keys_zone=http-cache:500m max_size=10g inactive=30d;
  proxy_temp_path /var/cache/nginx/proxy_cache/tmp;



server {
        listen       8080;
        server_name  host103;
        location /group1/M00/{
                root /home/fdfs/pic;
                ngx_fastdfs_module;
        }
}




upstream storage_server_group1{
        server 10.6.11.103:8080 weight=10;
}
 server {
        listen 18080;
        server_name host103;
        #ssl on;
        #ssl_certificate      /usr/local/ssl/server.cer;
        #ssl_certificate_key  /usr/local/ssl/server.key; 
        location /group1{
                proxy_redirect off;
                proxy_set_header Host $host:18080;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                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://storage_server_group1;
                expires 30d;
        }



        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

 }
}
View Code

 

 D:keepalived搭配nginx:

cat /etc/keepalived/nginx_check.sh

#!/bin/bash
A=`ps -C nginx --no-header | wc -l`
if [ $A -eq 0 ];then
    /usr/local/nginx/sbin/nginx #尝试重新启动nginx
    sleep 2  #睡眠2秒
    if [ `ps -C nginx --no-header | wc -l` -eq 0 ];then
        killall keepalived #启动失败,将keepalived服务杀死。将vip漂移到其它备份节点
    fi
fi
View Code

cat /etc/keepalived/keepalived.conf

global_defs {
   router_id fdfs1  #标识本节点的名称,通常为hostname
}

vrrp_script chk_nginx {
       script "/etc/keepalived/nginx_check.sh"
       interval 2 
       weight -20
}

vrrp_instance VI_1 {
    state BACKUP                  
    interface bond0              
    virtual_router_id 51          
    mcast_src_ip 188.68.88.123
    priority 100                  
    advert_int 1                  
    nopreempt
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        188.68.88.125
    }

    track_script {
       chk_nginx  # nginx存活状态检测脚本
    }
}
View Code

二节点keepalived配置:

global_defs {
   router_id fdfs2
}

vrrp_script chk_nginx {
    script "/etc/keepalived/nginx_check.sh"
    interval 2
    weight -20
}

vrrp_instance VI_1 {
    state BACKUP
    interface bond0
    virtual_router_id 51
    mcast_src_ip 188.68.88.124
    priority 90
    advert_int 1
    nopreempt
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        188.68.88.125
    }
    track_script {
       chk_nginx
    }
}
View Code

 

 

 

 

 

 

 

 

 

 

 

转载于:https://www.cnblogs.com/lp19910807/p/10951011.html

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Cpp五条/article/detail/169975
推荐阅读
相关标签
  

闽ICP备14008679号