Installation Environment:
1. centos-6.4-i386
2. fastdfs_v4.06
3. fastdfs-nginx-module_v1.15
4. Nginx-1.5.6 (see here for installation)
5. libevent-2.0.21-stable
Tracker Server IP:192.168.1.11
Storage1 server IP:192.168.1.12 group1
Storage2 server IP:192.168.1.13 group2
Storage3 server IP:192.168.1.14 group2
1. CentOS System initialization:
#yum预装常用的服务器软件
Yum-y Install GCC gcc-c++
2. Setting up the operating environment of the system
#软件安装包存储
/usr/local/src
#libevent安装目录
/usr/local/libevent
#fastdfs安装目录
/usr/local/fastdfs
#nginx安装目录
/usr/local/nginx
3. Install libevent(Fastdfs when compiling the source program Fastdfs internal call libevent processing mechanism, you need to use libevent some dependent files, or compile Fastdfs error)
#卸载系统自带libevent, with the version too low, installation Fastdfs error
1> Rpm-qa|grep libevent
2> Yum Remove libevent*
#下载安装libevent:
1> wget https://github.com/downloads/libevent/libevent/libevent-2.0.21-stable.tar.gz
2> TAR-ZXVF libevent-2.0.21-stable.tar.gz
3> CD libevent-2.0.21-stable
4>./configure--prefix=/usr/local/libevent
5> make && make install
#为libevent创建软链接到/lib Library, the 64-bit system corresponds to/LIB64
Ln-s/usr/local/libevent/lib/libevent-2.0.so.5/usr/lib/libevent-2.0.so.5
Ln-s/usr/local/libevent/lib/libevent-2.0.so.5/usr/lib64/libevent-2.0.so.5
4. Installing Fastdfs
1> wget http://fastdfs.googlecode.com/files/FastDFS_v4.06.tar.gz
2> TAR-ZXVF fastdfs_v4.06.tar.gz
3> CD Fastdfs
4> #由于定义/usr/local/fastdfs for the Fastdfs installation directory, so you need to modify the make.sh
VI make.sh
#内容更改如下
Target_prefix=/usr/local modified to/usr/local/fastdfs
Replace all/etc/fdfs with/usr/local/fastdfs/conf
5> #安装
./make.sh C_include_path=/usr/local/libevent/include Library_path=/usr/local/libevent/lib
./make.sh Install
5. Configure Tracker
① Create tracker directory save run Log
Mkdir-m 777-p/home/fastdfs/tracker
② Modifying the tracker.conf configuration
Vim/usr/local/fastdfs/conf/tracker.conf
The contents of the modification are as follows
# The Tracker server port
port=22122
# The base path to store data and log files
Base_path=/home/yuqing/fastdfs, Base_path=/home/fastdfs/tracker #日志目录
#开启自定义server ID instead of IP to facilitate internal network server replacement ip#** this way to focus on understanding, after 4.0 new features
USE_STORAGE_ID = True #使用server ID as Storage server identity
Storage_ids_filename = storage_ids.conf #<id> <group_name> <ip_or_hostname>
Id_type_in_filename = ID #文件名反解析中包含server ID, formerly IP
③ Moving storage_ids.conf files
Cp-r/usr/local/src/fastdfs/conf/storage_ids.conf/usr/local/fastdfs/conf/
④ edit Storage Server ID corresponds to IP address
Vim/usr/local/fastdfs/conf/storage_ids.conf
The contents of the modification are as follows
#<id> <group_name> <ip_or_hostname>
100001 group1 192.168.1.12
100002 group2 192.168.1.13
100003 group2 192.168.1.14
⑤ Editing a startup script
Vim/etc/init.d/fdfs_trackerd
The startup script content is as follows
#!/bin/bash
#
# fdfs_storaged starts fdfs_storaged
#
#
# chkconfig:2345 99 01
# DESCRIPTION:FASTDFS Storage Server
# # # BEGIN INIT INFO
# provides: $fdfs _storaged
# # # END INIT INFO
# Source function library.
. /etc/init.d/functions
fastdfs= '/usr/local/fastdfs '
conf= "$FastDfs/conf/storage.conf"
if [!-f $CONF]; Then
echo "File $CONF does not exist!"
Exit 2
Fi
prg= "$FastDfs/bin/fdfs_storaged"
if [!-f $PRG]; Then
echo "File $PRG does not exist!"
Exit 2
Fi
stop= "$FastDfs/bin/stop.sh"
if [!-f $Stop]; Then
echo "File $Stop does not exist!"
Exit 2
Fi
restart= "$FastDfs/bin/restart.sh"
if [!-f $Restart]; Then
echo "File $Restart does not exist!"
Exit 2
Fi
Retval=0
Start () {
Echo-n $ "Starting Fastdfs Storage server:"
$PRG $CONF &
Retval=$?
Echo
Return $RETVAL
}
Stop () {
Echo-n $ "Stop Fastdfs Storage Server:"
$Stop $PRG $CONF
Retval=$?
Return $RETVAL
}
Rhstatus () {
Status fdfs_storaged
}
Restart () {
$Restart $PRG $CONF &
}
Case "$" in
Start
Start
;;
Stop
Stop
;;
Status
Rhstatus
;;
Restart|reload)
Restart
;;
Condrestart)
Restart
;;
*)
echo $ "Usage: $ {Start|stop|status|restart|condrestart}"
Exit 1
Esac
Exit $?
⑥ adding permissions to the startup script
chmod 777/etc/init.d/fdfs_storaged
Start storage
Service fdfs_storaged Restart
Then there will be a lot of mkdir data path, which is the system in creating the database directory, as shown in
650) this.width=650; "Src=" http://images.cnitblog.com/blog/30432/201311/ 20123023-3cedc1f6fec643b398484dcb2da8d4ae.jpg "/>
⑦ boot successful, join boot start
Vim/etc/rc.d/rc.local
Join content as follows
Service fdfs_storaged Start
7. Installing Nginx(Storage only)
#创建nginx日志目录
Mkdir-m 777-p/home/www/logs
#安装nginx必需的库: Zlib-devel openssl-devel pcre
Yum-y Install Zlib-devel Openssl-devel
#手动安装pcre
1> wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.33.tar.gz
2> TAR-ZXVF pcre-8.33.tar.gz
3> CD pcre-8.33
4>./configure
5> make && make install
6> ln-s/usr/local/lib/libpcre.so.1/lib
#安装nginx
1> wget http://nginx.org/download/nginx-1.5.6.tar.gz
2> TAR-ZXVF nginx-1.5.6.tar.gz
3> CD nginx-1.5.6
4>./configure--prefix=/usr/local/nginx--with-http_stub_status_module--with-http_ssl_module
5> make && make install
#检查nginx配置是否正确
/usr/local/nginx/sbin/nginx-t
#出现以下类似信息表示配置正确
650) this.width=650; "Src=" http://images.cnitblog.com/blog/30432/201311/ 20143113-2db57ba228a34dadb38dc9abdf18fe07.jpg "/>
#查看nginx编译选项
/usr/local/nginx/sbin/nginx-v
#编辑启动脚本
Vim/etc/init.d/fdfs_storaged
#启动脚本内容如下
#!/bin/sh
#
# Nginx-this script starts and stops the Nginx daemin
#
# Chkconfig:-85 15
# Description:nginx is an HTTP (s) server, HTTP (s) reverse \
# Proxy and IMAP/POP3 proxy server
# Processname:nginx
# config:/usr/local/nginx/conf/nginx.conf
# Pidfile:/usr/local/nginx/nginx.pid
# admin Chenai
# Last Updated 20120.6.1
# Source function library.
. /etc/rc.d/init.d/functions
# Source Networking configuration.
. /etc/sysconfig/network
# Check that networking are up.
["$NETWORKING" = "no"] && exit 0
#必填
nginx= "/usr/local/nginx/sbin/nginx"
prog=$ (basename $nginx)
#必填
Nginx_conf_file= "/usr/local/nginx/conf/nginx.conf"
[-f/etc/sysconfig/nginx] &&. /etc/sysconfig/nginx
Lockfile=/var/lock/subsys/nginx
Start () {
[-X $nginx] | | Exit 5
[-F $NGINX _conf_file] | | Exit 6
Echo-n $ "Starting $prog:"
Daemon $nginx-C $NGINX _conf_file
Retval=$?
Echo
#service php-fpm Start
[$retval-eq 0] && Touch $lockfile
Return $retval
}
Stop () {
Echo-n $ "Stopping $prog:"
$nginx-S Stop
Echo_success
Retval=$?
Echo
#service php-fpm Stop
[$retval-eq 0] && rm-f $lockfile
Return $retval
}
Restart () {
Stop
Start
}
Reload () {
Configtest | | Return $?
Echo-n $ "Reloading $prog:"
$nginx-S Reload
Retval=$?
Echo
}
Force_reload () {
Restart
}
Configtest () {
$nginx-T-C $NGINX _conf_file
}
Version () {
$nginx-V
}
Rh_status () {
Status $prog
}
Rh_status_q () {
Rh_status >/dev/null 2>&1
}
Case "$" in
Start
Rh_status_q && Exit 0
$
;;
Stop
Rh_status_q | | Exit 0
$
;;
Restart|configtest|version)
$
;;
Reload
Rh_status_q | | Exit 7
$
;;
Force-reload)
Force_reload
;;
Status
Rh_status
;;
Condrestart|try-restart)
Rh_status_q | | Exit 0
;;
*)
echo $ "Usage: $ {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest|version}"
Exit 2
Esac
#给启动脚本增加权限
chmod 777/etc/init.d/nginxd
#启动nginx
Service Nginxd Restart
#启动成功, join the boot start
Vim/etc/rc.d/rc.local
#加入内容如下
Service Nginxd Start
8. Install the Nginx-module module (storage only)
1> wget http://fastdfs.googlecode.com/files/fastdfs-nginx-module_v1.15.tar.gz
2> TAR-ZXVF fastdfs-nginx-module_v1.15.tar.gz;
#修改插件配置文件
Vim/usr/local/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/local/fastdfs/include/fastdfs/usr/local/fastdfs/include/fastcommon/"
core_libs= "$CORE _libs-l/usr/local/fastdfs/lib-lfastcommon-lfdfsclient"
cflags= "$CFLAGS-d_file_offset_bits=64-dfdfs_output_chunk_size= ' 256*1024 '-dfdfs_mod_conf_filename= ' \"/usr/local /fastdfs/conf/mod_fastdfs.conf\ "'"
#复制mod_fastdfs. conf to the/usr/local/fastdfs/conf/directory
cp/usr/local/src/fastdfs-nginx-module/src/mod_fastdfs.conf/usr/local/fastdfs/conf/
#将/usr/local/fastdfs/lib Join the System file/etc/ld.so.conf (dynamic link library used at compile time)
Vim/etc/ld.so.conf
#修改内容如下
/usr/local/fastdfs/lib
#更新库文件缓存ld. So.cache
/sbin/ldconfig
#编译fastdfs-nginx-module Module
1> CD nginx-1.1.19/
2>./configure here to add Nginx before the compilation parameters (using the/usr/local/nginx/sbin/nginx-v command to view)--add-module=/usr/local/src/ Fastdfs-nginx-module/src
3> make && make install
#修改mod_fastdfs. conf configuration
Vim/usr/local/fastdfs/conf/mod_fastdfs.conf
#修改内容如下
# If load Fastdfs parameters from tracker server
# since V1.12
# default value is False
Load_fdfs_parameters_from_tracker=true
# Fastdfs Tracker_server can ocur more than once, and Tracker_server format is
# "Host:port", host can be hostname or IP address
# valid only if Load_fdfs_parameters_from_tracker is true
tracker_server=192.168.25.11:22122
# The port of the local storage server
# The default value is 23000
storage_server_port=23000
# The group name of the local storage server
Group_name=group1 #当前storage机器组名
# if the Url/uri including the group name
# set to False when Uri Like/m00/00/00/xxx
# set to True when URIs like ${group_name}/m00/00/00/xxx, such as Group1/m00/xxx
# default value is False
Url_have_group_name = True
# path (disk or mount point) count, default value is 1
# must same as storage.conf
Store_path_count=1
# store_path#, based 0, if Store_path0 not exists, it's value is Base_path
# The paths must be exist
# must same as storage.conf
Store_path0=/home/fastdfs/storage
# Set the log filename, such as/usr/local/apache2/logs/mod_fastdfs.log
# Empty for output to stderr (Apache and nginx error_log file)
Log_filename=/home/www/logs/mod_fastdfs.log
#修改nginx. conf configuration
Vim/usr/local/nginx/conf/nginx.conf
#修改内容如下
Worker_processes 2;
Error_log/home/www/logs/error.log notice;
Pid/home/www/logs/nginx.pid;
Worker_rlimit_nofile 5120;
Events {
Use Epoll;
Worker_connections 5120;
}
HTTP {
Include Mime.types;
Default_type Application/octet-stream;
Sendfile on;
Tcp_nopush on;
Keepalive_timeout 60;
Tcp_nodelay on;
server {
Listen 80;
server_name localhost;
Location/Group name/M00 {
Alias/home/fastdfs/storage/data;
Ngx_fastdfs_module;
}
}
}
#重启nginx服务
Service Nginxd Restart
9. Test Fastdfs
CentOS 6.4 Install Fastdfs, use Nginx as file to access Web server