安装环境:
1. CentOS-6.4-i386
2. FastDFS_v4.06
3. fastdfs-nginx-module_v1.15
4. Nginx-1.5.6(安装见此)
5. libevent-2.0.21-stable
#yum预装常用的服务器软件
yum -y install gcc gcc-c++
#软件安装包存储
/usr/local/src
#libevent安装目录
/usr/local/libevent
/usr/local/fastdfs
#nginx安装目录
/usr/local/nginx
#卸载系统自带libevent,自带版本过低,安装fastdfs会出错
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库下,64位系统对应/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
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为fastdfs安装目录,所以需要修改make.sh
vi make.sh
#内容更改如下
将/etc/fdfs 全部替换为 /usr/local/fastdfs/conf
5> #安装
./make.sh C_INCLUDE_PATH=/usr/local/libevent/include LIBRARY_PATH=/usr/local/libevent/lib
./make.sh install
#创建tracker目录保存运行日志
mkdir -m 777 -p /home/fastdfs/tracker
#修改tracker.conf配置
vim /usr/local/fastdfs/conf/tracker.conf
#修改内容如下所示
# 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取代ip形式,方便内部网络服务器更换ip#**此方式要重点理解,4.0以后新特性 use_storage_id = true #使用server ID作为storage server标识 storage_ids_filename = storage_ids.conf #<id> <group_name> <ip_or_hostname> id_type_in_filename = id #文件名反解析中包含server ID,以前是ip
#移动storage_ids.conf文件
cp -r /usr/local/src/FastDFS/conf/storage_ids.conf /usr/local/fastdfs/conf/
#编辑storage服务器ID与IP地址的对应关系
vim /usr/local/fastdfs/conf/storage_ids.conf
#修改内容如下所示
#<id> <group_name> <ip_or_hostname> 100001 group1 192.168.1.12 100002 group2 192.168.1.13 100003 group2 192.168.1.14
#编辑启动脚本
vim /etc/init.d/fdfs_trackerd
#启动脚本内容如下
#!/bin/bash # # fdfs_trackerd Starts fdfs_trackerd # # # chkconfig: 2345 99 01 # description: FastDFS tracker server ### BEGIN INIT INFO # Provides: $fdfs_trackerd ### END INIT INFO # Source function library. . /etc/init.d/functions FastDfs='/usr/local/fastdfs' CONF="$FastDfs/conf/tracker.conf" if [ ! -f $CONF ]; then echo "file $CONF does not exist!" exit 2 fi PRG="$FastDfs/bin/fdfs_trackerd" 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 tracker server: " $PRG $CONF & RETVAL=$? echo return $RETVAL } stop() { echo -n $"Stop FastDFS tracker server: " $Stop $PRG $CONF RETVAL=$? return $RETVAL } rhstatus() { status fdfs_trackerd } restart() { $Restart $PRG $CONF & } case "$1" in start) start ;; stop) stop ;; status) rhstatus ;; restart|reload) restart ;; condrestart) restart ;; *) echo $"Usage: $0 {start|stop|status|restart|condrestart}" exit 1 esac exit $?
#给启动脚本增加权限
chmod 777 /etc/init.d/fdfs_trackerd
#启动tracker
service fdfs_trackerd restart
#启动成功,加入开机启动
vim /etc/rc.d/rc.local
#加入内容如下
service fdfs_trackerd start
#防火墙开启tracker端口22122
vim /etc/sysconfig/iptables
#加入内容如下
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22122 -j ACCEPT
#重启防火墙
service iptables restart
#创建Storage目录保存运行日志及其data数据
mkdir -m 777 -p /home/fastdfs/storage
#修改storage.conf配置
vim /usr/local/fastdfs/conf/storage.conf
#修改内容如下所示
vim /usr/local/fastdfs/conf/storage.conf # the name of the group this storage server belongs to group_name=group1 #设置组名 # the name of the group this storage server belongs to # the storage server port #the storage server port port=23000 # the base path to store data and log files #日志目录 base_path=/home/yuqing/fastdfs -> /home/fastdfs/storage # store_path#, based 0, if store_path0 not exists, it's value is base_path #data数据存储目录 # the paths must be exist store_path0=/home/fastdfs/storage # tracker_server can ocur more than once, and tracker_server format is # "host:port", host can be hostname or ip address tracker_server=192.168.209.121:22122 ->192.168.1.11:22122
#编辑启动脚本
vim /etc/init.d/fdfs_storaged
#启动脚本内容如下
#!/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 "$1" in start) start ;; stop) stop ;; status) rhstatus ;; restart|reload) restart ;; condrestart) restart ;; *) echo $"Usage: $0 {start|stop|status|restart|condrestart}" exit 1 esac exit $?
#给启动脚本增加权限
chmod 777 /etc/init.d/fdfs_storaged
#启动storage
service fdfs_storaged restart
#接下来会出现很多mkdir data path,这是系统在创建数据目录,如下图所示
#启动成功,加入开机启动
vim /etc/rc.d/rc.local
#加入内容如下
service fdfs_storaged start
7. 安装nginx(仅Storage)
#创建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
#出现以下类似信息表示配置正确
#查看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 is 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 "$1" in start) rh_status_q && exit 0 $1 ;; stop) rh_status_q || exit 0 $1 ;; restart|configtest|version) $1 ;; reload) rh_status_q || exit 7 $1 ;; force-reload) force_reload ;; status) rh_status ;; condrestart|try-restart) rh_status_q || exit 0 ;; *) echo $"Usage: $0 {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
#启动成功,加入开机启动
vim /etc/rc.d/rc.local
#加入内容如下
service nginxd start
8. 安装nginx-module模块(仅Storage)
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到/usr/local/fastdfs/conf/目录下
cp /usr/local/src/fastdfs-nginx-module/src/mod_fastdfs.conf /usr/local/fastdfs/conf/
#将/usr/local/fastdfs/lib 加入系统文件/etc/ld.so.conf中(编译时使用的动态链接库)
vim /etc/ld.so.conf
#修改内容如下
/usr/local/fastdfs/lib
#更新库文件缓存ld.so.cache
/sbin/ldconfig
#编译fastdfs-nginx-module模块
1> cd nginx-1.1.19/
2> ./configure 此处加上nginx之前的编译参数(使用 /usr/local/nginx/sbin/nginx -V 命令查看) --add-module=/usr/local/src/fastdfs-nginx-module/src
3> make && make install
#修改mod_fastdfs.conf配置
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 when 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 uri 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配置
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 /组名/M00 { alias /home/fastdfs/storage/data; ngx_fastdfs_module; } } }
#重启nginx服务
service nginxd restart
9. 测试FastDFS