FastDFS安裝配置,fastdfs
FastDFS
FastDFS為互連網量身定製,充分考慮了冗餘備份、負載平衡、線性擴容等機制,並注重高可用、高效能等指標,使用FastDFS很容易搭建一套高效能的檔案伺服器叢集提供檔案上傳、下載等服務。
1.所需要的安裝包
2.安裝伺服器(關閉伺服器防火牆service iptables stop setenforce 0)
192.168.241.137------------------------>tracker伺服器
192.168.241.138------------------------>storage伺服器(group1)
192.168.241.139------------------------>storage伺服器(group1)
3.tracker安裝
yum -y install gcc-c++ (安裝編譯工具)
yum -y install libevent (FastDFS依賴libevent庫)
mv libfastcommonV1.0.7.tar.gz /usr/local (將libfastcommon放到/usr/local目錄下)
cd /usr/local
tar -zxvf libfastcommonV1.0.7.tar.gz (解壓libfastcommon)
cd libfastcommon-1.0.7/
./make.sh (編譯libfastcommon)
./make.sh install (安裝libfastcommon)
cp /usr/lib64/libfastcommon.so /usr/lib (注意:libfastcommon安裝好後會自動將庫檔案拷貝至/usr/lib64下,由於FastDFS程式引用usr/lib目錄所以需要將/usr/lib64下的庫檔案拷貝至/usr/lib下)
mv FastDFS_v5.05.tar.gz /usr/local/ (將FastDFS安裝包放到/usr/local目錄下)
cd /usr/local
tar -zxvf FastDFS_v5.05.tar.gz (解壓FastDFS安裝包)
cd FastDFS
./make.sh (編譯FastDFS)
./make.sh install (安裝FastDFS)
cp /usr/local/FastDFS/conf/http.conf /etc/fdfs/ (將http.conf拷貝到/etc/fdfs目錄下)
cp /usr/local/FastDFS/conf/mime.types /etc/fdfs/ (將mime.types拷貝到/etc/fdfs目錄下)
cd /etc/fdfs/ (進入FastDFS設定檔目錄)
cp tracker.conf.sample tracker.conf (拷貝一份新的tracker設定檔)
mkdir -p /home/FastDFS (建立FastDFS工作目錄)
vim tracker.conf (配置設定檔,# HTTP port on this tracker server http.server_port=8080 # the tracker server port port=22122 這裡的連接埠沒有配置使用預設連接埠)
base_path=/home/FastDFS
/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart (啟動tracker伺服器)
4.storage安裝
yum -y install gcc-c++ (安裝編譯工具)
yum -y install libevent (FastDFS依賴libevent庫)
mv libfastcommonV1.0.7.tar.gz /usr/local (將libfastcommon放到/usr/local目錄下)
cd /usr/local
tar -zxvf libfastcommonV1.0.7.tar.gz (解壓libfastcommon)
cd libfastcommon-1.0.7/
./make.sh (編譯libfastcommon)
./make.sh install (安裝libfastcommon)
cp /usr/lib64/libfastcommon.so /usr/lib (注意:libfastcommon安裝好後會自動將庫檔案拷貝至/usr/lib64下,由於FastDFS程式引用usr/lib目錄所以需要將/usr/lib64下的庫檔案拷貝至/usr/lib下)
mv FastDFS_v5.05.tar.gz /usr/local/ (將FastDFS安裝包放到/usr/local目錄下)
cd /usr/local
tar -zxvf FastDFS_v5.05.tar.gz (解壓FastDFS安裝包)
cd FastDFS
./make.sh (編譯FastDFS)
./make.sh install (安裝FastDFS)
cp /usr/local/FastDFS/conf/http.conf /etc/fdfs/ (將http.conf拷貝到/etc/fdfs目錄下)
cp /usr/local/FastDFS/conf/mime.types /etc/fdfs/ (將mime.types拷貝到/etc/fdfs目錄下)
cd /etc/fdfs/ (進入FastDFS設定檔目錄)
cp storage.conf.sample storage.conf (拷貝一份新的tracker設定檔)
vim storage.conf(# the port of the web server on this storage server http.server_port=8888 預設,根據需要設定)
group_name=group1 (組名)
base_path=/home/FastDFS (基礎目錄)
store_path0=/home/FastDFS/fdfs_storage (儲存目錄)
tracker_server=192.168.101.3:22122 (tracker伺服器)
mkdir -p /home/FastDFS (建立FastDFS工作目錄)
mkdir -p /home/FastDFS/fdfs_storage (儲存目錄)
/usr/bin/fdfs_storaged /etc/fdfs/storage.conf restart (啟動storage伺服器)
5.上傳圖片測試(tracker伺服器)
cd /etc/fdfs/
cp client.conf.sample client.conf (FastDFS安裝成功可通過/usr/bin/fdfs_test測試上傳、下載等操作)
vim client.conf (修改設定檔)
base_path=/home/FastDFS
tracker_server=192.168.241.137:22122
使用格式:/usr/bin/fdfs_test 用戶端設定檔地址 upload 上傳檔案
比如將/home下的圖片上傳到FastDFS中:/usr/bin/fdfs_test /etc/fdfs/client.conf upload /home/567.png tracker伺服器顯示日誌:storage伺服器:
6.FastDFS和nginx整合
tracker伺服器裝nginx實現負載平衡,nginx伺服器裝nginx實現http下載
為了體現出負載平衡效果,將192.168.241.138配置為group1;192.168.241.139配置為group2
6.1在tracker上裝nginx
yum install -y pcre pcre-devel (依賴)
yum install -y zlib zlib-devel (依賴)
yum install -y openssl openssl-devel (依賴)
mv nginx-1.8.0.tar.gz /usr/local (將nginx安裝包放到/usr/local/目錄下)
cd /usr/local
tar -zxvf nginx-1.8.0.tar.gz (解壓nginx安裝包)
mkdir -p /var/temp/nginx (建立nginx臨時檔案目錄)
cd /usr/local/nginx-1.8.0
(配置nginx prefix,指定安裝目錄,指定的是nginx的安裝目錄 上邊將臨時檔案目錄指定為/var/temp/nginx,需要在/var下建立temp及nginx目錄)
./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 make (編譯) make install (安裝)
cd /usr/local/nginx/conf/ (開啟nginx設定檔)
vim nginx.conf (編輯nginx設定檔)
upstream storage_server_group1{ server 192.168.241.138:8888 weight=10; } upstream storage_server_group2{ server 192.168.241.139:8888 weight=10; } server { listen 8080; server_name ccc.test.com; 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_pass http://storage_server_group1; } location /group2{ 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_pass http://storage_server_group2; } }
6.2storage上裝nginx
yum install -y pcre pcre-devel (依賴)yum install -y zlib zlib-devel (依賴)yum install -y openssl openssl-devel (依賴)
mv fastdfs-nginx-module_v1.16.tar.gz /usr/local (將fastdfs和nginx整合包放到/usr/local下)
mv nginx-1.8.0.tar.gz /usr/local (將nginx安裝包放在/usr/local下)
tar -zxvf fastdfs-nginx-module_v1.16.tar.gz (解壓整合包)
cd fastdfs-nginx-module/src/ (開啟設定檔夾)
vim config
修改config檔案將/usr/local/路徑改為/usr/
cp /usr/local/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs/ (將整合設定檔放在fastdfs設定檔夾下)
vi /etc/fdfs/mod_FastDFS.conf (修改設定檔)
base_path=/home/FastDFS
tracker_server=192.168.101.3:22122
url_have_group_name=true #url中包含group名稱
store_path0=/home/FastDFS/fdfs_storage #指定檔案儲存體路徑
cp /usr/lib64/libfdfsclient.so /usr/lib/
mkdir -p /var/temp/nginx/client (建立nginx/client目錄)
nginx安裝
tar -zxvf nginx-1.8.0.tar.gz
cd nginx-1.8.0
./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 make
make install
cd /usr/local/nginx/conf/ (開啟nginx設定檔)
vim nginx.conf (編輯nginx設定檔)
server { listen 8888; server_name 192.168.241.138; location /group1/M00/{ root /home/FastDFS/fdfs_storage/data; ngx_fastdfs_module; } }
說明:server_name指定本機iplocation /group1/M00/:group1為nginx 服務FastDFS的分組名稱,M00是FastDFS自動產生編號,對應store_path0=/home/FastDFS/fdfs_storage,如果FastDFS定義store_path1,這裡就是M01