1. 安裝所需要的配置
(1)安裝gcc(編譯時需要)
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運作所需要的一些基礎庫。
####1. 上傳 libfastcommonV1.0.7.tar.gz到Centos機器上;####
####2. 将 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
2. 安裝tracker
2.1 上傳 FastDFS_v5.05.tar.gz 到 centos 上;
2.2 将FastDFS_v5.05.tar.gz 解壓至/usr/local/下
`tar -zxvf FastDFS_v5.05.tar.gz -C /usr/local`
2.3 切換目錄到: /usr/local/FastDFS/ 下,編譯和安裝;
cd /usr/local/FastDFS/
./make.sh && ./make.sh install #編譯之後接着進行安裝
2.4 安裝成功将安裝目錄下的conf下的檔案拷貝到/etc/fdfs/下;
cp /usr/local/FastDFS/conf/* /etc/fdfs/
3.配置和啟動tracker
3.1 切換目錄到: /etc/fdfs/ 目錄下;
3.2 拷貝一份新的tracker配置檔案
cp tracker.conf.sample tracker.conf
3.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端口
3.4 建立 /home/fastdfs 目錄
mkdir /home/fastdfs
3.5 啟動tracker
/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart
注意:在/home/fastdfs/ 目錄下生成兩個目錄, 一個是資料,一個是日志;
4.配置和啟動storage
由于上面已經安裝過FastDFS,這裡隻需要配置storage就好了;
4.1 切換目錄到: /etc/fdfs/ 目錄下;
4.2 拷貝一份新的storage配置檔案
cp storage.conf.sample storage.conf
4.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.1.106:22122
#如果有多個則配置多個tracker
tracker_server=192.168.1.107:22122
#配置http端口
http.server_port=88
4.4 建立 /home/fdfs_storage 目錄
mkdir /home/fdfs_storage
4.5 啟動storage, 運作指令如下:
/usr/bin/fdfs_storaged /etc/fdfs/storage.conf restart
啟動完成後進入 /home/fdfs_storage/data 目錄下,顯示目錄如下:
表示成功!
##5. FastDFS 和nginx整合 ##
5.1 在tracker上安裝 nginx
在每個tracker上安裝nginx,的主要目的是做負載均衡及實作高可用。如果隻有一台tracker可以不配置nginx。
一個tracker對應多個storage,通過nginx對storage負載均衡;
5.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=/home/fastdfs
tracker_server=192.168.1.106:22122
#tracker_server=192.168.1.107:22122 #(多個tracker配置多行)
url_have_group_name=true #url中包含group名稱
store_path0=/home/fdfs_storage #指定檔案存儲路徑(上面配置的store路徑)
(7)将libfdfsclient.so拷貝至/usr/lib下
(8)建立nginx/client目錄
###5.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解壓的目錄下
(5) 在/var下建立temp及nginx目錄,在/var/temp/建立nginx目錄
####(6) 加入子產品指令配置
./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
####(7) 編譯并安裝
`make && make install
(8) 拷貝配置檔案到 /etc/fdfs 下;
cd /usr/local/FastDFS/conf
cp http.conf mime.types /etc/fdfs/
(9) 修改nginx配置檔案
mkdir /usr/local/nginx/logs # 建立logs目錄
cd /usr/local/nginx/conf/
vim nginx.conf
做如下的修改
在#pid logs/nginx.pid:下添加
pid /usr/local/nginx/logs/nginx.pid
另外修改紅框中的内容如下
說明:
(a.) server_name指定本機ip;
(b.) location /group1/M00/:group1為nginx 服務FastDFS的分組名稱,M00是FastDFS自動生成編号,對應store_path0=/home/fdfs_storage,如果FastDFS定義store_path1,這裡就是M01
(10)nginx的啟動
cd /usr/local/nginx/sbin/
./nginx
查詢nginx程序
ps -ef | grep nginx
一定要注意這裡有兩個程序,分别是worker process 和 master process 可以多,但是一個都不能少,不然就是有問題,上次我們就出過這個問題,沒有worker程序,導緻無法啟動url服務,解決方法是按照步驟重裝nginx
(11)fastdfs 和 nginx 服務的開機自啟
虛拟機每次啟動之後都要重新啟動一下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
6.在浏覽器中通路上傳到fastDFS的圖檔
因為Centos系統有防火牆,需要先關閉掉,才可以在浏覽器中通路;
9.1 CentOS 7.0預設使用的是firewall作為防火牆;若沒有啟用iptables 作為防火牆,則使用以下方式關閉防火牆:
systemctl stop firewalld.service #停止firewall
systemctl disable firewalld.service #禁止firewall開機啟動
firewall-cmd --state #檢視預設防火牆狀态(關閉後顯示notrunning,開啟後顯示running)
9.2 若已經啟用iptables作為防火牆,則使用以下方式關閉:
service iptables stop #臨時關閉防火牆
chkconfig iptables off #永久關閉防火牆