Nginx 跳轉fastdfs儲存圖片地址報錯問題分析過程匯總

來源:互聯網
上載者:User

標籤:

1,問題描述

上傳壓縮圖片報錯:org.csource.common.MyException: getStoreStorage fail, errno code: 2


原因是dns網域名稱ping不通traker,改成ip地址OK了,如下所示:

[[email protected] logs]# vim/etc/fdfs/storage_group2.conf

#tracker_server=tracker.mytest.com:22122

tracker_server=192.168.121.219:22122

然後重啟storeage服務

/usr/local/bin/fdfs_storaged/etc/fdfs/storage_group2.conf &


 

2,check,進去/home/plocc/fastdfs_group2目錄下面有logs目錄

再進去看日誌資訊,一切正常,如下所示:

[[email protected] ~]# ll/home/plocc/fastdfs_group2/

total 8

drwxr-xr-x. 259 root root 4096 May  4  2014data

drwxr-xr-x.   2 root root 4096 May  4  2014logs

[[email protected] ~]#

cd /home/plocc/fastdfs_group2/logs

[[email protected] logs]# tail -f storaged.log

...... 

[2015-03-30 09:41:07] INFO - file:storage_param_getter.c, line: 187, use_storage_id=0, id_type_in_filename=ip,storage_ip_changed_auto_adjust=1, store_path=0, reserved_storage_space=20.00%,use_trunk_file=0, slot_min_size=256, slot_max_size=16 MB, trunk_file_size=64MB, trunk_create_file_advance=0, trunk_create_file_time_base=02:00,trunk_create_file_interval=86400, trunk_create_file_space_threshold=20 GB,trunk_init_check_occupying=0, trunk_init_reload_from_binlog=0,store_slave_file_use_link=0

[2015-03-30 09:41:07] INFO - file:storage_func.c, line: 174, tracker_client_ip: 192.168.121.220,my_server_id_str: 192.168.121.220, g_server_id_in_filename: -596006720

[2015-03-30 09:41:07] INFO -local_host_ip_count: 2,  127.0.0.1  192.168.121.220

[2015-03-30 09:41:08] INFO - file:tracker_client_thread.c, line: 308, successfully connect to tracker server192.168.121.219:22122, as a tracker client, my ip is 192.168.121.220

[2015-03-30 09:41:08] INFO - file:tracker_client_thread.c, line: 1124, tracker server 192.168.121.219:22122, settracker leader: 192.168.121.219:22122

 

3,新問題來了,然後圖片下載的時候,報錯如下:

下載圖片group2/M00/00/B4/wKh53FUYq1eAPeAWAABs0PIXl7w885.jpg 時出錯.

先去查下fastdfs伺服器上是否有這個檔案,查詢到確實有這個檔案的

[[email protected] data]# find . -namewKh53FUYq1eAPeAWAABs0PIXl7w885.jpg

./00/B4/wKh53FUYq1eAPeAWAABs0PIXl7w885.jpg

[[email protected] data]# pwd

/home/plocc/fastdfs_group2/data

[[email protected] data]#

 

問題在哪裡呢?,我們通過網站上一個能訪問的圖片地址,來檢查判斷。隨意開啟網站一個圖片,在圖片上面右鍵點擊,選擇“複製圖片地址”,得到如下資訊:

http://static.mytest.com/group1/M00/03/AF/wKi0d1QGA0qANZk5AABawNvHeF0411.png

 

4,ping下static.mytest.com,去上面檢查nginx配置

ping一下這個static.mytest.com,去看下是在哪一台伺服器上面:

[[email protected] ~]# ping static.mytest.com

PING static.mytest.com (192.168.121.221)56(84) bytes of data.

64 bytes from 192.168.121.221: icmp_seq=1ttl=64 time=0.251 ms

64 bytes from 192.168.121.221: icmp_seq=2ttl=64 time=0.326 ms

64 bytes from 192.168.121.221: icmp_seq=3ttl=64 time=0.305 ms

64 bytes from 192.168.121.221: icmp_seq=4ttl=64 time=0.299 ms

^C

--- static.mytest.com ping statistics ---

4 packets transmitted, 4 received, 0%packet loss, time 3762ms

rtt min/avg/max/mdev =0.251/0.295/0.326/0.030 ms

[[email protected] ~]#

 

然後進去192.168.121.221裡面去查看裡面的nginx配置,進入

[[email protected] ~]# cd/usr/local/nginx/conf

[[email protected] conf]# vim nginx.conf #進去檢索/group2或者group1

會發現如下配置:

       location ~* ^/group1/.*$ {

         proxy_pass http://filebackend;

       }

 

       location ~* ^/group2/.*$ {

         proxy_pass http://filebackend;

       }

然後再繼續在nginx.cnf裡面需找filebackend的配置,會看到如下配置:

  upstream filebackend{

     server dfs.mytest.com:8090;

    }

 

5,去檢查nginx裡面filebackend所對應的dfs.mytest.com

去ping下dfs.mytest.com,看看去訪問那個地址

[[email protected] ~]# ping dns.mytest.com

PING dns.mytest.com (192.168.121.212)56(84) bytes of data.

64 bytes from 192.168.121.212: icmp_seq=1ttl=64 time=0.081 ms

64 bytes from 192.168.121.212: icmp_seq=2ttl=64 time=0.110 ms

64 bytes from 192.168.121.212: icmp_seq=3ttl=64 time=0.104 ms

^C

--- dns.mytest.com ping statistics ---

3 packets transmitted, 3 received, 0%packet loss, time 2275ms

rtt min/avg/max/mdev =0.081/0.098/0.110/0.014 ms

[[email protected] ~]#

 

然後去192.168.121.212裡面去看下nginx配置,需找/group1或者group2,發現有group1沒有group2

       location ~* ^/group1/.*$ {

         proxy_pass http://filebackend;

         include proxy.conf;

 

         error_log  logs/file_error.loginfo;

         access_log logs/file_access.log  main;

       }

 

所以追加一個group2

       location ~* ^/group2/.*$ {

         proxy_pass http://filebackend;

         include proxy.conf;

 

         error_log  logs/file_error.loginfo;

         access_log logs/file_access.log  main;

       }                

 

我們在繼續在nginx.conf裡面檢索filebackend,看看指向哪裡

   upstream filebackend{

     server 192.168.121.220:8090;

}

 

6,去upstream伺服器121.220上面查看nginx服務8090

 

看到指向192.168.121.220,然後我們去192.168.121.220上找fastdfs檔案伺服器,先去查看下後台進程找到fastdfs的設定檔路徑

[[email protected] bin]# ps -eaf|grepfdfs_storaged

root    25036     1  0 09:41 ?        00:00:00 /usr/local/bin/fdfs_storaged/etc/fdfs/storage_group2.conf

root    25176 25121  0 11:00 pts/2    00:00:00 grep fdfs_storaged

[[email protected] bin]#

 

然後再去設定檔裡面/etc/fdfs/storage_group2.conf去查看圖片檔案存放路徑

[[email protected] bin]# vim /etc/fdfs/storage_group2.conf

# the base path to store data and log files

base_path=/home/plocc/fastdfs_group2

然後去/home/plocc/fastdfs_group2路徑下面尋找下載圖片儲存的圖片是否存在這裡:

然後圖片下載的時候,報錯如下:下載圖片

group2/M00/00/B4/wKh53FUYq1eAPeAWAABs0PIXl7w885.jpg 時出錯.

[[email protected] fastdfs_group2]# find .-name wKh53FUYq1eAPeAWAABs0PIXl7w885.jpg

./data/00/B4/wKh53FUYq1eAPeAWAABs0PIXl7w885.jpg

[[email protected] fastdfs_group2]#

檔案是存在的,所以然後需要在fastdfs本地提供的服務 server 192.168.121.220:8090;去找8090連接埠

 

 

[[email protected] conf]# netstat -anp |grep8090

tcp        0     0 0.0.0.0:8090               0.0.0.0:*                   LISTEN      1266/nginx         

[[email protected] conf]#

是在nginx上面,我們去看nginx的配置

   server {

       listen       8090;

       server_name  localhost;

 

       #charset koi8-r;

 

       #access_log logs/host.access.log  main;

 

       location /group1/M00 {

           root   /home/plocc/fastdfs/data;

           ngx_fastdfs_module;

       }

       location /group2/M00 {

           root   /home/plocc/fastdfs_group2;

           ngx_fastdfs_module;

       }

看到裡面有/group2/M00,我們再去/home/plocc/fastdfs_group2裡面看片是否存在這裡面

[[email protected] conf]# cd/home/plocc/fastdfs_group2

[[email protected] fastdfs_group2]# find .-name wKh53FUYq1eAPeAWAABs0PIXl7w885.jpg

./data/00/B4/wKh53FUYq1eAPeAWAABs0PIXl7w885.jpg

[[email protected] fastdfs_group2]#

圖片是存在的,那麼我們套用下group1的地址首碼http://static.mytest.com,套在下載失敗的那個上面,url如下

http://static.mytest.com/group2/M00/00/B4/wKh53FUYq1eAPeAWAABs0PIXl7w885.jpg,如下1.png所示:

 


跟開發人員說地址能正常訪問,開發人員去查看了下代碼,結果發現問題出在他配置的圖片下載host地址的路徑不對,修改正常的host路徑,就能訪問圖片了。

 

 

 

7,Nginx報錯:open log file "/home/plocc/fastdfs/logs/mod_fastdfs.log"to write fail,

 

PS:一個報錯總結記錄

[[email protected] logs]# tail -f error.log

2015/03/30 14:52:22 [alert] 26293#0: workerprocess 26297 exited with fatal code 2 and cannot be respawned

open log file"/home/plocc/fastdfs/logs/mod_fastdfs.log" to write fail, errno: 13,error info: Permission denied2015/03/30 14:52:22 [alert] 26293#0: workerprocess 26294 exited with fatal code 2 and cannot be respawned

ngx_http_fastdfs_process_init pid=26305

ngx_http_fastdfs_process_init pid=26306

open log file"/home/plocc/fastdfs/logs/mod_fastdfs.log" to write fail, errno: 13,error info: Permission deniedngx_http_fastdfs_process_init pid=26308

ngx_http_fastdfs_process_init pid=26307

open log file"/home/plocc/fastdfs/logs/mod_fastdfs.log" to write fail, errno: 13,error info: Permission deniedopen log file "/home/plocc/fastdfs/logs/mod_fastdfs.log"to write fail, errno: 13, error info: Permission denied2015/03/30 14:53:50[alert] 26304#0: worker process 26305 exited with fatal code 2 and cannot berespawned

2015/03/30 14:53:50 [alert] 26304#0: workerprocess 26306 exited with fatal code 2 and cannot be respawned

open log file"/home/plocc/fastdfs/logs/mod_fastdfs.log" to write fail, errno: 13,error info: Permission denied2015/03/30 14:53:50 [alert] 26304#0: workerprocess 26308 exited with fatal code 2 and cannot be respawned

2015/03/30 14:53:50 [alert] 26304#0: workerprocess 26307 exited with fatal code 2 and cannot be respawned

 

^C

[[email protected] logs]#

需要賦予777的許可權

chmod 777/home/plocc/fastdfs/logs/mod_fastdfs.log

然後重啟fastdfs storage服務,搞定。


 ----------------------------------------------------------------------------------------------------------------
<著作權所有,文章允許轉載,但必須以連結方式註明源地址,否則追究法律責任!>
原部落格地址:      http://blog.itpub.net/26230597/viewspace-1479382/
原黃杉 (mchdba)
----------------------------------------------------------------------------------------------------------------

Nginx 跳轉fastdfs儲存圖片地址報錯問題分析過程匯總

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.