Centos7 搭建 FastDFS

目录

1.工具

2.分别安装gcc,解压命令unzip,libevent插件

3.安装libfastcommon-master

4安装fastdfs

4.1查看是否安装成功

 4.2配置并启动tracker服务

4.3配置并启动storage服务

5.安装fastdfs-nginx-module

5.1配置nginx与FastDFS关联配置文件

6.安装nginx

扫描二维码关注公众号,回复: 8789558 查看本文章

7.启动nginx

7.1查看是否启动成功

         7.2设置nginx开机自启


1.工具

 1.下面是自己定义的一个路径以及所使用的工具(此次单间是单节点搭建)

2.分别安装gcc,解压命令unzip,libevent插件

yum -y install gcc

yum install -y unzip zip

yum -y install libevent

3.安装libfastcommon-master

解压
unzip libfastcommon-master.zip

进入到解压目录
cd libfastcommon-master

编译并且安装:
./make.sh 
./make.sh install

4安装fastdfs

解压
tar -zxvf FastDFS_v5.08.tar.gz

进入到解压目录
cd FastDFS

编译安装
./make.sh 
./make.sh install

4.1查看是否安装成功

ll /etc/init.d/ | grep fdfs

// 查看默认的配置文件模板
ll /etc/fdfs/

 4.2配置并启动tracker服务

第一步:复制模板文件
cp /etc/fdfs/tracker.conf.sample /etc/fdfs/tracker.conf

第二步:编辑配置文件
vi /etc/fdfs/tracker.conf 

修改如下,配置存储日志和数据的根目录
base_path=/fadfs/tracker 

第三步:新建目录
mkdir -p /fadfs/tracker

第四步:关闭防火墙
systemctl stop firewalld.service
查看防火墙状态
systemctl status firewalld.service

第五步:启动fadfs_trackerd服务器
service fdfs_trackerd start  #停止stop

第六步:检查FastDFS Tracker Server是否启动成功
ps -ef | grep fdfs_trackerd

第七步:设置tracker服务开机启动
chkconfig fdfs_trackerd on

4.3配置并启动storage服务

第一步:复制模板文件
cp /etc/fdfs/storage.conf.sample /etc/fdfs/storage.conf

第二步:修改配置文件
vi /etc/fdfs/storage.conf

修改如下
base_path=/fadfs/storage                 # 数据和日志文件存储根目录 

store_path0=/fadfs/storage           # 第一个存储目录 

tracker_server=192.168.60.73:22122       #  tracker服务器IP和端口 

第三步:新建目录
mkdir -p /fadfs/storage

第四步:关闭防火墙
systemctl stop firewalld.service
查看防火墙状态
systemctl status firewalld.service

第五步:启动fdfs_storaged服务
service fdfs_storaged start  #停止用stop

第六步:设置开机自启
chkconfig fdfs_storaged on

第七步:查看是否启动成功
ps -ef | grep fdfs

5.安装fastdfs-nginx-module

第一步:解压
tar -zxvf fastdfs-nginx-module_v1.16.tar.gz

第二步:定位到src目录下,修改config

vi config

第三步:将所有的/usr/local替换为 /usr
:%s+/usr/local/+/usr/+g

5.1配置nginx与FastDFS关联配置文件

第一步:定位到fastdfs-nginx-module的src目录,复制配置文件到/etc/fdfs 目录
cp mod_fastdfs.conf /etc/fdfs/

第二步:修改配置文件
vi /etc/fdfs/mod_fastdfs.conf

修改如下
connect_timeout=10                       # 客户端访问文件连接超时时长(单位:秒)

tracker_server=192.168.60.73:22122    # tracker服务IP和端口

url_have_group_name=true                # 访问链接前缀加上组名

store_path0=/fadfs/storage            # 文件存储路径

第三步:定位到 FastDFS 的conf目录,复制http.conf mime.types 到/etc/fdfs/目录下
cp http.conf mime.types /etc/fdfs/

6.安装nginx

1.安装nginx依赖库
yum -y install gcc pcre pcre-devel zlib zlib-devel openssl openssl-devel

2.解压
tar -zxvf nginx-1.10.0.tar.gz

3.进入到解压目录,配置FastDFS 模块
./configure --prefix=/opt/nginx --sbin-path=/usr/bin/nginx --add-module=/usr/local/fadfs/fastdfs-nginx-module/src

4.编译并安装
make && make install

5.修改nginx配置文件
vi /opt/nginx/conf/nginx.conf

修改如下
server {
        listen       80;
        server_name  image.fadfs.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;
        }
    }

7.启动nginx

nginx	# 启动nginx

nginx -s stop	# 停止nginx

nginx -s reload	# 重新载入配置文件

7.1查看是否启动成功

ps -ef | grep nginx

7.2设置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

如有问题,欢迎评论回复!

发布了240 篇原创文章 · 获赞 435 · 访问量 9万+

猜你喜欢

转载自blog.csdn.net/fjxcsdn/article/details/103667745