前面已經講 一張圖秒懂微服務的網絡架構,經過此文章能夠了解FastDFS組件中單機安裝流程。html
如下爲單機FastDFS安裝步驟nginx
CentOS 7.Xgit
libfastcommon 使用的版本: libfastcommon-1.0.41.tar.gzgithub
FastDFS 使用的版本: fastdfs-6.01.tar.gzshell
fastdfs-nginx-module 使用的版本:fastdfs-nginx-module-1.21.tar.gzvim
nginx 使用的版本: nginx-1.16.1.tar.gz服務器
tar -zxvf libfastcommon-1.0.41.tar.gz cd libfastcommon-1.0.41/ ./make.sh ./make.sh install
tar -zxvf fastdfs-6.01.tar.gz cd fastdfs-6.01/ ./make.sh ./make.sh install
cp /etc/fdfs/tracker.conf.sample /etc/fdfs/tracker.conf cp /etc/fdfs/storage.conf.sample /etc/fdfs/storage.conf cp /etc/fdfs/client.conf.sample /etc/fdfs/client.conf
vim /etc/fdfs/tracker.conf
#tracker server端口號 port=22122 #存儲日誌和數據的根目錄 base_path=/opt/apps/fastdfs/tracker
vim /usr/lib/systemd/system/fastdfs-tracker.service
vim /etc/fdfs/storage.conf
#storage server端口號 port=23000 #數據和日誌文件存儲根目錄 base_path=/opt/apps/fastdfs/storage #第一個存儲目錄 store_path0=/opt/apps/fastdfs/storepath0 #tracker服務器IP和端口 tracker_server=192.168.0.1:22122 #http訪問文件的端口(默認8888,看狀況修改,和nginx中保持一致) http.server_port=8888
vim /usr/lib/systemd/system/fastdfs-storage.service
fdfs_monitor /etc/fdfs/storage.conf list
查看狀態是否正常微信
Storage 1:
id = 6.0.36.243
ip_addr = 6.0.36.243 (anantes-651-1-49-net.w2-0.abo.wanadoo.fr) ACTIVE網絡
vim /etc/fdfs/client.conf
# base_path=/opt/apps/fastdfs/client #tracker服務器IP和端口 tracker_server=192.168.0.1:22122
fdfs_upload_file /etc/fdfs/client.conf test.jpg
test.jpg 是測試本地上傳的圖片,路徑請填寫正確架構
#解壓fastdfs-nginx-module tar -zxvf fastdfs-nginx-module-1.21.tar.gz cd fastdfs-nginx-module-1.21/ cp ./src/mod_fastdfs.conf /etc/fdfs #解壓nginx tar -zxvf nginx-1.16.1.tar.gz cd nginx-1.16.1/ #安裝nginx_http_image_filter_module yum -y install gd-devel #添加模塊 ./configure --add-module=../fastdfs-nginx-module-1.21/src --prefix=/usr/local/nginx --with-http_image_filter_module #編譯nginx make #安裝nginx make install
/usr/local/nginx/sbin/nginx -V
查看插件是否安裝成功
[root@FastDFS nginx-1.16.1]# /usr/local/nginx/sbin/nginx -V nginx version: nginx/1.16.1 built by gcc 4.8.5 20150623 (Red Hat 4.8.5-11) (GCC) configure arguments: --add-module=../fastdfs-nginx-module-1.21/src --prefix=/usr/local/nginx --with-http_image_filter_module [root@FastDFS nginx-1.16.1]#
vim /etc/fdfs/mod_fastdfs.conf
修改配置以下:
#tracker服務器IP和端口 tracker_server=192.168.0.1:22122 #是否啓用group組名 url_have_group_name=true # base_path=/opt/apps/fastdfs/tracker # store_path0=/opt/apps/fastdfs/storepath0
vim /usr/local/nginx/conf/nginx.conf
修改配置以下:
server { listen 80; server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; location / { root html; index index.html index.htm; } #圖片帶壓縮訪問 location ~ /group1/M00/(.*)\.(jpg|gif|png)!format=([0-9]+)_([0-9]+) { alias /home/fastdfs/storage/data/; ngx_fastdfs_module; set $w $3; set $h $4; rewrite group1/M00(.+)\.(jpg|gif|png)!format=([0-9]+)_([0-9]+)$ group1/M00$1.$2 break; image_filter resize $w $h; image_filter_buffer 5M; } #主圖訪問 location ~ /group([0-9])/M00/(.+)\.?(.+) { alias /home/fastdfs/storage/data/; ngx_fastdfs_module; } ... }
經過以上配置完成FastDFS的搭建。
圖片訪問示例:
主圖訪問
http://218.2.204.124:30308/group1/M00/00/03/BgAk813IvTCAIxxxAAD44NFKFPc908.png
壓縮圖片 (主圖後加
!format=寬度_高度
)訪問http://218.2.204.124:30308/group1/M00/00/03/BgAk813IvTCAIxxxAAD44NFKFPc908.png!format=400_10
壓縮圖片使用主圖後?format=寬度_高度
本文由博客一文多發平臺 OpenWrite 發佈!
再次感謝!!! 您已看徹底文,歡迎關注微信公衆號猿碼
,你的支持是我持續更新文章的動力!