CentOS 7 下搭建FastDFS 5.11文件服务器

1.下载服务包及依赖包


fastdfs-5.11.tar.gz

下载址址:https://github.com/happyfish100/fastdfs/releases

libfastcommon-1.0.39.tar.gz

下载址址:https://github.com/happyfish100/libfastcommon/releases

fastdfs-nginx-module-1.20.tar.gz

下载址址: https://github.com/happyfish100/fastdfs-nginx-module/releases

nginx-1.14.2.tar.gz

下载址址:http://nginx.org/download/nginx-1.14.2.tar.gz

2.安装相关依赖

yum install gcc gcc-c++ make automake autoconf libtool pcre* zlib openssl openssl-devel

3.新建用户

[root@localhost ~]# useradd fastdfs

##设置密码并确认即可
[root@localhost ~]# passwd fastdfs
Changing password for user fastdfs.
New password: 
BAD PASSWORD: The password is shorter than 8 characters
Retype new password: 
passwd: all authentication tokens updated successfully.
[root@localhost ~]# su - fastdfs
[fastdfs@localhost ~]$ 

4.创建安装目录

[fastdfs@localhost ~]$ mkdir -p /home/fastdfs/opt/fastdfs
####存放软件安装包
[fastdfs@localhost ~]$ mkdir -p /home/fastdfs/soft 
 
[fastdfs@localhost ~]$ pwd
/home/fastdfs
[fastdfs@localhost ~]$ ll
总用量 0
drwxrwxr-x. 3 fastdfs fastdfs 21 8月  14 14:54 opt
drwxrwxr-x. 2 fastdfs fastdfs  6 8月  14 14:54 soft
[fastdfs@localhost ~]$ cd soft
[fastdfs@localhost soft]$ ll
总用量 1496
-rwxr-xr-x. 1 fastdfs fastdfs  336939 8月  14 14:57 fastdfs-5.11.tar.gz
-rwxr-xr-x. 1 fastdfs fastdfs   19825 8月  14 14:57 fastdfs-nginx-module-1.20.tar.gz
-rwxr-xr-x. 1 fastdfs fastdfs  153951 8月  14 14:57 libfastcommon-1.0.39.tar.gz
-rwxr-xr-x. 1 fastdfs fastdfs 1015384 8月  14 14:58 nginx-1.14.2.tar.gz

 

5.编译安装libfastcommon

##设置安装路径
[fastdfs@localhost soft]$ export DESTDIR=/home/fastdfs/opt/fastdfs
[fastdfs@localhost soft]# tar -zxvf libfastcommon-1.0.39.tar.gz 
[fastdfs@localhost soft]# cd libfastcommon-1.0.39/
[fastdfs@localhost libfastcommon-1.0.39]# ./make.sh 
[fastdfs@localhost libfastcommon-1.0.39]# ./make.sh install
mkdir -p /home/fastdfs/opt/fastdfs/usr/lib64
mkdir -p /home/fastdfs/opt/fastdfs/usr/lib
mkdir -p /home/fastdfs/opt/fastdfs/usr/include/fastcommon
install -m 755 libfastcommon.so /home/fastdfs/opt/fastdfs/usr/lib64
install -m 644 common_define.h hash.h chain.h logger.h base64.h shared_func.h pthread_func.h ini_file_reader.h _os_define.h sockopt.h sched_thread.h http_func.h md5.h local_ip_func.h avl_tree.h ioevent.h ioevent_loop.h fast_task_queue.h fast_timer.h process_ctrl.h fast_mblock.h connection_pool.h fast_mpool.h fast_allocator.h fast_buffer.h skiplist.h multi_skiplist.h flat_skiplist.h skiplist_common.h system_info.h fast_blocked_queue.h php7_ext_wrapper.h id_generator.h char_converter.h char_convert_loader.h common_blocked_queue.h multi_socket_client.h skiplist_set.h fc_list.h /home/fastdfs/opt/fastdfs/usr/include/fastcommon
if [ ! -e /home/fastdfs/opt/fastdfs/usr/lib/libfastcommon.so ]; then ln -s /home/fastdfs/opt/fastdfs/usr/lib64/libfastcommon.so /home/fastdfs/opt/fastdfs/usr/lib/libfastcommon.so; fi

#### libfastcommon.so 默认安装到了/usr/lib64/libfastcommon.so,但是FastDFS主程序设置的lib目录是/home/fastdfs/opt/fastdfs/usr/lib,所以此处需要重新设置软链接

[fastdfs@localhost libfastcommon-1.0.39]$  ln -s /home/fastdfs/opt/fastdfs/usr/lib64/libfastcommon.so /home/fastdfs/opt/fastdfs/usr/lib/libfastcommon.so

6.编译安装fastdfs

6.1. 编译安装fastdfs

[fastdfs@localhost soft]$ tar -zxvf fastdfs-5.11.tar.gz 
[fastdfs@localhost soft]$ cd fastdfs-5.11/

6.2. 修改make.sh文件

LIBS="-Wl,-rpath=/home/fastdfs/opt/fastdfs/usr/lib64"

$TARGET_CONF_PATH

6.3. 修改Makefile.in文件,文件不同修改方法相同

vi /home/fastdfs/soft/fastdfs-5.11/tracker/Makefile.in

vi /home/fastdfs/soft/fastdfs-5.11/storage/Makefile.in

vi /home/fastdfs/soft/fastdfs-5.11/client/Makefile.in

${DESTDIR}

-L${DESTDIR}/usr/lib64

6.4. 编译并安装

cd /home/fastdfs/soft/fastdfs-5.11/

./make.sh

./make.sh install

6.5. 检查是否安装程序正常加载所有依赖

ldd /home/fastdfs/opt/fastdfs/usr/bin/fdfs_trackerd

ldd /home/fastdfs/opt/fastdfs/usr/bin/fdfs_storaged

ldd /home/fastdfs/opt/fastdfs/usr/bin/fdfs_monitor

7.安装nginx和fastdfs-nginx-module

7.1. 到相应目录下解压安装包

cd /home/fastdfs/soft/

tar zxvf nginx-1.14.2.tar.gz

tar zxvf fastdfs-nginx-module-1.20.tar.gz

7.2. 修改fastdfs-nginx-module编译配置

vi fastdfs-nginx-module-1.20/src/config

${DESTDIR}/usr/include

${DESTDIR}/usr/include/fastcommon

7.3. 复制fastdfs-nginx-module配置文件到fastdfs存放配置文件的目录

cp /home/fastdfs/soft/fastdfs-nginx-module-1.20/src/mod_fastdfs.conf /home/fastdfs/opt/fastdfs/etc/fdfs

7.4.修改配置

修改ip为本机地址

[fastdfs@localhost src]$ cd /home/fastdfs/soft/fastdfs-nginx-module-1.20/src
[fastdfs@localhost src]$ vim mod_fastdfs.conf 
##找到tracker_server修改成本机IP
tracker_server=172.16.87.165:22122
[fastdfs@localhost src]$ cd /home/fastdfs/soft/fastdfs-5.11/conf/
[fastdfs@localhost conf]$ vim storage.conf 
##找到tracker_server修改成本机IP
tracker_server=172.16.87.165:22122

[fastdfs@localhost conf]$ vim client.conf 
##找到tracker_server修改成本机IP
tracker_server=172.16.87.165:22122

7.5.编译Nginx

[fastdfs@localhost nginx-1.14.2]$  cd /home/fastdfs/soft/nginx-1.14.2
[fastdfs@localhost nginx-1.14.2]$ export DESTDIR=/home/fastdfs/opt/fastdfs
[fastdfs@localhost nginx-1.14.2]$ export DESTDIR=/home/fastdfs/opt/fastdfs
[fastdfs@localhost nginx-1.14.2]$ ./configure --prefix=/home/fastdfs/opt/nginx-fdfs --add-module=/home/fastdfs/soft/fastdfs-nginx-module-1.20/src --with-http_ssl_module --with-ld-opt="-L /home/fastdfs/opt/fastdfs/usr/lib -Wl,-rpath=/home/fastdfs/opt/fastdfs/usr/lib64"
[fastdfs@localhost nginx-1.14.2]$ make
[fastdfs@localhost nginx-1.14.2]$ export DESTDIR=""
[fastdfs@localhost nginx-1.14.2]$ make install
[fastdfs@localhost nginx-1.14.2]$ cp /home/fastdfs/soft/fastdfs-5.11/conf/mime.types /home/fastdfs/opt/fastdfs/etc/fdfs

7.6.检查nginx是否正常加载所有依赖

ldd /home/fastdfs/opt/nginx-fdfs/sbin/nginx

7.7.复制fastdfs源码中给的参考配置文件到fastdfs安装目录

[fastdfs@localhost nginx-1.14.2]$ cd /home/fastdfs/soft/fastdfs-5.11/conf

[fastdfs@localhost conf]$ cp ./*.conf /home/fastdfs/opt/fastdfs/etc/fdfs/

8.启动脚本

8.1. 创建启动脚本目录

[fastdfs@localhost conf]$ cd /home/fastdfs/
[fastdfs@localhost ~]$ mkdir -p /home/fastdfs/data/storage
[fastdfs@localhost ~]$ mkdir -p /home/fastdfs/data/fastdfs
[fastdfs@localhost ~]$ mkdir -p /home/fastdfs/bin
[fastdfs@localhost ~]$ cp /home/fastdfs/opt/fastdfs/etc/init.d/* /home/fastdfs/bin

8.2. 修改启动脚本

vim /home/fastdfs/bin/fdfs_trackerd

PRG=/home/fastdfs/opt/fastdfs/usr/bin/fdfs_trackerd

CONF=/home/fastdfs/opt/fastdfs/etc/fdfs/tracker.conf

vim /home/fastdfs/bin/fdfs_storaged

PRG=/home/fastdfs/opt/fastdfs/usr/bin/fdfs_storaged

CONF=/home/fastdfs/opt/fastdfs/etc/fdfs/storage.conf

8.3. 启停命令

cd /home/fastdfs/bin

./fdfs_trackerd start|stop|restart

./fdfs_storaged start|stop|restart

9.配置并启动Nginx

9.1.修改nginx.conf

vi /home/fastdfs/opt/nginx-fdfs/conf/nginx.conf

include /home/fastdfs/opt/nginx-fdfs/conf/fastdfs.conf;

9.2.新增fastdfs.conf文件

[fastdfs@localhost soft]$ cd /home/fastdfs/opt/nginx-fdfs/conf/
[fastdfs@localhost conf]$ touch fastdfs.conf
[fastdfs@localhost conf]$ vim  fastdfs.conf
###添加以下内容#####
upstream fdfs_group1 {
        server 172.16.26.80:6666;
    }
    server {
        listen       8888;
        server_name  fastdfs;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

    location ~/group[1-3]/M00 {
            root /home/fastdfs/data/storage;
            ngx_fastdfs_module;
        }

     location /group1/M00 {
        proxy_pass http://fdfs_group1;
    }
}

9.3.启动nginx

./home/fastdfs/opt/nginx-fdfs/sbin/nginx

10.测试执行

1)上传图片

2)执行/home/fastdfs/opt/fastdfs/usr/bin/fdfs_upload_file  /home/fastdfs/opt/fastdfs/etc/fdfs/client.conf  ./1.png

成功显示:

 

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
CentOS 7 上搭建 FastDFS 文件服务器的步骤如下: 1. 安装必要的依赖库: ``` yum install -y gcc gcc-c++ make automake autoconf libtool pcre pcre-devel zlib zlib-devel openssl openssl-devel wget ``` 2. 下载 FastDFS 源码: ``` wget https://github.com/happyfish100/fastdfs/archive/V6.06.tar.gz ``` 3. 解压源码并编译安装: ``` tar zxvf V6.06.tar.gz cd fastdfs-6.06/ ./make.sh ./make.sh install ``` 4. 配置 Tracker 服务器: 在 Tracker 服务器上创建一个 tracker.conf 配置文件,并添加以下内容: ``` # 配置 Tracker 服务器的 IP 和端口号 port=22122 bind_addr=192.168.0.1 # 配置存储服务器的组名和存储服务器的 IP 和端口号 group_name=group1 group_count=1 group0_ip=192.168.0.2 group0_port=23000 # 配置日志文件的路径和级别 log_level=info log_filename=/var/log/fdfs/trackerd.log ``` 5. 启动 Tracker 服务器: ``` /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart ``` 6. 配置 Storage 服务器: 在 Storage 服务器上创建一个 storage.conf 配置文件,并添加以下内容: ``` # 配置 Tracker 服务器的 IP 和端口号 tracker_server=192.168.0.1:22122 # 配置存储服务器的 IP 和端口号 port=23000 bind_addr=192.168.0.2 # 配置存储服务器的组名和容量 group_name=group1 store_path_count=1 store_path0=/data/fastdfs/storage # 配置心跳时间和同步文件的时间 heart_beat_interval=30 sync_wait_msec=600 # 配置日志文件的路径和级别 log_level=info log_filename=/var/log/fdfs/storaged.log ``` 7. 启动 Storage 服务器: ``` /usr/bin/fdfs_storaged /etc/fdfs/storage.conf restart ``` 8. 测试上传和下载文件: 在客户端机器上安装 FastDFS 客户端工具: ``` yum install -y libfastcommon wget https://github.com/happyfish100/fastdfs/archive/V6.06.tar.gz tar zxvf V6.06.tar.gz cd fastdfs-6.06/ ./make.sh ./make.sh install ``` 上传文件: ``` /usr/bin/fdfs_upload_file /etc/fdfs/client.conf /path/to/local/file ``` 下载文件: ``` /usr/bin/fdfs_download_file /etc/fdfs/client.conf group1 M00/00/00/xxx /path/to/local/file ``` 以上就是在 CentOS 7 上搭建 FastDFS 文件服务器的步骤。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值