一,下載 fastdfs6.06
1,官方地址
https://github.com/happyfish100
2,說明:當前版本:共3個子模塊
fastdfs v6.06 libfastcommon v1.0.43 fastdfs-nginx-module v 1.22
說明:劉宏締的架構森林是一個專注架構的博客,地址:https://www.cnblogs.com/architectforest
對應的源碼可以訪問這里獲取: https://github.com/liuhongdi/
說明:作者:劉宏締 郵箱: 371125307@qq.com
3,下載
[root@localhost source]# wget https://github.com/happyfish100/fastdfs/archive/V6.06.tar.gz [root@localhost source]# wget https://github.com/happyfish100/fastdfs-nginx-module/archive/V1.22.tar.gz [root@localhost source]# wget https://github.com/happyfish100/libfastcommon/archive/V1.0.43.tar.gz
二,下載nginx
1,官網地址:
http://nginx.org/
2,下載nginx
[root@localhost source]# wget http://nginx.org/download/nginx-1.17.8.tar.gz
三,安裝fastdfs所需的程序包
[root@localhost dest]# yum install gcc gcc-c++ [root@localhost dest]# yum install libtool zlib zlib-devel openssl openssl-devel [root@localhost dest]# yum -y install pcre pcre-devel libevent libevent-devel perl unzip net-tools wget
說明:在fastdfs的編譯安裝時會用到這些包,避免編譯時出現報錯
四,libfastcommon的安裝
1,解壓libfastcommon的壓縮包
[root@localhost source]# tar -zxvf V1.0.43.tar.gz
2, 編譯並安裝
[root@localhost source]# cd libfastcommon-1.0.43/ [root@localhost libfastcommon-1.0.43]# ./make.sh && ./make.sh install
3,檢查執行的結果,看安裝是否成功:
[root@localhost libfastcommon-1.0.43]# ls /usr/lib64|grep libfastcommon libfastcommon.so [root@localhost libfastcommon-1.0.43]# ls /usr/lib|grep libfastcommon libfastcommon.so
說明:如果能看到libfastcommon.so,說明安裝成功
五,編譯安裝fastdfs
1,解壓fastdfs
[root@localhost source]# tar -zxvf V6.06.tar.gz
2,安裝fastdfs
[root@localhost source]# cd fastdfs-6.06/ [root@localhost fastdfs-6.06]# ./make.sh && ./make.sh install
3,檢查fastdfs是否安裝成功?
[root@localhost fastdfs-6.06]# ls /usr/bin|grep fdfs fdfs_appender_test fdfs_appender_test1 fdfs_append_file fdfs_crc32 fdfs_delete_file fdfs_download_file fdfs_file_info fdfs_monitor fdfs_regenerate_filename fdfs_storaged fdfs_test fdfs_test1 fdfs_trackerd fdfs_upload_appender fdfs_upload_file
說明:能看到fdfs_打頭的這些程序,則表示安裝成功
六,生成啟動fastdfs所需的配置文件
[root@localhost fastdfs-6.06]# cd /etc/fdfs/ [root@localhost fdfs]# cp storage.conf.sample storage.conf [root@localhost fdfs]# cp client.conf.sample client.conf [root@localhost fdfs]# cp tracker.conf.sample tracker.conf
七,啟動tracker服務
1,創建tracker服務所需的目錄
[root@localhost fdfs]# mkdir /data/fastdfs [root@localhost fdfs]# mkdir /data/fastdfs/tracker [root@localhost fdfs]# chmod 777 /data/fastdfs/tracker
2,配置tracker服務,
修改 tracker.conf 文件
[root@localhost fdfs]# vi /etc/fdfs/tracker.conf
只修改base_path一項的值為我們在上面所創建的目錄即可
base_path = /data/fastdfs/tracker
3,啟動 tracker 服務
[root@localhost fdfs]# /etc/init.d/fdfs_trackerd start
4,檢查tracker服務啟動是否成功
[root@localhost fdfs]# ps auxfww | grep fdfs root 15067 0.0 0.0 12320 964 pts/0 S+ 15:14 0:00 | | \_ grep --color=auto fdfs root 15026 0.0 0.1 90160 5940 ? Sl 15:13 0:00 /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf
能看到 fdfs_trackerd,表示tracker服務啟動成功
5,檢查tracker服務是否已綁定端口 22122?
[root@localhost dest]# netstat -anp | grep 22122 tcp 0 0 0.0.0.0:22122 0.0.0.0:* LISTEN 15026/fdfs_trackerd
說明: 22122端口是在/etc/fdfs/tracker.conf中定義的,
如下:
# the tracker server port port = 22122
八,啟動storage服務
1,創建storage服務所需的目錄
[root@localhost fdfs]# mkdir /data/fastdfs/storage [root@localhost fdfs]# chmod 777 /data/fastdfs/storage/
2, 配置storage服務
編輯storage的配置文件:
[root@localhost fdfs]# vi /etc/fdfs/storage.conf
各配置項包括:
配置base_path為上面所創建的storage目錄
base_path = /data/fastdfs/storage
store_path0 = /data/fastdfs/storage
//上面的store_path :存儲所在的目錄,可以設置多個,注意從0開始
tracker_server = 192.168.3.172:22122
//上面是tracker_server的ip和端口
http.server_port = 80
//上面是指定http服務的端口
說明:從上面我們可以看到,storage_server在啟動時要注冊到tracker_server,
從而實現由tracker_server對其進行調度
3,啟動storage服務
[root@localhost fdfs]# /etc/init.d/fdfs_storaged start
正在啟動 fdfs_storaged (via systemctl): [ 確定 ]
4,檢查storage服務啟動是否成功?
[root@localhost fdfs]# ps auxfww | grep fdfs root 15630 0.0 0.0 12320 972 pts/0 S+ 15:46 0:00 | | \_ grep --color=auto fdfs root 15026 0.0 0.1 155696 6964 ? Sl 15:13 0:00 /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf root 15573 2.7 1.7 150736 66292 ? Sl 15:45 0:02 /usr/bin/fdfs_storaged /etc/fdfs/storage.conf
說明:看到fdfs_storaged,表示storage服務啟動成功
5,檢查storage服務是否已綁定到端口:23000?
[root@localhost fdfs]# netstat -anp | grep 23000 tcp 0 0 0.0.0.0:23000 0.0.0.0:* LISTEN 15573/fdfs_storaged
說明:23000 端口是在配置文件 /etc/fdfs/storage.conf中定義的,如下:
# the storage server port port = 23000
九,配置fastdfs的客戶端使用的配置文件
1,配置客戶端要使用的client.conf
[root@localhost fdfs]# vi /etc/fdfs/client.conf
以下兩項配置用到的tracker目錄和服務器地址端口
base_path = /data/fastdfs/tracker tracker_server = 192.168.3.172:22122
2,從客戶端的配置可以看到:客戶端只需要了解tracker_server的信息
Tracker server作用也正是負載均衡和調度
3, Storage server作用是文件存儲,客戶端上傳的文件最終存儲在 Storage 服務器上
十,安裝nginx及fastdfs-nginx-module
1,解壓nginx:
[root@localhost source]# tar -zxvf nginx-1.17.8.tar.gz
2,解壓fastdfs-nginx-module
[root@localhost source]# tar -zxvf V1.22.tar.gz
3,修改config文件,把/usr/local 替換成 /usr
[root@localhost source]# cd fastdfs-nginx-module-1.22/ [root@localhost fastdfs-nginx-module-1.22]# cd src [root@localhost src]# vi config
4,nginx配置,添加fastdfs-nginx-module和http_stub_status_module 模塊
[root@localhost fdfs]# cd /usr/local/source/nginx-1.17.8/ [root@localhost nginx-1.17.8]# ./configure --prefix=/usr/local/soft/nginx --with-http_stub_status_module --add-module=/usr/local/source/fastdfs-nginx-module-1.22/src/
5,編譯安裝nginx
[root@localhost nginx-1.17.8]# make && make install
6,檢查安裝是否成功?
[root@localhost nginx-1.17.8]# ls /usr/local/soft/ | grep nginx nginx
7,查看指定的編譯參數是否起作用?
[root@localhost fdfs]# /usr/local/soft/nginx/sbin/nginx -V nginx version: nginx/1.17.8 built by gcc 8.3.1 20190507 (Red Hat 8.3.1-4) (GCC) configure arguments: --prefix=/usr/local/soft/nginx --with-http_stub_status_module --add-module=/usr/local/source/fastdfs-nginx-module-1.22/src/
十一,配置fastdfs-nginx-module
1,生成配置文件:
[root@localhost nginx-1.17.8]# cp /usr/local/source/fastdfs-nginx-module-1.22/src/mod_fastdfs.conf /etc/fdfs/
2,編輯配置文件:
[root@localhost nginx-1.17.8]# vi /etc/fdfs/mod_fastdfs.conf
配置以下幾項
connect_timeout=10 tracker_server=192.168.3.172:22122 url_have_group_name = true store_path0=/data/fastdfs/storage
3,復制另兩個web訪問用到配置文件到fdfs配置目錄下:
[root@localhost nginx-1.17.8]# cd /usr/local/source/fastdfs-6.06/conf/ [root@localhost conf]# cp http.conf /etc/fdfs/ [root@localhost conf]# cp mime.types /etc/fdfs/
十二,配置nginx
編輯nginx的配置文件:
[root@localhost conf]# vi /usr/local/soft/nginx/conf/nginx.conf
在server listen 80 的這個server配置下面,
增加一個location
location ~/group([0-9]) { root /data/fastdfs/storage/data; ngx_fastdfs_module; }
十三,啟動nginx
1,啟動
[root@localhost storage]# /usr/local/soft/nginx/sbin/nginx
2,檢查nginx是否已成功啟動
[root@localhost storage]# ps auxfww | grep nginx root 24590 0.0 0.0 12320 980 pts/0 S+ 16:44 0:00 | | \_ grep --color=auto nginx root 24568 0.0 0.0 41044 428 ? Ss 16:44 0:00 \_ nginx: master process /usr/local/soft/nginx/sbin/nginx nobody 24569 0.0 0.1 74516 4940 ? S 16:44 0:00 \_ nginx: worker process
十四,測試上傳一張圖片
1,准備一張圖片,然后上傳
[root@localhost storage]# /usr/bin/fdfs_upload_file /etc/fdfs/client.conf /home/liuhongdi/image/nginx.jpg group1/M00/00/00/wKgDrF5U32GAZAo1AAAyP-hllUI402.jpg
注意fdfs所返回的地址,我們需要使用這個地址進行訪問
2,打開瀏覽器:訪問這個地址:
http://192.168.3.172/group1/M00/00/00/wKgDrF5U32GAZAo1AAAyP-hllUI402.jpg
可以看到圖片
3,說明:192.168.3.172是拼接的本地服務器的ip
4,實際的圖片位於文件系統中什么位置?
[root@localhost data]# pwd /data/fastdfs/storage/data
[root@localhost data]# ls 00/00 wKgDrF5U32GAZAo1AAAyP-hllUI402.jpg
可見/group1/M00這兩個目錄是由fdfs所管理生成的目錄:
它們分別代表fdfs生成的組名和磁盤
十五,查看fdfs的版本
[root@localhost data]# fdfs_monitor /etc/fdfs/client.conf | grep version [2020-02-25 16:58:01] DEBUG - base_path=/data/fastdfs/tracker, connect_timeout=5, network_timeout=60, tracker_server_count=1, anti_steal_token=0, anti_steal_secret_key length=0, use_connection_pool=0, g_connection_pool_max_idle_time=3600s, use_storage_id=0, storage server id count: 0 version = 6.06
十六,監控fdfs的運行狀態
[root@localhost data]# fdfs_monitor /etc/fdfs/client.conf
十七,查看本地centos的版本
[root@localhost lib]# cat /etc/redhat-release CentOS Linux release 8.1.1911 (Core)