FastDFS安装笔记和使用
版本
| 組件 | 版本 | 文件或下載地址 |
| Ubuntu | 18.04 | ? |
| Python | 3.6.9 | ? |
| nginx | 1.16 | fastdfs-nginx-module_v1.16.tar.gz ? nginx-1.16.0.tar.gz ? |
| libfastcommon | 1.0.36 | https://github.com/happyfish100/libfastcommon/tags |
| fastdfs | 5.11 | ? |
#----------------------------------------準備工作-----------------------------------------------
如果是Ubuntu16.04那么版本參考[8]
?sed -i "s#from django.utils import six#import six#g" `grep -rl "from django.utils import six"`
因為fdfs_client有不少錯誤,下面的repository是修正過的,clone以后拷貝到虛擬環境的指定位置即可
https://github.com/appleyuchi/fdfs_client/
下面開始,
$表示普通權限
#表示root權限
#--------------------------------------------------------------------------------------
本文的系統是ubuntu18.04
#--------------------------------------------------------------------------------------
需要確保以下端口打開:
8888
6379
23000
22122
#------------------------------------------------------------------------------
獲取本地端口:
(python3.7) appleyuchi@ubuntu19:~$ ifconfig -a
enp2s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> ?mtu 1500
? ? ? ? inet 192.168.0.103 ?netmask 255.255.255.0 ?broadcast 192.168.0.255
? ? ? ? inet6 fe80::f078:b77e:8aa6:114a ?prefixlen 64 ?scopeid 0x20<link>
? ? ? ? ether 74:d4:35:2e:da:c0 ?txqueuelen 1000 ?(Ethernet)
? ? ? ? RX packets 542176 ?bytes 542922795 (542.9 MB)
? ? ? ? RX errors 0 ?dropped 0 ?overruns 0 ?frame 0
? ? ? ? TX packets 450827 ?bytes 70216048 (70.2 MB)
? ? ? ? TX errors 0 ?dropped 0 overruns 0 ?carrier 0 ?collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> ?mtu 65536
? ? ? ? inet 127.0.0.1 ?netmask 255.0.0.0
? ? ? ? inet6 ::1 ?prefixlen 128 ?scopeid 0x10<host>
? ? ? ? loop ?txqueuelen 1000 ?(Local Loopback)
? ? ? ? RX packets 197672 ?bytes 58855077 (58.8 MB)
? ? ? ? RX errors 0 ?dropped 0 ?overruns 0 ?frame 0
? ? ? ? TX packets 197672 ?bytes 58855077 (58.8 MB)
? ? ? ? TX errors 0 ?dropped 0 overruns 0 ?carrier 0 ?collisions 0
得到局域網的端口是:
192.168.0.103
#---------------------------------------------------------------------安裝流程-----------------------------------------------------------
libfastcommon-master.zip(是從FastDFS和FastDHT中提取出來的公共C函數庫)
# cd libfastcommon-master/
# ./make.sh
$ cd libfastcommon-1.0.36
$ ./make.sh
# ./make.sh install
$ cd fastdfs-5.11
$ ./make.sh
# ./make.sh install
# apt-get install libpcre3 libpcre3-dev openssl libssl-dev libperl-dev
cd nginx-1.16.1/
$ ./configure --add-module=../fastdfs-nginx-module/src
# ln -sv /usr/include/fastcommon /usr/local/include/fastcommon?
# ln -sv /usr/include/fastdfs /usr/local/include/fastdfs?
# ln -sv /usr/lib64/libfastcommon.so /usr/local/lib/libfastcommon.so
$ make
# make install
下面這個貌似是路由:
# cd fastdfs-5.11
# cp conf/mime.types /etc/fdfs
# cp conf/http.conf /etc/fdfs
conf里面的所有配置文件拷貝到/etc/fdfs
#--------------------------------------------注意事項---------------------------------------------------------
其實這樣安裝就等于有兩套nginx
/usr/local/nginx/sbin/nginx -t 這個是用來查看nginx.conf的路徑的
可以得到默認路徑是:
/usr/local/nginx/conf/nginx.conf
?#touch /usr/local/nginx/logs/nginx.pid
# /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
# /usr/local/nginx/sbin/nginx -s stop #此方式相當于先查出nginx進程id再使用kill命令強制殺掉進程
# /usr/local/nginx/sbin/nginx -s quit #此方式停止步驟是待nginx進程處理任務完畢進行停止
# /usr/local/nginx/sbin/nginx -s reload(為了方便查看error.log可以刪除/etc/nginx/處的error.log然后使用此處的命令重新生成error.log)
這里注意,我們平常都是直接輸入nginx -c xxx/xxx/nginx.conf,
這里不行,必須指定新版本的nginx路徑。
#--------------------------------------------端口的作用---------------------------------------------------------
/etc/fdfs總共有四個端口
#--------------------------------------------配置流程---------------------------------------------------------
$ mkdir -p ~/fastdfs/storage
$ mkdir -p ~/fastdfs/tracker
?
#cd?/fastdfs-5.05
# cp conf/*.conf /etc/fdfs/
注意配置文件中:
同一個組的storage端口號必須一致,
storage的端口必須與nginx中的對應
啟動FastDFS:
# /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf start
# /usr/bin/fdfs_storaged /etc/fdfs/storage.conf start
重啟FastDFS
# /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart
# /usr/bin/fdfs_storaged /etc/fdfs/storage.conf restart
#------------運維方法-------------------
查看storage啟動日志:進入指定的base_path(~/fastdfs/storage)中有個logs目錄,查看storage.log文件
通過monitor來查看storage是否成功綁定,如果輸入命令后卡住了,檢查storage.conf中的IP是否可以ping通
/usr/bin/fdfs_monitor /etc/fdfs/storage.conf
查看端口情況:netstat -apn|grep fdfs
查看FastDFS是否啟動:
ps aux | grep fdfs
注意查看nginx.conf中設定 的報錯文件error.log是否有啥信息
subl /etc/nginx/error.log
#------------------------------------
根據這個生鮮網站的作者所言,
FastDFS是已經被淘汰的技術,
在2014年發布,是阿里出來的.
#------------測試流程------------------------
命令上傳文件:
fdfs_upload_file /etc/fdfs/client.conf 1.jpg
python接口上傳文件:
python upload.py
返回:
('ret=', {'Status': 'Upload successed.', 'Storage IP': '106.14.24.151', 'Remote file_id': 'group1/M00/00/00/rBEaJV57dIyAPFC2AAYSaMf7HAU782.jpg', 'Group name': 'group1', 'Local file name': '1.jpg', 'Uploaded size': '388.00KB'})
?
瀏覽器打開(測試):/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
瀏覽器打不開圖片的時候記得讓nginx重啟下,以及看下/etc/nginx/error.log
瀏覽器的完整鏈接是:
http://49.235.108.13:8888/group1/M00/00/00/rBEAAl9oYTuAeAtjAAYSaMf7HAU443.jpg
#----------------可能的報錯--------------------
①檢查配置文件中的IP
②檢查配置文件中的路徑
③[7]
pkill -9 fdfs
/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf
/usr/bin/fdfs_storaged /etc/fdfs/storage.conf
#-----------python上傳------------------------
from fdfs_client.client import Fdfs_client client = Fdfs_client('/etc/fdfs/client.conf') ret = client.upload_by_filename('1.jpg') print("ret=",ret)#------------參考鏈接------------------------
[1]unknown directive "ngx_fastdfs_module" 問題
[2]fastdfs-nginx-module安裝和配置
[3]【那些踩過的坑】搭建FastDFS文件服務器安裝nginx問題(新手安裝前一定要看!!!)
[4]fdfs安裝
[5]Ubuntu18.04安裝FastDFS和Nginx(這個 是比較詳細的博客)
[6]FastDFS 注意事項(一些排錯的問題)
[7]FastDFS重啟后上傳文件報錯的解決方案
[8]安裝fastdfs出現/usr/local/lib/libfastcommon.so: undefined reference to `fcntl64@GLIBC_2.28'
?
#------------nginx.conf------------------------
下面的這個就是云主機的nginx.conf不需要刻意去修改server_name中的localhost哈
user root; worker_processes 2; error_log /etc/nginx/error.log; pid /usr/local/nginx/logs/nginx.pid;events {worker_connections 1024; }http {include /etc/nginx/mime.types;default_type application/octet-stream;sendfile on;keepalive_timeout 65;server {listen 8888;server_name localhost;location ~/group([0-9])/M00 {root /home/appleyuchi/fastdfs/storage/data;ngx_fastdfs_module;}error_page 500 502 503 504 /50x.html;location = /50x.html {root html;}}server {listen 10072;server_name localhost;location / {proxy_pass http://127.0.0.1:10071;proxy_set_header Host $host:$server_port;proxy_set_header X-Real-IP $remote_addr;proxy_set_header REMOTE-HOST $remote_addr;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;}location /static {root /home/appleyuchi;autoindex on;}}}
?
總結
以上是生活随笔為你收集整理的FastDFS安装笔记和使用的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 连续设置多张背景图片并且平铺
- 下一篇: UT890D的二极管档的使用