搭建環境準備:
traker: 192.168.124.84
storage: 192.168.124.155
nginx(及其依賴包)+fastdfs(及其依賴包)
一、在tracker上配置
關閉防火牆
systemctl stop firewalld
setenforce 0
1.安裝libfastcommon
這裡會顯示報錯
./make.sh: line 14: gcc: command not found
./make.sh: line 15: ./a.out: no such file or directory
cc -wall -d_file_offset_bits=64 -d_gnu_source -g -o3 -c -o hash.o hash.c
make: cc: command not found
make: *** [hash.o] error 127
解決方法:
yum install -y gcc*(編譯時需要gcc環境)
2.安裝libevent
3.安裝tracker
4.配置檔案
vim /data/server/fastdfs/conf/tracker.conf
5.啟動tracker
cd /data/server/fastdfs/tracker
fdfs_trackerd /data/server/fastdfs/conf/tracker.conf
6.檢視是否啟動成功
cat /fdfs/tracker/logs/trackerd.log
++++++++++++++++++++++++++++++++++++++++++++
以下内容在在操作完storage的第1步到第18步之後再操作
7.建立緩存目錄
mkdir -p /var/cache/nginx/proxy_cache
8.安裝nginx及其插件
9.配置nginx檔案
vim /data/server/nginx/conf/nginx.conf
添加補充下面内容
http {
server_names_hash_bucket_size 128;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
client_max_body_size 300m;
include mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /data/server/nginx/logs/access.log main; #寫自己的日志路徑
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
gzip on; #注釋去掉
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;
proxy_temp_path /var/cache/nginx/proxy_cache/tmp;
#設定head的伺服器
upstream fdfs_head {
server 192.168.124.155:8080 fail_timeout=30s; # storage的ip
}
#設定other的伺服器
upstream fdfs_other {
server 192.168.124.155:8080 fail_timeout=30s; # storage的ip
server {
listen 8888;
server_name localhost;
#設定head的負載均衡參數
location /head/m00 {
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://fdfs_head;
expires 30d;
#設定other的負載均衡參數
location /other/m00 {
proxy_pass http://fdfs_other;
#此location子產品要與server子產品對齊
location ~ /purge(/.*) {
allow 127.0.0.1;
allow 192.168.124.0/24; #改成自己的網段
deny all;
proxy_cache_purge http-cache $1$is_args$args;
+++++++++++++++++++++++++++++++++++++++++
10.修改client.conf檔案
vim /data/server/fastdfs/conf/client.conf
+++++++++++++++++++++++++++++++
去storage上操作第19步
11.運作nginx
cd /data/server/nginx/sbin
./nginx
12.上傳圖檔
去storage上操作第30步(檢測資料是否存儲成功)
二、在storage上配置
3.安裝storage
vim /data/server/fastdfs/conf/storage.conf
修改以下内容
disabled=false #啟用配置檔案
max_connections=300 #最大連接配接數
work_threads=1 #工作線程數,最好和cpu核數相同
group_name=head #組名,
port=23000 #設定storage的端口号
base_path=/fdfs/storage #設定storage的日志目錄(事先建立好的那個)
store_path_count=1 #存儲路徑個數,需要和store_path個數比對
store_path0=/fdfs/head #存儲路徑
tracker_server=192.168.124.84:22122 #tracker伺服器的ip位址和端口号
http.server_port=8080 #設定http端口号
5.運作storage
cd /data/server/fastdfs/storage
fdfs_storaged /data/server/fastdfs/conf/storage.conf
6.确認是否運作成功
cat /fdfs/storage/logs/storaged.log
7.檢視存儲目錄
cd /fdfs/head/data
ls
location ~/other/m00 { #組other
root /fdfs/other/data;
ngx_fastdfs_module;
10.建立other組
cd /data/server/fastdfs/conf/
cp storage.conf storage_other.conf
11.配置storage other組
vim /data/server/fastdfs/conf/storage_other.conf
12.啟動other的storage
fdfs_storaged /data/server/fastdfs/conf/storage_other.conf
13.檢視存儲狀況
cd /fdfs/other/data
14.配置相關檔案
vim /data/server/fastdfs-nginx-module/src/mod_fastdfs.conf
15.建立軟連結
ln -s /fdfs/head/data /fdfs/head/data/m00
ln -s /fdfs/other/data /fdfs/other/data/m00
16.檢視軟連結
ll /fdfs/head/data/m00
ll /fdfs/other/data/m00
17.運作nginx
18.通路網頁
在浏覽器輸入192.168.124.155:8080(storage的ip:8080)
會出現如下頁面
在這裡會出現無法通路頁面的情況
++++++++++++++++++++++++++++++++++++++++++++++++
此時,去tracker上操作第7到第9步
19.修改client.conf檔案
++++++++++++++++++++++++
去tracker上操作第11到第12步
20.檢測
cd /fdfs/head/data/00/00
cd /fdfs/other/data/00/00