centos7安装fastdfs集群+nginx1.18(生产环境)

一、服务器信息

1. 主机:server1-2,10.10.10.11,10.10.10.12

2. 数据:/data1

二、部署服务

1. 部署依赖公共组件

yum install -y gcc gcc-c   perl pcre pcre-devel zlib zlib-devel openssl openssl-devel libnl libnl-devel

下载依赖源码并编译安装

wget -O libfastcommon-master.zip https://codeload.github.com/happyfish100/libfastcommon/zip/master
unzip libfastcommon-master.zip
cd libfastcommon-master
./make.sh
./make.sh install
ln -s /usr/lib64/libfastcommon.so /usr/lib/libfastcommon.so

2. 部署FastDFS
下载FastDFS源码并编译安装

wget -O fastdfs-master.zip https://codeload.github.com/happyfish100/fastdfs/zip/master
unzip fastdfs-master.zip
cd fastdfs-master
./make.sh
./make.sh install
```

三、配置FastDFS

1. 两个节点配置tracker

bash

#创建tracker数据存储目录
mkdir /data1/fdfs/tracker -p
#ip地址根据实际修改
mv /etc/fdfs/tracker.conf.sample /etc/fdfs/tracker.conf
sed -i \'s/bind_addr=/bind_addr=10.10.10.11/g\' /etc/fdfs/tracker.conf
#修改base_path
sed -i \'s:base_path=/home/yuqing/fastdfs:base_path=/data1/fdfs/tracker:g\' /etc/fdfs/tracker.conf
#其他要修改的参数自行根据实际调整

2. 两个节点配置storage

#创建storage数据存储目录
mkdir /data1/fdfs/storage -p
mkdir /data1/fdfs/storage -p
#ip地址根据实际修改
mv /etc/fdfs/storage.conf.sample /etc/fdfs/storage.conf
sed -i \'s/bind_addr=/bind_addr=10.10.10.11/g\' /etc/fdfs/storage.conf
#修改base_path
sed -i \'s:base_path=/home/yuqing/fastdfs:base_path=/data1/fdfs/storage:g\' /etc/fdfs/storage.conf
#修改文件存储目录
sed -i \'s:store_path0=/home/yuqing/fastdfs:store_path0=/data1/fdfs/storage/data:g\' /etc/fdfs/storage.conf
#修改tracker地址
sed -i \'s/tracker_server=192.168.209.121:22122/tracker_server=10.10.10.11:22122/g\' /etc/fdfs/storage.conf
sed -i \'/^tracker_server/atracker_server=10.10.10.12:22122\' /etc/fdfs/storage.conf
#若有n个存储数据目录(数据盘),需要增加store_path1,2,3,(n-1),并修改store_path_count=n

四、启动服务

fdfs_trackerd /etc/fdfs/tracker.conf start
fdfs_storaged /etc/fdfs/storage.conf start
```

五、测试验证

1. 查看集群状态

mv /etc/fdfs/client.conf.sample /etc/fdfs/client.conf
mkdir /data1/fdfs/client -p
#修改base_path
sed -i \'s:base_path=/home/yuqing/fastdfs:base_path=/data1/fdfs/client:g\' /etc/fdfs/client.conf
#修改tracker地址
sed -i \'s/tracker_server=192.168.0.197:22122/tracker_server=10.10.10.11:22122/g\' /etc/fdfs/client.conf
#查看监控信息、查看storage的状态是否为ACTIVE
fdfs_monitor /etc/fdfs/client.conf
```

2. 验证上传\下载\删除cd

#上传后会返回一个以gropu开头的ID
fdfs_upload_file /etc/fdfs/client.conf xxx.txt
group1/M00/00/00/ChxS9l2gL5KAPQExAAAABKV9Avc785.txt
#下载时指定ID,并可以指定下载后的文件名,例如:xxx1.txt
fdfs_download_file /etc/fdfs/client.conf group1/M00/00/00/ChxS9l2gL5KAPQExAAAABKV9Avc785.txt xxx1.txt
#删除时指定ID
fdfs_delete_file /etc/fdfs/client.conf group1/M00/00/00/ChxS9l2gL5KAPQExAAAABKV9Avc785.txt
```

---
`分隔线`:**若是通过程序直接读写文件,到此FastDFS集群部署完成。若是程序只负责写,需要通过Nginx以域名的方式访问文件,需要继续执行以下步骤。**

---

六、FastDFS与Nginx整合

1. 下载并修改fastdfs-nginx-module

wget -O fastdfs-nginx-module-master.zip https://codeload.github.com/happyfish100/fastdfs-nginx-module/zip/master
unzip fastdfs-nginx-module-master.zip
sed -i \'s:/usr/local/include:/usr/include/fastdfs /usr/include/fastcommon:g\' fastdfs-nginx-module-master/src/config
```

2. 下载Nginx源码包并编译

wget http://nginx.org/download/nginx-1.16.1.tar.gz
tar xf nginx-1.16.1.tar.gz
mkdir /usr/local/nginx
#安装nginx依赖
yum install zlib pcre pcre-devel openssl openssl-devel gd-devel -y
#编译nginx
./configure --prefix=/usr/local/nginx --with-http_realip_module \
--with-http_sub_module --with-http_stub_status_module \
--with-http_gzip_static_module --with-http_image_filter_module \
--with-http_ssl_module --add-module=/opt/soft/fastdfs-nginx-module-master/src/
make -j 4
make install
```

3. 配置mod_fastdfs

#复制mod_fastdfs.conf
cp fastdfs-nginx-module-master/src/mod_fastdfs.conf /etc/fdfs/
cp fastdfs-master/conf/mime.types /etc/fdfs/
cp fastdfs-master/conf/http.conf /etc/fdfs/
#修改mod_fastdfs.conf配置
mkdir /data1/fdfs/mod -p
#修改base_path
sed -i \'s:base_path=/tmp:base_path=/data1/fdfs/mod:g\' /etc/fdfs/mod_fastdfs.conf
#修改tracker地址
sed -i \'s/tracker_server=tracker:22122/tracker_server=10.10.10.11:22122/g\' /etc/fdfs/mod_fastdfs.conf
sed -i \'/^tracker_server/atracker_server=10.10.10.12:22122\' /et19c/fdfs/mod_fastdfs.conf
#修改文件存储目录
sed -i \'s:store_path0=/home/yuqing/fastdfs:store_path0=/data1/fdfs/storage/data:g\' /etc/fdfs/mod_fastdfs.conf
#若有n个存储数据目录(数据盘),需要增加store_path1,2,3,(n-1),并修改store_path_count=n
#若被访问的url中要包括上传文件后返回ID中的group,例如group0/M0/00/xx,则需要修改url_have_group_name = true
sed -i \'s/url_have_group_name = false/url_have_group_name = true/g\' /etc/fdfs/mod_fastdfs.conf
#当整个集群有多个group时(横向扩展时使用),需要修改group_count=n,n为group个数,并增加group对应的信息。例如:
#[group1]
#group_name=group1
#storage_server_port=23000
#store_path_count=2
#store_path0=/home/yuqing/fastdfs
#store_path1=/home/yuqing/fastdfs1
```

### 4. 创建nginx配置文件

``` bash
cat fdfs.conf
server {
listen 8888;
server_name localhost;

location ~/group([1-9])/M0([0-9])/{
ngx_fastdfs_module;
}
}
```

5. 验证

curl localhost:8888/group1/M00/00/00/ChxS9l2gL5KAPQExAAAABKV9Avc785.txt

6. 配置域名反向代理到两个节点的nginx模块

cat file.xxxx.com.conf
upstream fdfsfile {
        server 10.10.10.11:8888;
        server 10.10.10.12:8888 backup;
}
server {
        listen       443 ssl;
        server_name  file.xxxx.com;
        ssl_certificate /usr/local/nginx/conf/ssl/xxxx.com.pem;
        ssl_certificate_key /usr/local/nginx/conf/ssl/xxxx.com.key;
        ssl_session_timeout 5m;
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        ssl_ciphers ALL:!DH:!EXPORT:!RC4: HIGH: MEDIUM:!LOW:!aNULL:!eNULL;
        ssl_prefer_server_ciphers on;

        location / {
           valid_referers *.xxxx.com;
           if ($invalid_referer) {
               return 403;
           }
           proxy_pass http://fdfsfile;
           proxy_redirect off;
           proxy_set_header HOST $host;
           proxy_set_header X-Real-IP $remote_addr;
           proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
           client_max_body_size 100m;
           client_body_buffer_size 1024k;
           proxy_connect_timeout 90;
           proxy_send_timeout 90;
           proxy_read_timeout 90;
           proxy_buffer_size 32k;
           proxy_buffers 4 32k;
           proxy_busy_buffers_size 64k;
           proxy_temp_file_write_size 64k;
           }

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

内容出处:,

声明:本网站所收集的部分公开资料来源于互联网,转载的目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。如果您发现网站上有侵犯您的知识产权的作品,请与我们取得联系,我们会及时修改或删除。文章链接:http://www.yixao.net/tech/22598.html

发表评论

登录后才能评论