FastDFS 內部綁定了 libevent 做爲 http 服務器 ,在V2.X版本必須安裝 libevent ,本文安裝的是V2.2版本,所以必須安裝libevent。(官方也推薦使用 http 方式下載 文件 )html
若是已經安裝了 libevent,請確認安裝路徑是 /usr , 由於 FastDFS 在編譯源程序時,須要到此目錄下查找一些依賴文件,不然編譯 FastDFS 會出錯 。若是不是,建議首先卸載 libevent ,而後安裝到 /usr 下。Ubuntu10.4默認是安裝了libevent,能夠到軟件中心卸載掉而後按照下面介紹的方式安裝。nginx
依次執行:c++
1> rpm -qa|grep libevent 2> yum remove libevent* tar -zxvf libevent-2.0.21-stable.tar.gz 3> cd libevent-2.0.21-stable 4> ./configure --prefix=/usr/local/libevent 5> make && make install
注意: 1)執行 make install 時可能須要 root 權限。2)libevent會安裝到 /usr/lib 或 /usr/local/lib 下。vim
測試libevent是否安裝成功緩存
ls -al /usr/lib | grep libevent(或 ls -al /usr/local/lib | grep libevent)
tar命令解壓FastDFS_v5.01.tar.gz源代碼包,服務器
[root@tracker opt]# cd /home/winkey/FastDFS/ [root@tracker src]# tar zxf FastDFS_v5.01.tar.gz [root@tracker src]# cd FastDFS
運行make.sh,確認make成功。期間若是有錯誤,若是提示錯誤,可能缺乏依賴的軟件包(yum install -y gcc gcc-c++),需先安裝依賴包,需安裝後再次make。負載均衡
[root@tracker FastDFS]# ./make.sh
運行make.sh install,確認install成功。tcp
[root@tracker FastDFS]# ./make.sh install
編輯配置文件目錄下的tracker.conf,設置相關信息並保存。測試
[root@tracker FastDFS]# vim /etc/fdfs/tracker.conf
通常只需改動如下幾個參數便可:url
disabled=false #啓用配置文件 bind_addr=192.168.1.149 #設置綁定地址 port=22122 #設置tracker的端口號 base_path=/fdfs/tracker #設置tracker的數據文件和日誌目錄(需預先建立) http.server_port=9900 #設置http端口號
編輯配置文件目錄下的storage.conf,設置相關信息並保存
vim /etc/fdfs/storage.conf 通常只需改動如下幾個參數便可: disabled=false #啓用配置文件 group_name=group1 #組名,根據實際狀況修改 bind_addr=192.168.1.149 #設置綁定地址 port=23000 #設置storage的端口號 base_path=/fdfs/storage #設置storage的日誌目錄(需預先建立) store_path_count=1 #存儲路徑個數,須要和store_path個數匹配 store_path0=/fdfs/storage #存儲路徑 tracker_server=192.168.1.149:22122 #tracker服務器的IP地址和端口號 http.server_port=9901 #設置http端口號
運行tracker以前,先要把防火牆中對應的端口打開(本例中爲22122)
[root@tracker FastDFS]# iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 22122 -j ACCEPT [root@tracker FastDFS]# /etc/init.d/iptables save iptables:將防火牆規則保存到 /etc/sysconfig/iptables:[肯定]
啓動tracker,確認啓動是否成功。(查看是否對應端口22122是否開始監聽
[root@tracker FastDFS]# /usr/local/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart [root@tracker FastDFS]# netstat -unltp | grep fdfs tcp 0 0.0.0.0:22122 0.0.0.0:* LISTEN 1766/fdfs_trackerd
注意:這裏的fdfs_trackerd文件也能夠從你安裝的Fastdfs目錄下拷過來的(若是已經存在則不須要拷貝)
也可查看tracker的日誌是否啓動成功或是否有錯誤。
[root@tracker FastDFS]# cat /fdfs/tracker/logs/trackerd.log
確認啓動成功後,能夠運行fdfs_monitor查看storage服務器是否已經登記到tracker服務器。 運行tracker以前,先要把防火牆中對應的端口打開(本例中爲22122)。
[root@tracker FastDFS]# iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 23000 -j ACCEPT [root@tracker FastDFS]# /etc/init.d/iptables save iptables:將防火牆規則保存到 /etc/sysconfig/iptables:[肯定] [root@storage1 FastDFS]# /usr/local/bin/fdfs_monitor /etc/fdfs/storage.conf
使用nginx-1.5.12.tar.gz源代碼包以及FastDFS的nginx插件fastdfs-nginx-module_v1.16.tar.gz。
首先將代碼包和插件複製到系統的/home/winkey/FastDFS內(可選),而後使用tar命令解壓
[root@storage1 opt]# cd /home/winkey/FastDFS/ [root@storage1 src]# tar zxf nginx-1.5.12.tar.gz [root@storage1 src]# tar zxf fastdfs-nginx-module_v1.16.tar.gz [root@storage1 src]# tar zxf pcre-8.35.tar.gz [root@storage1 src]# tar zxf zlib-1.2.8.tar.gz [root@storage1 src]# cd nginx-1.5.12
運行./configure進行安裝前的設置,主要設置安裝路徑、FastDFS插件模塊目錄、pcre庫目錄、zlib庫目錄。若是提示錯誤,可能缺乏依賴的軟件包(yum install -y gcc gcc-c++),需先安裝依賴包
yum -y install openssl openssl-devel 再次運行./configure ./configure --prefix=/usr/local/nginx --with-http_stub_status_module --add-module=../fastdfs-nginx-module/src --with-pcre=../pcre-8.35 --with-zlib=../zlib-1.2.8
運行make進行編譯,確保編譯成功。
[root@storage1 nginx-1.5.12]# make
運行make install進行安裝。
[root@storage1 nginx-1.5.12]# make install
將FastDFS的nginx插件模塊的配置文件copy到FastDFS配置文件目錄。
root@storage1 nginx-1.5.12]# cp /home/winkey/FastDFS/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs/
編輯/usr/local/nginx/conf配置文件目錄下的nginx.conf,設置添加storage信息並保存。
vim /usr/local/nginx/conf/nginx.conf
創建M00至存儲目錄的符號鏈接。
worker_processes 4; #根據CPU核心數而定 events { worker_connections 1024; #最大連接數 } http { #設置緩存參數 server_names_hash_bucket_size 128; client_header_buffer_size 32k; large_client_header_buffers 4 32k; client_max_body_size 300m; tcp_nopush on; proxy_redirect off; proxy_set_header Host $http_host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_connect_timeout 90; proxy_send_timeout 90; proxy_read_timeout 90; proxy_buffer_size 16k; proxy_buffers 4 64k; proxy_busy_buffers_size 128k; proxy_temp_file_write_size 128k; #設置緩存存儲路徑、存儲方式、分配內存大小、磁盤最大空間、緩存期限 proxy_cache_path /var/cache/nginx/proxy_cache levels=1:2 keys_zone=http-cache:500m max_size=10g inactive=30d; proxy_temp_path /var/cache/nginx/proxy_cache/tmp; #(建立目錄:nginx/proxy_cache/tmp) #設置group1的服務器 upstream fdfs_group1 { #設置group1的服務器 server 192.168.1.149:9901 weight=1 max_fails=2 fail_timeout=30s; } #設置storage代理 server { listen 9901; server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; location ~/group[1]/M00 { root /fdfs/storage/data; ngx_fastdfs_module; } location / { root html; index index.html index.htm; } } #設置tracker代理配置 server { listen 9900; server_name somename alias another.alias; location / { root html; index index.html index.htm; } location /group1/M00 { #設置group1的負載均衡參數 proxy_next_upstream http_502 http_504 error timeout invalid_header; proxy_cache http-cache; proxy_cache_valid 200 304 12h; proxy_cache_key $uri$is_args$args; proxy_pass http://fdfs_group1; expires 30d; } }
編輯/etc/fdfs配置文件目錄下的mod_fastdfs.conf,設置storage信息並保存。
[root@storage1 nginx-1.5.12]# vim /etc/fdfs/mod_fastdfs.conf
通常只需改動如下幾個參數便可
base_path=/fdfs/storage #保存日誌目錄 tracker_server=192.168.1.149:22122 #tracker服務器的IP地址以及端口號 storage_server_port=23000 #storage服務器的端口號 group_name=group1 #當前服務器的group名 url_have_group_name = true #文件url中是否有group名 store_path_count=1 #存儲路徑個數,須要和store_path個數匹配 store_path0=/fdfs/storage #存儲路徑 http.need_find_content_type=true #從文件擴展名查找文件類型(nginx時爲true) group_count = 1 #設置組的個數 在末尾增長3個組的具體信息: [group1] group_name=group1 storage_server_port=23000 store_path_count=1 store_path0=/fdfs/storage
[root@storage1 nginx-1.5.12]# ln -s /fdfs/storage/data /fdfs/storage/data/M00 [root@storage1 nginx-1.5.12]# ll /fdfs/storage/data/M00 lrwxrwxrwx. 1 root root 19 3月 26 03:44 /fdfs/storage/data/M00 -> /fdfs/storage/data/
運行nginx以前,先要把防火牆中對應的端口打開(本例中爲9900)。
[root@storage1 nginx-1.5.12]# iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 9900 -j ACCEPT [root@storage1 nginx-1.5.12]# /etc/init.d/iptables save iptables:將防火牆規則保存到 /etc/sysconfig/iptables:[肯定]
運行nginx以前,先要把防火牆中對應的端口打開(本例中爲9901)
[root@storage1 nginx-1.5.12]# iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 9901 -j ACCEPT [root@storage1 nginx-1.5.12]# /etc/init.d/iptables save iptables:將防火牆規則保存到 /etc/sysconfig/iptables:[肯定]
啓動nginx,確認啓動是否成功。(查看是否對應端口9900是否開始監聽)
[root@storage1 nginx-1.5.12]# /usr/local/nginx/sbin/nginx ngx_http_fastdfs_set pid=40638 [root@storage1 nginx-1.5.12]# netstat -unltp | grep nginx tcp 0 0.0.0.0:9900 0.0.0.0:* LISTEN 40639/nginx