Centos7 fastdfs/nginx 安裝與配置
參考文章
伺服器環境
- CentOS7
- IP: 192.168.219.21
FastDFS安裝與配置
安裝開發環境
yum groupinstall "Development Tools" "Server platform Development"
安裝 libfastcommon
安裝 fastdfs
配置 tracker
cd /etc/fdfs
cp tracker.conf.sample tracker.conf
vim /etc/fdfs/tracker.confdisabled=false(預設為false,表示是否無效)
port=22122(預設為22122)
base_path=/data/fdfs/tracker
配置 client.conf
cd /etc/fdfs
cp client.conf.sample client.conf
vim /etc/fdfs/client.confbase_path=/data/fdfs/tracker
tracker_server=192.168.219.21:22122
建立 tracker 目錄
mkdir -pv /data/fdfs/tracker
啟動 tracker
centos6 啟動方式
service fdfs_trackerd start
centos7 啟動方式
/etc/init.d/fdfs_trackerd start
檢視埠
ss -lntup|grep 22122
tcp LISTEN 0 128 :22122 :* users:((“fdfs_trackerd”,3785,5))
關閉tracker
/etc/init.d/fdfs_trackerd stop
注意:雖然FastDFS區分tracker和storage伺服器,但是安裝的軟體及步驟均相同,只是不同的配置檔案而已,因此以上安裝適用tracker server和storage server
配置 storage
cd /etc/fdfs
cp storage.conf.sample storage.conf
vim /etc/fdfs/storage.confdisabled=false(預設為false,表示是否無效)
port=23000(預設為23000)
group_name=group1 #指定組名
base_path=/data/fdfs/storage # 用於儲存資料
store_path_count=2 # 設定裝置數量
store_path0=/data/fdfs/storage/m0 #指定儲存路徑0
store_path1=/data/fdfs/storage/m1 #指定儲存路徑1
注意:同一組記憶體儲路徑不能衝突,例如:下一個節點的儲存路徑就是m2,m3….等
tracker_server=192.168.219.21:22122 #指定tracker
http.server_port=8888(預設為8888,nginx中配置的監聽埠那之一致)mkdir -pv /data/fdfs/storage/{m0,m1} # 建立資料目錄
啟動 storage
必須先啟動tracker,再啟動storage
// centos6 啟動方式
service fdfs_storaged start
// centos7 啟動方式
/etc/init.d/fdfs_storaged start
// 檢視埠
ss -lntup|grep 23000
LISTEN 0 128 :23000 :*
// 關閉storage
/etc/init.d/fdfs_storaged stop
檔案上傳測試
/usr/bin/fdfs_upload_file /etc/fdfs/client.conf /home/alex/test.png
group1/M00/00/00/wKjbFVoXuUqALADZAAdIM2UokFM563.png
返回檔案ID即說明檔案已經上傳成功
儲存伺服器(storage server)安裝並配置nginx
安裝 fastdfs-nginx-module 模組
cd /root
git clone https://github.com/happyfish100/fastdfs-nginx-module
cp /root/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs/
vim /etc/fdfs/mod_fastdfs.confconnect_timeout=10
base_path=/tmp(預設為/tmp)
tracker_server=192.168.219.21:22122
storage_server_port=23000(預設配置為23000)
url_have_group_name = true
store_path_count=2 # 設定裝置數量
store_path0=/data/fdfs/storage/m0
store_path0=/data/fdfs/storage/m1
group_name=group1(預設配置為group1)
安裝 nginx 依賴庫
yum -y install pcre-devel zlib-devel
yum -y install openssl openssl-devel
安裝 nginx
cd /root
wget http://nginx.org/download/nginx-1.8.1.tar.gz
tar xf nginx-1.8.1.tar.gz
cd nginx-1.8.1
./configure --prefix=/application/nginx/ --add-module=../fastdfs-nginx-module/src/
make && make install
cp /root/fastdfs/conf/http.conf /etc/fdfs/
cp /root/fastdfs/conf/mime.types /etc/fdfs/
配置 nginx
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;
}
}
}
啟動 nginx
cp /application/nginx/sbin/nginx /etc/init.d/
/etc/init.d/nginxss -lntup|grep 8888
tcp LISTEN 0 128 :8888 :* users:((“nginx”,7308,6),(“nginx”,7309,6))
配置 firewalld-cmd
開啟8888埠
新增
firewall-cmd –zone=public –add-port=8888/tcp –permanent (–permanent永久生效,沒有此引數重啟後失效)
重新載入
firewall-cmd –reload