前言:
如今兄弟们对“nginx上传到fastdfs”大体比较珍视,朋友们都需要分析一些“nginx上传到fastdfs”的相关文章。那么小编同时在网络上汇集了一些关于“nginx上传到fastdfs””的相关文章,希望姐妹们能喜欢,朋友们快快来学习一下吧!一、服务器信息
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 libfastcommon-master.zipcd libfastcommon-master./make.sh./make.sh installln -s /usr/lib64/libfastcommon.so /usr/lib/libfastcommon.so
2. 部署FastDFS
下载FastDFS源码并编译安装
wget -O fastdfs-master.zip fastdfs-master.zipcd 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.confsed -i 's/bind_addr=/bind_addr=10.10.10.11/g' /etc/fdfs/tracker.conf#修改base_pathsed -i 's:base_path=/home/yuqing/fastdfs:base_path=/data1/fdfs/tracker:g' /etc/fdfs/tracker.conf#其他要修改的参数自行根据实际调整
2. 两个节点配置storage
#创建storage数据存储目录mkdir /data1/fdfs/storage -pmkdir /data1/fdfs/storage -p#ip地址根据实际修改mv /etc/fdfs/storage.conf.sample /etc/fdfs/storage.confsed -i 's/bind_addr=/bind_addr=10.10.10.11/g' /etc/fdfs/storage.conf#修改base_pathsed -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.confsed -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 startfdfs_storaged /etc/fdfs/storage.conf start```
五、测试验证
1. 查看集群状态
mv /etc/fdfs/client.conf.sample /etc/fdfs/client.confmkdir /data1/fdfs/client -p#修改base_pathsed -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的状态是否为ACTIVEfdfs_monitor /etc/fdfs/client.conf```
2. 验证上传\下载\删除cd
#上传后会返回一个以gropu开头的IDfdfs_upload_file /etc/fdfs/client.conf xxx.txtgroup1/M00/00/00/ChxS9l2gL5KAPQExAAAABKV9Avc785.txt#下载时指定ID,并可以指定下载后的文件名,例如:xxx1.txtfdfs_download_file /etc/fdfs/client.conf group1/M00/00/00/ChxS9l2gL5KAPQExAAAABKV9Avc785.txt xxx1.txt#删除时指定IDfdfs_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 fastdfs-nginx-module-master.zipsed -i 's:/usr/local/include:/usr/include/fastdfs /usr/include/fastcommon:g' fastdfs-nginx-module-master/src/config```
2. 下载Nginx源码包并编译
wget xf nginx-1.16.1.tar.gzmkdir /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 4make install```
3. 配置mod_fastdfs
#复制mod_fastdfs.confcp 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_pathsed -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.confsed -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 = truesed -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配置文件``` bashcat fdfs.confserver {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.confupstream 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 ; 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; } }
版权声明:
本站文章均来自互联网搜集,如有侵犯您的权益,请联系我们删除,谢谢。
标签: #nginx上传到fastdfs