当前位置: > CentOS > CentOS教程 >

CentOS 6.5安装FastDFS_5.05

时间:2016-04-02 03:37来源:linux.it.net.cn 作者:IT网
1.安装依赖包和开发工具:
yum install vim vim-enhanced wget zip unzip telnet ntsysv compat* apr* pcre* pcre-* nasm* gcc gcc* gcc-c++ ntp make imake cmake automake autoconf zlib zlib-devel glibc glibc-devel glib2 libxml glib2-devel libxml2 libxml2-devel bzip2 bzip2-devel libXpm libXpm-devel libidn libidn-devel libtool libtool-ltdl-devel* libmcrypt libmcrypt-devel libevent-devel libmcrypt* curl curl-devel perl perl-Net-SSLeay pcre pcre-devel ncurses ncurses-devel openssl openssl-devel openldap openldap-devel openldap-clients openldap-servers krb5 krb5-devel e2fsprogs e2fsprogs-devel libjpeg libpng libjpeg-devel libjpeg-6b libjpeg-devel-6b libpng-devel libtiff-devel freetype freetype-devel fontconfig-devel gd gd-devel kernel screen sysstat flex bison nss_ldap pam-devel compat-libstdc++-33 gettext-devel libXft-devel libXtst-devel

2.安装libfastcommon:
tar zxvf libfastcommon-1.0.7.tar.gz -C /usr/src
cd /usr/src/libfastcommon-1.0.7/
./make.sh
./make.sh install
ln -s /usr/lib64/libfastcommon.so /usr/local/lib/libfastcommon.so
ln -s /usr/lib64/libfastcommon.so /usr/lib/libfastcommon.so
ln -s /usr/lib64/libfdfsclient.so /usr/local/lib/libfdfsclient.so
ln -s /usr/lib64/libfdfsclient.so /usr/lib/libfdfsclient.so

3.安装FastDFS_5.02:
tar zxvf FastDFS_v5.05.tar.gz -C /usr/src/
cd /usr/src/fastdfs-5.05/
sed -i 's#/usr/local/bin/#/usr/bin/#g' init.d/fdfs_storaged
sed -i 's#/usr/local/bin/#/usr/bin/#g' init.d/fdfs_trackerd
./make.sh
./make.sh install

4.编辑tracker.conf配置文件:
mkdir -p /home/fdfs/tracker
cp /etc/fdfs/tracker.conf.sample /etc/fdfs/tracker.conf
vim /etc/fdfs/tracker.conf
disabled=false
bind_addr=
port=22122
connect_timeout=30
network_timeout=60
base_path=/home/fdfs/tracker/
max_connections=256
accept_threads=1
work_threads=4
store_lookup=1
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
trunk_compress_binlog_min_interval = 0
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
log_file_keep_days = 0
use_connection_pool = false
connection_pool_max_idle_time = 3600
http.server_port=8080
http.check_alive_interval=30
http.check_alive_type=tcp
http.check_alive_uri=/status.html


5.启动trackerd服务:
service fdfs_trackerd start
cat /home/fdfs/tracker/logs/trackerd.log
chkconfig --level 2345 fdfs_trackerd on
ps -aux | grep fdfs_trackerd

6.编辑storage.conf配置文件:
mkdir -p /home/fdfs/storage
cp /etc/fdfs/storage.conf.sample /etc/fdfs/storage.conf
vim /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/fdfs/storage/
max_connections=256
buff_size = 256KB
accept_threads=1
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/fdfs/storage/
subdir_count_per_path=256
tracker_server=127.0.0.1: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
log_file_keep_days = 0
file_sync_skip_invalid_record=false
use_connection_pool = false
connection_pool_max_idle_time = 3600
http.domain_name=
http.server_port=80


7.启动storaged服务:
service fdfs_storaged start
cat /home/fdfs/storage/logs/storaged.log
chkconfig --level 2345 fdfs_storaged on
ps -aux | grep fdfs_storaged

8.安装Nginx:
tar zxvf fastdfs-nginx-module_v1.16.tar.gz -C /usr/src
vim /usr/src/fastdfs-nginx-module/src/config
ngx_addon_name=ngx_http_fastdfs_module
HTTP_MODULES="$HTTP_MODULES ngx_http_fastdfs_module"
NGX_ADDON_SRCS="$NGX_ADDON_SRCS $ngx_addon_dir/ngx_http_fastdfs_module.c"
CORE_INCS="$CORE_INCS /usr/include/fastdfs /usr/include/fastcommon/"
CORE_LIBS="$CORE_LIBS -L/usr/local/lib -lfastcommon -lfdfsclient"
CFLAGS="$CFLAGS -D_FILE_OFFSET_BITS=64 -DFDFS_OUTPUT_CHUNK_SIZE='256*1024' -DFDFS_MOD_CONF_FILENAME='"/etc/fdfs/mod_fastdfs.conf"'"


groupadd www
useradd -s /sbin/nologin -g www www
mkdir -p /home/www/log
mkdir -p /home/www/pid

tar zxvf nginx-1.9.0.tar.gz -C /usr/src/
cd /usr/src/nginx-1.9.0/
./configure --prefix=/usr/local/nginx \
--add-module=/usr/src/fastdfs-nginx-module/src \
--user=www \
--group=www \
--with-http_gunzip_module \
--with-pcre
make && make install

9.配置Nginx:
cp /usr/src/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs/
cp /usr/src/fastdfs-5.05/conf/{anti-steal.jpg,http.conf,mime.types} /etc/fdfs/
touch /home/www/log/mod_fastdfs.log
ln -s /home/fdfs/storage/data /home/fdfs/storage/data/M00

vim /usr/local/nginx/conf/nginx.conf
user www www;
worker_processes auto;
error_log /home/www/log/error.log error;
pid /home/www/pid/nginx.pid;
worker_rlimit_nofile 51200;
events {
    worker_connections  51200;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';
    sendfile        on;
    keepalive_timeout  65;
    server {
        listen       80;
        server_name  localhost;
        access_log  /home/www/log/access.log  main;
        location / {
            root   html;
            index  index.html index.htm;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    location /group1/M00{
    root /home/fdfs/storage/;
    ngx_fastdfs_module;
    }
    }
}


vim /etc/fdfs/mod_fastdfs.conf
connect_timeout=2
network_timeout=30
base_path=/tmp
load_fdfs_parameters_from_tracker=true
storage_sync_file_max_delay = 86400
use_storage_id = false
storage_ids_filename = storage_ids.conf
tracker_server=127.0.0.1:22122
storage_server_port=23000
group_name=group1
url_have_group_name = true
store_path_count=1
store_path0=/home/fdfs/storage/
log_level=info
log_filename=/home/www/log/mod_fastdfs.log
response_mode=proxy
if_alias_prefix=
#include http.conf
flv_support = true
flv_extension = flv
group_count = 1
[group1]
group_name=group1
storage_server_port=23000
store_path_count=1
store_path0=/home/fdfs/storage/


chown -R www:www /home/www/pid
chown -R www:www /home/www/log
chown -R www:www /home/www/log/mod_fastdfs.log

10.启动nginx服务:
service nginx start
ps -aux | grep nginx
netstat -anptu | grep 80

11.配置客户端:
ln -s /home/fdfs/storage/data /home/fdfs/storage/data/M00
cp /etc/fdfs/client.conf.sample /etc/fdfs/client.conf
vim /etc/fdfs/client.conf
connect_timeout=30
network_timeout=60
base_path=/tmp
tracker_server=127.0.0.1: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=80


12.测试:
上传:
fdfs_upload_file /etc/fdfs/client.conf /etc/fdfs/anti-steal.jpg
#能返回类似"group1/M00/00/00/wKgfolWmGAyAQSuqAABdrZgsqUU285.jpg"这样的路径即为成功!

下载:
fdfs_download_file /etc/fdfs/client.conf group1/M00/00/00/wKgfolWmGAyAQSuqAABdrZgsqUU285.jpg

查看文件属性:
fdfs_file_info /etc/fdfs/client.conf group1/M00/00/00/wKgfolWmGAyAQSuqAABdrZgsqUU285.jpg

删除文件:
fdfs_delete_file /etc/fdfs/client.conf group1/M00/00/00/wKgfolWmGoOEBO0bAAAAAHf4omo816.log

查看storage状态:
fdfs_monitor /etc/fdfs/client.conf
##################################################
#STORAGE SERVER的状态通常有七种:
# FDFS_STORAGE_STATUS:INIT      :初始化,尚未得到同步已有数据的源服务器
# FDFS_STORAGE_STATUS:WAIT_SYNC :等待同步,已得到同步已有数据的源服务器
# FDFS_STORAGE_STATUS:SYNCING   :同步中
# FDFS_STORAGE_STATUS:DELETED   :已删除,该服务器从本组中摘除
# FDFS_STORAGE_STATUS:OFFLINE   :离线
# FDFS_STORAGE_STATUS:ONLINE    :在线,尚不能提供服务
# FDFS_STORAGE_STATUS:ACTIVE    :在线,可以提供服务
##################################################


(责任编辑:IT)
------分隔线----------------------------
栏目列表
推荐内容