centos7安裝fastDfs,centos7部署fastDFS

相信網上很多這種教程,但是最近半年個人總結出來算是比較靠譜的,本人已經親自搭建成功,理論上你不需要動腦筋,直接複製粘貼我的命令就搞定。

一:先下載資源:

①:下載fastDFS的相關依賴

wget https://github.com/happyfish100/libfastcommon/archive/V1.0.7.tar.gz

上面命令下載到的文件名是:V1.0.7.tar.gz這樣一個包,如果你看不爽,你自己修改名字,這裏我修改爲“libfastcommonV1.0.7.tar.gz”

②:下載fastDFS關於nginx的擴展插件

wget http://jaist.dl.sourceforge.net/project/fastdfs/FastDFS%20Nginx%20Module%20Source%20Code/fastdfs-nginx-module_v1.16.tar.gz

③:下載fastDFS的安裝包,下面的命令會下載到這樣一個包V5.05.tar.gz,我這裏將下載之後的包改名爲"FastDFS_v5.05.tar.gz"

wget https://github.com/happyfish100/fastdfs/archive/V5.05.tar.gz

④:下載nginx安裝包(*如果你服務器已經安裝過了nginx,這步你可以省略不過如果你服務器的nginx可以卸載的話建議卸載掉,按我的版本安裝,以確保你按此教程能安裝成功),下面我會給出描述和安裝命令。

nginx資源列表地址:http://mirrors.sohu.com/nginx/,這裏我使用的是“nginx-1.8.0.tar.gz”這個版本,當然我也建議你安裝這個版本,其它版本不保證你能安裝成功。很多人估計軟件就喜歡安裝最新的習慣,這是15年的版本,你不用擔心,直接安裝就行。

下載nginx包命令如下:(不保證下載地址過段時間不會過期,如果過期了請從http://mirrors.sohu.com/nginx/這個地址自己去找對應版本下載)

wget http://mirrors.sohu.com/nginx/nginx-1.8.0.tar.gz

--------------------------------------華麗的分割線---------------------------------------

二:開始安裝

(安裝之前提醒一下各位:本文章的裏面涉及到的填寫ip,請填寫你自己的服務器ip,記得開放對應的端口,如果你使用的服務器商的服務器默認設置有安全組的也別忘了同時放開一下。)

FastDFS是C語言開發,安裝FastDFS需要先將官網下載的源碼進行編譯,編譯依賴gcc環境,如果沒有gcc環境,需要安裝gcc

yum install -y gcc gcc-c++

2、安裝libevent(運行時需求)

 若安裝了桌面圖形界面,就不需要安裝;FastDFS依賴libevent庫;

yum -y install libevent

 3、 安裝libfastcommon

  libfastcommon是FastDFS官方提供的,libfastcommon包含了FastDFS運行所需要的一些基礎庫。

將 libfastcommonV1.0.7.tar.gz解壓至/usr/local/下:

tar -zxvf libfastcommonV1.0.7.tar.gz -C /usr/local/

(3)切換目錄到:/usr/local/libfastcommon-1.0.7/ 下,接着進行編譯和安裝;

cd /usr/local/libfastcommon-1.0.7/
./make.sh           #編譯
./make.sh install   #安裝

安裝後的截圖:

 

(4)libfastcommon安裝好後會在/usr/lib64 目錄下生成  libfastcommon.so 庫文件;

  

  注意:由於FastDFS程序引用usr/lib目錄所以需要將/usr/lib64下的庫文件拷貝至/usr/lib下。

cp libfastcommon.so /usr/lib

 

 4、安裝tracker

 (1)上傳 FastDFS_v5.05.tar.gz 到 centos 上;

(2)將FastDFS_v5.05.tar.gz 解壓至/usr/local/下

tar -zxvf FastDFS_v5.05.tar.gz -C /usr/local

(3)切換目錄到: /usr/local/FastDFS/ 下,編譯和安裝;

cd /usr/local/FastDFS/
./make.sh && ./make.sh install  #編譯之後接着進行安裝

安裝後的截圖:

 

(4)安裝成功將安裝目錄下的conf下的文件拷貝到/etc/fdfs/下;

cp /usr/local/FastDFS/conf/* /etc/fdfs/

 

 5、配置和啓動tracker

(1)切換目錄到: /etc/fdfs/ 目錄下;

(2)拷貝一份新的tracker配置文件

cp tracker.conf.sample tracker.conf

(3)修改tracker.conf ;   vim tracker.conf

base_path=/home/yuqing/fastdfs  改爲:  base_path=/home/fastdfs
http.server_port  改爲: 80
base_path=/home/fastdfs
http.server_port=80  #配置http端口

(4)創建 /home/fastdfs 目錄

mkdir /home/fastdfs

 (5)啓動tracker,運行如下命令:

/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart

注意:在/home/fastdfs/ 目錄下生成兩個目錄, 一個是數據,一個是日誌;

 

6、配置和啓動storage

 由於上面已經安裝過FastDFS,這裏只需要配置storage就好了;

(1)切換目錄到: /etc/fdfs/ 目錄下;

(2)拷貝一份新的storage配置文件

cp storage.conf.sample storage.conf

(3)修改storage.conf ;   vim storage.conf

group_name=group1 #配置組名
base_path=/home/yuqing/fastdfs    改爲:  base_path=/home/fastdfs

#store存放文件的位置(store_path)
store_path0=/home/yuqing/fastdfs  改爲: store_path0=/home/fdfs_storage 
#如果有多個掛載磁盤則定義多個store_path,如下
#store_path1=.....
#store_path2=......

#配置tracker服務器:IP
tracker_server=192.168.172.20:22122
#如果有多個則配置多個tracker
#tracker_server=192.168.101.4:22122

#配置http端口
http.server_port=88

 (4)創建 /home/fdfs_storage 目錄

mkdir /home/fdfs_storage

(5)啓動storage, 運行命令如下:

/usr/bin/fdfs_storaged /etc/fdfs/storage.conf restart

啓動完成後進入 /home/fdfs_storage/data 目錄下,顯示目錄如下:

 

 7、使用FastDFS自帶工具測試

(1)切換目錄到 /etc/fdfs/ 目錄下;

(2)拷貝一份新的client配置文件

cp client.conf.sample client.conf

(3)修改client.conf ;   vim client.conf,修改基本路徑和tracker_server如下:

 

  

注意:若tracker有多個,可以配置多個,如下:

  #tracker_server=......

  #tracker_server=......

(4)拷貝一張圖片luzhouYue.jpg 到Centos服務器上的 /usr1 目錄下;

  

(5)進行測試,運行如下:(運行測試程序,讀取/etc/fdfs/client.conf 文件,上傳/usr1目錄下的luzhouYue.jpg文件)

/usr/bin/fdfs_test /etc/fdfs/client.conf upload /usr1/luzhouYue.jpg

 結果如下,表示搭建成功;

以上圖中的文件地址:http://192.168.172.20/group1/M00/00/00/wKisFFpBG9eAHaQvAAAWKd1hQR4158_big.jpg  對應storage服務器上的/home/fdfs_storage/data/00/00/wKisFFpBG9eAHaQvAAAWKd1hQR4158_big.jpg文件;

由於現在還沒有和nginx整合無法使用http下載。

 

8、FastDFS 和nginx整合(相信很多人都會在這步出問題,如果出現報錯的,請看我最後的其它解決方案)

 8.1 在tracker上安裝 nginx

 在每個tracker上安裝nginx,的主要目的是做負載均衡及實現高可用。如果只有一臺tracker可以不配置nginx。

 一個tracker對應多個storage,通過nginx對storage負載均衡;

 8.2 在storage 上安裝nginx

 (1)上傳 fastdfs-nginx-module_v1.16.tar.gz 到Centos服務器上;

(2)解壓 fastdfs-nginx-module_v1.16.tar.gz 到 /usr/local目錄下;

tar -zxvf fastdfs-nginx-module_v1.16.tar.gz -C /usr/local

(3)切換目錄到: /usr/local/fastdfs-nginx-module/src/ 目錄下

cd /usr/local/fastdfs-nginx-module/src/

(4)修改config文件,將文件中的所有 /usr/local/ 路徑改爲 /usr/

 

修改完成後:

(5)將fastdfs-nginx-module/src下的mod_fastdfs.conf拷貝至/etc/fdfs/下

cp mod_fastdfs.conf /etc/fdfs/

(6)並修改 /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路徑)

(7)將libfdfsclient.so拷貝至/usr/lib下

cp /usr/lib64/libfdfsclient.so /usr/lib/

(8)創建nginx/client目錄

mkdir -p /var/temp/nginx/client

 

8.3 Nginx的安裝

(1)上傳 nginx-1.8.0.tar.gz 到Centos服務器上;

(2)解壓 nginx-1.8.0.tar.gz 到 /usr/local目錄下;

tar -zxvf nginx-1.8.0.tar.gz -C /usr/local/

(3)安裝nginx的依賴庫

yum install pcre
yum install pcre-devel
yum install zlib
yum install zlib-devel
yum install openssl
yum install openssl-devel

(4)進入nginx解壓的目錄下:cd /usr/local/nginx-1.8.0/

(5)加入模塊命令配置

./configure \
--prefix=/usr/local/nginx \
--pid-path=/var/run/nginx/nginx.pid \
--lock-path=/var/lock/nginx.lock \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--with-http_gzip_static_module \
--http-client-body-temp-path=/var/temp/nginx/client \
--http-proxy-temp-path=/var/temp/nginx/proxy \
--http-fastcgi-temp-path=/var/temp/nginx/fastcgi \
--http-uwsgi-temp-path=/var/temp/nginx/uwsgi \
--http-scgi-temp-path=/var/temp/nginx/scgi \
--add-module=/usr/local/fastdfs-nginx-module/src

 

 

 

(6)編譯並安裝

make && make install

安裝成功後查看生成的目錄,如下所示:

 

(7)拷貝配置文件到 /etc/fdfs 下;

cd /usr/local/FastDFS/conf
cp http.conf mime.types /etc/fdfs/

(8)修改nginx配置文件

mkdir /usr/local/nginx/logs # 創建logs目錄
cd /usr/local/nginx/conf/
vim nginx.conf

做如下的修改:

  

  

 

(9)nginx的啓動

cd /usr/local/nginx/sbin/
./nginx 

 查詢nginx進程

  

(10) fastdfs 和 nginx 服務的開機自啓動: http://www.cnblogs.com/yufeng218/p/8215381.html

nginx + fastdfs 的開機自啓動
虛擬機每次啓動之後都要重新啓動一下fastdfs 和 nginx服務,比較麻煩,所以增加開機自啓動;

編輯 /etc/rc.d/rc.local 文件,增加啓動項;

1、編輯文件

 

vim /etc/rc.d/rc.local
 

2、增加如下:

# fastdfs start
/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart
/usr/bin/fdfs_storaged /etc/fdfs/storage.conf restart

# nginx start
/usr/local/nginx/sbin/nginx


3、在centos7中, /etc/rc.d/rc.local 文件的權限被降低了,需要給rc.local 文件增加可執行的權限;

chmod +x /etc/rc.d/rc.local

 

 

9、在瀏覽器中訪問上傳到fastDFS的圖片

因爲Centos系統有防火牆,需要先關閉掉,纔可以在瀏覽器中訪問;

(1)CentOS 7.0默認使用的是firewall作爲防火牆;若沒有啓用iptables 作爲防火牆,則使用以下方式關閉防火牆:

systemctl stop firewalld.service #停止firewall
systemctl disable firewalld.service #禁止firewall開機啓動
firewall-cmd --state #查看默認防火牆狀態(關閉後顯示notrunning,開啓後顯示running)

  

(2)若已經啓用iptables作爲防火牆,則使用以下方式關閉:

service iptables stop  #臨時關閉防火牆
chkconfig iptables off #永久關閉防火牆

防火牆的相關鏈接:http://www.jb51.net/article/101576.htm

           http://www.linuxidc.com/Linux/2015-05/117473.htm

 (3)在谷歌瀏覽器中訪問剛纔上傳的圖片:

剛纔上傳的圖片地址爲:http://192.168.172.20/group1/M00/00/00/wKisFFpBG9eAHaQvAAAWKd1hQR4158_big.jpg

 

【整合nginx如果報錯,幾個解決方案如下】:

在新的服務器安裝nginx,在make編譯時報錯:

make: *** No rule to make target `build', needed by `default'. Stop.

進入nginx的目錄,先編譯參數:

./configure \

--prefix=/usr/local/nginx \

--pid-path=/usr/local/nginx/run \

--user=nginx \

--group=nginx \

--with-http_ssl_module \

--with-http_flv_module \

--with-http_stub_status_module \

--with-http_gzip_static_module \

--with-pcre \

--with-http_image_filter_module \

--with-debug \

 

然後  make

報錯如下:



 

百度上說是要安裝前置依賴,像gcc ,openssl等,但是我make之前已經安裝了這些依賴。

我的解決方式:

更新yum

yum update

更新完成後,先刪除之前準備make的nginx包,然後重新解壓一個。

 

安裝前置庫:

[root@cqakserver local]# yum install -y gcc pcre pcre-devel openssl openssl-devel gd gd-devel

進入nginx目錄重新編譯一次參數:

./configure \

--prefix=/usr/local/nginx \

--pid-path=/usr/local/nginx/run \

--user=nginx \

--group=nginx \

--with-http_ssl_module \

--with-http_flv_module \

--with-http_stub_status_module \

--with-http_gzip_static_module \

--with-pcre \

--with-http_image_filter_module \

--with-debug \

 

再次 make && make install 

成功了。
錯誤二

./configure: error: the HTTP gzip module requires the zlib library.
You can either disable the module by using –without-http_gzip_module
option, or install the zlib library into the system, or build the zlib library
statically from the source with nginx by using –with-zlib=<path> option.


則需要安裝“zlib-devel”即可。SSH執行以下命令:


 


yum install -y zlib-devel

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章