Fastdfs環境搭建

環境準備

使用的系統軟件

名稱 說明
centos 7.x
libfatscommon FastDFS分離出的一些公用函數包
FastDFS FastDFS本體
fastdfs-nginx-module FastDFS和nginx的關聯模塊
nginx nginx1.15.4

編譯環境

yum install git gcc gcc-c++ make automake autoconf libtool pcre pcre-devel zlib zlib-devel openssl-devel wget vim -y

磁盤目錄

說明 位置
全部安裝包 /usr/local/src
數據存儲位置 /home/dfs/
#這裏我爲了方便把日誌什麼的都放到了dfs  
mkdir /home/dfs #建立數據存儲目錄 cd /usr/local/src #切換到安裝目錄準備下載安裝包

安裝libfatscommon

git clone https://github.com/happyfish100/libfastcommon.git --depth 1
cd libfastcommon/
./make.sh && ./make.sh install #編譯安裝

安裝FastDFS

cd ../ #返回上一級目錄 git clone https://github.com/happyfish100/fastdfs.git --depth 1 cd fastdfs/ ./make.sh && ./make.sh install #編譯安裝 #配置文件準備 cp /etc/fdfs/tracker.conf.sample /etc/fdfs/tracker.conf cp /etc/fdfs/storage.conf.sample /etc/fdfs/storage.conf cp /etc/fdfs/client.conf.sample /etc/fdfs/client.conf #客戶端文件,測試用 cp /usr/local/src/fastdfs/conf/http.conf /etc/fdfs/ #供nginx訪問使用 cp /usr/local/src/fastdfs/conf/mime.types /etc/fdfs/ #供nginx訪問使用

安裝fastdfs-nginx-module

cd ../ #返回上一級目錄 git clone https://github.com/happyfish100/fastdfs-nginx-module.git --depth 1 cp /usr/local/src/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs

安裝nginx

wget http://nginx.org/download/nginx-1.15.4.tar.gz #下載nginx壓縮包 tar -zxvf nginx-1.15.4.tar.gz #解壓 cd nginx-1.15.4/ #添加fastdfs-nginx-module模塊 ./configure --add-module=/usr/local/src/fastdfs-nginx-module/src/ make && make install #編譯安裝

單機部署

tracker配置

#服務器ip爲 192.168.52.1 #我建議用ftp下載下來這些文件 本地修改 vim /etc/fdfs/tracker.conf #須要修改的內容以下 port=22122 # tracker服務器端口(默認22122,通常不修改) base_path=/home/dfs # 存儲日誌和數據的根目錄

storage配置

vim /etc/fdfs/storage.conf
#須要修改的內容以下 port=23000 # storage服務端口(默認23000,通常不修改) base_path=/home/dfs # 數據和日誌文件存儲根目錄 store_path0=/home/dfs # 第一個存儲目錄 tracker_server=192.168.52.1:22122 # tracker服務器IP和端口 http.server_port=8888 # http訪問文件的端口(默認8888,看狀況修改,和nginx中保持一致)

client測試

vim /etc/fdfs/client.conf
#須要修改的內容以下 base_path=/home/dfs tracker_server=192.168.52.1:22122 #tracker服務器IP和端口 #保存後測試,返回ID表示成功 如:group1/M00/00/00/xx.tar.gz fdfs_upload_file /etc/fdfs/client.conf /usr/local/src/nginx-1.15.4.tar.gz

配置nginx訪問

vim /etc/fdfs/mod_fastdfs.conf
#須要修改的內容以下 tracker_server=192.168.52.1:22122 #tracker服務器IP和端口 url_have_group_name=true store_path0=/home/dfs #配置nginx.config vim /usr/local/nginx/conf/nginx.conf #添加以下配置 server { listen 8888; ## 該端口爲storage.conf中的http.server_port相同 server_name localhost; location ~/group[0-9]/ { ngx_fastdfs_module; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } #測試下載,用外部瀏覽器訪問剛纔已傳過的nginx安裝包,引用返回的ID http://192.168.52.1:8888/group1/M00/00/00/wKgAQ1pysxmAaqhAAA76tz-dVgg.tar.gz #彈出下載單機部署所有跑通

分佈式部署

tracker配置

#服務器ip爲 192.168.52.2,192.168.52.3,192.168.52.4 #我建議用ftp下載下來這些文件 本地修改 vim /etc/fdfs/tracker.conf #須要修改的內容以下 port=22122 # tracker服務器端口(默認22122,通常不修改) base_path=/home/dfs # 存儲日誌和數據的根目錄

storage配置

vim /etc/fdfs/storage.conf
#須要修改的內容以下 port=23000 # storage服務端口(默認23000,通常不修改) base_path=/home/dfs # 數據和日誌文件存儲根目錄 store_path0=/home/dfs # 第一個存儲目錄 tracker_server=192.168.52.2:22122 # 服務器1 tracker_server=192.168.52.3:22122 # 服務器2 tracker_server=192.168.52.4:22122 # 服務器3 http.server_port=8888 # http訪問文件的端口(默認8888,看狀況修改,和nginx中保持一致)

client測試

vim /etc/fdfs/client.conf
#須要修改的內容以下 base_path=/home/moe/dfs tracker_server=192.168.52.2:22122 # 服務器1 tracker_server=192.168.52.3:22122 # 服務器2 tracker_server=192.168.52.4:22122 # 服務器3 #保存後測試,返回ID表示成功 如:group1/M00/00/00/xx.tar.gz fdfs_upload_file /etc/fdfs/client.conf /usr/local/src/nginx-1.15.4.tar.gz

配置nginx訪問

vim /etc/fdfs/mod_fastdfs.conf
#須要修改的內容以下 tracker_server=192.168.52.2:22122 # 服務器1 tracker_server=192.168.52.3:22122 # 服務器2 tracker_server=192.168.52.4:22122 # 服務器3 url_have_group_name=true store_path0=/home/dfs #配置nginx.config vim /usr/local/nginx/conf/nginx.conf #添加以下配置 server { listen 8888; ## 該端口爲storage.conf中的http.server_port相同 server_name localhost; location ~/group[0-9]/ { ngx_fastdfs_module; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } }

啓動

防火牆

#不關閉防火牆的話沒法使用 systemctl stop firewalld.service #關閉 systemctl restart firewalld.service #重啓

tracker

/etc/init.d/fdfs_trackerd start #啓動tracker服務 /etc/init.d/fdfs_trackerd restart #重啓動tracker服務 /etc/init.d/fdfs_trackerd stop #中止tracker服務 chkconfig fdfs_trackerd on #自啓動tracker服務

storage

/etc/init.d/fdfs_storaged start #啓動storage服務 /etc/init.d/fdfs_storaged restart #重動storage服務 /etc/init.d/fdfs_storaged stop #中止動storage服務 chkconfig fdfs_storaged on #自啓動storage服務

nginx

/usr/local/nginx/sbin/nginx #啓動nginx /usr/local/nginx/sbin/nginx -s reload #重啓nginx /usr/local/nginx/sbin/nginx -s stop #中止nginx

檢測集羣

/usr/bin/fdfs_monitor /etc/fdfs/storage.conf
# 會顯示會有幾臺服務器 有3臺就會 顯示 Storage 1-Storage 3的詳細信息

說明

配置文件

tracker_server #有幾臺服務器寫幾個 group_name #地址的名稱的命名 bind_addr #服務器ip綁定 store_path_count #store_path(數字)有幾個寫幾個 store_path(數字) #設置幾個儲存地址寫幾個 從0開始

可能遇到的問題

若是不是root 用戶 你必須在除了cd的命令以外 所有加sudo
若是不是root 用戶 編譯和安裝分開進行 先編譯再安裝
若是上傳成功 可是nginx報錯404 先檢查mod_fastdfs.conf文件中的store_path0是否一致
若是nginx沒法訪問 先檢查防火牆 和 mod_fastdfs.conf文件tracker_server是否一致
若是不是在/usr/local/src文件夾下安裝 可能會編譯出錯文章轉自:https://github.com/happyfish100/fastdfs/wiki
相關文章
相關標籤/搜索