FastDFS安裝擴(kuò)展篇——安裝PHP、Apache及Nginx的FastDFS擴(kuò)展
關(guān)于linux下如何安裝FastDFS請參考:/p/4843.html
一、安裝配置FastDFS支持PHPFastDFS不是通用的文件系統(tǒng),只能通過專用的API來訪問,目前提供了C JAVA PHP的API,下面我們來安裝php擴(kuò)展。讓Fastdfs支持php,在FastDFS的源碼包解壓后里面有個(gè)php_client目錄,進(jìn)入此目錄,參照README進(jìn)行安裝:
phpize./configuremakemake install
安裝完成后會(huì)自動(dòng)把modules/fastdfs_client.so 拷貝到/usr/lib/php5/20090626目錄下,只需要把fastdfs_client.ini copy到/etc/php5/conf.d目錄下,執(zhí)行php fastdfs_test.php 進(jìn)行測試,php5 -m也會(huì)看到fastdfs_client模塊,在README中還有相關(guān)的php函數(shù)解釋,可以進(jìn)行測試。
測試:
創(chuàng)建一個(gè)test-file文件,內(nèi)容:I’m test file,然后使用fdfs_upload_file命令上傳,結(jié)果如下:
編寫test.php測試界面:
<?php$file_info=fastdfs_get_file_info1(’group1/M00/00/00/CgEGflArNZmlRB8kAAAADvvpdFc8638629’);var_dump($file_info);?>
測試結(jié)果如下:
二、安裝apache2擴(kuò)展:在每臺(tái)storage server上部署web server,直接對外提供HTTP服務(wù),tracker server上不需要部署web server,如果請求文件在當(dāng)前storage上不存在,通過文件ID反解出源storage,直接請求源storage,F(xiàn)astDFS擴(kuò)展模塊不依賴于FastDFS server,可以獨(dú)立存在!
在storage上安裝apache2
apt-get install apache2 apache2.2-common apache2.2-bin apache2-utils apache2-mpm-prefork libapache2-mod-php5 apache2-prefork-dev
下載擴(kuò)展包
wget http://fastdfs.googlecode.com/files/fastdfs-apache-module_v1.10.tar.gz
由于默認(rèn)的包的配置都是centos下的配置,所以在安裝前需要修改一下Makefile文件
tar zxvf fastdfs-apache-module_v1.10.tar.gzcd fastdfs-apache-module/srcvi Makefile#相對應(yīng)的變量改成以下值,只針對debian6下apt方式安裝的apache2APACHE_BASE_PATH=/usr/share/apache2/APXS=/usr/bin/apxs2APACHECTL=/usr/bin/apachectl
安裝
makemake install
修改apache2配置
#創(chuàng)建mod_fastdfs.load文件vi /etc/apache2/mods-available/mod_fastdfs.loadLoadModule fastdfs_module /usr/lib/apache2/modules/mod_fastdfs.so<Location /M00> sethandler fastdfs</Location>
#加載mod_fastdfs.so模塊a2enmod mod_fastdfs
#修改虛擬主機(jī)配置,修改相關(guān)變量值,增加alias行配置vi /etc/apache2/sites-enabled/000-defaultDocumentRoot /var/www<Directory /var/www>alias /group1/M00 /var/www/data
修改mod_fastdfs.conf配置
vi /etc/fdfs/mod_fastdfs.confbase_path=/var/wwwtracker_server=x.x.x.x:22122store_path0=/var/www
配置生效
/etc/init.d/apache2 restart
測試先上傳一個(gè)圖片:
fdfs_upload_file /etc/fdfs/client.conf 2.jpg
返回文件ID:group1/M00/00/00/CgEGflArRqG5Nsu_AACLn3wEca8908.jpg
在瀏覽器中測試如下:
三、添加nginx擴(kuò)展:下載擴(kuò)展包:
wget http://fastdfs-nginx-module.googlecode.com/files/fastdfs-nginx-module_v1.10.tar.gz
由于nginx的模塊都為靜態(tài)加載,所以需要編譯安裝nginx,過程如下:
./configure --prefix=/etc/nginx2/ --user=nginx --group=nginx --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_stub_status_module --with-file-aio --with-ipv6 --add-module=/root/fastdfs-nginx-module/srcmake && make install
修改nginx.conf,添加如下內(nèi)容:
vi /etc/nginx2/conf/nginx.conf#在server字段下添加以下內(nèi)容location /M00 { root /opt/fdfs/data; ngx_fastdfs_module;}
/etc/fdfs/mod_fastdfs.conf配置文件的修改和apache2一致,經(jīng)過測試可以正常工作
相關(guān)文章:
1. js select支持手動(dòng)輸入功能實(shí)現(xiàn)代碼2. 如何在PHP中讀寫文件3. java加載屬性配置properties文件的方法4. PHP正則表達(dá)式函數(shù)preg_replace用法實(shí)例分析5. 什么是Python變量作用域6. 《Java程序員修煉之道》作者Ben Evans:保守的設(shè)計(jì)思想是Java的最大優(yōu)勢7. CSS3中Transition屬性詳解以及示例分享8. php redis setnx分布式鎖簡單原理解析9. bootstrap select2 動(dòng)態(tài)從后臺(tái)Ajax動(dòng)態(tài)獲取數(shù)據(jù)的代碼10. vue使用moment如何將時(shí)間戳轉(zhuǎn)為標(biāo)準(zhǔn)日期時(shí)間格式
