参考博客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