设为首页 收藏本站
查看: 1716|回复: 0

[经验分享] CentOS 6.4 i386 版本安装 FastDFS、使用Nginx作为文件访问WEB服务器

[复制链接]

尚未签到

发表于 2015-3-14 16:53:36 | 显示全部楼层 |阅读模式
  安装环境:
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


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系统初始化:
    #yum预装常用的服务器软件
      yum -y install gcc gcc-c++


2. 系统操作环境的设置
    #软件安装包存储
      /usr/local/src
    #libevent安装目录
      /usr/local/libevent

    #fastdfs安装目录
      /usr/local/fastdfs
    #nginx安装目录
      /usr/local/nginx



3. 安装libevent( fastdfs在编译源程序时fastdfs内部调用libevent的处理机制,,需要用到libevent一些依赖文件,否则编译fastdfs会出错)
    #卸载系统自带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



4. 安装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为fastdfs安装目录,所以需要修改make.sh
           vi make.sh
           #内容更改如下

           TARGET_PREFIX=/usr/local 修改为 /usr/local/fastdfs
           将/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



5. 配置Tracker
#创建tracker目录保存运行日志
     mkdir -m 777 -p /home/fastdfs/tracker
   #修改tracker.conf配置
     vim /usr/local/fastdfs/conf/tracker.conf
     #修改内容如下所示

DSC0000.gif DSC0001.gif


# 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_type_in_filename = id #文件名反解析中包含server ID,以前是ip
View Code   #移动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
     #修改内容如下所示





#  
100001          group1           192.168.1.12
100002          group2           192.168.1.13
100003          group2           192.168.1.14
View Code   #编辑启动脚本
     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 $?
View Code   #给启动脚本增加权限
     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



6. 配置Storage
#创建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
View Code   #编辑启动脚本
     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 $?
View Code   #给启动脚本增加权限
     chmod 777 /etc/init.d/fdfs_storaged
   #启动storage
     service fdfs_storaged restart
   #接下来会出现很多mkdir data path,这是系统在创建数据目录,如下图所示
    DSC0002.jpg
   #启动成功,加入开机启动
     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
     #出现以下类似信息表示配置正确
       DSC0003.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 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
View Code   #给启动脚本增加权限
       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\"'"
View Code   #复制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
View Code   #修改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;
}
}
}
View Code   #重启nginx服务
    service nginxd restart

  9. 测试FastDFS
   
  

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-46725-1-1.html 上篇帖子: CentOS 下 FastDFS _ V4.06 安装部署 下篇帖子: ubuntu+FastDFS php_client 安装 api
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表