CentOs7安装FastDFS5.08

目录

 版本说明

 安装环境

1.安装C语言编译工具 

2.安装zip文件的解压命令

3.安装libevent插件

4.新建一个文件夹用于存储

5.上传fastdfs所需文件

6.安装libfastcommon-master

7.安装fastdfs

8.配置中继服务器

9.启动中继服务器

10.配置存储服务器

11.启动存储服务器

使用nginx访问FastDFS

1.安装fastdfs-nginx-module 

2.配置nginx与FastDFS关联配置文件

3.配置媒体类型 

安装Nginx

1.安装nginx的依赖库 

2.解压nginx 

3.配置nginx安装包

4.编译并安装nginx

5.编辑nginx配置文件

6.启动nginx

7.设置nginx开机自启动


 版本说明

centos: 7.7.1908

fastdfs: 5.08

 安装FastDFS

1.安装C语言编译工具 

yum install gcc

2.安装zip文件的解压命令

yum install -y unzip zip

3.安装libevent插件

yum -y install libevent

4.新建一个文件夹用于存储

cd /usr/local
mkdir leyou
cd leyou/

5.上传fastdfs所需文件

6.安装libfastcommon-master

  先解压,在leyou目录下输入

unzip libfastcommon-master.zip

然后我们cd进入到解压后的目录中

cd libfastcommon-master

先编译

./make.sh

 再安装

./make.sh install

7.安装fastdfs

先cd到leyou目录

cd ..

然后解压文件 

tar -zxvf FastDFS_v5.08.tar.gz

cd进去 

cd FastDFS

编译

./make.sh

安装

./make.sh install

查看是否安装成功

ll /etc/init.d/ | grep fdfs

如图代表安装成功~ 

8.配置中继服务器

在FastDFS文件夹中,先把fastdfs自带的sample配置文件夹模板改名

cp /etc/fdfs/tracker.conf.sample /etc/fdfs/tracker.conf

然后我们编辑配置文件

vim /etc/fdfs/tracker.conf

修改存储路径为/leyou/tracker

级联创建一个文件夹

mkdir -p /leyou/tracker

可以看到在根目录下创建了一个leyou/tracker 

查看一下防火墙状态,我们这里选择关闭防火墙

firewall-cmd --state

可以看到防火墙是关闭的 

9.启动中继服务器

启动服务

service fdfs_trackerd start

查看是否启动成功 

ps -ef | grep fdfs_trackerd

启动成功如图所示 

我们设置中继服务器开机自启

chkconfig fdfs_trackerd on

10.配置存储服务器

首先将模板文件复制

cp /etc/fdfs/storage.conf.sample /etc/fdfs/storage.conf

修改复制后的配置文件 

vim /etc/fdfs/storage.conf

在里面需要修改三个配置

修改完成之后,我们级联创建一个文件夹

mkdir -p /leyou/storage

根目录下中leyou下就会有2个目录了 

11.启动存储服务器

输入启动命令

service fdfs_storaged start

输入命令检查是否启动成功

ps -ef | grep fdfs

可以看到已经启动成功了 

设置开机自启动

chkconfig fdfs_storaged on

使用nginx访问FastDFS

1.安装fastdfs-nginx-module 

cd到leyou目录下

cd ..

解压

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

进入到文件夹中

cd fastdfs-nginx-module/src/

编辑config文件

vim config

进行全局了路径的替换

:%s+/usr/local/+/usr/+g

保存并退出

2.配置nginx与FastDFS关联配置文件

先复制module的配置文件到/etc/fdfs目录中

cp /usr/local/leyou/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs/

修改 

vi /etc/fdfs/mod_fastdfs.conf

修改以下内容 

connect_timeout=20
tracker_server=192.168.62.128:22122
url_have_group_name = true
store_path0=/leyou/storage

3.配置媒体类型 

cd /usr/local/leyou/FastDFS/conf
cp http.conf mime.types /etc/fdfs/

安装Nginx

1.安装nginx的依赖库 

yum -y install gcc pcre pcre-devel zlib zlib-devel openssl openssl-devel

2.解压nginx 

cd到leyou目录下

cd ../..
tar -zxvf nginx-1.10.0.tar.gz 

3.配置nginx安装包

cd nginx-1.10.0
./configure --prefix=/opt/nginx --sbin-path=/usr/bin/nginx --add-module=/usr/local/leyou/fastdfs-nginx-module/src

4.编译并安装nginx

make && make install

5.编辑nginx配置文件

nginx默认的nginx.conf文件路径在这里 

/opt/nginx/conf

我们双击打开它,把里面的server完全替换为下面的代码

    server {
        listen       80;
        server_name  image.leyou.com;

    	# 监听域名中带有group的,交给FastDFS模块处理
        location ~/group([0-9])/ {
            ngx_fastdfs_module;
        }

        location / {
            root   html;
            index  index.html index.htm;
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }

6.启动nginx

启动命令就是nginx 

nginx

下图代表启动成功 

再次验证

ps -ef |grep nginx

如下图一个主进程一个工作进程代表没问题

 

7.设置nginx开机自启动

新建一个脚本 

vim /etc/init.d/nginx

复制如下内容即可,如果你的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

到此,我们的配置就完成了~

发布了343 篇原创文章 · 获赞 162 · 访问量 14万+

猜你喜欢

转载自blog.csdn.net/Delicious_Life/article/details/104220529