yum -y install gcc gcc-c++
yum -y install zip unzip
yum -y install vim*
yum -y install pcre* zlib* opssl*
systemctl stop firewalld.service
systemctl disable firewalld
makdir -p /usr/local/apps
wget https://codeload.github.com/happyfish100/fastdfs/tar.gz/V5.05
wget https://codeload.github.com/happyfish100/libfastcommon/tar.gz/V1.0.36
wget http://219.239.26.11/files/1095000009284083/nginx.org/download/nginx-1.8.1.tar.gz
wget https://codeload.github.com/happyfish100/fastdfs-nginx-module/tar.gz/V1.20
wget https://codeload.github.com/FRiCKLE/ngx_cache_purge/tar.gz/2.3
tracker
服务器(192.168.150.20)vim /etc/sysconfig/network-scripts/[静态网卡名]
tracker
tar -zxvf libfastcommon.tar.gz
mv libfastcommon ../
进入 libfastcommon目录,执行:./make.sh && ./make.sh install
tar ...
./make.sh && ./make.sh install
mkdir -p /opt/fastdfs_tracker
cd /etc/fdfs
cp tracker.conf.sample tracker.conf
vim tracker.conf
disabled=false #启用配置文件(默认启用)
port=22122 #设置tracker的端口号,通常采用22122这个默认端口
base_path=/opt/fastdfs_tracker #设置tracker的数据文件和日志目录
http.server_port=8080 #设置http端口号,默认为8080
/usr/local/bin
然而,实际安装却是在/usr/bin
)
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
ngx_cache_purge-2.3
移动到/usr/local
目录下/usr/local
目录下nginx-1.8.1
目录./configure --add-module=/usr/local/ngx_cache_purge-2.3
make && make install
mkdir -p /fastdfs/cache/nginx/proxy_cache
mkdir -p /fastdfs/cache/nginx/proxy_cache/tmp
vim /usr/local/nginx/conf/nginx.conf
user root;
worker_processes 1;
events {
worker_connections 1024;
use epoll;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
tcp_nopush on;
keepalive_timeout 65;
# 设置缓存
server_names_hash_bucket_size 128;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
client_max_body_size 300m;
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 /fastdfs/cache/nginx/proxy_cache levels=1:2
keys_zone=http-cache:200m max_size=1g inactive=30d;
proxy_temp_path /fastdfs/cache/nginx/proxy_cache/tmp;
# group1的服务设置
upstream fdfs_group1 {
server 192.168.150.22:8888 weight=1 max_fails=2 fail_timeout=30s;
server 192.168.150.23:8888 weight=1 max_fails=2 fail_timeout=30s;
}
# group2的服务设置
upstream fdfs_group2 {
server 192.168.150.24:8888 weight=1 max_fails=2 fail_timeout=30s;
server 192.168.150.25:8888 weight=1 max_fails=2 fail_timeout=30s;
}
server {
listen 8000;
server_name localhost;
# charset koi8-r;
# access_log logs/host.access.log main;
# 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;
# 对应group1的服务设置
proxy_pass http://fdfs_group1;
expires 30d;
}
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;
# 对应group2的服务设置
proxy_pass http://fdfs_group2;
expires 30d;
}
location ~/purge(/.*) {
allow 127.0.0.1;
allow 192.168.150.0/255;
deny all;
proxy_cache_purge http-cache $1$is_args$args;
}
location / {
root html;
index index.html index.htm;
}
# error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
storage
(192.168.150.22)libfastcommon和fastdfs
(不需要配置tracker)vim /etc/fdfs/storage.conf
disabled=false #启用配置文件(默认启用)
group_name=group1 #组名,根据实际情况修改
port=23000 #设置storage的端口号,默认是23000,同一个组的storage端口号必须一致
base_path=/opt/fastdfs_storage #设置storage数据文件和日志目录
store_path_count=1 #存储路径个数,需要和store_path个数匹配
store_path0=/opt/fastdfs_storage_data #实际文件存储路径
tracker_server=192.168.150.20:22122 #tracker 服务器的 IP地址和端口号,如果是单机搭建,IP不要写127.0.0.1,否则启动不成功(此处的ip是我的CentOS虚拟机ip)
http.server_port=8888 #设置 http 端口号
mkdir -p /opt/fastdfs_storage
mkdir -p /opt/fastdfs_storage_data
ln -s /usr/bin/fdfs_storaged /usr/local/bin
fastdfs-nginx-module
移动到/usr/local
fastdfs-nginx-modul
vim src/config
CORE_INCS
中的local
,因为实际安装在/usr/bin
目录nginx-1.8.1
移动到/usr/local
nginx-1.8.1
,./configure --prefix=/usr/local/nginx --add-module=/usr/local/fastdfs-nginx-module-master/src
make && make install
cp -r /usr/local/fastdfs-5.05/conf/http.conf /etc/fdfs/
cp -r /usr/local/fastdfs-5.05/conf/mime.types /etc/fdfs/
cp -r /usr/local/fastdfs-nginx-module-master/src/mod_fastdfs.conf /etc/fdfs/
vim /etc/fdfs/mod_fastdfs.conf
connect_timeout=10
tracker_server=192.168.150.20:22122
tracker_server=192.168.150.21:22122
storage_server_port=23000//默认就是2300,不用做修改
url_have_group_name=true
store_path0=/opt/fastdfs_storage_data
group_name=group1
group_count=2
[group1]
group_name=group1
storage_server_port=23000
store_path_count=1
store_path0=/opt/fastdfs_storage_data
[group2]
group_name=group2
storage_server_port=23000
store_path_count=1
store_path0=/opt/fastdfs_storage_data
listen 8888;
location ~/group([0-9])/M00 {
ngx_fastdfs_module;
}
storage.conf
中group_name=group2
,修改mod_fastdfs.conf
中group_name=group2
nginx-1.8.1
移动到/usr/local
./configure --prefix=/usr/local/nginx --with-http_ssl_module
vim /usr/local/nginx/conf/nginx.conf
# 以下在http模块里面
upstream fastdfs_tracker {
server 192.168.150.20:8080 weight=1 max_fails=2 fail_timeout=30s;
server 192.168.150.21:8080 weight=1 max_fails=2 fail_timeout=30s;
}
# 以下在server模块里
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
proxy_pass http://fastdfs_tracker/;
proxy_set_header Host $http_host;
proxy_set_header Cookie $http_cookie;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
client_max_body_size 300m;
}
在两台tracker
服务器中执行
chmod +x /etc/rc.d/rc.local
cd /root
vim tracker.sh
#!/bin/bash
service network restart;# 重启network,因为配置双网卡,不知道为什么每次都需要重启
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf;# 启动nginx
service fdfs_trackerd start;# 启动tracker服务
chmod +x /root/tracker.sh
vim /etc/rc.d/rc.local
/root/tracker.sh
在4台storage
做如下配置
chmod +x /etc/rc.d/rc.local
cd /root
vim storage.sh
#!/bin/bash
service network restart;# 重启network,因为配置双网卡,不知道为什么每次都需要重启
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf;# 启动nginx
service fdfs_storaged start;# 启动storage
chmod +x /root/tracker.sh
vim /etc/rc.d/rc.local
/root/storage.sh
chmod +x /etc/rc.d/rc.local
vim /etc/rc.d/rc.local
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
n
个tracker
,方法同理,m
个storage
方法也同理,注意:我们虽然有4个storage,但是只有2个group,这样等于主-备
,同一个组
的一个storage
挂了,另外一台立马顶上,当然也可搭建h
个nginx反向代理
,在加一层slb
或者lvs
等等,都可以storage
是基于tracker
的,所以要先启动两台tracker
,再启动4台storage
,至于最后一台nginx服务
,什么时候启动都可以netstat -unltp|grep fdfs
看是否有22122
,23000
端口test.jpg
base_path
为tracker
的base_path
,tracker_server
修改为实际的tracker
服务器ip(不要写127.0.0.1)/usr/bin/fdfs_upload_file /etc/fdfs/client.conf /root/timg.jpg
group1/M00/00/00/wKiWh1tawuqAAjwEAADX0sGyaUA511.jpg
nginx反向代理服务器访问
: http://192.168.150.26/group1/M00/00/00/wKiWh1tawuqAAjwEAADX0sGyaUA511.jpg
id6a