FasterDFS基礎(chǔ)配置安裝-創(chuàng)新互聯(lián)

FasterDFS基礎(chǔ)配置安裝

基本概述

? FastDFS是一個(gè)開(kāi)源的輕量級(jí)分布式文件系統(tǒng),它對(duì)文件進(jìn)行管理,功能包括:文件存儲(chǔ)、文件同步、文件訪問(wèn)(文件上傳、文件下載)等,解決了大容量存儲(chǔ)和負(fù)載均衡的問(wèn)題。特別適合以文件為載體的在線服務(wù),如相冊(cè)網(wǎng)站、視頻網(wǎng)站等等。

成都創(chuàng)新互聯(lián)公司是一家專注于做網(wǎng)站、成都網(wǎng)站建設(shè)IDC機(jī)房托管的網(wǎng)絡(luò)公司,有著豐富的建站經(jīng)驗(yàn)和案例。

? FastDFS為互聯(lián)網(wǎng)量身定制,充分考慮了冗余備份、負(fù)載均衡、線性擴(kuò)容等機(jī)制,并注重高可用、高性能等指標(biāo),使用FastDFS很容易搭建一套高性能的文件服務(wù)器集群提供文件上傳、下載等服務(wù)。

基本結(jié)構(gòu)圖

FasterDFS基礎(chǔ)配置安裝

FastDFS服務(wù)端有兩個(gè)角色:跟蹤器(tracker)和存儲(chǔ)節(jié)點(diǎn)(storage)。跟蹤器主要做調(diào)度工作,在訪問(wèn)上起負(fù)載均衡的作用。 跟蹤器和存儲(chǔ)節(jié)點(diǎn)都可以由一臺(tái)或多臺(tái)服務(wù)器構(gòu)成。跟蹤器和存儲(chǔ)節(jié)點(diǎn)中的服務(wù)器均可以隨時(shí)增加或下線而不會(huì)影響線上服務(wù)。其中跟蹤器中的所有服務(wù)器都是對(duì)等的,可以根據(jù)服務(wù)器的壓力情況隨時(shí)增加或減少。

在卷中增加服務(wù)器時(shí),同步已有的文件由系統(tǒng)自動(dòng)完成,同步完成后,系統(tǒng)自動(dòng)將新增服務(wù)器切換到線上提供服務(wù)。

基本實(shí)驗(yàn)部署

1、實(shí)驗(yàn)準(zhǔn)備

名稱 角色 IP地址
centos7-1tracker192.168.45.135
centos7-2storage+nginx192.168.45.132

實(shí)驗(yàn)軟件包提取碼

鏈接:https://pan.baidu.com/s/1_Xs09mdST6VNLue11dqhyQ
提取碼:9ql5

2、開(kāi)始安裝

修改兩臺(tái)服務(wù)器的名稱

一臺(tái)改為tracker,一臺(tái)改為storage

hostnamectl set-hostname tracker    storage
su
安裝基本環(huán)境包
yum -y install libevent  libevent-devel perl  make gcc zlib  zlib-devel pcre pcre-devel  gcc-c++  openssl-devel
安裝libfastcommon服務(wù)(所有節(jié)點(diǎn)均進(jìn)行安裝)
mount.cifs //192.168.100.3/lzp /mnt
#安裝libfastcommon服務(wù)
cd /mnt/fastDFS/
tar zxvf libfastcommon-1.0.39.tar.gz -C /opt
cd /opt/libfastcommon-1.0.39/
#編譯安裝并建立軟鏈接以方便系統(tǒng)識(shí)別
./make.sh && ./make.sh install
ln -s /usr/lib64/libfastcommon.so /usr/local/lib/libfastcommon.so
ln -s /usr/lib64/libfdfsclient.so /usr/local/lib/libfdfsclient.so
ln -s /usr/lib64/libfdfsclient.so /usr/lib/libfdfsclient.so
安裝FastDFS服務(wù)(所有節(jié)點(diǎn)均進(jìn)行安裝)
cd /mnt/fastDFS/
tar zxvf fastdfs-5.11.tar.gz -C /opt
#編譯安裝
cd /opt/fastdfs-5.11/
./make.sh && ./make.sh install
 cd /etc/fdfs/
cp tracker.conf.sample tracker.conf
cp storage.conf.sample storage.conf
cp client.conf.sample client.conf
tracker監(jiān)控配置
# 建立數(shù)據(jù)文件、日志文件存放目錄
[root@tracker ~]# mkdir -m 755 -p /opt/fastdfs

修改tracker配置文件
[root@tracker ~]# vim /etc/fdfs/tracker.conf
#修改以下配置
#port=22122         //tracker服務(wù)默認(rèn)端口22122即可
base_path=/opt/fastdfs      //22行tracker存儲(chǔ)data和log的跟路徑,必須提前創(chuàng)建好tracker存儲(chǔ)data和log的跟路徑,必須提前創(chuàng)建好
#http.server_port=8080 //tracker服務(wù)器上啟動(dòng)http服務(wù)進(jìn)程,沒(méi)裝忽略
#開(kāi)啟服務(wù)
fdfs_trackerd /etc/fdfs/tracker.conf start
#設(shè)置開(kāi)機(jī)自啟
[root@tracker ~]# vim  /etc/rc.local
#末行添加
fdfs_trackerd   /etc/fdfs/tracker.conf start 
#關(guān)閉防火墻和安全功能
[root@tracker ~]# systemctl stop firewalld
[root@tracker ~]# setenforce 0
storage服務(wù)端修改
#建立數(shù)據(jù)文件、日志文件存放目錄
[root@storage ~]# mkdir -m 755 -p /opt/fastdfs

修改storage配置文件
[root@storage ~]# vim /etc/fdfs/storage.conf
#修改以下配置
group_name=group1        //默認(rèn)組名,根據(jù)實(shí)際情況修改
port=23000       //storge默認(rèn)23000,同一個(gè)組的storage端口號(hào)必須一致
base_path=/opt/fastdfs          //storage日志文件的根路徑
store_path_count=1              //與下面路徑個(gè)數(shù)相同,默認(rèn)為1
store_path0=/opt/fastdfs       //109提供的存儲(chǔ)路徑(默認(rèn)與日志文件存放在一起)
tracker_server=192.168.45.135:22122      //自己的tracker服務(wù)器IP(重點(diǎn)?。。。?http.server_port=80            //http訪問(wèn)文件的端口默認(rèn)為8888,nginx中配置的監(jiān)聽(tīng)端口保持一致

開(kāi)啟服務(wù)并設(shè)置開(kāi)機(jī)自啟

#開(kāi)啟服務(wù)(命令支持start|stop|restart)
[root@storage ~]# fdfs_storaged  /etc/fdfs/storage.conf start
[root@storage ~]# netstat -atnp | grep 23000
tcp        0      0 0.0.0.0:23000           0.0.0.0:*               LISTEN      40430/fdfs_storaged

#設(shè)置開(kāi)機(jī)自啟
[root@storage ~]# vim  /etc/rc.local
#末行添加
fdfs_storaged   /etc/fdfs/storage.conf start 

[root@storage ~]# systemctl stop firewalld
[root@storage ~]# setenforce 0
檢查是否與tracker監(jiān)控端關(guān)聯(lián)成功
fdfs_monitor /etc/fdfs/storage.conf

FasterDFS基礎(chǔ)配置安裝

安裝nginx服務(wù)(storage:192.168.45.132)

這里為了減少虛擬機(jī)開(kāi)啟的數(shù)量,就在storage端進(jìn)行nginx的安裝

cd /mnt/fastDFS/
[root@storage fastDFS]# tar zxvf nginx-1.12.0.tar.gz -C /opt
 tar zxvf fastdfs-nginx-module-1.20.tar.gz -C /opt
# 修改/opt/fastdfs-nginx-module-1.20/src/config文件 
[root@storage fastDFS]# vim /opt/fastdfs-nginx-module-1.20/src/config
ngx_module_incs="/usr/include/fastdfs /usr/include/fastcommon/"
CORE_INCS="$CORE_INCS /usr/include/fastdfs /usr/include/fastcommon/"
#編譯安裝
cd /opt/nginx-1.12.0/
[root@storage nginx-1.12.0]# ./configure \
--prefix=/usr/local/nginx \
--add-module=/opt/fastdfs-nginx-module-1.20/src/

make && make install

cd /opt/fastdfs-nginx-module-1.20/src
cp mod_fastdfs.conf /etc/fdfs/ 
#修改fastdfs-nginx-module模塊配置文件mod-fasts.conf
[root@storage nginx-1.12.0]# cd /etc/fdfs
[root@storage fdfs]# vim mod_fastdfs.conf
#檢查一下配置
base_path=/opt/fastdfs         //存放數(shù)據(jù)文件、日志的路徑
tracker_server=192.168.45.135/:22122    //tracker端的地址(重點(diǎn)?。。。?url_have_group_name = true  //url是否包含group名稱
storage_server_port=23000           //需要和storage配置的相同
store_path_count=1              //存儲(chǔ)路徑個(gè)數(shù),需要和store_path個(gè)數(shù)匹配
store_path0=/opt/fastdfs               //62行文件存儲(chǔ)的位置

#修改nginx配置文件
[root@storage fdfs]# vim /usr/local/nginx/conf/nginx.conf
#server中空行處添加
location ~/M00 {
                root /opt/fastdfs/data;
                ngx_fastdfs_module;
}
#創(chuàng)建軟鏈接
[root@localhost ~]# ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/
#檢車(chē)nginx配置文件
[root@localhost ~]# nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
#啟動(dòng)nginx
[root@localhost ~]# nginx

#拷貝fastdfs解壓目錄中的http.conf和mime.types不做這步可能會(huì)導(dǎo)致報(bào)錯(cuò)
[root@storage fdfs]# cd /opt/fastdfs-5.11/conf/
[root@storage conf]# cp mime.types http.conf /etc/fdfs/
修改storage端
#修改配置文件
[root@storage ~]# vim /etc/fdfs/client.conf
#檢查以下配置
base_path=/opt/fastdfs     //tracker服務(wù)器文件路徑
tracker_server=192.168.45.135:22122            //tracker服務(wù)器IP地址和端口號(hào)
http.tracker_server_port=8080                  // tracker服務(wù)器的http端口號(hào),必須和

上傳測(cè)試文件命令:

/usr/bin/fdfs_upload_file <config_file> <local_filename>

命令演示:

[root@localhost mnt]# /usr/bin/fdfs_upload_file /etc/fdfs/client.conf 1.jpg
group1/M00/00/00/wKgthF4AKVmAY9WYABIrwU4wXNs537.jpg

FasterDFS基礎(chǔ)配置安裝

下載文件命令:
/usr/bin/fdfs_download_file <config_file> <file_id> [local_filename]

示例

/usr/bin/fdfs_download_file /etc/fdfs/client.conf group1/M00/00/00/wKiOTV354W2AIf7GAAAAEh4TEws726.jpg test2.jpg**
刪除文件命令:
/usr/bin/fdfs_delete_file <config_file> <file_id>

實(shí)例:

fdfs_delete_file /etc/fdfs/client.conf group1/M00/00/00/wKiOTV354W2AIf7GAAAAEh4TEws726.jpg

另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)cdcxhl.cn,海內(nèi)外云服務(wù)器15元起步,三天無(wú)理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國(guó)服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場(chǎng)景需求。

網(wǎng)頁(yè)題目:FasterDFS基礎(chǔ)配置安裝-創(chuàng)新互聯(lián)
網(wǎng)頁(yè)URL:http://muchs.cn/article32/dpsjsc.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供微信小程序、定制網(wǎng)站、外貿(mào)建站自適應(yīng)網(wǎng)站、網(wǎng)頁(yè)設(shè)計(jì)公司網(wǎng)站設(shè)計(jì)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

外貿(mào)網(wǎng)站建設(shè)