搭建FastDFS+Nginx(Censor7)

【安装步骤】
group1的主机IP为192.168.124.91
group2的主机对应的ip为192.168.124.245
一、安装前准备
1、安装依赖包

1 yum -y install pcre* pcre-* gcc-c++ gcc* zlib zlib-devel openssl openssl-devel gc-devel gd gd-devel git

2、安装libfastcommon 套件

1 cd /usr/local/src
2 git clone https://github.com/happyfish100/libfastcommon.git
3 cd libfastcommon
4 ./make.sh && ./make.sh install     //安装在当前目录

3、建立链接

ln -s /usr/lib64/libfastcommon.so /usr/lib/
ln -s /usr/lib64/libfastcommon.so /usr/local/lib/
ln -s /usr/lib64/libfastcommon.so /usr/local/lib64/
ln -s /usr/lib64/libfdfsclient.so /usr/lib/
ln -s /usr/lib64/libfdfsclient.so /usr/local/lib/
ln -s /usr/lib64/libfdfsclient.so /usr/local/lib64/

二、安装fastdfs
1、解压FastDFS.zip包

1 cd /usr/local/src
2 git clone https://github.com/happyfish100/fastdfs.git
3 cd fastdfs      //进入到fastdfs-master目录
4 ./make.sh && ./make.sh install     //安装到当前目录

2、拷贝fastdfs-master中的conf所有文件到 /etc/fdfs/中,完成配置

1 cp -r /usr/local/src/fastdfs/conf/* /etc/fdfs/
2 cd /etc/fdfs/

3、配置相应的配置文件

//group1的主机配置需求

(1)配置tracker.conf 文件

vim /etc/fdfs/tracker.conf

bind_addr=192.168.124.91
port=22122
base_path=/data/server/fastdfs
store_lookup=0
store_group=group1
store_server=0
use_storage_id = true
id_type_in_filename = id

(2)配置storage_ids.conf文件 [取消注释]

vim /etc/fdfs/storage_ids.conf

  100001   group1  192.168.124.91
  100002   group2  192.168.124.245

(3)配置client.conf 文件

vim /etc/fdfs/client.conf

1 base_path=/data/server/fastdfs_cli
   tracker_server=192.168.124.91:22122
   use_storage_id = true

(4)配置storage.conf文件

vim /etc/fdfs/storage.conf

1 group_name=group1
2 bind_addr=192.168.124.91
3 port=23000
4 base_path=/data/server/fastdfs_sto
5 store_path0=/data/server/fastdfs_sto
6 tracker_server=192.168.124.91:22122

(5)创建上面配置文件里涉及的目录

1 mkdir /data/server/fastdfs_cli
2 mkdir /data/server/fastdfs_sto
3 mkdir /data/server/fastdfs

(6)启动

1 fdfs_trackerd /etc/fdfs/tracker.conf
2 fdfs_storaged /etc/fdfs/storage.conf

//group2的主机配置需求
1、配置storage_ids.conf文件

vim /etc/fdfs/storage_ids.conf

1  100001   group1  192.168.124.91
2  100002   group2  192.168.124.245

2、配置storage.conf文件

vim /etc/fdfs/storage.conf

1 group_name=group2
2   bind_addr=192.168.124.245
3   port=23000
4   base_path=/data/server/fastdfs_sto
5   store_path0=/data/server/fastdfs_sto
6   tracker_server=192.168.124.245:22122

3、创建目录

mkdir /data/server/fastdfs_sto

4、启动

1 fdfs_storaged /etc/fdfs/storage.conf

1、安装nginx插件

1 cd /usr/local/src
2 wget https://raw.githubusercontent.com/ww1230258u/server/master/fastdfs-nginx-module_v1.16.tar.gz
3 tar zxvf fastdfs-nginx-module_v1.16.tar.gz

vim /usr/local/src/fastdfs-nginx-module/src/config

1 CORE_INCS="$CORE_INCS /usr/include/fastdfs /usr/include/fastcommon/"   //修改这条语句,去掉/local

2、解压nginx-1.14.2.tar.gz,进行安装。

1 cd /usr/local/src
2 wget https://raw.githubusercontent.com/ww1230258u/server/master/nginx-1.14.2.tar.gz
3 tar zxf nginx-1.14.2.tar.gz
4 cd nginx-1.14.2

#进行nginx编译

./configure --prefix=/data/server/nginx --add-module=/usr/local/src/fastdfs-nginx-module/src --with-http_gunzip_module --with-pcre --with-http_image_filter_module --with-http_stub_status_module

make && make install //进行安装

3、配置nginx配置文件
(1)group1端

vim /data/server/nginx/conf/nginx.conf //在server的函数下编录以后语句

location ~* /group1/M00/(\w+)/(\w+)/(.+)_(\d+)x(\d+)\.(png|jpg|gif) {
       root "/data/server/nginx/html/";
                      ngx_fastdfs_module;
                      set $iw "$4";
                      set $ih "$5";
                      image_filter resize $iw $ih;
                      image_filter_buffer 2M;
                     try_files /group1/M00/$1/$2/$3.$6 /404.html;
}
location /group1/M00 {
        root "/data/server/nginx/html/";
        ngx_fastdfs_module;
}
location = /favicon.ico {
        log_not_found off;
        access_log off;
}    

(2)group2端

   location ~* /group2/M00/(\w+)/(\w+)/(.+)_(\d+)x(\d+)\.(png|jpg|gif) {
           root "/data/server/nginx/html/";
                          ngx_fastdfs_module;
                          set $iw "$4";
                          set $ih "$5";
                          image_filter resize $iw $ih;
                          image_filter_buffer 2M;
                         try_files /group2/M00/$1/$2/$3.$6 /404.html;
    }
    location /group2/M00 {
            root "/data/server/nginx/html/";
            ngx_fastdfs_module;
    }
    location = /favicon.ico {
            log_not_found off;
            access_log off;
    }    

/data/server/nginx/sbin/nginx //启动nginx服务

四、配置mod_fastdfs.conf文件

1 mkdir /data/server/nginx/html/group1/
2 ln -s /data/server/fastdfs_storage/data /data/server/nginx/html/group1/M00

//注意:“/data/server/fastdfs_storage/data”后面不加“/”

1 cp /usr/local/src/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs/
2 
3 vim /etc/fdfs/mod_fastdfs.conf     

//配置group1

1 use_storage_id = true
2 tracker_server=192.168.124.91:22122
3 url_have_group_name = true
4 group_name=group1
5 store_path0=/data/server/fastdfs_sto
6 [group1]
7 group_name=group1
8 storage_server_port=23000
9 store_path_count=1
10 store_path0=/data/server/fastdfs_sto

//配置group2

vim /etc/fdfs/mod_fastdfs.conf

 1  use_storage_id = true
 2  tracker_server=192.168.124.245:22122
 3  url_have_group_name = true
 4  group_name=group2
 5  store_path0=/data/server/fastdfs_sto
 6  [group2]
 7  group_name=group2
 8  storage_server_port=23000
 9  store_path_count=2
 10  store_path0=/data/server/fastdfs_sto

【安装后结果】
测试图片是否上传

1 fdfs_upload_file /etc/fdfs/client.conf /etc/fdfs/anti-steal.jpg
2
3 group1/M00/00/00/oYYBAFwvZOyALm1UAABdreSfEnY259.jpg

测试图片是否能缩进

192.168.124.91/group1/M00/00/00/oYYBAFwvZOyALm1UAABdreSfEnY259_100x50.jpg

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值