1. 程式人生 > >搭建圖片伺服器

搭建圖片伺服器

一、安裝並配置FastDFS

1、執行環境及相關軟體

CentOS 7.4 64位

FastDFS_v5.08.tar.gz

nginx-1.8.1.tar.gz

fastdfs-nginx-module_v1.16.tar.gz

libfastcommon

2、伺服器規劃

伺服器名稱 IP地址和埠 備註
fastdfs-tracker 192.168.25.133:22122 跟蹤伺服器/排程伺服器
fastdfs-storage 192.168.25.133:23000 儲存伺服器

3、安裝FastDFS

3.1 首先建立工具目錄(非必須)

[[email protected]
~]# mkdir -p /home/oldcat/tools [[email protected] ~]# cd /home/oldcat/tools/

3.2 下載並安裝FastDFS依賴包libfastcommon

[[email protected] tools]# wget https://codeload.github.com/happyfish100/libfastcommon/zip/master
[[email protected] tools]# unzip master
[[email protected] tools]# cd libfastcommon-master/
[
[email protected]
libfastcommon-master]# ls HISTORY INSTALL libfastcommon.spec make.sh php-fastcommon README src [[email protected] libfastcommon-master]# ./make.sh [[email protected] libfastcommon-master]# ./make.sh install
提示:如果執行第二句話報以下錯,沒報錯直接3.3
-bash: unzip: command not found

則是命令沒有找到,其原因肯定是沒有安裝unzip。
安裝命令是:

yum install -y unzip zip

3.3 下載並安裝FastDFS

[[email protected] tools]# wget http://jaist.dl.sourceforge.net/project/fastdfs/FastDFS%20Server%20Source%20Code/FastDFS%20Server%20with%20PHP%20Extension%20Source%20Code%20V5.08/FastDFS_v5.08.tar.gz
[[email protected] tools]# tar xf FastDFS_v5.08.tar.gz
[[email protected] tools]# cd FastDFS
[[email protected] FastDFS]# ./make.sh && ./make.sh install

採用預設方式安裝後的檔案及目錄:

  • 服務指令碼:
[[email protected] ~]# ll /etc/init.d/ |grep fdfs
-rwxr-xr-x. 1 root root   918 4月  22 22:08 fdfs_storaged
-rwxr-xr-x. 1 root root   920 4月  22 22:08 fdfs_trackerd
  • 樣例配置檔案
[[email protected] ~]# ll /etc/fdfs/
總用量 20
-rw-r--r--. 1 root root 1461 4月  22 22:08 client.conf.sample
-rw-r--r--. 1 root root 7927 4月  22 22:08 storage.conf.sample
-rw-r--r--. 1 root root 7200 4月  22 22:08 tracker.conf.sample
  • 命令列工具
[[email protected] ~]# ll /usr/bin|grep fdfs
-rwxr-xr-x.   1 root root     252272 4月  22 22:08 fdfs_appender_test
-rwxr-xr-x.   1 root root     252225 4月  22 22:08 fdfs_appender_test1
-rwxr-xr-x.   1 root root     242449 4月  22 22:08 fdfs_append_file
-rwxr-xr-x.   1 root root     242013 4月  22 22:08 fdfs_crc32
-rwxr-xr-x.   1 root root     242508 4月  22 22:08 fdfs_delete_file
-rwxr-xr-x.   1 root root     243627 4月  22 22:08 fdfs_download_file
-rwxr-xr-x.   1 root root     243369 4月  22 22:08 fdfs_file_info
-rwxr-xr-x.   1 root root     255657 4月  22 22:08 fdfs_monitor
-rwxr-xr-x.   1 root root     863913 4月  22 22:08 fdfs_storaged
-rwxr-xr-x.   1 root root     258712 4月  22 22:08 fdfs_test
-rwxr-xr-x.   1 root root     257881 4月  22 22:08 fdfs_test1
-rwxr-xr-x.   1 root root     365232 4月  22 22:08 fdfs_trackerd
-rwxr-xr-x.   1 root root     243547 4月  22 22:08 fdfs_upload_appender
-rwxr-xr-x.   1 root root     244453 4月  22 22:08 fdfs_upload_file
注意:雖然FastDFS區分tracker和storage伺服器,但是安裝的軟體及步驟均相同,只是不同的配置檔案而已,因此以上安裝適用tracker server和storage server

4、配置跟蹤伺服器(tracker server)

4.1拷貝tracker server和client端樣例配置檔案並重命名

[[email protected] ~]# cp /etc/fdfs/tracker.conf.sample /etc/fdfs/tracker.conf
[[email protected] ~]# cp /etc/fdfs/client.conf.sample /etc/fdfs/client.conf

4.2 編輯tracker server配置檔案tracker.conf,需要修改內容如下:

disabled=false(預設為false,表示是否無效)
port=22122(預設為22122)
base_path=/data/fastdfs/tracker

4.3 編輯client端的配置檔案client.conf,需要修改內如下

base_path=/data/fastdfs/tracker
tracker_server=192.168.25.133:22122
IP填寫自己伺服器的公有IP(必須),如果是虛擬機器直接用下面的
例:192.168.25.133

4.4 建立tracker server資料目錄

[[email protected] ~]# mkdir -p /data/fastdfs/tracker

4.5 測試啟動trackerserver,啟動成功會自動在/data/fastdfs/tracker目錄建data和logs目錄

[[email protected]fs-tracker ~]# cd /data/fastdfs/tracker/
[[email protected] tracker]# ls
[[email protected] tracker]# /etc/init.d/fdfs_trackerd start
Starting FastDFS tracker server:
[[email protected] tracker]# ss -lntup|grep 22122
tcp    LISTEN     0      128                    *:22122                 *:*      users:(("fdfs_trackerd",3785,5)) 
[[email protected] tracker]# ls
data  logs

4.6 關閉tracker server

[[email protected] tracker]# /etc/init.d/fdfs_trackerd stop
waiting for pid [3785] exit ...
pid [3785] exit.

5、配置儲存伺服器(storage server)

5.1 拷貝storage server樣例配置檔案並重命名

[[email protected] ~]# cp /etc/fdfs/storage.conf.sample /etc/fdfs/storage.conf

5.2 編輯storage server配置檔案storage.conf,需要修改內容如下:

disabled=false(預設為false,表示是否無效)
port=23000(預設為23000)
base_path=/data/fastdfs/storage
tracker_server=192.168.25.133:22122
store_path0=/data/fastdfs/storage
http.server_port=8888(預設為8888,nginx中配置的聽埠那之一致)
IP填寫自己伺服器的公有IP(必須),如果是虛擬機器直接用下面的,必須與上面的tracker server一致
例:192.168.25.133

5.3 建立storage server資料目錄

[[email protected] ~]# mkdir -p /data/fastdfs/storage

5.4 測試啟動storage server,啟動成功會自動在/data/fastdfs/tracker目錄新建data和logs目錄(啟動storage server的前提是tracker server必須事先已啟動)

[[email protected] ~]# cd /data/fastdfs/storage/
[[email protected] storage]# ls
[[email protected] storage]# /etc/init.d/fdfs_storaged start
Starting FastDFS storage server:
[[email protected] storage]# ss -lntup|grep 23000
tcp    LISTEN     0      128                    *:23000                 *:*      users:(("fdfs_storaged",3786,5))
[[email protected] storage]# ls
data  logs

6、檔案上傳測試

執行如下上傳命令:

[[email protected] ~]#mkdir /home/oldcat/imgs
然後通過sftp傳一張圖片到伺服器即可(改名為test.xxx);
[[email protected] ~]# /usr/bin/fdfs_upload_file /etc/fdfs/client.conf /home/oldcat/imgs/test.jpg
group1/M00/00/00/rBIK6VcaP0aARXXvAAHrUgHEviQ394.jpg
返回檔案ID即說明檔案已經上傳成功

二、儲存伺服器(storage server)安裝並配置nginx

1、下載並安裝fastdfs-nginx-module模組

注:FastDFS通過Tracker伺服器,將檔案放在Storage伺服器儲存,但是同組儲存伺服器之間需要進入檔案複製,有同步延遲的問題。假設Tracker伺服器將檔案上傳到了192.168.4.125,上傳成功後文件ID已經返回給客戶端。此時FastDFS儲存叢集機制會將這個檔案同步到同組儲存192.168.4.126,在檔案還沒有複製完成的情況下,客戶端如果用這個檔案ID在192.168.4.126上取檔案,就會出現檔案無法訪問的錯誤。而fastdfs-nginx-module可以重定向檔案連線到源伺服器取檔案,避免客戶端由於複製延遲導致的檔案無法訪問錯誤。

[[email protected]  tools]# wget http://nchc.dl.sourceforge.net/project/fastdfs/FastDFS%20Nginx%20Module%20Source%20Code/fastdfs-nginx-module_v1.16.tar.gz
[[email protected] tools]# tar xf fastdfs-nginx-module_v1.16.tar.gz 
[[email protected] tools]# cd fastdfs-nginx-module/src/
[[email protected] src]# vim config
編輯config檔案,執行如下命令進行批量替換並儲存退出
:%s+/usr/local/+/usr/+g

2、拷貝fastdfs-nginx-module模組中配置檔案到/etc/fdfs目錄中並編輯

[[email protected] ~]# cp /home/oldcat/tools/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs/
[[email protected] ~]# vim /etc/fdfs/mod_fastdfs.conf
修改內容如下:
connect_timeout=10
base_path=/tmp(預設為/tmp)
tracker_server=192.168.25.133:22122(雲伺服器為公有IP)
storage_server_port=23000(預設配置為23000)
url_have_group_name = true
store_path0=/data/fastdfs/storage
group_name=group1(預設配置為group1)

3、安裝nginx依賴庫

[[email protected] nginx-1.8.1]# yum install -y pcre-devel zlib-devel

4、下載並安裝nginx

[[email protected]  tools]# wget http://nginx.org/download/nginx-1.8.1.tar.gz
[[email protected] tools]# tar xf nginx-1.8.1.tar.gz
[[email protected] tools]# cd nginx-1.8.1
[[email protected] nginx-1.8.1]# ./configure --prefix=/application/nginx/ --add-module=../fastdfs-nginx-module/src/
[[email protected] nginx-1.8.1]# make && make install

5、拷貝FastDFS中的部分配置檔案到/etc/fdfs目錄中

[[email protected] ~]# cp /home/oldcat/tools/FastDFS/conf/http.conf /etc/fdfs/
[[email protected] ~]# cp /home/oldcat/tools/FastDFS/conf/mime.types /etc/fdfs/

6、配置nginx,如下所示:

[[email protected] ~]# vim /application/nginx/conf/nginx.conf
    user  root;    
    worker_processes  1;
    events {
       worker_connections  1024;
    }
    http {
        include       mime.types;
        default_type  application/octet-stream;
        sendfile        on;
        keepalive_timeout  65;
        server {
            listen       8888;
            server_name  localhost;
            location ~/group[0-9]/ {
                ngx_fastdfs_module;
            }
            error_page   500 502 503 504  /50x.html;
            location = /50x.html {
            root   html;
            }
        }
    }

說明:

  • "user root"是解決下載操作時報404的問題
  • 8888埠號與/etc/fdfs/storage.conf中的http.server_port=8888相對應
  • storage對應有多個group的情況下,訪問路徑帶group名稱,例如:/group1/M00/00/00/**,對應nginx配置:
    location ~/group[0-9]/ {
        ngx_fastdfs_module;
    }

7、拷貝nginx服務到/etc/init.d/目錄下並啟動

[[email protected] ~]# cp /application/nginx/sbin/nginx /etc/init.d/
[[email protected] ~]# /etc/init.d/nginx
[[email protected] ~]# ss -lntup|grep 8888
tcp    LISTEN     0      128                    *:8888                  *:*      users:(("nginx",7308,6),("nginx",7309,6))

8、通過瀏覽器訪問之前已經上傳的檔案

例:IP:8888/group1/M00/00/00/rBGcBVqBZ_mAGl9oAAEfvSdB99w682.jpg

image
瀏覽器可以成功訪問到上傳的圖片,說明使用FastDFS搭建的圖片伺服器成功完成!

注意:若是在遠端伺服器上此處IP應為公網IP,並且伺服器需要設定安全組開放8888埠

相關推薦

nginx+fastdfs搭建圖片伺服器

本文作者:禹明明,叩丁狼高階講師。原創文章,轉載請註明出處。  fastdfs 是淘寶資深架構師餘慶貢獻的一款開源分散式檔案系統,通常用來做小檔案的儲存或訪問服務,具體用途和架構我們就不多說了,可以看這篇博文了解一下https://blog.csdn.net/u013378

nginx+ftp搭建圖片伺服器(Windows Server伺服器環境下)

轉載請註明出處:https://blog.csdn.net/u012932409/article/details/84892299 幾種圖片伺服器的對比 1、直接使用ftp伺服器,訪問圖片路徑為 ftp://賬戶:密碼@192.168.0.106/31275

nginx+vsftpd搭建圖片伺服器

1.使用yum安裝vsftpd yum -y install vsftpd 2.新增一個ftp使用者,並設定密碼,輸入兩次一樣的密碼 useradd ftpuser passwd ftpuser 使用該使用者登入後,預設的路徑為 /home/ftpuser 3

Nginx搭建圖片伺服器

楔子 指定一個目錄存放圖片,現在需要將其指定給Nginx,使用Nginx作為伺服器來訪問。 Nginx配置 配置參考 位置B 。其實如果僅僅作為圖片訪問,Nginx 不配置其他,直接修改位置A的目錄

windows nginx 搭建 圖片伺服器

windows   nginx   搭建  圖片伺服器    配置如下: #user nobody; worker_processes 2; #錯誤日誌存放路徑 #error_log logs/error.log; #error_log logs/e

FastDFS+Nginx搭建圖片伺服器(親測OK)

前言 操作環境:CentOS7 X64,以下操作都是單機環境。 我把所有的安裝包下載到/softpackage/下,解壓到當前目錄。 先做一件事,修改hosts,將檔案伺服器的ip與域名對映(單機TrackerServer環境),因為後面很多配置裡面都需要去配置伺服器地址,ip變

Ubuntu系統下nginx和ftp搭建圖片伺服器,處理外網訪問不到檔案問題

主要原因:nginx.conf的配置問題 需要配置圖片伺服器 方法一、在配置檔案server{}中location /{} 修改配置: location / {       root /home/uftp/www;#定義伺服器預設的網站根目錄位置       i

linux系統搭建圖片伺服器

第一步:把fastDFS都上傳到linux系統。 第二步:安裝FastDFS之前,先安裝libevent工具包。 yum -y install libevent 第三步:安裝libfastcommonV1.0.7工具包。 1、解壓縮 2、./make.

搭建圖片伺服器

一、安裝並配置FastDFS 1、執行環境及相關軟體 CentOS 7.4 64位 FastDFS_v5.08.tar.gz nginx-1.8.1.tar.gz fastdfs-nginx-mo

使用nginx和vsftpd搭建圖片伺服器

參考一下博文: 目前已知第三步通過nginx訪問虛擬目錄時報404,解決方案是不使用root而是alias,詳情參考下面的博文 目前還差第四步:後臺java程式碼springMVC+spring實現圖片上傳

linux上搭建圖片伺服器

一、安裝Nginx 先安裝Nginx,這裡我就不說怎麼上傳檔案,然後安裝了,現在直接用yum方式安裝吧,命令  yum -y install nginx 二、安裝vsftpd 再安裝vsftpd元件,還是直接yum方式吧,簡單粗暴: yum -y install vsftpd 三、開始搭建Ngi

nginx和vsftpd搭建圖片伺服器

前面已經安裝了vsftpd服務:Vsftpd的安裝和配置。現在再安裝一個nginx伺服器,配合起來就能夠完成一個簡易的圖片伺服器。nginx伺服器之前也研究過,但是沒有做什麼筆記也都全忘了,事實證明不能太相信自己的記憶,好記性不如爛筆頭。 nginx的

搭建圖片伺服器《一》-linux安裝ftp元件

網上好的資料有很多,那麼我就把我自己搭建的過程記錄下來。 1.安裝ftp元件 (1)有網狀態下,並且有yum安裝軟體元件: yum -y install vsftpd (2)不能使用yum或者使用yum安裝失敗的,(我由於linux是redhat5,使用yum安

linux 下nginx+ftp搭建圖片伺服器在本機訪問出現403錯誤的解決辦法

nginx+ftp搭建圖片伺服器修改nginx 配置檔案中root路徑403錯誤 進入配置檔案目錄 cd /usr/local/nginx/conf/ nginx+ftp搭建圖片伺服器修改nginx

Nginx+FastDFS圖片伺服器搭建

文章目錄 nginx的反向代理 反向代理模擬 複製兩個tomcat模擬反向代理 修改tomcat配置檔案 無法訪問歡迎頁面【防火牆問題】 更改兩個index.jsp主頁 反向代理

搭建一個用於學習的 圖片伺服器的過程記錄

 1, 使用IDEA建立一個maven的web工程, 作為伺服器只需要在webapp下建立一個images資料夾作為圖片的儲存目錄,然後在web.xml裡面配置tomcat外掛, 虛擬路徑設定為/, 埠號改為 8003,防止8080埠被意外佔用.  2, 使用springMV

Python中使用Flask、MongoDB搭建簡易圖片伺服器

轉載:http://www.cppcns.com/shujuku/mongodb/119378.html 這篇文章主要介紹了Python中使用Flask、MongoDB搭建簡易圖片伺服器,本文是一個詳細完整的教程,需要的朋友可以參考下 1、前期準備 通過 pip 或 easy_insta

淘淘商城第二天—完成商品新增功能 商品類目選擇 圖片上傳 圖片伺服器搭建 kindEditor富文字編輯器的使用 商品新增功能

1、實現商品類目選擇功能 1.1需求 在商品新增頁面,點選“選擇類目”顯示商品類目列表: 請求初始化樹形控制元件的url:/item/cat/list 1.2 EasyUI tree資料結構 資料結構中必須包含: Id:節點id Text:節

圖片伺服器搭建

當高併發的時候容易發生圖盤上傳到一個伺服器從另一個伺服器需要讀取照片 解決方法: 專門儲存圖片,不管是哪個伺服器接收到圖片,都把圖片上傳到圖片伺服器。 圖片伺服器上需要安裝一個http伺服器,可以使用tomcat、apache、nginx 1、1什麼是FastDFS  

Docker一鍵搭建 FastDFS單機版 圖片伺服器

本教程基於docker和docker-compose環境,使用了morunchang/fastdfs映象(包含nginx訪問模組).可快速實現FastDFS的單機圖片伺服器部署. 1 建立docker檔案結構 檔案結構如下 2 編寫docker