1. 程式人生 > 其它 >linux --------fastDFS安裝+配置Nginx

linux --------fastDFS安裝+配置Nginx

技術標籤:伺服器搭建linuxnginx

linux 下fastDFS安裝+配置Nginx:

環境:fastDFS 5.05
nginx 1.8.0
fastdfs-nginx-module 1.16

千萬要注意版本, 千萬要注意版本, 千萬要注意版本

直接上命令:

yum install -y gcc gcc-c++
wget https://github.com/happyfish100/libfastcommon/archive/V1.0.7.tar.gz
tar -zxvf V1.0.7.tar.gz
cd libfastcommon-1.0.7
./make.sh
// 安裝,命令:
./make.sh install
wget https://github.com/happyfish100/fastdfs/archive/V5.05.tar.gz
tar -zxvf V5.05.tar.gz
cd fastdfs-5.05
./make.sh
安裝,命令:
./make.sh install

1. 配置Tracker 服務

cp tracker.conf.sample tracker.conf
vim tracker.conf

開啟tracker.conf檔案,只需要找到你只需要改這兩個引數就可以了。

 base_path=/home/java/fastdfs
 http.server_port=80
 /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf start

使用ln -s 建立軟連結:

 ln -s /usr/bin/fdfs_trackerd /usr/local/bin
 ln -s /usr/bin/stop.sh /usr/local/bin
 ln -s /usr/bin/restart.sh /usr/local/bin

啟動服務,檢視監聽:

service fdfs_trackerd start
netstat -unltp|grep fdfs

2. 配置 Storage 服務:

cp storage.conf.sample storage.conf
vim storage.conf

修改:

base_path=/home/java/fastdfs
store_path0=/home/java/fastdfs
tracker_server=192.168.13.53:22122   //可以修改所需埠號

ln -s建立軟連結:

ln -s /usr/bin/fdfs_storaged /usr/local/bin

啟動服務

service fdfs_storaged start

配置client.conf

cd /etc/fdfs
cp client.conf.sample client.conf
vim client.conf

base_path=/home/java/fastdfs
tracker_server=192.168.13.53:22122

Fast配置Nginx模組

環境所需nginx:fastdfs-nginx-module_v1.16.tar.gz

注意版本 ,注意版本 ,注意版本

yum install -y gcc gcc-c++
yum -y install openssl openssl-devel
wget https://nginx.org/download/nginx-1.8.0.tar.gz
tar -zxvf nginx-1.8.0.tar.gz
tar -zxvf fastdfs-nginx-module_v1.16.tar.gz

進入fastdfs-nginx-module,修改config

CORE_INCS="$CORE_INCS /usr/include/fastdfs /usr/include/fastcommon/"

修改完之後:

ngx_addon_name=ngx_http_fastdfs_module
HTTP_MODULES="$HTTP_MODULES ngx_http_fastdfs_module"
NGX_ADDON_SRCS="$NGX_ADDON_SRCS $ngx_addon_dir/ngx_http_fastdfs_module.c"
CORE_INCS="$CORE_INCS /usr/include/fastdfs /usr/include/fastcommon/"
CORE_LIBS="$CORE_LIBS -L/usr/local/lib -lfastcommon -lfdfsclient"
CFLAGS="$CFLAGS -D_FILE_OFFSET_BITS=64 -DFDFS_OUTPUT_CHUNK_SIZE='256*1024' -DFDFS_MOD_CONF_FILENAME='\"/etc/fdfs/mod_fastdfs.conf\"'"

修改mod_fastdfs.conf

cd /software/fastdfs-nginx-module-master/src/
vim mod_fastdfs.conf

修改點:

tracker_server=192.168.13.53:22122
url_have_group_name = true
store_path0=/home/java/fastdfs
cp anti-steal.jpg http.conf mime.types /etc/fdfs/

nginx配置:

./configure --prefix=/usr/local/nginx  --add-module=/home/java/fastdfs-nginx-module/src/
make && make install
cd /usr/local/nginx/sbin

./nginx -V 檢視fastdfs-nginx-module 是否加進去了
沒有先刪除 /usr/local/nginx 在到make目錄 make clean
可能會產生錯誤:

1:make[1]: *** [objs/src/core/ngx_murmurhash.o] Error 1

解決辦法:cd nginx安裝目錄objs/ 修改Makefile 刪除-Werrori

/-Werrori  快捷定位

2:怎麼也找不到fastdfs-nginx-module-master unknown directive "ngx_fastdfs_module"

由於版本問題無法解決這個問題,換fastdfs-nginx-module-master版本

nginx 配置檔案中配置

server {
        listen       80;
        server_name  192.168.13.53; //改你自己伺服器IP


        #charset koi8-r;


        #access_log  logs/host.access.log  main;


        location / {
            root   html;
            index  index.html index.htm;
        }
        location ~/group([0-9])/M00 {
                ngx_fastdfs_module;
            }

啟動nginx

cd  /usr/localhost/nginx/sbin
./nginx -c /usr/localhost/nginx/conf/nginx.conf  //帶配置啟動
./nginx -s stop  //停止

上傳測試fastDFS: 後面 /home/java/test.png 為要上傳圖片的地址
/usr/bin/fdfs_t
est /etc/fdfs/client.conf upload /home/java/test.png

伺服器屬於內網環境:直接使用下面地址是訪問不通的
http://192.168.13.53/group1/M00/00/00/wKgNNV_I1xCAFStkAABzZSCzVUY582_big.png為瀏覽器測試地址

參考地址,但需排坑:https://blog.csdn.net/qq_32953079/article/details/83789461?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-2.control&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-2.control