目錄php
1、 安裝... 3nginx
(一) 下載FastDFS安裝包... 3apache
1. 安裝... 3centos
2. 配置... 5瀏覽器
FastDFS官方論壇:http://www.csource.org
下載1:http://sourceforge.net/projects/fastdfs/files/
下載2:https://code.google.com/p/fastdfs/downloads/list
本手冊使用CentOS 6.5 x86_64版操做系統,按照如下網絡結構進行部署:
所須要下載的壓縮包有:
FastDFS源代碼:FastDFS_v5.01.tar.gz
nginx模塊源代碼:fastdfs-nginx-module_v1.15.tar.gz
nginx服務器源代碼:nginx-1.4.7.tar.gz
nginx cache purge插件源代碼:ngx_cache_purge-2.1.tar.gz
nginx依賴的pcre庫源代碼:pcre-8.34.tar.gz
nginx依賴的zlib庫源代碼:zlib-1.2.8.tar.gz
首先在172.16.1.202上安裝FastDFS tracker,使用FastDFS_v5.01.tar.gz源代碼包。
能夠直接從Linux系統下載源代碼包並解壓安裝。若是是在Windows系統下載,能夠在Linux系統中掛載Windows的共享目錄而且將源代碼包複製進Linux系統內。掛載命令以下
[root@centos-db01 ~]# mount -o ro //Windows主機的IP地址/共享目錄名/掛載目標目錄 |
l 首先將代碼包複製到系統的/usr/local/src內(這一步可選),而後使用tar命令解壓
[root@tracker opt]# cp FastDFS_v5.01.tar.gz /usr/local/src/ [root@tracker opt]# cd /usr/local/src/ [root@tracker src]# tar zxf FastDFS_v5.01.tar.gz [root@tracker src]# cd FastDFS [root@tracker FastDFS]# ll 總用量 128 drwxrwxr-x. 3 500 500 4096 2月 6 18:07 client drwxrwxr-x. 2 500 500 4096 2月 6 18:07 common drwxrwxr-x. 2 500 500 4096 2月 6 18:07 conf -rw-rw-r--. 1 500 500 35067 7月 28 2008 COPYING-3_0.txt -rw-rw-r--. 1 500 500 29691 2月 2 13:17 HISTORY drwxrwxr-x. 2 500 500 4096 2月 6 18:07 init.d -rw-rw-r--. 1 500 500 7639 1月 5 14:08 INSTALL -rwxrwxr-x. 1 500 500 5531 12月 7 15:19 make.sh drwxrwxr-x. 2 500 500 4096 2月 6 18:07 php_client -rw-rw-r--. 1 500 500 2380 7月 28 2008 README -rwxrwxr-x. 1 500 500 1768 4月 12 2010 restart.sh -rwxrwxr-x. 1 500 500 1680 4月 10 2010 stop.sh drwxrwxr-x. 4 500 500 4096 2月 6 18:07 storage drwxrwxr-x. 2 500 500 4096 2月 6 18:07 test drwxrwxr-x. 2 500 500 4096 2月 6 18:07 tracker |
l 運行make.sh,確認make成功。期間若是有錯誤,可能會是缺乏依賴的軟件包,需安裝後再次make。
[root@tracker FastDFS]# ./make.sh |
l 運行make.shinstall,確認install成功。
[root@tracker FastDFS]# ./make.sh install |
安裝完成後,全部可執行文件在/usr/local/bin下,以fdfs開頭:
[root@tracker FastDFS]# ll /usr/local/bin/fdfs* -rwxr-xr-x. 1 root root 522918 3月 25 14:57 /usr/local/bin/fdfs_appender_test -rwxr-xr-x. 1 root root 522871 3月 25 14:57 /usr/local/bin/fdfs_appender_test1 -rwxr-xr-x. 1 root root 514023 3月 25 14:57 /usr/loal/bin/fdfs_append_file -rwxr-xr-x. 1 root root 513433 3月 25 14:57 /usr/local/bin/fdfs_crc32 -rwxr-xr-x. 1 root root 513967 3月 25 14:57 /usr/local/bin/fdfs_delete_file -rwxr-xr-x. 1 root root 514377 3月 25 14:57 /usr/local/bin/fdfs_download_file -rwxr-xr-x. 1 root root 514133 3月 25 14:57 /usr/local/bin/fdfs_file_info -rwxr-xr-x. 1 root root 525064 3月 25 14:57 /usr/local/bin/fdfs_monitor -rwxr-xr-x. 1 root root 1179682 3月 25 14:57 /usr/local/bin/fdfs_storaged -rwxr-xr-x. 1 root root 529845 3月 25 14:57 /usr/local/bin/fdfs_test -rwxr-xr-x. 1 root root 527774 3月 25 14:57 /usr/local/bin/fdfs_test1 -rwxr-xr-x. 1 root root 655809 3月 25 14:57 /usr/local/bin/fdfs_trackerd -rwxr-xr-x. 1 root root 514213 3月 25 14:57 /usr/local/bin/fdfs_upload_appender -rwxr-xr-x. 1 root root 514999 3月 25 14:57 /usr/local/bin/fdfs_upload_file |
全部配置文件在/etc/fdfs下:
[root@tracker FastDFS]# ll /etc/fdfs/ 總用量 60 -rw-r--r--. 1 root root 1461 3月 13 15:15 client.conf -rw-r--r--. 1 root root 858 3月 13 15:15 http.conf -rw-r--r--. 1 root root 31172 3月 13 15:15 mime.types -rw-r--r--. 1 root root 3837 3月 25 10:03 mod_fastdfs.conf -rw-r--r--. 1 root root 7515 3月 24 10:36 storage.conf -rw-r--r--. 1 root root 6989 3月 13 15:15 tracker.conf |
l 至此tracker安裝完成。
l 編輯配置文件目錄下的tracker.conf,設置相關信息並保存。
[root@tracker FastDFS]# vim /etc/fdfs/tracker.conf |
通常只需改動如下幾個參數便可:
disabled=false #啓用配置文件
port=22122 #設置tracker的端口號
base_path=/fdfs/tracker #設置tracker的數據文件和日誌目錄(需預先建立)
http.server_port=8080 #設置http端口號
如須要進行性能調優,能夠參照附錄的配置文件的詳細說明。
l 運行tracker以前,先要把防火牆中對應的fd端口打開(本例中爲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:[肯定] |
l 啓動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 |
也可查看tracker的日誌是否啓動成功或是否有錯誤。
[root@tracker FastDFS]#cat /fdfs/tracker/logs/trackerd.log |
l 設置開機自動啓動。
[root@tracker FastDFS]# vim /etc/rc.d/rc.local |
將運行命令行添加進文件:/usr/local/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart
首先在172.16.1.203上安裝FastDFS storage,使用FastDFS_v5.01.tar.gz源代碼包。
l 首先將代碼包複製到系統的/usr/local/src內(這一步可選),而後使用tar命令解壓
[root@storage1opt]# cp FastDFS_v5.01.tar.gz /usr/local/src/ [root@storage1opt]# cd /usr/local/src/ [root@storage1src]# tar zxf FastDFS_v5.01.tar.gz [root@storage1src]# cd FastDFS [root@storage1FastDFS]# ll 總用量 128 drwxrwxr-x. 3 500 500 4096 2月 6 18:07 client drwxrwxr-x. 2 500 500 4096 2月 6 18:07 common drwxrwxr-x. 2 500 500 4096 2月 6 18:07 conf -rw-rw-r--. 1 500 500 35067 7月 28 2008 COPYING-3_0.txt -rw-rw-r--. 1 500 500 29691 2月 2 13:17 HISTORY drwxrwxr-x. 2 500 500 4096 2月 6 18:07 init.d -rw-rw-r--. 1 500 500 7639 1月 5 14:08 INSTALL -rwxrwxr-x. 1 500 500 5531 12月 7 15:19 make.sh drwxrwxr-x. 2 500 500 4096 2月 6 18:07 php_client -rw-rw-r--. 1 500 500 2380 7月 28 2008 README -rwxrwxr-x. 1 500 500 1768 4月 12 2010 restart.sh -rwxrwxr-x. 1 500 500 1680 4月 10 2010 stop.sh drwxrwxr-x. 4 500 500 4096 2月 6 18:07 storage drwxrwxr-x. 2 500 500 4096 2月 6 18:07 test drwxrwxr-x. 2 500 500 4096 2月 6 18:07 tracker |
l 運行make.sh,確認make成功。期間若是有錯誤,可能會是缺乏依賴的軟件包,需安裝後再次make。
[root@storage1FastDFS]# ./make.sh |
l 運行make.shinstall,確認install成功。
[root@storage1FastDFS]# ./make.sh install |
安裝完成後,全部可執行文件在/usr/local/bin下,以fdfs開頭:
[root@storage1FastDFS]# ll /usr/local/bin/fdfs* -rwxr-xr-x. 1 root root 522918 3月 25 14:57 /usr/local/bin/fdfs_appender_test -rwxr-xr-x. 1 root root 522871 3月 25 14:57 /usr/local/bin/fdfs_appender_test1 -rwxr-xr-x. 1 root root 514023 3月 25 14:57 /usr/local/bin/fdfs_append_file -rwxr-xr-x. 1 root root 513433 3月 25 14:57 /usr/local/bin/fdfs_crc32 -rwxr-xr-x. 1 root root 513967 3月 25 14:57 /usr/local/bin/fdfs_delete_file -rwxr-xr-x. 1 root root 514377 3月 25 14:57 /usr/local/bin/fdfs_download_file -rwxr-xr-x. 1 root root 514133 3月 25 14:57 /usr/local/bin/fdfs_file_info -rwxr-xr-x. 1 root root 525064 3月 25 14:57 /usr/local/bin/fdfs_monitor -rwxr-xr-x. 1 root root 1179682 3月 25 14:57 /usr/local/bin/fdfs_storaged -rwxr-xr-x. 1 root root 529845 3月 25 14:57 /usr/local/bin/fdfs_test -rwxr-xr-x. 1 root root 527774 3月 25 14:57 /usr/local/bin/fdfs_test1 -rwxr-xr-x. 1 root root 655809 3月 25 14:57 /usr/local/bin/fdfs_trackerd -rwxr-xr-x. 1 root root 514213 3月 25 14:57 /usr/local/bin/fdfs_upload_appender -rwxr-xr-x. 1 root root 514999 3月 25 14:57 /usr/local/bin/fdfs_upload_file |
全部配置文件在/etc/fdfs下:
[root@storage1FastDFS]# ll /etc/fdfs/ 總用量 60 -rw-r--r--. 1 root root 1461 3月 13 15:15 client.conf -rw-r--r--. 1 root root 858 3月 13 15:15 http.conf -rw-r--r--. 1 root root 31172 3月 13 15:15 mime.types -rw-r--r--. 1 root root 3837 3月 25 10:03 mod_fastdfs.conf -rw-r--r--. 1 root root 7515 3月 24 10:36 storage.conf -rw-r--r--. 1 root root 6989 3月 13 15:15 tracker.conf |
l 至此storage安裝完成。
l 編輯配置文件目錄下的storage.conf,設置相關信息並保存。
[root@storage1FastDFS]# vim /etc/fdfs/storage.conf |
通常只需改動如下幾個參數便可:
disabled=false #啓用配置文件
group_name=group1#組名,根據實際狀況修改
port=23000#設置storage的端口號
base_path=/fdfs/storage#設置storage的日誌目錄(需預先建立)
store_path_count=1#存儲路徑個數,須要和store_path個數匹配
store_path0=/fdfs/storage#存儲路徑
tracker_server=172.16.1.202:22122#tracker服務器的IP地址和端口號
http.server_port=8080 #設置http端口號
如須要進行性能調優,能夠參照附錄的配置文件的詳細說明。
l 運行storage以前,先要把防火牆中對應的端口打開(本例中爲23000)。
[root@storage1 FastDFS]# iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 23000 -j ACCEPT [root@storage1FastDFS]# /etc/init.d/iptables save iptables:將防火牆規則保存到 /etc/sysconfig/iptables:[肯定] |
l 啓動storage,會根據配置文件的設置自動建立多級存儲目錄,確認啓動是否成功。(查看是否對應端口23000是否開始監聽)
[root@storage1 FastDFS]#/usr/local/bin/fdfs_storaged /etc/fdfs/storage.conf restart data path: /fdfs/storage/data, mkdir sub dir... mkdir data path: 00 ... mkdir data path: 01 ... mkdir data path: 02 ... mkdir data path: 03 ... ... data path: /fdfs/storage/data, mkdir sub dir done. [root@storage1 FastDFS]#netstat -unltp | grep fdfs tcp 0 0.0.0.0:23000 0.0.0.0:* LISTEN 1766/fdfs_storaged |
也可查看storage的日誌是否啓動成功或是否有錯誤。
[root@storage1 FastDFS]#cat /fdfs/storage/logs/storaged.log |
確認啓動成功後,能夠運行fdfs_monitor查看storage服務器是否已經登記到tracker服務器。
[root@storage1 FastDFS]# /usr/local/bin/fdfs_monitor /etc/fdfs/storage.conf [2014-03-26 01:51:20] DEBUG - base_path=/fdfs/storage, 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 172.16.1.202:22122
group count: 1
Group 1: group name = group1 disk total space = 27789 MB disk free space = 23920 MB trunk free space = 0 MB storage server count = 1 active server count = 1 storage server port = 23000 storage HTTP port = 8080 store path count = 1 subdir count per path = 256 current write server index = 0 current trunk file id = 0
Storage 1: id = 172.16.1.203 ip_addr = 172.16.1.203 ACTIVE http domain = version = 5.01 join time = 2014-03-26 01:48:19 up time = 2014-03-26 01:48:19 total storage = 27789 MB free storage = 23920 MB upload priority = 10 store_path_count = 1 subdir_count_per_path = 256 storage_port = 23000 storage_http_port = 8080 current_write_path = 0 source storage id= if_trunk_server= 0 total_upload_count = 0 success_upload_count = 0 total_append_count = 0 success_append_count = 0 total_modify_count = 0 success_modify_count = 0 total_truncate_count = 0 success_truncate_count = 0 total_set_meta_count = 0 success_set_meta_count = 0 total_delete_count = 0 success_delete_count = 0 total_download_count = 0 success_download_count = 0 total_get_meta_count = 0 success_get_meta_count = 0 total_create_link_count = 0 success_create_link_count = 0 total_delete_link_count = 0 success_delete_link_count = 0 total_upload_bytes = 0 success_upload_bytes = 0 total_append_bytes = 0 success_append_bytes = 0 total_modify_bytes = 0 success_modify_bytes = 0 stotal_download_bytes = 0 success_download_bytes = 0 total_sync_in_bytes = 0 success_sync_in_bytes = 0 total_sync_out_bytes = 0 success_sync_out_bytes = 0 total_file_open_count = 0 success_file_open_count = 0 total_file_read_count = 0 success_file_read_count = 0 total_file_write_count = 0 success_file_write_count = 0 last_heart_beat_time = 2014-03-26 01:51:03 last_source_update = 1970-01-01 08:00:00 last_sync_update = 1970-01-01 08:00:00 last_synced_timestamp = 1970-01-01 08:00:00 |
看到「172.16.1.203 ACTIVE」便可確認storage運行正常。
l 設置開機自動啓動。
[root@storage1 FastDFS]# vim /etc/rc.d/rc.local |
將運行命令行添加進文件:/usr/local/bin/fdfs_storaged /etc/fdfs/storage.conf restart
l 以後依次在172.16.1.204~208上所有安裝上storage並確認運行正常。注意配置文件中group名參數須要根據實際狀況調整,本例中group是這樣分配的:
group1:172.16.1.203,172.16.1.204
group2:172.16.1.205,172.16.1.206
group3:172.16.1.207,172.16.1.208
另外每一個group中全部storage的端口號必須一致。
在storage上安裝的nginx主要爲了提供http的訪問服務,同時解決group中storage服務器的同步延遲問題。(須要安裝ngx_cache_purge-2.1.tar.gz)
首先在172.16.1.203上安裝nginx,使用nginx-1.4.7.tar.gz源代碼包以及FastDFS的nginx插件fastdfs-nginx-module_v1.15.tar.gz。
l 首先將代碼包和插件複製到系統的/usr/local/src內(可選),而後使用tar命令解壓
[root@storage1opt]# cp nginx-1.4.7.tar.gz /usr/local/src [root@storage1opt]# cp fastdfs-nginx-module_v1.15.tar.gz /usr/local/src [root@storage1opt]# cp pcre-8.34.tar.gz /usr/local/src [root@storage1opt]# cp zlib-1.2.8.tar.gz /usr/local/src [root@storage1opt]# cd /usr/local/src/ [root@storage1src]# tar zxf nginx-1.4.7.tar.gz [root@storage1src]# tar zxf fastdfs-nginx-module_v1.15.tar.gz [root@storage1src]# tar zxf pcre-8.34.tar.gz [root@storage1src]# tar zxf zlib-1.2.8.tar.gz [root@storage1src]# cd nginx-1.4.7 [root@storage1nginx-1.4.7]# ll 總用量 592 drwxr-xr-x. 6 1001 1001 4096 3月 26 02:34 auto -rw-r--r--. 1 1001 1001 225213 3月 18 21:17 CHANGES -rw-r--r--. 1 1001 1001 343040 3月 18 21:17 CHANGES.ru drwxr-xr-x. 2 1001 1001 4096 3月 26 02:34 conf -rwxr-xr-x. 1 1001 1001 2369 3月 18 21:17 configure drwxr-xr-x. 3 1001 1001 4096 3月 26 02:34 contrib drwxr-xr-x. 2 1001 1001 4096 3月 26 02:34 html -rw-r--r--. 1 1001 1001 1397 3月 18 21:17 LICENSE drwxr-xr-x. 2 1001 1001 4096 3月 26 02:34 man -rw-r--r--. 1 1001 1001 49 3月 18 21:17 README drwxr-xr-x. 8 1001 1001 4096 3月 26 02:34 src |
l 運行./configure進行安裝前的設置,主要設置安裝路徑、FastDFS插件模塊目錄、pcre庫目錄、zlib庫目錄。
若是提示錯誤,可能缺乏依賴的軟件包,需先安裝依賴包,再次運行./configure
[root@storage1 nginx-1.4.7]# ./configure --prefix=/usr/local/nginx --add-module=/usr/local/src/fastdfs-nginx-module/src --with-pcre=/usr/local/src/pcre-8.34/ --with-zlib=/usr/local/src/zlib-1.2.8 |
l 運行make進行編譯,確保編譯成功。
[root@storage1 nginx-1.4.7]#make |
l 運行makeinstall進行安裝。
[root@storage1 nginx-1.4.7]#make install |
l 將FastDFS的nginx插件模塊的配置文件copy到FastDFS配置文件目錄。
[root@storage1 nginx-1.4.7]#cp /usr/local/src/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs/ |
安裝完成後,nginx全部文件在/usr/local/nginx下:
[root@storage1 nginx-1.4.7]# ll /usr/local/nginx/ 總用量 16 drwxr-xr-x. 2 root root 4096 3月 26 03:11 conf drwxr-xr-x. 2 root root 4096 3月 26 03:11 html drwxr-xr-x. 2 root root 4096 3月 26 03:11 logs drwxr-xr-x. 2 root root 4096 3月 26 03:11 sbin |
l 至此nginx以及FastDFS的nginx插件模塊安裝完成。
l 編輯/usr/local/nginx/conf配置文件目錄下的nginx.conf,設置添加storage信息並保存。
[root@storage1 nginx-1.4.7]# vim /usr/local/nginx/conf/nginx.conf |
將server段中的listen端口號改成8080:
listen 8080;
在server段中添加:
location~/group[1-3]/M00{
root/fdfs/storage/data;
ngx_fastdfs_module;
}
l 編輯/etc/fdfs配置文件目錄下的mod_fastdfs.conf,設置storage信息並保存。
[root@storage1 nginx-1.4.7]# vim /etc/fdfs/mod_fastdfs.conf |
通常只需改動如下幾個參數便可:
base_path=/fdfs/storage#保存日誌目錄
tracker_server=172.16.1.202: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= 3 #設置組的個數
在末尾增長3個組的具體信息:
[group1]
group_name=group1
storage_server_port=23000
store_path_count=1
store_path0=/fdfs/storage
[group2]
group_name=group2
storage_server_port=23000
store_path_count=1
store_path0=/fdfs/storage
[group3]
group_name=group3
storage_server_port=23000
store_path_count=1
store_path0=/fdfs/storage
l 創建M00至存儲目錄的符號鏈接。
[root@storage1 nginx-1.4.7]# ln -s /fdfs/storage/data /fdfs/storage/data/M00 [root@storage1 nginx-1.4.7]# ll /fdfs/storage/data/M00 lrwxrwxrwx. 1 root root 19 3月 26 03:44 /fdfs/storage/data/M00 -> /fdfs/storage/data/ |
l 至此,nginx以及FastDFS插件模塊設置完成。
l 運行nginx以前,先要把防火牆中對應的端口打開(本例中爲8080)。
[root@storage1nginx-1.4.7]# iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 8080 -j ACCEPT [root@storage1nginx-1.4.7]# /etc/init.d/iptables save iptables:將防火牆規則保存到 /etc/sysconfig/iptables:[肯定] |
l 啓動nginx,確認啓動是否成功。(查看是否對應端口8080是否開始監聽)
[root@storage1 nginx-1.4.7]# /usr/local/nginx/sbin/nginx ngx_http_fastdfs_set pid=40638 [root@storage1 nginx-1.4.7]# netstat -unltp | grep nginx tcp 0 0.0.0.0:8080 0.0.0.0:* LISTEN 40639/nginx |
也可查看nginx的日誌是否啓動成功或是否有錯誤。
[root@storage1 nginx-1.4.7]# cat /usr/local/nginx/logs/error.log ngx_http_fastdfs_process_init pid=40640 [2014-03-26 03:47:17] INFO - local_host_ip_count: 2, 127.0.0.1 172.16.1.203 [2014-03-26 03:47:17] INFO - fastdfs apache / nginx module v1.15, response_mode=proxy, base_path=/tmp, url_have_group_name=1, group_count=3, connect_timeout=2, network_timeout=30, tracker_server_count=1, if_alias_prefix=, local_host_ip_count=2, need_find_content_type=1, default_content_type=application/octet-stream, anti_steal_token=0, token_ttl=0s, anti_steal_secret_key length=0, token_check_fail content_type=, token_check_fail buff length=0, load_fdfs_parameters_from_tracker=1, storage_sync_file_max_delay=86400s, use_storage_id=0, storage server id count=0, flv_support=1, flv_extension=flv [2014-03-26 03:47:17] INFO - group 1. group_name=group1, storage_server_port=23000, path_count=1, store_path0=/fdfs/storage [2014-03-26 03:47:17] INFO - group 2. group_name=group2, storage_server_port=23000, path_count=1, store_path0=/fdfs/storage [2014-03-26 03:47:17] INFO - group 3. group_name=group3, storage_server_port=23000, path_count=1, store_path0=/fdfs/storage |
在error.log中沒有錯誤,既啓動成功。能夠打開瀏覽器,直接訪問http://172.16.1.203:8080,查看是否彈出nginx歡迎頁面。
以後依次在172.16.1.204~208上所有安裝上nginx並確認運行正常。
l 設置開機自動啓動。
[root@storage1 nginx-1.4.7]# vim /etc/rc.d/rc.local |
將運行命令行添加進文件:/usr/local/nginx/sbin/nginx
在tracker上安裝的nginx主要爲了提供http訪問的反向代理、負載均衡以及緩存服務。
l 首先將代碼包和插件複製到系統的/usr/local/src內(可選),而後使用tar命令解壓
[root@trackeropt]# cp nginx-1.4.7.tar.gz /usr/local/src [root@tracker opt]# cp ngx_cache_purge-2.1.tar.gz /usr/local/src [root@tracker opt]# cp pcre-8.34.tar.gz /usr/local/src [root@tracker opt]# cp zlib-1.2.8.tar.gz /usr/local/src [root@tracker opt]# cd /usr/local/src/ [root@tracker src]# tar zxf nginx-1.4.7.tar.gz [root@tracker src]# tar zxf ngx_cache_purge-2.1.tar.gz [root@tracker src]# tar zxf pcre-8.34.tar.gz [root@tracker src]# tar zxf zlib-1.2.8.tar.gz [root@tracker src]# cd nginx-1.4.7 [root@tracker nginx-1.4.7]# ll 總用量 592 drwxr-xr-x. 6 1001 1001 4096 3月 26 02:34 auto -rw-r--r--. 1 1001 1001 225213 3月 18 21:17 CHANGES -rw-r--r--. 1 1001 1001 343040 3月 18 21:17 CHANGES.ru drwxr-xr-x. 2 1001 1001 4096 3月 26 02:34 conf -rwxr-xr-x. 1 1001 1001 2369 3月 18 21:17 configure drwxr-xr-x. 3 1001 1001 4096 3月 26 02:34 contrib drwxr-xr-x. 2 1001 1001 4096 3月 26 02:34 html -rw-r--r--. 1 1001 1001 1397 3月 18 21:17 LICENSE drwxr-xr-x. 2 1001 1001 4096 3月 26 02:34 man -rw-r--r--. 1 1001 1001 49 3月 18 21:17 README drwxr-xr-x. 8 1001 1001 4096 3月 26 02:34 src |
l 運行./configure進行安裝前的設置,主要設置安裝路徑、nginx cache purge插件模塊目錄、pcre庫目錄、zlib庫目錄。
若是提示錯誤,可能缺乏依賴的軟件包,需先安裝依賴包,再次運行./configure
[root@storage1 nginx-1.4.7]# ./configure --prefix=/usr/local/nginx --add-module=/usr/local/src/ngx_cache_purge-2.1--with-pcre=/usr/local/src/pcre-8.34/ --with-zlib=/usr/local/src/zlib-1.2.8 |
l 運行make進行編譯,確保編譯成功。
[root@storage1 nginx-1.4.7]#make |
l 運行makeinstall進行安裝。
[root@storage1 nginx-1.4.7]#make install |
l 至此nginx以及nginx cachepurge插件模塊安裝完成。
l 編輯/usr/local/nginx/conf配置文件目錄下的nginx.conf,設置負載均衡以及緩存。
[root@storage1 nginx-1.4.7]# vim /usr/local/nginx/conf/nginx.conf |
worker_processes 4; #根據CPU核心數而定
events{
worker_connections 65535; #最大連接數
use epoll;#新版本的Linux可以使用epoll加快處理性能
}
http{
#設置緩存參數
server_names_hash_bucket_size 128;
client_header_buffer_size32k;
large_client_header_buffers 4 32k;
client_max_body_size300m;
sendfile on;
tcp_nopushon;
proxy_redirectoff;
proxy_set_headerHost $http_host;
proxy_set_headerX-Real-IP $remote_addr;
proxy_set_headerX-Forwarded-For $proxy_add_x_forwarded_for;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffer_size16k;
proxy_buffers 4 64k;
proxy_busy_buffers_size128k;
proxy_temp_file_write_size128k;
#設置緩存存儲路徑、存儲方式、分配內存大小、磁盤最大空間、緩存期限
proxy_cache_path/var/cache/nginx/proxy_cache levels=1:2 keys_zone=http-cache:500m max_size=10ginactive=30d;
proxy_temp_path/var/cache/nginx/proxy_cache/tmp;
#設置group1的服務器
upstreamfdfs_group1 {
server172.16.1.203:8080 weight=1 max_fails=2 fail_timeout=30s;
server172.16.1.204:8080 weight=1 max_fails=2 fail_timeout=30s;
}
#設置group2的服務器
upstreamfdfs_group2 {
server172.16.1.205:8080 weight=1 max_fails=2 fail_timeout=30s;
server172.16.1.206:8080 weight=1 max_fails=2 fail_timeout=30s;
}
#設置group3的服務器
upstreamfdfs_group3 {
server172.16.1.207:8080 weight=1 max_fails=2 fail_timeout=30s;
server172.16.1.208:8080 weight=1 max_fails=2 fail_timeout=30s;
}
server{
#設置服務器端口
listen 8080;
#設置group1的負載均衡參數
location/group1/M00 {
proxy_next_upstream http_502http_504 error timeout invalid_header;
proxy_cachehttp-cache;
proxy_cache_valid 200 304 12h;
proxy_cache_key $uri$is_args$args;
proxy_pass http://fdfs_group1;
expires30d;
}
#設置group2的負載均衡參數
location/group2/M00 {
proxy_next_upstream http_502http_504 error timeout invalid_header;
proxy_cachehttp-cache;
proxy_cache_valid 200 304 12h;
proxy_cache_key $uri$is_args$args;
proxy_pass http://fdfs_group2;
expires30d;
}
#設置group3的負載均衡參數
location/group3/M00 {
proxy_next_upstream http_502http_504 error timeout invalid_header;
proxy_cachehttp-cache;
proxy_cache_valid 200 304 12h;
proxy_cache_key $uri$is_args$args;
proxy_pass http://fdfs_group3;
expires30d;
}
#設置清除緩存的訪問權限
location~ /purge(/.*) {
allow127.0.0.1;
allow172.16.1.0/24;
denyall;
proxy_cache_purgehttp-cache $1$is_args$args;
}
l 至此,nginx以及nginx cachepurge插件模塊設置完成。
運行nginx以前,先要把防火牆中對應的端口打開(本例中爲8080)。
[root@trackernginx-1.4.7]# iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 8080 -j ACCEPT [root@trackernginx-1.4.7]# /etc/init.d/iptables save iptables:將防火牆規則保存到 /etc/sysconfig/iptables:[肯定] |
啓動nginx,確認啓動是否成功。(查看是否對應端口8080是否開始監聽)
[root@trackernginx-1.4.7]# /usr/local/nginx/sbin/nginx ngx_http_fastdfs_set pid=40638 [root@trackernginx-1.4.7]# netstat -unltp | grep nginx tcp 0 0.0.0.0:8080 0.0.0.0:* LISTEN 40639/nginx |
l 嘗試上傳一個文件到FastDFS,而後訪問試試。先配置client.conf文件。
[root@trackernginx-1.4.7]# vim /etc/fdfs/client.conf |
修改如下參數:
base_path=/fdfs/tracker #日誌存放路徑
tracker_server=172.16.1.202:22122 #tracker服務器IP地址和端口號
http.tracker_server_port=8080 #tracker服務器的http端口號
使用/usr/local/bin/fdfs_upload_file上傳一個文件,程序會自動返回文件的URL。
[root@trackernginx-1.4.7]# /usr/local/bin/fdfs_upload_file /etc/fdfs/client.conf /mnt/monk.jpg group3/M00/00/00/rBABz1MzKG6Ad_hBAACKLsUDM60560.jpg |
而後使用瀏覽器訪問:
能夠看到文件被正確讀取出來了。
查看nginx的access.log日誌,能夠看到訪問返回200成功。
[root@trackernginx-1.4.7]# tail -n 10 -f /usr/local/nginx/logs/access.log 172.16.1.201 - - [26/Mar/2014:13:15:00 +0800] "GET /group3/M00/00/00/rBABz1MzKG6Ad_hBAACKLsUDM60560.jpg HTTP/1.1" 200 35374 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko" |
查看nginx的cache目錄,能夠看到已經生成了緩存文件。
[root@tracker nginx-1.4.7]# ll /var/cache/nginx/proxy_cache/ -R /var/cache/nginx/proxy_cache/: 總用量 8 drwx------. 3 nobody nobody 4096 3月 26 12:57 6 drwxr-xr-x. 2 nobody root 4096 3月 26 13:14 tmp
/var/cache/nginx/proxy_cache/6: 總用量 4 drwx------. 2 nobody nobody 4096 3月 26 13:08 11
/var/cache/nginx/proxy_cache/6/11: 總用量 36 -rw-------. 1 nobody nobody 35686 3月 26 13:08 b1f6fb1f7266f796765b6d6965021116 |
若是要手動清除緩存,能夠在文件URL以前加上purge:
l 設置開機自動啓動。
[root@trackernginx-1.4.7]# vim /etc/rc.d/rc.local |
將運行命令行添加進文件:/usr/local/nginx/sbin/nginx
至此,tracker服務器上的http反向代理+負載均衡+緩存已經安裝完成。
FastDFS提供了多種方式上傳文件:
l 使用fdfs_upload_file上傳(以前已經有演示)
l 使用C語言客戶端接口上傳
l 使用PHP客戶端接口上傳
l 使用Java客戶端接口上傳
l 使用Python客戶端接口上傳
l 使用.NET客戶端接口上傳
根據具體狀況選擇使用。上傳均支持斷點續傳。
l 使用fdfs_download_file經過tracker服務器下載
l 使用nginx經過http方式直接從storage下載(支持斷點續傳,做者推薦)
l 使用fdfs_monitor查看tracker和全部group的運行狀況。
[root@tracker tmp]# /usr/local/bin/fdfs_monitor /etc/fdfs/client.conf 2014-03-26 15:01:07] DEBUG - base_path=/fdfs/tracker, 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 172.16.1.202:22122
group count: 3
Group 1: group name = group1 disk total space = 27789 MB disk free space = 23825 MB trunk free space = 0 MB storage server count = 2 active server count = 2 storage server port = 23000 storage HTTP port = 8080 store path count = 1 subdir count per path = 256 current write server index = 1 current trunk file id = 0
Storage 1: id = 172.16.1.203 ip_addr = 172.16.1.203 ACTIVE http domain = version = 5.01 join time = 2014-03-26 01:48:19 up time = total storage = 27789 MB free storage = 23844 MB upload priority = 10 store_path_count = 1 subdir_count_per_path = 256 storage_port = 23000 storage_http_port = 8080 current_write_path = 0 source storage id= if_trunk_server= 0 total_upload_count = 1 success_upload_count = 1 total_append_count = 0 success_append_count = 0 total_modify_count = 0 success_modify_count = 0 total_truncate_count = 0 success_truncate_count = 0 total_set_meta_count = 0 success_set_meta_count = 0 total_delete_count = 0 success_delete_count = 0 total_download_count = 0 success_download_count = 0 total_get_meta_count = 0 success_get_meta_count = 0 total_create_link_count = 0 success_create_link_count = 0 total_delete_link_count = 0 success_delete_link_count = 0 total_upload_bytes = 24 success_upload_bytes = 24 total_append_bytes = 0 success_append_bytes = 0 total_modify_bytes = 0 success_modify_bytes = 0 stotal_download_bytes = 0 success_download_bytes = 0 total_sync_in_bytes = 0 success_sync_in_bytes = 0 total_sync_out_bytes = 24 success_sync_out_bytes = 24 total_file_open_count = 1 success_file_open_count = 1 total_file_read_count = 0 success_file_read_count = 0 total_file_write_count = 1 success_file_write_count = 1 last_heart_beat_time = 2014-03-26 15:00:47 last_source_update = 2014-03-26 13:13:55 last_sync_update = 1970-01-01 08:00:00 last_synced_timestamp = 1970-01-01 08:00:00 Storage 2: id = 172.16.1.204 ip_addr = 172.16.1.204 ACTIVE http domain = version = 5.01 join time = 2014-03-26 18:53:19 up time = 2014-03-26 18:53:19 total storage = 27789 MB free storage = 23825 MB upload priority = 10 store_path_count = 1 subdir_count_per_path = 256 storage_port = 23000 storage_http_port = 8080 current_write_path = 0 source storage id= 172.16.1.203 if_trunk_server= 0 total_upload_count = 0 success_upload_count = 0 total_append_count = 0 success_append_count = 0 total_modify_count = 0 success_modify_count = 0 total_truncate_count = 0 success_truncate_count = 0 total_set_meta_count = 0 success_set_meta_count = 0 total_delete_count = 0 success_delete_count = 0 total_download_count = 0 success_download_count = 0 total_get_meta_count = 0 success_get_meta_count = 0 total_create_link_count = 0 success_create_link_count = 0 total_delete_link_count = 0 success_delete_link_count = 0 total_upload_bytes = 0 success_upload_bytes = 0 total_append_bytes = 0 success_append_bytes = 0 total_modify_bytes = 0 success_modify_bytes = 0 stotal_download_bytes = 0 success_download_bytes = 0 total_sync_in_bytes = 24 success_sync_in_bytes = 24 total_sync_out_bytes = 0 success_sync_out_bytes = 0 total_file_open_count = 1 success_file_open_count = 1 total_file_read_count = 0 success_file_read_count = 0 total_file_write_count = 1 success_file_write_count = 1 last_heart_beat_time = 2014-03-26 15:00:40 last_source_update = 1970-01-01 08:00:00 last_sync_update = 2014-03-27 03:38:23 last_synced_timestamp = 2014-03-26 13:13:56 (-1s delay)
Group 2: group name = group2 disk total space = 27789 MB disk free space = 23825 MB trunk free space = 0 MB storage server count = 2 active server count = 2 storage server port = 23000 storage HTTP port = 8080 store path count = 1 subdir count per path = 256 current write server index = 0 current trunk file id = 0
Storage 1: id = 172.16.1.205 ip_addr = 172.16.1.205 ACTIVE http domain = version = 5.01 join time = 2014-03-26 19:37:36 up time = 2014-03-26 19:37:36 total storage = 27789 MB free storage = 23825 MB upload priority = 10 store_path_count = 1 subdir_count_per_path = 256 storage_port = 23000 storage_http_port = 8080 current_write_path = 0 source storage id= if_trunk_server= 0 total_upload_count = 0 success_upload_count = 0 total_append_count = 0 success_append_count = 0 total_modify_count = 0 success_modify_count = 0 total_truncate_count = 0 success_truncate_count = 0 total_set_meta_count = 0 success_set_meta_count = 0 total_delete_count = 0 success_delete_count = 0 total_download_count = 0 success_download_count = 0 total_get_meta_count = 0 success_get_meta_count = 0 total_create_link_count = 0 success_create_link_count = 0 total_delete_link_count = 0 success_delete_link_count = 0 total_upload_bytes = 0 success_upload_bytes = 0 total_append_bytes = 0 success_append_bytes = 0 total_modify_bytes = 0 success_modify_bytes = 0 stotal_download_bytes = 0 success_download_bytes = 0 total_sync_in_bytes = 0 success_sync_in_bytes = 0 total_sync_out_bytes = 0 success_sync_out_bytes = 0 total_file_open_count = 0 success_file_open_count = 0 total_file_read_count = 0 success_file_read_count = 0 total_file_write_count = 0 success_file_write_count = 0 last_heart_beat_time = 2014-03-26 15:01:02 last_source_update = 1970-01-01 08:00:00 last_sync_update = 1970-01-01 08:00:00 last_synced_timestamp = 1970-01-01 08:00:00 Storage 2: id = 172.16.1.206 ip_addr = 172.16.1.206 ACTIVE http domain = version = 5.01 join time = 2014-03-26 22:38:04 up time = 2014-03-26 22:38:04 total storage = 27789 MB free storage = 23825 MB upload priority = 10 store_path_count = 1 subdir_count_per_path = 256 storage_port = 23000 storage_http_port = 8080 current_write_path = 0 source storage id= 172.16.1.205 if_trunk_server= 0 total_upload_count = 0 success_upload_count = 0 total_append_count = 0 success_append_count = 0 total_modify_count = 0 success_modify_count = 0 total_truncate_count = 0 success_truncate_count = 0 total_set_meta_count = 0 success_set_meta_count = 0 total_delete_count = 0 success_delete_count = 0 total_download_count = 0 success_download_count = 0 total_get_meta_count = 0 success_get_meta_count = 0 total_create_link_count = 0 success_create_link_count = 0 total_delete_link_count = 0 success_delete_link_count = 0 total_upload_bytes = 0 success_upload_bytes = 0 total_append_bytes = 0 success_append_bytes = 0 total_modify_bytes = 0 success_modify_bytes = 0 stotal_download_bytes = 0 success_download_bytes = 0 total_sync_in_bytes = 0 success_sync_in_bytes = 0 total_sync_out_bytes = 0 success_sync_out_bytes = 0 total_file_open_count = 0 success_file_open_count = 0 total_file_read_count = 0 success_file_read_count = 0 total_file_write_count = 0 success_file_write_count = 0 last_heart_beat_time = 2014-03-26 15:01:02 last_source_update = 1970-01-01 08:00:00 last_sync_update = 1970-01-01 08:00:00 last_synced_timestamp = 1970-01-01 08:00:00
Group 3: group name = group3 disk total space = 27789 MB disk free space = 23825 MB trunk free space = 0 MB storage server count = 2 active server count = 2 storage server port = 23000 storage HTTP port = 8080 store path count = 1 subdir count per path = 256 current write server index = 1 current trunk file id = 0
Storage 1: id = 172.16.1.207 ip_addr = 172.16.1.207 ACTIVE http domain = version = 5.01 join time = 2014-03-26 22:50:28 up time = 2014-03-26 22:50:28 total storage = 27789 MB free storage = 23825 MB upload priority = 10 store_path_count = 1 subdir_count_per_path = 256 storage_port = 23000 storage_http_port = 8080 current_write_path = 0 source storage id= 172.16.1.208 if_trunk_server= 0 total_upload_count = 1 success_upload_count = 1 total_append_count = 0 success_append_count = 0 total_modify_count = 0 success_modify_count = 0 total_truncate_count = 0 success_truncate_count = 0 total_set_meta_count = 0 success_set_meta_count = 0 total_delete_count = 0 success_delete_count = 0 total_download_count = 0 success_download_count = 0 total_get_meta_count = 0 success_get_meta_count = 0 total_create_link_count = 0 success_create_link_count = 0 total_delete_link_count = 0 success_delete_link_count = 0 total_upload_bytes = 35374 success_upload_bytes = 35374 total_append_bytes = 0 success_append_bytes = 0 total_modify_bytes = 0 success_modify_bytes = 0 stotal_download_bytes = 0 success_download_bytes = 0 total_sync_in_bytes = 0 success_sync_in_bytes = 0 total_sync_out_bytes = 0 success_sync_out_bytes = 0 total_file_open_count = 1 success_file_open_count = 1 total_file_read_count = 0 success_file_read_count = 0 total_file_write_count = 1 success_file_write_count = 1 last_heart_beat_time = 2014-03-26 15:01:20 last_source_update = 2014-03-27 03:20:13 last_sync_update = 1970-01-01 08:00:00 last_synced_timestamp = 1970-01-01 08:00:00 Storage 2: id = 172.16.1.208 ip_addr = 172.16.1.208 ACTIVE http domain = version = 5.01 join time = 2014-03-26 22:49:37 up time = 2014-03-26 22:49:37 total storage = 27789 MB free storage = 23825 MB upload priority = 10 store_path_count = 1 subdir_count_per_path = 256 storage_port = 23000 storage_http_port = 8080 current_write_path = 0 source storage id= if_trunk_server= 0 total_upload_count = 0 success_upload_count = 0 total_append_count = 0 success_append_count = 0 total_modify_count = 0 success_modify_count = 0 total_truncate_count = 0 success_truncate_count = 0 total_set_meta_count = 0 success_set_meta_count = 0 total_delete_count = 0 success_delete_count = 0 total_download_count = 0 success_download_count = 0 total_get_meta_count = 0 success_get_meta_count = 0 total_create_link_count = 0 success_create_link_count = 0 total_delete_link_count = 0 success_delete_link_count = 0 total_upload_bytes = 0 success_upload_bytes = 0 total_append_bytes = 0 success_append_bytes = 0 total_modify_bytes = 0 success_modify_bytes = 0 stotal_download_bytes = 0 success_download_bytes = 0 total_sync_in_bytes = 35374 success_sync_in_bytes = 35374 total_sync_out_bytes = 0 success_sync_out_bytes = 0 total_file_open_count = 1 success_file_open_count = 1 total_file_read_count = 0 success_file_read_count = 0 total_file_write_count = 1 success_file_write_count = 1 last_heart_beat_time = 2014-03-26 15:01:32 last_source_update = 1970-01-01 08:00:00 last_sync_update = 2014-03-27 03:20:19 last_synced_timestamp = 2014-03-27 03:20:14 (-1s delay) |
l 使用fdfs_crc32獲取文件CRC
l 使用fdfs_delete_file刪除文件
l 使用fdfs_file_info查看文件屬性信息
以上全部功能都可使用接口在代碼中調用。