fastdfs文件服务器的基本安装和配置记录

安装包

wget https://github.com/happyfish100/libfastcommon/archive/V1.0.7.tar.gz
wget http://jaist.dl.sourceforge.net/project/fastdfs/FastDFS%20Nginx%20Module%20Source%20Code/fastdfs-nginx-module_v1.16.tar.gz
wget https://github.com/happyfish100/fastdfs/archive/V5.05.tar.gz
wget http://nginx.org/download/nginx-1.12.1.tar.gz

gcc

yum -y install gcc gcc-c++ autoconf pcre pcre-devel make automake
yum -y install wget httpd-tools vim

安装libfastcommon

/**解压
**/
tar -zxvf libfastcommonV1.0.7.tar.gz
./make.sh
./make.sh install
/**
安装成功后将目录conf内的文件拷贝到/etc/fdfs目录下:
**/
cp /data/fastDFS/software/FastDFS/conf/* /etc/fdfs/

安装tracker
进入/etc/fdfs目录,修改tracker.conf文件。如果不存在,就拷贝tracker.conf.sample文件为tracker.conf,然后再修改
fdfs_trackerd /etc/fdfs/tracker.conf start
netstat -unltp | grep tracker
安装storage

/**
由于storage和tracker运行的都是fastDFS程序,每一台服务器都部署一台fasfDFS,一台服务器是tracker,一台是storage

修改storage.conf文件。如果不存在,就拷贝storage.conf.sample文件为storage.conf,然后再修改:
**/
base_path=/home/yuqing/fastdfs >>> base_path=/home/logs/storage (日志路径)

store_path0=/home/yuqing/fastdfs >>> store_path0=/home/data/storage  (实际储存文件路径,可以配置多个)

tracker_server=192.168.209.121:22122 >>> tracker_server=192.168.2.231:22122 (连接tracker服务器地址)//内网地址,内网

group_name=group1 (必须和tracker的组名相同)

http.server_port=80 (这个端口也要改)//我都使用默认的
/**
启动
fdfs_storaged /etc/fdfs/storage.conf start 
查看
netstat -unltp | grep storage
**/

安装Nginx

#gcc安装 
yum install gcc-c++

#PCRE pcre-devel 安装
yum install -y pcre pcre-devel

# zlib 安装
yum install -y zlib zlib-devel

#OpenSSL 安装
yum install -y openssl openssl-devel
#解压、编译、安装。
tar -zxvf nginx-1.12.1.tar.gz
cd nginx-1.12.1
./configure
make
make install

安装fastdfs-nginx-module
首先解压fastdfs-nginx-module_v1.16.tar.gz,修改/fastdfs-nginx-module/src/config文件。去掉所有的local(三个)

#拷贝usr/lib64目录下库文件libfdfsclient.so 
cp /usr/lib64/libfdfsclient.so /usr/lib 
#在nginx安装目录下执行如下命令:把module添加nginx中。通过设置安装参数方式添加模块。
cd nginx-1.12.1
./configure --add-module=../fastdfs-nginx-module/src
#重新安装编译
make && make install
#查看Nginx的模块
/usr/local/nginx/sbin/nginx -V
#复制 fastdfs-nginx-module 源码中的配置文件到/etc/fdfs 目录, 并修改
cd fastdfs-nginx-module/src
cp mod_fastdfs.conf /etc/fdfs/
#进入/etc/fdfs/修改mod_fastdfs.conf如下配置,其他默认 我没有配置也可
# 连接超时时间
connect_timeout=10

# Tracker Server
tracker_server=192.168.2.231:22122

# StorageServer 默认端口
storage_server_port=23000

# 如果文件ID的uri中包含/group**,则要设置为true
url_have_group_name = true

# Storage 配置的store_path0路径,必须和storage.conf中的一致
store_path0=/home/data/storage

# the base path to store log files
base_path=/home/logs/storage
#配置iNginx ,进入/usr/local/nginx/conf目录下修改nginx.conf
/**
location ~/group([0-9])/M00 {
    ngx_fastdfs_module;
}
**/
#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

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

         location /group1/M00 {
                alias /home/yuqing/fastdfs/data;
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

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


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

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

}

启动nginx

#启动nginx
cd /usr/local/nginx/sbin/
./nginx 

直接启动
/usr/local/nginx/sbin/nginx

#设置开机启动
vim /etc/rc.local
/usr/local/nginx/sbin/nginx

# 设置执行权限
chmod 755 rc.local
#关闭防火墙
iptables -L;iptables -F;service iptables stop
#去阿里云将端口打开
启动fastdfs:
先启动tracker,在启动storage
/usr/bin/fdfs_trackerd /mnt/fdfs/tracker.conf
/usr/bin/fdfs_storaged /mnt/fdfs/storage.conf

关闭fastdfs
killall fdfs_trackerd
killall fdfs_storaged

查看是否启动成功
ps -ef |grep fdfs
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。