ubuntu傻瓜式搭建fastDFS
阿新 • • 發佈:2021-08-13
-
安裝基礎環境
-
apt install git gcc make automake autoconf libtool wget vim -y
-
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資料夾下了,請根據實際情況)- 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
-
安裝pcre庫
- wget https://ftp.pcre.org/pub/pcre/pcre-8.33.tar.gz
- tar zxvf pcre-8.33.tar.gz
- ./configure
- make && make install
- wget https://ftp.pcre.org/pub/pcre/pcre-8.33.tar.gz
-
安裝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/
- ./configure --add-module=/usr/local/src/fastdfs-nginx-module/src/ # 新增fastdfs-nginx-module模組
- make && make install #編譯安裝
-
單機部署 tracker配置
- 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.1.172:22122 # tracker伺服器IP和埠 http.server_port=8888 # http訪問檔案的埠(預設8888,看情況修改,和nginx中保持一致)
-
client配置
- vim /etc/fdfs/client.conf
base_path=/home/dfs
2. tracker_server=192.168.1.172:22122 #tracker伺服器IP和埠
-
進行測試上傳功能
-
fdfs_upload_file /etc/fdfs/client.conf /usr/local/src/nginx-1.15.4.tar.gz
-
儲存後測試,返回ID表示成功 如:group1/M00/00/00/xx.tar.gz
-
-
配置fastdfs-nginx-module模組
- vim /etc/fdfs/mod_fastdfs.conf
tracker_server=192.168.1.172:22122 #tracker伺服器IP和埠 url_have_group_name=true store_path0=/home/dfs
-
配置nginx
- 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.1.172:8888/group1/M00/00/00/wKgAQ1pysxmAaqhAAA76tz-dVgg.tar.gz
- 其他問題
- 使用
/usr/local/nginx/sbin/nginx
啟動nginx時,出現/usr/local/nginx/sbin/nginx: error while loading shared libraries: libpcre.so.1: cannot open shared object file: No such file or directory
,可以查閱pcre常見問題
- 使用
彈出下載單機部署全部跑通
常用命令
tracker
- fdfs_trackerd /etc/fdfs/tracker.conf #啟動trackerd
- fdfs_trackerd /etc/fdfs/tracker.conf restart #重啟動tracker服務
- fdfs_trackerd /etc/fdfs/tracker.conf stop #停止tracker服務
- chkconfig fdfs_trackerd on #自啟動tracker服務
storage
-
fdfs_storaged /etc/fdfs/storage.conf # 啟動storage服務
-
fdfs_storaged /etc/fdfs/storage.conf restart #重動storage服務
-
fdfs_storaged /etc/fdfs/storage.conf 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/local/nginx/sbin/nginx -t #校驗配置檔案正確性