安装nginx及fastdfs-nginx-module
1. 解压缩 nginx-1.8.1.tar.gz
2. 解压缩 fastdfs-nginx-module-master.zip
3. 进入nginx-1.8.1目录中
4. 执行
sudo ./configure --prefix=/usr/local/nginx/ --add-module=fastdfs-nginx-module-master解压后的目录的绝对路径/src
sudo ./configure --prefix=/usr/local/nginx/ --add-module=/home/python/bj18/fastdfs-nginx-module-master/src
sudo ./make
sudo make
sudo ./make install
sudo make install
安装后所在目录 /usr/local/nginx
5. sudo cp fastdfs-nginx-module-master解压后的目录中src下的mod_fastdfs.conf /etc/fdfs/mod_fastdfs.conf
6. sudo vim /etc/fdfs/mod_fastdfs.conf
修改内容:
connect_timeout=10
tracker_server=自己ubuntu虚拟机的ip地址:22122
url_have_group_name=true
store_path0=/home/python/fastdfs/storage
7. sudo cp 解压缩的fastdfs-master的conf目录中的http.conf /etc/fdfs/http.conf
8. sudo cp 解压缩的fastdfs-master的conf目录中的mime.types /etc/fdfs/mime.types
9.sudo vim /usr/local/nginx/conf/nginx.conf
在http部分中添加配置信息如下:
server {
listen 8888;
server_name localhost;
location ~/group[0-9]/ {
ngx_fastdfs_module;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
10. 启动nginx
sudo /usr/local/nginx/sbin/nginx
测试是否成功
浏览器输入
http://192.168.137.130:8888/
http://192.168.137.130:8888/group1/M00/00/00/wKiJgl2TOT2AEmIoAAA2pLUeB60003.jpg
6. 使用python客户端上传测试
1. workon django_py3
2. 进入fdfs_client-py-master.zip所在目录
3. pip install fdfs_client-py-master.zip
或 pip install fdfs-client-py==1.2.6
4.
>>> from fdfs_client.client import Fdfs_client
报错
Traceback (most recent call last): File "/home/python/.virtualenvs/bj18_py3/lib/python3.5/site-packages/django/core/management/commands/shell.py", line 69, in handle self.run_shell(shell=options[‘interface‘]) File "/home/python/.virtualenvs/bj18_py3/lib/python3.5/site-packages/django/core/management/commands/shell.py", line 61, in run_shell raise ImportError ImportError During handling of the above exception, another exception occurred: Traceback (most recent call last): File "<console>", line 1, in <module> File "/home/python/.virtualenvs/bj18_py3/lib/python3.5/site-packages/fdfs_client/client.py", line 11, in <module> from fdfs_client.tracker_client import * File "/home/python/.virtualenvs/bj18_py3/lib/python3.5/site-packages/fdfs_client/tracker_client.py", line 17, in <module> from fdfs_client.utils import * File "/home/python/.virtualenvs/bj18_py3/lib/python3.5/site-packages/fdfs_client/utils.py", line 8, in <module> from mutagen._compat import StringIO ImportError: No module named ‘mutagen‘
缺少mutagen
安装mutagen
pip install mutagen
继续报错
>>> from fdfs_client.client import Fdfs_client Traceback (most recent call last): File "/home/python/.virtualenvs/bj18_py3/lib/python3.5/site-packages/django/core/management/commands/shell.py", line 69, in handle self.run_shell(shell=options[‘interface‘]) File "/home/python/.virtualenvs/bj18_py3/lib/python3.5/site-packages/django/core/management/commands/shell.py", line 61, in run_shell raise ImportError ImportError During handling of the above exception, another exception occurred: Traceback (most recent call last): File "<console>", line 1, in <module> File "/home/python/.virtualenvs/bj18_py3/lib/python3.5/site-packages/fdfs_client/client.py", line 11, in <module> from fdfs_client.tracker_client import * File "/home/python/.virtualenvs/bj18_py3/lib/python3.5/site-packages/fdfs_client/tracker_client.py", line 17, in <module> from fdfs_client.utils import * File "/home/python/.virtualenvs/bj18_py3/lib/python3.5/site-packages/fdfs_client/utils.py", line 10, in <module> from requests.compat import basestring ImportError: No module named ‘requests‘
解决
>>> client = Fdfs_client(‘/etc/fdfs/client.conf‘)
>>> ret = client.upload_by_filename(‘test‘) # test要在当前文件夹
>>> ret
{‘Group name‘:‘group1‘,‘Status‘:‘Upload successed.‘, ‘Remote file_id‘:‘group1/M00/00/00/
wKjzh0_xaR63RExnAAAaDqbNk5E1398.py‘,‘Uploaded size‘:‘6.0KB‘,‘Local file name‘:‘test‘
, ‘Storage IP‘:‘192.168.243.133‘}
文档 https://github.com/jefforeilly/fdfs_client-py