一、服務器部署規劃
|
服務器IP
|
部署服務
|
|
192.168.*. |
tracker、storage、nginx
|
二、數據存儲目錄
|
應用
|
目錄
|
|
fastdfs
|
/usr/bin
|
|
nginx
|
/usr/local/nginx
|
|
tracker_data
|
/data/fastdfs/tracker
|
|
storage_data
|
/data/fastdfs/storage
|
|
安裝包
|
/home/fastdfs/resources
|
三、安裝部署
1.基本環境依賴安裝
yum install -y zlib zlib-devel pcre pcre-devel gcc gcc-c++ openssl openssl-devel libevent libevent-devel perl unzip wget net-tools
2.libfastcommon 環境部署
[root@ks1 ~]# mkdir -p /home/fastdfs/resources
[root@ks1 ~]# cd /home/fastdfs/resources
[root@ks1 resources]# wget https://github.com/happyfish100/libfastcommon/archive/master.zip
[root@ks1 resources]# unzip master.zip
[root@ks1 resources]# cd libfastcommon-master
[root@ks1 libfastcommon-master]# ./make.sh
[root@ks1 libfastcommon-master]# ./make.sh install
3.fastdfs v5.12安裝
[root@ks1 libfastcommon-master]# cd ..
[root@ks1 resources]# rm -rf master.zip
[root@ks1 resources]# wget https://github.com/happyfish100/fastdfs/archive/FastDFS_v5.12.zip
[root@ks1 resources]# unzip FastDFS_v5.12.zip
[root@ks1 resources]# mv FastDFS_v5.12 fastdfs-master
[root@ks1 resources]# cd fastdfs-master
[root@ks1 fastdfs-master]# chmod +x make.sh
[root@ks1 fastdfs-master]# ./make.sh
[root@ks1 fastdfs-master]# ./make.sh install
[root@ks1 fastdfs-master]# cp -ar conf/* /etc/fdfs/
[root@ks1 fastdfs-master]# rm -f /home/fastdfs/resources/FastDFS_v5.12.zip
4.tracker server 配置、啓動
[root@ks1 fastdfs-master]# sed -i "s/home\/yuqing\/fastdfs/data\/fastdfs\/tracker/g" `grep home/yuqing/fastdfs -rl /etc/fdfs/tracker.conf`
[root@ks1 fastdfs-master]# sed -i "s/use_connection_pool = false/use_connection_pool = true/g" `grep use_connection_pool -rl /etc/fdfs/tracker.conf`
[root@ks1 fastdfs-master]# mkdir -p /data/fastdfs/tracker
[root@ks1 fastdfs-master]# /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf start
- [注意]
ARM服務器上搭建Fastdfs和X86一樣的安裝包和安裝步驟,唯一注意的是修改這兩個參數,如果不修改trackerd和storage會一直起不來。
1.tracker配置文件tracker.conf
thread_stack_size = 128KB
2.storage配置文件storage.conf
thread_stack_size=1024KB
檢查tracker server 是否啓動成功
[root@ks1 resources]# ps -ef | grep fdfs_trackerd
root 1117 1 0 08:54 ? 00:00:00 /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart
root 2417 1389 0 09:33 pts/0 00:00:00 grep --color=auto fdfs_trackerd
5.storage server 配置、啓動
[root@ks1 fastdfs-master]# sed -i "s/home\/yuqing\/fastdfs/data\/fastdfs\/storage/g" `grep home/yuqing/fastdfs -rl /etc/fdfs/storage.conf`
[root@ks1 fastdfs-master]# vim /etc/fdfs/storage.conf
裏面自帶的一個tracker_server 把註釋
tracker_server=192.168.**.**:22122
[root@ks1 fastdfs-master]# mkdir -p /data/fastdfs/storage
[root@ks1 fastdfs-master]# /usr/bin/fdfs_storaged /etc/fdfs/storage.conf start
## 注意 storage.conf 文件一定要放到 /etc/fdfs/下 不然異常 異常如下
[root@localhost conf]# /usr/bin/fdfs_storaged ./storage.conf start
[root@localhost conf]# [2022-04-01 10:33:30] ERROR - file: shared_func.c, line: 968, file /./storage.conf not exist
[2022-04-01 10:33:30] ERROR - file: storage_func.c, line: 1087, load conf file "./storage.conf" fail, ret code: 2
[2022-04-01 10:33:30] CRIT - exit abnormally!
檢查storage server是否開啓成功
[root@ks1 resources]# ps -ef | grep fdfs_storage
root 1120 1 0 08:54 ? 00:00:01 /usr/bin/fdfs_storaged /etc/fdfs/storage.conf restart
root 2510 1389 0 09:39 pts/0 00:00:00 grep --color=auto fdfs_storage
[root@ks1 resources]#
四、文件上傳測試
1.修改tracker server 服務器客户端配置文件
[root@ks1 fastdfs-master]# sed -i "s/home\/yuqing\/fastdfs/data\/fastdfs\/client/g" `grep home/yuqing/fastdfs -rl /etc/fdfs/client.conf`
[root@ks1 fastdfs-master]# vim /etc/fdfs/client.conf
tracker_server=192.168.**.**:22122
mkdir -p /data/fastdfs/client
2.執行文件上傳命令
[root@ks1 fastdfs-master]# cd /tmp
[root@ks1 tmp]# echo "123" > test.txt
[root@ks1 tmp]# fdfs_test /etc/fdfs/client.conf upload test.txt
This is FastDFS client test program v5.12
Copyright (C) 2008, Happy Fish / YuQing
FastDFS may be copied only under the terms of the GNU General
Public License V3, which may be found in the FastDFS source kit.
Please visit the FastDFS Home Page http://www.csource.org/
for more detail.
[2021-06-10 09:43:51] DEBUG - base_path=/data/fastdfs/client, connect_timeout=30, network_timeout=60, tracker_server_count=2, 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
.......
五、安裝fastdfs-nginx-module
[root@ks1 tmp]# cd /usr/local/src
[root@ks1 src]# wget http://sourceforge.net/projects/fastdfs/files/FastDFS%20Nginx%20Module%20Source%20Code/fastdfs-nginx-module_v1.16.tar.gz
[root@ks1 src]# tar -zxvf fastdfs-nginx-module_v1.16.tar.gz
[root@ks1 src]# rm -f fastdfs-nginx-module_v1.16.tar.gz
[root@ks1 src]# cd fastdfs-nginx-module/src
[root@ks1 src]# vim config
CORE_INCS="$CORE_INCS /usr/include/fastdfs /usr/include/fastcommon/"
CORE_LIBS="$CORE_LIBS -L/usr/lib64 -lfastcommon -lfdfsclient"
[root@ks1 src]# sed -i "s/home\/yuqing\/fastdfs/data\/fastdfs\/storage/g" `grep home/yuqing/fastdfs -rl mod_fastdfs.conf`
[root@ks1 src]# sed -i "s/tmp/data\/fastdfs\/storage/g" `grep tmp -rl mod_fastdfs.conf`
[root@ks1 src]# sed -i "s/false/true/g" `grep url_have_group_name -rl mod_fastdfs.conf`
[root@ks1 src]# vim mod_fastdfs.conf
tracker_server=192.168.**.**:22122
[group1]
group_name=group1
storage_server_port=23000
store_path_count=2
store_path0=/data/fastdfs/storage
[root@ks1 src]# cp mod_fastdfs.conf /etc/fdfs
[root@ks1 src]# ln -s /data/fastdfs/storage/data/ /data/fastdfs/storage/data/M00
切記 我們把mod_fastdfs.conf 複製到/ect/fdfa下,一定要修改/etc/fdfs/mod_fastdfs.conf下面的地址(修改成自己的地址)
vim /etc/fdfs/
tracker_server=192.168.**.**:22122
六、nginx安裝、配置
1.解壓ngx_cache_purge-2.3模塊
[root@ks1 src]# cd /usr/local/src
[root@ks1 src]# wget http://labs.frickle.com/files/ngx_cache_purge-2.3.tar.gz
[root@ks1 src]# tar -zxvf ngx_cache_purge-2.3.tar.gz
[root@ks1 src]# rm -f ngx_cache_purge-2.3.tar.gz
2.nginx編譯安裝
[root@ks1 src]# wget http://nginx.org/download/nginx-1.8.0.tar.gz
[root@ks1 src]# tar -zxvf nginx-1.8.0.tar.gz
[root@ks1 src]# rm -f nginx-1.8.0.tar.gz
[root@ks1 src]# cd nginx-1.8.0
[root@ks1 nginx-1.8.0]# useradd -s /sbin/nologin nginx
[root@ks1 nginx-1.8.0]# ./configure --user=nginx --group=nginx --add-module=/usr/local/src/ngx_cache_purge-2.3 --add-module=/usr/local/src/fastdfs-nginx-module/src --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_realip_module
[root@ks1 nginx-1.8.0]# make
[root@ks1 nginx-1.8.0]# make install
[root@ks1 nginx-1.8.0]# cd /usr/local/nginx/conf
[root@ks1 conf]# mkdir -p /var/cache/nginx/proxy_cache
3.配置文件修改()
[root@ks1 conf]# vim nginx.conf
worker_processes 1;
error_log logs/error.log info;
pid logs/nginx.pid;
events {
worker_connections 1024;
use epoll;
}
http {
server_tokens off;
include mime.types;
default_type application/octet-stream;
sendfile on;
tcp_nopush on;
keepalive_timeout 65;
server_names_hash_bucket_size 128;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
client_max_body_size 300m;
proxy_redirect off;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffer_size 16k;
proxy_buffers 4 64k;
proxy_busy_buffers_size 128k;
proxy_temp_file_write_size 128k;
proxy_cache_path /var/cache/nginx/proxy_cache levels=1:2
keys_zone=http-cache:500m max_size=10g inactive=30d use_temp_path=off;
proxy_temp_path /var/cache/nginx/proxy_cache/tmp;
upstream storage_server_group1{
server 192.168.**.**:8080;
}
server {
listen 80;
server_name 192.168.**.**;
location /group1{
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_next_upstream http_502 http_504 error timeout invalid_header;
# proxy_cache http-cache;
# proxy_cache_valid 200 304 12h;
# proxy_cache_key $uri$is_args$args;
proxy_pass http://storage_server_group1;
expires 30d;
}
location ~/purge(/.*) {
allow 192.168.**.**;
#allow 192.168.**.**;
#allow 192.168.**.**;
deny all;
# proxy_cache_purge http-cache $1$is_args$args;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
server {
listen 8080;
server_name localhost 192.168.**.**;
location / {
root html;
index index.html index.html;
}
location /group1/M00/{
root /storage/fdfs/storage-data;
ngx_fastdfs_module
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
4.nginx啓動
[root@ks1 conf]# /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
[root@ks1 conf]# netstat -npl | grep -E "nginx|fdfs"
tcp 0 0 0.0.0.0:8080 0.0.0.0:* LISTEN 1147/nginx: master
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 1147/nginx: master
tcp 0 0 0.0.0.0:23000 0.0.0.0:* LISTEN 1120/fdfs_storaged
tcp 0 0 0.0.0.0:22122 0.0.0.0:* LISTEN 1117/fdfs_trackerd
5.fs自啓動
[root@ks1 conf]# vim /etc/rc.d/rc.local
# fastdfs
/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart
/usr/bin/fdfs_storaged /etc/fdfs/storage.conf restart
# nginx
/usr/local/nginx/sbin/nginx
[root@ks1 conf]# chmod +x /etc/rc.d/rc.local
6.瀏覽器驗證
http://192.168.**.**/group1/M00/00/00/wKgFgWDBeECAOzbKAAAABFqCAvc968_big.txt
本文章為轉載內容,我們尊重原作者對文章享有的著作權。如有內容錯誤或侵權問題,歡迎原作者聯繫我們進行內容更正或刪除文章。