FastDFS分布式文件系统编译安装 - 管理猿 2019 年 07 月 27 日 |访问: 1,049 次

操作系统:CentOS release 6.10 (Final)
FastDFS:fastdfsv5.05
主机IP地址:172.0.6.102
文件存放位置:/data/fastdfs/storage/
上传的安装软件存放位置:/root/fastFDS/fastFDS/
一:安装编译环境必须的软件,需要确保网络畅通

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

二:安装libfastcommon

cd /root/fastFDS/fastFDS/
tar -zxvf libfastcommon-1.0.7.tar.gz
cd libfastcommon-1.0.7
./make.sh
./make.sh install

三:安装fastdfs-5.05

cd /root/fastFDS/fastFDS/
tar -zxvf fastdfs-5.05.tar.gz
cd fastdfs-5.05
./make.sh
./make.sh install
cp /etc/fdfs/tracker.conf.sample /etc/fdfs/tracker.conf
vi /etc/fdfs/tracker.conf

找到以下两个参数并修改base_path和http.server_port

base_path=/data/fastdfs
http.server_port=80

QQ截图20190727103214.png
QQ截图20190727103301.png
然后wq保存,建立软连接到命令中

ln -s /usr/bin/fdfs_trackerd /usr/local/bin
ln -s /usr/bin/stop.sh /usr/local/bin
ln -s /usr/bin/restart.sh /usr/local/bin

创建存储文件使用的目录,并尝试启动服务

mkdir -p /data/fastdfs/storage
service fdfs_trackerd start
chkconfig fdfs_trackerd on

查看端口使用情况看服务是否启动

netstat -lnp | grep fdfs

QQ截图20190727103634.png

修改存储空间的相关配置

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

修改以下三个参数,其中IP不能为127.0.0.1,必须是机器的真实IP地址

base_path=/data/fastdfs/storage
store_path0=/data/fastdfs/storage
tracker_server=172.0.6.102:22122

QQ截图20190727103912.png
QQ截图20190727104128.png
然后wq保存,并尝试启动相关服务

ln -s /usr/bin/fdfs_storaged /usr/local/bin
service fdfs_storaged start
chkconfig fdfs_storaged on

查看是否启动成功
QQ截图20190727104356.png

四:安装nginx服务,不能使用yum或者rpm安装,因为没有必须的扩展

cd /root/fastFDS/fastFDS/
tar -zxvf nginx-1.15.0.tar.gz
mv /root/fastFDS/fastFDS/nginx-1.15.0 /usr/local/
cd /root/fastFDS/fastFDS/
tar -zxvf fastdfs-nginx-module_v1.16.tar.gz
mv fastdfs-nginx-module /usr/local/nginx-1.15.0/
ln -s /usr/include/fast* /usr/local/include/
cd /usr/local/nginx-1.15.0/
./configure --prefix=/usr/local/nginx --add-module=fastdfs-nginx-module/src/
make 
make install
cp /usr/local/nginx-1.15.0/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs/
vi /etc/fdfs/mod_fastdfs.conf

修改以下几个参数然后保存,IP地址为本机真实IP。

tracker_server=172.0.6.102:22122
url_have_group_name = true
store_path0=/data/fastdfs/storage

QQ截图20190727105431.png

QQ截图20190727105511.png
复制部分配置文件到制定目录

cd /root/fastFDS/fastFDS/fastdfs-5.05/conf/
cp anti-steal.jpg http.conf mime.types /etc/fdfs/

将nginx加入系统服务并设置开机自启

vi /etc/init.d/nginx

将以下内容复制粘贴进去

#!/bin/bash
# nginx Startup script for the Nginx HTTP Server
# it is v.0.0.2 version.
# chkconfig: - 85 15
# description: Nginx is a high-performance web and proxy server.
#              It has a lot of features, but it's not for everyone.
# processname: nginx
# pidfile: /var/run/nginx.pid
# config: /usr/local/nginx/conf/nginx.conf

nginxd=/usr/local/nginx/sbin/nginx       
nginx_config=/usr/local/nginx/conf/nginx.conf    
nginx_pid=/var/run/nginx.pid    
RETVAL=0
prog="nginx"
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0
[ -x $nginxd ] || exit 0
# Start nginx daemons functions.
start() {
    if [ -e $nginx_pid ];then
       echo "nginx already running...."
   exit 1
    fi
       echo -n $"Starting $prog: "
       daemon $nginxd -c ${nginx_config}
   RETVAL=$?
   echo
       [ $RETVAL = 0 ] && touch /var/lock/subsys/nginx
   return $RETVAL
}

# Stop nginx daemons functions.
stop() {
    echo -n $"Stopping $prog: "
    killproc $nginxd
    RETVAL=$?
    echo
    [ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx /var/run/nginx.pid
}

# reload nginx service functions.
reload() {
    echo -n $"Reloading $prog: "
    #kill -HUP `cat ${nginx_pid}`
    killproc $nginxd -HUP
    RETVAL=$?
    echo
}

# See how we were called.
    case "$1" in
start)
    start
    ;;
stop)
    stop
    ;;
reload)
    reload
    ;;
restart)
    stop
    start
    ;;
status)
    status $prog
    RETVAL=$?
    ;;
*)
    echo $"Usage: $prog {start|stop|restart|reload|status|help}"
    exit 1
esac
exit $RETVAL

然后wq保存,接下来设置权限和开机自启

chmod 755 /etc/init.d/nginx 
chkconfig --add nginx
chkconfig nginx on
service nginx start

复制nginx目录需要的文件,并修改nginx的配置文件

cp -r /root/fastFDS/fastFDS/nginx/* /usr/local/nginx/html/
> /usr/local/nginx/conf/nginx.conf
vi /usr/local/nginx/conf/nginx.conf

将以下内容复制粘贴,然后wq保存

user root ;
worker_processes  8;
error_log  /usr/local/nginx/logs/error.log;
events {
    worker_connections  102400;
}
http {
    include       mime.types;
    default_type  application/octet-stream;

    access_log  /dev/null;
    error_log  /dev/null;

    charset utf-8;
    server_names_hash_bucket_size 128;
    client_header_buffer_size 2k;
    large_client_header_buffers 4 4k;
    client_max_body_size 8m;
    sendfile        on;
    tcp_nopush     on;
    keepalive_timeout  60;
    client_header_timeout 10s;
    send_timeout 30s;
    gzip on;
    gzip_min_length 1k;
    gzip_buffers 4 16k;
    gzip_http_version 1.0;
    gzip_comp_level 2;
    gzip_types text/plain application/x-javascript text/css application/xml;
    gzip_vary on;

    server {
        listen       80;
        server_name  172.0.6.102;
        
        access_log  /dev/null;
        error_log  /dev/null;

        index index.html index.htm;
        root  /usr/local/nginx/html/;
        
        error_page  404        /404.html;
        location = /404.html {
            root   /usr/local/nginx/html;
        }
        error_page   500 502 503 504  /500.html;
        location = /500.html {
            root   /usr/local/nginx/html;
        }

        location /group1/M00 {
            #root /data/fastdfs/storage/data/;
            ngx_fastdfs_module;
            expires      30d;
        }
    }
}

测试有无语法错误

/usr/local/nginx/sbin/nginx -t

五:启动所有服务并测试系统

service nginx restart
service fdfs_storaged restart
service fdfs_trackerd restart
netstat -lnp | grep 

查看服务是否启动

netstat -lnp | grep -e "fdfs" -e "nginx"

QQ截图20190727111014.png
编辑客户端设置并测试

cp /etc/fdfs/client.conf.sample /etc/fdfs/client.conf
vi /etc/fdfs/client.conf

编辑以下两个参数

base_path=/data/fastdfs/storage
tracker_server=172.0.6.102:22122

QQ截图20190727111322.png
然后wq保存后开始测试,测试成功回返回一个URL链接,链接在浏览器能打开就测试成功,注意关闭防火墙策略

fdfs_test /etc/fdfs/client.conf upload /root/install.log

QQ截图20190727111553.png
最后,相关文件的下载链接
fastFDS.zip

标签:none

添加新评论