Centos安裝FastDFS+Nginx(一天時間搞定)
最近在研究和使用Fastdfs,別人搭的環境,終究是別人的,絕知此事要躬行~躬行啊~
下面的指令碼主要參考了官方的INSTALL檔案,這個是比較權威的,部分地方和實際情況不一致。
比如配置檔案的名字,Fastdfs的安裝位置。
一、下載
https://github.com/happyfish100/fastdfs fastdfs-5.05.zip
https://github.com/happyfish100/libfastcommon libfastcommon-1.0.7.zip
https://github.com/happyfish100/fastdfs-nginx-module fastdfs-nginx-module.zip
二、安裝
先安裝libfastcommon-1.0.7.zip
解壓命令 unzip libfastcommon-1.0.7.zip
cd libfastcommon-1.0.7
./make.sh
./make.sh install
再安裝fastdfs
unzip fastdfs-5.05.zip
./make.sh
./make.sh install
如果沒有先安裝libfastcommon,會報錯
"執行 ./make.sh 報以下錯誤:
cc -Wall -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -g -O -DDEBUG_FLAG -DOS_LINUX -DIOEVENT_USE_EPOLL -c -o ../common/fdfs_global.o ../common/fdfs_global.c -I../common -I/usr/include/fastcommon
../common/fdfs_global.c:20:20: fatal error: logger.h: No such file or directory
#include "logger.h"
^
compilation terminated."
三、配置和啟動
配置檔案的位置
/etc/fdfs/tracker.conf
/etc/fdfs/storage.conf
我的CentOS/etc/fdfs 有3個檔案client.conf.sample、storage.conf.sample、tracker.conf.sample
直接重新命名這3個檔案為,*.conf,修改配置~
先啟動tracker
/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart
再啟動storage
/usr/bin/fdfs_storaged /etc/fdfs/storage.conf restart
很奇怪,為啥沒有start命令,而是restart?
[root@AY1304131823374920ac ~]# ps -ef|grep tracker
root 25433 1 0 16:26 ? 00:00:00 /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart
[root@AY1304131823374920ac ~]# ps -ef|grep storage
root 25533 1 2 16:28 ? 00:00:00 /usr/bin/fdfs_storaged /etc/fdfs/storage.conf restart
四、上傳
#把配置檔案上傳了
/usr/bin/fdfs_test /etc/fdfs/client.conf upload /etc/fdfs/client.conf
[root@AY1304131823374920ac logs]# /usr/bin/fdfs_test /etc/fdfs/client.conf upload /etc/fdfs/client.conf
This is FastDFS client test program v5.05
Copyright (C) 2008, Happy Fish / YuQing
FastDFS may be copied only under the terms of the GNU General
Public License V3, which may be found in the FastDFS source kit.
Please visit the FastDFS Home Page http://www.csource.org/
for more detail.
[2015-10-28 17:27:29] DEBUG - base_path=/root/fdfsdata, connect_timeout=30, network_timeout=60, tracker_server_count=1, anti_steal_token=0, anti_steal_secret_key length=0, use_connection_pool=0, g_connection_pool_max_idle_time=3600s, use_storage_id=0, storage server id count: 0
tracker_query_storage_store_list_without_group:
server 1. group_name=, ip_addr=42.96.184.84, port=23000
group_name=group1, ip_addr=42.96.184.84, port=23000
storage_upload_by_filename
group_name=group1, remote_filename=M00/00/00/KmC4VFYwlQGAItigAAAFsHrMXek69.conf
source ip address: 42.96.184.84
file timestamp=2015-10-28 17:27:29
file size=1456
file crc32=2060213737
example file url: http://42.96.184.84:8090/group1/M00/00/00/KmC4VFYwlQGAItigAAAFsHrMXek69.conf
storage_upload_slave_by_filename
group_name=group1, remote_filename=M00/00/00/KmC4VFYwlQGAItigAAAFsHrMXek69_big.conf
source ip address: 42.96.184.84
file timestamp=2015-10-28 17:27:29
file size=1456
file crc32=2060213737
example file url: http://42.96.184.84:8090/group1/M00/00/00/KmC4VFYwlQGAItigAAAFsHrMXek69_big.conf
五、監控
/usr/bin/fdfs_monitor /etc/fdfs/client.conf
[root@AY1304131823374920ac logs]# /usr/bin/fdfs_monitor /etc/fdfs/client.conf
[2015-10-28 17:25:13] DEBUG - base_path=/root/fdfsdata, connect_timeout=30, network_timeout=60, tracker_server_count=1, anti_steal_token=0, anti_steal_secret_key length=0, use_connection_pool=0, g_connection_pool_max_idle_time=3600s, use_storage_id=0, storage server id count: 0
server_count=1, server_index=0
tracker server is 42.96.184.84:22122
group count: 1
Group 1:
group name = group1
disk total space = 20157 MB
disk free space = 12235 MB
trunk free space = 0 MB
storage server count = 1
active server count = 1
storage server port = 23000
storage HTTP port = 8888
store path count = 1
subdir count per path = 256
current write server index = 0
六、訪問檔案
網上找了下,自帶的Http可能不能使用,可能啊~
server {
46 listen 80;
47 server_name file.fansunion.cn;
48
49 location /group1/M00 {
50 root /root/fdfsdata/data;
51 #ngx_fastdfs_module;
52 }
53 }
Nginx配置沒有使用ngx_fastdfs_module這個模組,出現了403.
http://file.fansunion.cn/group1/M00/00/00/KmC4VFYwlQGAItigAAAFsHrMXek69_big.conf
403 Forbidden
nginx/1.6.2
本地host已經配置了 42.96.184.84 file.fansunion.cn
七、嘗試安裝ngx_fastdfs_module,因為之前總是403各種問題
參考ngx_fastdfs_module中的INSTALL文件
1.原始碼安裝Nginx,之前的Nginx是直接安裝的
Nginx下載地址 http://nginx.org/en/download.html
寫在之前的Nginx,yum remove nginx
在安裝Nginx之前,可能需要安裝gcc、 openssl-devel、 pcre-devel和zlib-devel軟體庫,具體如下:
#沒用
yum install gcc-c++
#沒用
yum install openssl-devel
#用了
yum install pcre-devel
#用了
yum install zlib-devel
./configure --add-module=/root/soft/fastdfs-nginx-module-master/src
make;
make install;
#檢查語法
/usr/local/nginx/sbin/nginx -t
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
從這裡可以看出,預設使用的是/usr/local/nginx/conf/nginx.conf這個配置檔案
而之前手動命令安裝,配置檔案在/etc/nginx目錄下,這個需要注意哦~
#啟動-指定配置檔案
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
#
/usr/local/nginx/sbin/nginx -s reload
ps -ef|grep nginx
root 20897 1 0 10:39 ? 00:00:00 nginx: master process /usr/local/nginx/sbin/nginx
root 20918 13217 0 10:40 pts/3 00:00:00 grep nginx
再次上傳 /usr/bin/fdfs_test /etc/fdfs/client.conf upload /etc/fdfs/client.conf
訪問檔案 http://file.fansunion.cn/group1/M00/00/00/KmC4VFYwlQGAItigAAAFsHrMXek69_big.conf
ln -s /root/fdfsdata/data /root/fdfsdata/data/M00
八、搞了半天還沒有搞好,氣死我了啊~
配置防火牆,重新啟動,重新上傳
iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 23000 -j ACCEPT
/etc/init.d/iptables save
/usr/local/nginx/sbin/nginx
/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart
/usr/bin/fdfs_storaged /etc/fdfs/storage.conf restart
/usr/bin/fdfs_test /etc/fdfs/client.conf upload /etc/fdfs/client.conf
http://42.96.184.84:8080/group1/M00/00/00/KmC4VFYxlIWAOq-xAAAFsCOGhRQ76_big.conf
netstat -ano |grep 8080
各種除錯Nginx,都報錯,連最基本的配置都找不到了~
看Nginx的日誌,也沒有發現,最後才曉得,Nginx原始碼安裝的日誌檔案位於“/usr/local/nginx/logs”。
裡面報錯了,提示/etc/fdfs/下沒有mod_fastdfs.conf這個檔案~
拷貝一份http.conf到 /etc/fdfs目錄下
九、麻痺,麻痺啊~終於搞定了~
1.base_path 放在/root/fdfsdata和/root/fdfsdata2 下,都提示許可權不足。
放在了/home/fdfsdata下就行了。
2.mime.types等配置檔案,凡是提示找不到,就從fastdfs等原檔案的conf目錄copy一份到/etc/fdfs/
3.400或404
可能是Nginx配置或者group-name那個true選項
沒有開啟groupname的
http://42.96.184.84:8080/M00/00/00/KmC4VFYxy2OAAqGdAAAFrZvGHAA99.conf
server {
36 listen 80;
37 server_name 42.96.184.84 alias file.test;
38
39 location / {
40 # root /root/fdfsdata/data;
41 # ngx_fastdfs_module;
42 root /home/www;
43 index a.html;
44 }
45 }
46
47 server{
48 listen 8080;
49 server_name 42.96.184.84;
50
51 location /M00 {
52 root /home/fdfsdata/data;
53 ngx_fastdfs_module;
54 }
55
56 }
第1個server,是測試Nginx能正常啟動。
第2個server,是監聽8080埠,不帶group的對映,到fdfs的資料目錄。
帶group的url訪問
http://42.96.184.84:8080/group1/M00/00/00/KmC4VFYxy2OAAqGdAAAFrZvGHAA99.conf
Nginx配置
location /group1/M00 {
49 root /home/fdfsdata/data;
50 ngx_fastdfs_module;
51 }
/etc/fdfs/mod_fastdfs.conf 這個配置檔案吧。
url_have_group_name = true(預設為false,改為true)
重啟tracker、storage
重啟Nginx
搞定啦~哦也~
十、小結
花費一天的時間,終於成功搭建了初步的fdfs環境。
Nginx+Fastdfs。
參考資料:http://blog.csdn.net/gaofuqi/article/details/27052155
這個人寫得有模有樣,感覺比較可行啊~
我自己的,相對比較曲折,各種問題,但是都逐個解決了~
http://bbs.chinaunix.net/forum.php?mod=viewthread&tid=3598287
相關文章
- 開發者經驗談:如何一天時間搞定iOS遊戲開發?iOS遊戲開發
- Mixpanel:一天的時間 iOS 7安裝率就已升至33.13%iOS
- 騰訊雲centos7下搭建fastDFS+nginxCentOSASTNginx
- windows系統安裝時間修改,win10修改系統安裝時間WindowsWin10
- centos:時間同步CentOS
- Centos 時間同步CentOS
- 安裝npm install時,長時間停留NPM
- MySQL如何獲取當前時間的前一天和後一天時間MySql
- CentOS 6.5安裝Oracle 11.2.0.4------CentOS 6.5安裝CentOSOracle
- CentOS安裝jdkCentOSJDK
- CentOS安裝gitCentOSGit
- Centos 安裝RedisCentOSRedis
- CentOS 安裝 mavenCentOSMaven
- CentOS Docker 安裝CentOSDocker
- centOS安裝rabbitMQCentOSMQ
- CentOS 安裝 dockerCentOSDocker
- CentOS安裝pipCentOS
- Centos安裝opensslCentOS
- CentOS 安裝ScrapyCentOS
- CentOS 安裝ErlangCentOS
- CentOS安裝GraphicsMagickCentOS
- CentOS 安裝 JDKCentOSJDK
- Centos安裝rubyCentOS
- CentOS安裝DockerCentOSDocker
- CentOS 安裝PHPCentOSPHP
- CentOS安裝MySQLCentOSMySql
- centos 安裝swftoolsCentOS
- mongo centos 安裝GoCentOS
- CentOS 安裝 VNCCentOSVNC
- centos安裝mongodbCentOSMongoDB
- CentOS 安裝 SubversionCentOS
- CentOS安裝proftpdCentOSFTP
- centos安裝nodeCentOS
- centos 安裝pyenvCentOS
- Centos 安裝yum,安裝ansibleCentOS
- 【CentOS】CentOS7安裝PostgreSQLCentOSSQL
- 修改CentOS伺服器時間為北京時間CentOS伺服器
- Centos 更改系統時間CentOS