centos7下的FastDFS5.11的安裝與使用
FastDFS是一款開源的輕量級分散式檔案系統,純C實現,支援Linux、FreeBSD等Unix系統。
類google FS,不是通用的檔案系統,只能通過專有API訪問。
FastDFS服務端有兩種角色:跟蹤器(tracker)和儲存節點(storage)。
tracker主要做排程工作,在訪問上起負載均衡的作用,在記憶體中記錄叢集中group和storage的狀態資訊,是連線client和storage的樞紐。
storage儲存伺服器,檔案和檔案屬性都儲存到儲存伺服器上。
FastDFS是C語言開發,建議在linux上執行,本教程使用Centos6.4作為安裝環境。
安裝FastDFS需要先將官網下載的原始碼進行編譯,編譯依賴gcc環境,
如果沒有gcc環境,需要安裝gcc:
yum install -y gcc gcc-c++
如果沒有make命令
yum -y install gcc automake autoconf libtool make
安裝libevent
FastDFS依賴libevent庫,需要安裝:
yum -y install libevent
安裝libfastcommon包
最新下載地址 https://github.com/happyfish100/libfastcommon/releases tar -zxvf libfastcommon-1.0.38.tar.gz -C /usr/local/ cd /usr/local/libfastcommon-1.0.38/ ./make.sh #編譯 ./make.sh install #安裝
libfastcommon安裝好後會在/usr/lib64 目錄下生成 libfastcommon.so 庫檔案;
注意:由於FastDFS程式引用usr/lib目錄所以需要將/usr/lib64下的庫檔案拷貝至/usr/lib下。cp libfastcommon.so /usr/lib
不過最新的libfastcommon-1.0.38.tar安裝後已經不需要往 /usr/lib拷貝了
安裝fastdfs
https://github.com/happyfish100/fastdfs/releases tar -zxvf fastdfs-5.11.tar.gz cd fastdfs-5.11 ./make.sh && ./make.sh install
安裝成功將安裝目錄下的conf下的檔案拷貝到/etc/fdfs/下;
cp /usr/local/FastDFS/conf/* /etc/fdfs/
安裝成功後進入/etc/fdfs目錄:
修改tracker.conf
vi tracker.conf
base_path=/home/yuqing/FastDFS
改為:
base_path=/home/server/fastdfs
啟動tracker,執行如下命令:
/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart
設定開機自動啟動。
vim /etc/rc.d/rc.local
將執行命令列新增進檔案:/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart
配置和啟動storage
由於上面已經安裝過FastDFS,這裡只需要配置storage就好了;
切換目錄到: /etc/fdfs/ 目錄下;
修改storage.conf
vi storage.conf
group_name=group1
base_path=/home/yuqing/FastDFS改為:base_path=/home/FastDFS
store_path0=/home/yuqing/FastDFS改為:store_path0=/home/FastDFS/fdfs_storage
#如果有多個掛載磁碟則定義多個store_path,如下
#store_path1=.....
#store_path2=......
tracker_server=192.168.101.3:22122 #配置tracker伺服器:IP
#如果有多個則配置多個tracker
tracker_server=192.168.101.4:22122
啟動storage,配置開機啟動同trackerserver
/usr/bin/fdfs_storaged /etc/fdfs/storage.conf restart
FastDFS 和nginx整合
配置fastdfs-nginx-module
將FastDFS-nginx-module_v1.16.tar.gz傳至/usr/local/下
cd /usr/local
tar -zxvf FastDFS-nginx-module_v1.16.tar.gz
cd FastDFS-nginx-module/src
修改config檔案
CORE_INCS="$CORE_INCS /usr/include/fastdfs /usr/include/fastcommon/"
CORE_LIBS="$CORE_LIBS -L/usr/lib -lfastcommon -lfdfsclient"
將fastdfs-nginx-module/src下的mod_fastdfs.conf拷貝至/etc/fdfs/下
cp mod_fastdfs.conf /etc/fdfs/
並修改 /etc/fdfs/mod_fastdfs.conf 的內容;
vi /etc/fdfs/mod_fastdfs.conf
base_path=/tmp 修改為 base_path=/home/fastdfs
base_path=/home/fastdfs
tracker_server=192.168.172.20:22122
#tracker_server=192.168.172.20:22122 #(多個tracker配置多行)
url_have_group_name=true #url中包含group名稱
store_path0=/home/fdfs_storage #指定檔案儲存路徑(上面配置的store路徑)
安裝nginx
上傳 nginx-1.14.0.tar.gz 到Centos伺服器上;
解壓 tar -zxvf nginx-1.14.0.tar.gz
./configure \
--prefix=/home/server/nginx \
--conf-path=/home/server/nginx/conf/nginx.conf \
--pid-path=/home/server/nginx/conf/nginx.pid \
--lock-path=/home/server/nginx/lock/nginx.lock \
--error-log-path=/home/server/nginx/logs/error.log \
--http-log-path=/home/server/nginx/logs/access.log \
--with-http_gzip_static_module \
--http-client-body-temp-path=/home/server/nginx/temp/client \
--http-proxy-temp-path=/home/server/nginx/temp/proxy \
--http-fastcgi-temp-path=/home/server/nginx/temp/fastcgi \
--http-uwsgi-temp-path=/home/server/nginx/temp/uwsgi \
--http-scgi-temp-path=/home/server/nginx/temp/scgi \
--add-module=/home/server/fastdfs/fastdfs-nginx-module/src
make && make install
修改配置檔案ningx.config
user root;
worker_processes 1;
pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 7777;
server_name localhost;
location / {
root html;
index index.html index.htm;
}
location ~ /group([0-9])/M00/{
root /home/amm/server/fastdfs/fdfs_storage/data;
ngx_fastdfs_module;
}
}
}
建立nginx/client目錄
mkdir -p /var/temp/nginx/client
啟動nginx
/home/server/nginx/sbin/nginx -c /home/server/nginx/conf/nginx.conf -s reload
查詢埠是否有程序守護用如下命令grep對應埠,如80為埠號
例:netstat -nalp|grep 7777
檢視某個程式用到的埠
例: netstat -unltp|grep nginx
檢視開放埠
例:/sbin/iptables -L -n
參考資料: