參考博客html
http://www.linux178.com/storage/fastdfs-nginx-cache.htmljava
FastDFS 安裝及使用linux
http://www.linuxidc.com/Linux/2015-01/111889.htm nginx
軟硬件準備c++
最小化安裝的 CentOS 6.2
git
tracker1: 192.168.227.128
storage1: 192.168.227.130 storage1: 192.168.227.131
yum install http://mirrors.hustunique.com/epel//6/x86_64/epel-release-6-8.noarch.rpm
固然,你的訪問速度有些慢,你能夠嘗試以下操做,而後再安裝epelgithub
《Centos修改鏡像爲國內的阿里雲源或者163源等國內源》vim
卸載掉舊版本windows
rpm -qa libevent libevent-1.4.13-1.el6.x86_64 rpm -e --nodeps libevent
而後下載安裝新版本
1.下載libevent: wget https://github.com/downloads/libevent/libevent/libevent-2.0.21-stable.tar.gz 2.解壓libevent: tar -zxvpf libevent-2.0.21-stable.tar.gz 3.進入解壓目錄: cd libevent-2.0.21-stable 4.指定安裝目錄: ./configure --prefix=/usr/local/libevent-2.0.21 5.安裝 make && make install
爲libevent建立軟連接(相似windows快捷目錄)到/lib庫下,64位系統對應/lib64(此處能夠省略)
ln -s /usr/local/lib/libevent* /lib/ #若是是64bit系統,使用以下命令 #ln -s /usr/local/lib/libevent* /lib64/
Traceker和Storage都是一樣的安裝包,咱們只須要把FastDFS安裝在不一樣的主機上,經過配置進行區別
2、安裝FastDFS步驟以下: 1.下載FastDFS: wget http://fastdfs.googlecode.com/files/FastDFS_v4.06.tar.gz 2.解壓FastDFS: tar xvf FastDFS_v4.06.tar.gz 3.進入解壓目錄: cd FastDFS 4.修改FastDFS的安裝文件: vi make.sh TARGET_PREFIX=/usr/local/FastDFS ---安裝路徑 TARGET_CONF_PATH=/etc/fdfs ---配置文件路徑 WITH_LINUX_SERVICE=1 ---是否爲linux服務 5.指定libevent的lib目錄: ./make.sh C_INCLUDE_PATH=/usr/local/libevent-2.0.21/include LIBRARY_PATH=/usr/local/libevent-2.0.21/lib 6.安裝FastDFS: ./make.sh install 7.設置軟鏈接(不然編譯nginx時會出錯) ln -sv /usr/local/FastDFS/include/fastcommon /usr/local/include/fastcommon ln -sv /usr/local/FastDFS/include/fastdfs /usr/local/include/fastdfs ln -sv /usr/local/FastDFS/lib/libfastcommon.so /usr/local/lib/libfastcommon.so ln -sv /usr/local/FastDFS/lib/libfastcommon.so.1 /usr/local/lib/libfastcommon.so.1 ln -sv /usr/local/FastDFS/lib/libfdfsclient.so /usr/local/lib/libfdfsclient.so ln -sv /usr/local/FastDFS/lib/libfdfsclient.so.1 /usr/local/lib/libfdfsclient.so.1
在安裝Nginx以前,須要安裝gcc、 openssl-devel、 pcre-devel和zlib-devel軟件庫,具體以下:
yum install gcc-c++ openssl-devel pcre-devel zlib-devel
在storage上安裝的nginx主要爲了提供http的訪問服務,同時解決group中storage服務器的同步延遲問題。(須要安裝ngx_cache_purge-2.1.tar.gz)
wget http://nginx.org/download/nginx-1.6.0.tar.gz wget http://fastdfs.googlecode.com/files/fastdfs-nginx-module_v1.15.tar.gz 將安裝包文件上傳到/usr/local中執行如下操做: 1.進入文件目錄: cd /usr/local 2.解壓安裝包: tar -zxv -f nginx-1.6.0.tar.gz tar -xvf fastdfs-nginx-module_v1.15.tar.gz 3.修改安裝包目錄名稱: mv nginx-1.6.0 nginx 4.進入安裝包目錄: cd /usr/local/nginx 5.配置安裝目錄: ./configure --prefix=/usr/local/nginx --conf-path=/usr/local/nginx/nginx.conf --add-module=/usr/local/fastdfs-nginx-module/src6.安裝Nginx: makemake install 7.修改防火牆: vi + /etc/sysconfig/iptables 8.添加配置項 -A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT 9.重啓防火牆: service iptables restart 10.將libfastcommon.so、libfastcommon.so.一、libfdfsclient.so、libfdfsclient.so.1複製到/usr/lib, 不然nginx啓動會報錯。 Nginx的操做: 啓動: /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf或者 cd /usr/local/nginx/sbin ./nginx 中止服務: #查詢nginx主進程號 ps -ef | grep nginx #中止進程 kill -QUIT 主進程號 #快速中止 kill -TERM 主進程號 #強制中止 pkill -9 nginx 重啓: /usr/local/nginx/sbin/nginx -s reload
1. vi /etc/fdfs/tracker.conf bind_addr=192.168.227.128 port=22122 # 配置data和log的存放路徑,該路徑若是不存在,須要本身建立 base_path=/home/tracker/fastdfs 2.配置防火牆: iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 22122 -j 3.保存配置: /etc/init.d/iptables save 4. 啓動 tracker/usr/local/FastDFS/bin/fdfs_trackerd /etc/fdfs/tracker.conf 在啓動時報錯: /usr/local/bin/fdfs_trackerd: error while loading shared libraries: libevent-2.0.so.5: cannot open shared object file: No such file or directory 執行下面的命令便可正常啓動: echo '/usr/local/libevent-2.0.21/include/' >> /etc/ld.so.conf echo '/usr/local/libevent-2.0.21/lib/' >> /etc/ld.so.conf ldconfig 5. 查看監聽程序: netstat -ntpl | grep fdfs 6. 查看日誌文件: cat /home/tracker/fastdfs/logs/trackerd.log 7.添加開機啓動命令行: vim /etc/rc.d/rc.local/usr/local/FastDFS/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart
一、tracker
A、啓動命令 :/usr/local/bin/fdfs_trackerd /etc/fdfs/tracker.conf(tracker的配置文件路徑)
B、重啓命令:/usr/local/bin/restart.sh /usr/local/bin/fdfs_trackerd /usr/local/config/tracker.conf (tracker的配置文件路徑)
1. vi /etc/fdfs/storage.conf group_name=group1 bind_addr=192.168.227.130 base_path=/home/storage/fastdfs store_path0=/home/storage/fastdfs tracker_server=192.168.227.128:22122 #能夠設置多個-----------待驗證 http.server.port=80 #設置訪問storage服務器的端口號 #拷貝配置文件到etc下 2. cp /usr/local/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs/ #進行編輯mod_fastdfs.conf 3. vi /etc/fdfs/mod_fastdfs.conf tracker_server=192.168.227.128:22122 -- tracker server的ip和端口,此處能夠寫多個tracker server,每行一個 url_have_group_name = true --必須設置爲true才能支持多個group group_count = 2 --storage的group個數 [group1] base_path=/home/storage1/fastdfs group_name=group1 storage_server_port=23000 store_path_count=1 store_path0=/home/stroage1/fastdfs [group2] base_path=/home/storage1/fastdfs group_name=group2 storage_server_port=23000 store_path_count=1 store_path0=/home/stroage1/fastdfs #ngnix配置 4. vi /usr/local/nginx/conf/nginx.conf server { listen 80; server_name localhost; location ~ /group([1-2])/M00/ { root /home/storage1/fastdfs/data; ngx_fastdfs_module; } } 5.配置防火牆: iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 23000 -j ACCEPT 6.保存配置: /etc/init.d/iptables save 7.啓動 storage /usr/local/FastDFS/bin/fdfs_storaged /etc/fdfs/storage.conf 8. 查看監聽程序: netstat -ntpl | grep fdfs 9. 查看日誌文件: cat /home/storage/fastdfs/logs/storaged.log
二、storage
A、啓動命令:/usr/local/bin/fdfs_storaged /etc/fdfs/storage_p1.conf (storage配置文件路徑)
B、重啓命令:/usr/local/bin/restart.sh :/usr/local/bin/fdfs_storaged /etc/fdfs/storage_p1.conf (storage配置文件路徑)
vim /etc/fdfs/client.conf base_path=/home/storage/fastdfs tracker_server=192.168.1.128:22122
/usr/local/FastDFS/bin/fdfs_test /etc/fdfs/client.conf upload a.html
在瀏覽器上打開http://192.168.227.130/group1/M00/00/00/wKjjglOOkd2AdZiiAAAFng0Nczs9728851_big
測試成功!!!
九.在Traceker上安裝Ngnix(非重點內容,玩玩便可)
在tracker上安裝的nginx主要爲了提供http訪問的反向代理、負載均衡以及緩存服務。固然,也能夠單獨安裝Ngnix
worker_processes 4; #根據CPU核心數而定 events{ worker_connections 65535; #最大連接數 use epoll;#新版本的Linux可以使用epoll加快處理性能 } http{ #設置緩存參數 server_names_hash_bucket_size 128; client_header_buffer_size32k; large_client_header_buffers 4 32k; client_max_body_size300m; sendfile on; tcp_nopushon; proxy_redirectoff; proxy_set_headerHost $http_host; proxy_set_headerX-Real-IP $remote_addr; proxy_set_headerX-Forwarded-For $proxy_add_x_forwarded_for; proxy_connect_timeout 90; proxy_send_timeout 90; proxy_read_timeout 90; proxy_buffer_size16k; proxy_buffers 4 64k; proxy_busy_buffers_size128k; proxy_temp_file_write_size128k; #設置緩存存儲路徑、存儲方式、分配內存大小、磁盤最大空間、緩存期限 proxy_cache_path/var/cache/nginx/proxy_cache levels=1:2 keys_zone=http-cache:500m max_size=10ginactive=30d; proxy_temp_path/var/cache/nginx/proxy_cache/tmp; #設置group1的服務器 upstream fdfs_group1 { server 192.168.227.130:80 weight=1 max_fails=2 fail_timeout=30s; server 192.168.227.131:80 weight=1 max_fails=2 fail_timeout=30s; } #設置group2的服務器 upstream fdfs_group2 { server 192.168.227.130:80 weight=1 max_fails=2 fail_timeout=30s; server 192.168.227.131:80 weight=1 max_fails=2 fail_timeout=30s; } server{ #設置服務器端口 listen 80; #設置group1的負載均衡參數 location/group1/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_group1; expires 30d; } #設置group2的負載均衡參數 location/group2/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_group2; expires 30d; } #設置清除緩存的訪問權限 location~ /purge(/.*) { allow 127.0.0.1; allow 172.16.1.0/24; deny all; proxy_cache_purge http-cache $1$is_args$args; }
運行nginx以前,先要把防火牆中對應的端口打開(本例中爲80)。
具體參考:http://blog.csdn.net/lynnlovemin/article/details/39398043