Centos7安装FastDfs5.08详细教程

安装FastDfs

创建文件夹

mkdir fdfs

安装GCC依赖

GCC用来对C语言代码进行编译运行,使用yum命令安装:

sudo yum -y install gcc

安装unzip工具

unzip工具可以帮我们对压缩包进行解压

sudo yum install -y unzip zip

解压zip

unzip xx

删除文件

rm -fr libfastcommon-master.zip 

切换到目录安装

./make.sh && ./make.sh install

解压FastDFS_v5.08.tar.gz

tar xvf FastDFS_v5.08.tar.gz 

安装libevent依赖

sudo yum -y install libevent

安装依赖

yum -y install zlib zlib-devel pcre pcre-devel gcc gcc-c++ openssl openssl-devel libevent libevent-devel perl unzip net-tools wget  

切换到目录安装

./make.sh && ./make.sh install

查看是否安装完成

ll /etc/init.d/ | grep fdfs

修改配置文件

mv tracker.conf.sample tracker.conf

# 编辑
vi tracker.conf

# 修改
base_path=/leyou/fdfs/tracker

创建指定文件夹

mkdir -p /leyou/fdfs/tracker

启动

service fdfs_trackerd start

# 查看是否启动
ps -ef | grep fdfs

添加到自动启动

chkconfig fdfs_trackerd on

修改配置文件

mv storage.conf.sample storage.conf

vi storage.conf

base_path=/leyou/fdfs/storage # storage的数据和日志存放目录
store_path0=/leyou/fdfs/storage # storage的上传文件存放路径
tracker_server=192.168.25.128:22122 # tracker的地址

创建指定文件夹

mkdir -p /leyou/fdfs/storage

启动服务

sudo service fdfs_storaged start

开机自启
sudo chkconfig fdfs_storaged on

修改配置文件(测试文件上传)

mv client.conf.sample client.conf

修改配置文件,路径和ip

测试
/usr/bin/fdfs_upload_file client.conf /tmp/1.jpg

删除FastDFS_v5.08.tar.gz

rm -rf FastDFS_v5.08.tar.gz

安装nginx FastDFS模块

tar xvf fastdfs-nginx-module_v1.16.tar.gz

# 删除
rm -rf fastdfs-nginx-module_v1.16.tar.gz

修改配置文件

[root@localhost src]# vi config 

# 执行下面命令(将配置中的/usr/local改为/usr):
:%s+/usr/local/+/usr/+g

将配置文件复制到指定文件夹

cp mod_fastdfs.conf /etc/fdfs/

修改配置文件

connect_timeout=10                  		# 客户端访问文件连接超时时长(单位:秒)
tracker_server=192.168.25.128:22122  	# tracker服务IP和端口
url_have_group_name=true            		# 访问链接前缀加上组名
store_path0=/leyou/fdfs/storage        		# 文件存储路径

将配置文件复制到指定文件夹

cd /home/leyou/fdfs/FastFDFS/conf
[root@localhost conf]# cp http.conf mime.types /etc/fdfs/

安装Nginx

sudo ./configure --prefix=/opt/nginx --sbin-path=/usr/bin/nginx --add-module=/home/leyou/fdfs/fastdfs-nginx-module/src

编译,不安装

make

切换的nginx的objs目录,覆盖nginx文件

[root@localhost objs]# cp nginx /usr/bin/

配置Nginx

添加image服务器配置文件

配置Nginx开机自动

vi /etc/init.d/nginx

添加

#!/bin/sh
#
# nginx - this script starts and stops the nginx daemon
#
# chkconfig:   - 85 15
# description:  NGINX is an HTTP(S) server, HTTP(S) reverse \
#               proxy and IMAP/POP3 proxy server
# processname: nginx
# config:      /etc/nginx/nginx.conf
# config:      /etc/sysconfig/nginx
# pidfile:     /var/run/nginx.pid

# 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/bin/nginx"
prog=$(basename $nginx)

NGINX_CONF_FILE="/opt/nginx/conf/nginx.conf"

[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx

lockfile=/var/lock/subsys/nginx

make_dirs() {
   # make required directories
   user=`$nginx -V 2>&1 | grep "configure arguments:.*--user=" | sed 's/[^*]*--user=\([^ ]*\).*/\1/g' -`
   if [ -n "$user" ]; then
      if [ -z "`grep $user /etc/passwd`" ]; then
         useradd -M -s /bin/nologin $user
      fi
      options=`$nginx -V 2>&1 | grep 'configure arguments:'`
      for opt in $options; do
          if [ `echo $opt | grep '.*-temp-path'` ]; then
              value=`echo $opt | cut -d "=" -f 2`
              if [ ! -d "$value" ]; then
                  # echo "creating" $value
                  mkdir -p $value && chown -R $user $value
              fi
          fi
       done
    fi
}

start() {
    [ -x $nginx ] || exit 5
    [ -f $NGINX_CONF_FILE ] || exit 6
    make_dirs
    echo -n $"Starting $prog: "
    daemon $nginx -c $NGINX_CONF_FILE
    retval=$?
    echo
    [ $retval -eq 0 ] && touch $lockfile
    return $retval
}

stop() {
    echo -n $"Stopping $prog: "
    killproc $prog -QUIT
    retval=$?
    echo
    [ $retval -eq 0 ] && rm -f $lockfile
    return $retval
}

restart() {
    configtest || return $?
    stop
    sleep 1
    start
}

reload() {
    configtest || return $?
    echo -n $"Reloading $prog: "
    killproc $nginx -HUP
    RETVAL=$?
    echo
}

force_reload() {
    restart
}

configtest() {
  $nginx -t -c $NGINX_CONF_FILE
}

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)
        $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}"
        exit 2
esac

修改文件权限,并加入服务列表

# 修改权限
chmod 777 /etc/init.d/nginx 
# 添加到服务列表
chkconfig --add /etc/init.d/nginx 

设置开机启动

chkconfig nginx on

开启9001和10010存储端口

[root@localhost nginx-1.14.2]# firewall-cmd --zone=public --add-port=9001/tcp --permanent
success
[root@localhost nginx-1.14.2]# firewall-cmd --zone=public --add-port=10010/tcp --permanent
success

你可能感兴趣的:(Centos7安装FastDfs5.08详细教程)