码迷,mamicode.com
首页 > 其他好文 > 详细

fastdfs+nginx的安装部署

时间:2017-02-25 21:31:55      阅读:224      评论:0      收藏:0      [点我收藏+]

标签:hosts   host   user   .gz   check   active   slot   系统   tar   

 

 

原理图:

技术分享

fastdfs适用场景:

  fastdfs特别适合海量 中小文件(建议范围:4KB< file_size <500MB)为载体的在线服务。

 

安装系统介绍:

  CentOS6.6

安装准备软件包:

技术分享

 

一、安装fastdfs:


[root@xiaofan fxh]# pwd
/home/fxh
[root@xiaofan fxh]# tar xf libevent-2.0.19-stable.tar.gz
[root@xiaofan fxh]# cd libevent-2.0.19-stable
[root@xiaofan libevent-2.0.19-stable]# ./configure --prefix=/usr/local/libevent
[root@xiaofan libevent-2.0.19-stable]# make
[root@xiaofan libevent-2.0.19-stable]# make install

[root@xiaofan ~]# cd /home/fxh/
[root@xiaofan fxh]# tar xf FastDFS_4.06.tar.gz
[root@xiaofan fxh]# tar xf FastDFS_4.06.tar.gz
[root@xiaofan fxh]# cd FastDFS
[root@xiaofan FastDFS]# ./make.sh C_INCLUDE_PATH=/usr/local/libevent/include LIBRARY_PATH=/usr/local/libevent/lib
[root@xiaofan FastDFS]# ./make.sh install


配置文件路径:/etc/fdfs/
tracker.conf//负责均衡调度服务器配置文件
client.conf//客户端上传配置文件
http.conf//http服务器配置文件
storage.conf//文件存储服务器配置文件
mime.types//文件类型配置文件


tracker配置文件:
[root@xiaofan ~]# egrep -v "^#|^$" /etc/fdfs/tracker.conf
disabled=false
bind_addr=
port=22122
connect_timeout=30
network_timeout=60
base_path=/home/data #设置base_path
max_connections=1000
work_threads=4
store_lookup=2
store_group=group1
store_server=0
store_path=0
download_server=0
reserved_storage_space = 10%
log_level=info
run_by_group=
run_by_user=
allow_hosts=*
sync_log_buff_interval = 10
check_active_interval = 120
thread_stack_size = 64KB
storage_ip_changed_auto_adjust = true
storage_sync_file_max_delay = 86400
storage_sync_file_max_time = 300
use_trunk_file = false
slot_min_size = 256
slot_max_size = 16MB
trunk_file_size = 64MB
trunk_create_file_advance = false
trunk_create_file_time_base = 02:00
trunk_create_file_interval = 86400
trunk_create_file_space_threshold = 20G #
trunk_init_check_occupying = false
trunk_init_reload_from_binlog = false
use_storage_id = false
storage_ids_filename = storage_ids.conf
id_type_in_filename = ip
store_slave_file_use_link = false
rotate_error_log = false
error_log_rotate_time=00:00
rotate_error_log_size = 0
use_connection_pool = false
connection_pool_max_idle_time = 3600
http.server_port=8080 #http 端口
http.check_alive_interval=30
http.check_alive_type=tcp
http.check_alive_uri=/status.html

创建目录:
mkdir /home/data #启动可能会报错,哪个目录没创建,看日志就好了


添加iptables规则:
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22122 -j ACCEPT


启动tracker:
/usr/local/bin/fdfs_trackerd /etc/fdfs/tracker.conf


检查端口22122:
[root@xiaofan ~]# lsof -i :22122
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
fdfs_trac 1605 root 5u IPv4 13569 0t0 TCP *:22122 (LISTEN)
fdfs_trac 1605 root 25u IPv4 13666 0t0 TCP 10.10.168.104:22122->10.10.168.104:46410 (ESTABLISHED)
fdfs_trac 1605 root 26u IPv4 13699 0t0 TCP 10.10.168.104:22122->10.10.168.105:filenet-rmi (ESTABLISHED)
fdfs_trac 1605 root 27u IPv4 13705 0t0 TCP 10.10.168.104:22122->10.10.168.105:32781 (ESTABLISHED)
fdfs_stor 1631 root 26u IPv4 135680 0t0 TCP 10.10.168.104:41466->10.10.168.105:22122 (SYN_SENT)
fdfs_stor 1631 root 27u IPv4 13685 0t0 TCP 10.10.168.104:46410->10.10.168.104:22122 (ESTABLISHED)

 

storage配置文件:
[root@xiaofan ~]# egrep -v "^#|^$" /etc/fdfs/storage.conf
disabled=false
group_name=group1
bind_addr=
client_bind=true
port=23000
connect_timeout=30
network_timeout=60
heart_beat_interval=30
stat_report_interval=60
base_path=/home/data
max_connections=1000
buff_size = 256KB
work_threads=4
disk_rw_separated = true
disk_reader_threads = 1
disk_writer_threads = 1
sync_wait_msec=50
sync_interval=0
sync_start_time=00:00
sync_end_time=23:59
write_mark_file_freq=500
store_path_count=1
store_path0=/home/data/storage
subdir_count_per_path=256
tracker_server=10.10.168.104:22122
tracker_server=10.10.168.105:22122
log_level=info
run_by_group=
run_by_user=
allow_hosts=*
file_distribute_path_mode=0
file_distribute_rotate_count=100
fsync_after_written_bytes=0
sync_log_buff_interval=10
sync_binlog_buff_interval=10
sync_stat_file_interval=300
thread_stack_size=512KB
upload_priority=10
if_alias_prefix=
check_file_duplicate=0
file_signature_method=hash
key_namespace=FastDFS
keep_alive=0
use_access_log = false
rotate_access_log = false
access_log_rotate_time=00:00
rotate_error_log = false
error_log_rotate_time=00:00
rotate_access_log_size = 0
rotate_error_log_size = 0
file_sync_skip_invalid_record=false
use_connection_pool = false
connection_pool_max_idle_time = 3600
http.domain_name=
http.server_port=8888

 

iptables规则:
-A INPUT -m state --state NEW -m tcp -p tcp --dport23000 -j ACCEPT


启动stroage:
/usr/local/bin/fdfs_storaged /etc/fdfs/storage.conf
#启动时会看到屏幕创建一叠的目录。


检查端口:
[root@xiaofan ~]# lsof -i :23000
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
fdfs_stor 1631 root 5u IPv4 13670 0t0 TCP *:inovaport1 (LISTEN)
fdfs_stor 1631 root 29u IPv4 13701 0t0 TCP 10.10.168.104:inovaport1->10.10.168.105:39237 (ESTABLISHED)


如果报错libevent库找不到:
解决方法1:
find / -name libevent-2.0.so.5
ln -s /usr/local/libevent/lib/libevent-2.0.so.5 /usr/lib64/libevent-2.0.so.5
解决方法2:
find / -name libevent-2.0.so.5
[root@xiaofan ~]# tail -1 /etc/profile
export LD_LIBRARY_PATH=/usr/local/lib/
[root@xiaofan ~]# source /etc/profile


二、安装配置nginx结合fastdfs:
[root@xiaofan fxh]# tar xf fastdfs-nginx-module_v1.16.tar.gz
[root@xiaofan fxh]# tar xf nginx-1.2.0.tar.gz
[root@xiaofan fxh]# yum install -y pcre-devel zlib-devel
[root@xiaofan fxh]# cd nginx-1.2.0
[root@xiaofan nginx-1.2.0]# ./configure --prefix=/usr/local/nginx --with-http_stub_status_module --add-module=/home/fxh/fastdfs-nginx-module/src --with-http_ssl_module
[root@xiaofan nginx-1.2.0]# make
[root@xiaofan nginx-1.2.0]# make install

修改配置文件mod_fastdfs:
[root@xiaofan nginx-1.2.0]# cp /home/fxh/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs/
[root@xiaofan nginx-1.2.0]# egrep -v "^#|^$" /etc/fdfs/mod_fastdfs.conf
connect_timeout=2 #
network_timeout=30
base_path=/home/data
load_fdfs_parameters_from_tracker=true
storage_sync_file_max_delay = 86400
use_storage_id = false
storage_ids_filename = storage_ids.conf
tracker_server=10.10.168.104:22122
tracker_server=10.10.168.105:22122
storage_server_port=23000
group_name=group1
url_have_group_name = true
store_path_count=1
store_path0=/home/data/storage
log_level=info
log_filename=
response_mode=proxy
if_alias_prefix=
flv_support = true
flv_extension = flv
group_count = 0
/usr/local/nginx/sbin/nginx

进行文件上传测试:

修改client配置文件:
[root@xiaofan ~]# egrep -v "^#|^$" /etc/fdfs/client.conf
connect_timeout=30
network_timeout=60
base_path=/home/data
tracker_server=10.10.168.104:22122
tracker_server=10.10.168.105:22122
log_level=info
use_connection_pool = false
connection_pool_max_idle_time = 3600
load_fdfs_parameters_from_tracker=false
use_storage_id = false
storage_ids_filename = storage_ids.conf
http.tracker_server_port=8080

修改nginx配置文件:
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
server {
listen 80;
  server_name localhost;
  #charset koi8-r;
  #access_log logs/host.access.log main;
  location /group1/M00 {
  #alias /home/data/storage/data;
  root /home/data/storage/data;
  ngx_fastdfs_module;
   }
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
    }
  }
}

 

修改iptables配置:
-A INPUT -m state --state NEW -m tcp -p tcp --dport80 -j ACCEPT


启动ngnx:
/usr/local/nginx/sbin/nginx -t
/usr/local/nginx/sbin/nginx

进行测试:
[root@xiaofan ~]# echo "test" > test.txt
[root@xiaofan ~]# /usr/local/bin/fdfs_upload_file /etc/fdfs/client.conf ./test.txt
group1/M00/00/00/CgqoaFixY6SAb2xYAAAABelE2rQ054.txt
[root@xiaofan ~]# curl http://10.10.168.104/group1/M00/00/00/CgqoaFixY6SAb2xYAAAABelE2rQ054.txt
test


上传个图片测试:
[root@xiaofan 00]# pwd
/home/data/storage/data/00/00
[root@xiaofan 00]# ls
Cgoel1c0YxqAcDLvAAB5mpJABlg563.jpg CgqoaFixY6SAb2xYAAAABelE2rQ054.txt

 技术分享

 

fastdfs+nginx的安装部署

标签:hosts   host   user   .gz   check   active   slot   系统   tar   

原文地址:http://www.cnblogs.com/fanxuanhui/p/6442716.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!