CentOS安装FastDFS

1 环境:

操作系统: CentOS 7.4 64位

连接工具:putty

2 安装包下载

2.1 创建文件夹保存下载文件

# 创建文件目录并进入指定目录
mkdir -p ~/fastdfs/ && cd ~/fastdfs

2.2 下载所需要的文件(阿里云OSS下载)

wget https://halo-83-start.oss-cn-shenzhen.aliyuncs.com/file/download/FastDFS/fastdfs-6.06.tar.gz

wget https://halo-83-start.oss-cn-shenzhen.aliyuncs.com/file/download/FastDFS/fastdfs-client-java-1.29-SNAPSHOT.jar

wget https://halo-83-start.oss-cn-shenzhen.aliyuncs.com/file/download/FastDFS/fastdfs-client-java-master.zip

wget https://halo-83-start.oss-cn-shenzhen.aliyuncs.com/file/download/FastDFS/fastdfs-nginx-module-1.22.tar.gz

wget https://halo-83-start.oss-cn-shenzhen.aliyuncs.com/file/download/FastDFS/libfastcommon-1.0.43.zip

wget https://halo-83-start.oss-cn-shenzhen.aliyuncs.com/file/download/FastDFS/nginx-1.16.1.tar.gz

image-20220315143024408

3 安装必要的软件

3.1 安装C语言工具

yum  -y install cmake make gcc-c++

3.2 安装解压工具

yum -y install unzip

4 安装libfastcommon服务器

4.1 创建文件夹保存文件

# 创建目录
mkdir -p /usr/local/fastdfs 

4.2 安装libfastcommon资源包

# 在 ~/fastdfs 下解压资源包
cd ~/fastdfs
unzip libfastcommon-1.0.43.zip -d /usr/local/fastdfs/
# 进入资源包
cd /usr/local/fastdfs/libfastcommon-1.0.43

image-20220315145618751

# 编译
./make.sh

image-20220315145331820

image-20220315145355557

# 安装
./make.sh install

image-20220315145439444

安装好之后可以看到 libfastcommon.so 安装到了/usr/lib64/libfastcommon.so

img

4.3 创建软连接

ln -s /usr/lib64/libfastcommon.so /usr/local/lib/libfastcommon.so

ln -s /usr/local/lib64/libfdfsclient.so /usr/local/lib/libfdfsclient.so

ln -s /usr/local/lib64/libfdfsclient.so /usr/lib/libfdfsclient.so 

5 安装FastDFS

5.1 解压文件夹

# 进入下载目录
cd ~/fastdfs
tar zxvf  fastdfs-6.06.tar.gz -C /usr/local/fastdfs/

5.2 安装 FastDFS 资源包

# 进入文件
cd /usr/local/fastdfs/fastdfs-6.06
# 修改编译和安装的路径(可选)
# ==== vim make.sh ====

TARGET_PREFIX=$DESTDIR/usr/local

image-20220315150925253

# 编译
./make.sh

image-20220315151002538

# 安装
./make.sh install 

image-20220315151418361

# 查看服务脚本文件
cd /etc/init.d

ll

image-20220315151649812

# 查看模板文件
cd /etc/fdfs
ls -al

image-20220315152007919

# 查看内置命令
cd /usr/local/bin

image-20220315152321292

6 安装 tracker服务器

开始配置tracker,配置FastDFS跟踪器(Tracker):

6.1 准备工作

# 创建目录
mkdir -p /fastdfs/tracker

# 切换目录
cd /etc/fdfs

# 拷贝文件
cp tracker.conf.sample tracker.conf

# 编辑文件
vim tracker.conf

6.2 修改文件内容

# ===== 修改内容 =====

# the base path to store data and log files
# Tracker 数据和日志目录地址
base_path=/fastdfs/tracker

6.3 修改目录(可选)

如果在 5.2 安装 FastDFS 资源包 中没有修改路径直接编译运行,就可以省略跳过这一步骤。

# 进入目录
cd /etc/init.d/

# 备份文件
cp fdfs_trackerd fdfs_trackerd.bak

# 修改文件
vim fdfs_trackerd
# ===== 修改内容 =====
PRG=/usr/local/bin/fdfs_trackerd

6.4 开安全组的端口

打开相应的腾讯云服务器端口号了,不然会报各种各样的连接失败的错误。

除了22122端口号,我们还需要开放80和23000端口号。

6.5 启动Tracker

./fdfs_trackerd start

image-20220315154431179

6.7 检验启动成功

检验安装成功:1

查看 FastDFS Tracker 是否已成功启动 ,22122端口正在被监听,则算是Tracker服务安装成功:

netstat -unltp|grep fdfs

如果看到上面显示的,则表明你tracker安装成功啦,端口号也打开啦。

# netstat -unltp|grep fdfs
tcp    0  0 0.0.0.0:22122  0.0.0.0:*    LISTEN      7790/fdfs_trackerd

检验安装成功:2

./fdfs_trackerd status

image-20220315154657570

6.8 关闭Tracker命令(不关闭)

./fdfs_trackerd stop

6.9 重启Tracker 命令

./fdfs_trackerd restart

6.10 设置开机启动

vim /etc/rc.d/rc.local
# 添加内容
/etc/init.d/fdfs_tracked start

image-20220315180008916

7 配置 Storage服务器

7.1 准备工作

# 创建目录
mkdir -p /fastdfs/storage/base

mkdir -p /fastdfs/storage/store
# 切换目录
cd /etc/fdfs

# 复制配置文件
cp storage.conf.sample storage.conf

# 编辑配置文件
vim storage.conf

7.2 编辑文件

# 基本目录
base_path = /fastdfs/storage/base

# 存放文件的目录
store_path0 = /fastdfs/storage/store

# 追踪服务器的地址
tracker_server = 120.79.2.168:22122

7.3 修改目录(可选)

如果在 5.2 安装 FastDFS 资源包 中没有修改路径直接编译运行,就可以省略跳过这一步骤。

# 进入目录
cd /etc/init.d/

# 备份文件
cp fdfs_storaged fdfs_storaged.bak

# 修改文件
vim fdfs_storaged
# ===== 修改内容 =====
PRG=/usr/local/bin/fdfs_storaged

image-20220315181820065

7.4 启动 Storage

# 切换目录
cd /etc/init.d/

# 启动程序
./fdfs_storaged start

7.5 检查启动

检查方式1:

netstat -unltp|grep fdfs

如果出现了上面所示,则表明你成功了!如果没出现,肯定就是端口号没开放,或者ip地址配置配置错了,或者没给阿里云服务器自己授权!

# netstat -unltp|grep fdfs
tcp    0  0 0.0.0.0:23000  0.0.0.0:*    LISTEN      7823/fdfs_storaged
tcp    0  0 0.0.0.0:22122  0.0.0.0:*    LISTEN      7790/fdfs_trackerd

检查方式2:

./fdfs_storaged status

7.6 关闭Storage命令(不关闭)

./fdfs_storaged stop

这里不建议

8 配置 Client 客户端配置文件

8.1 准备工作

# 创建文件夹
mkdir -p /fastdfs/client
# 切换目录
cd /etc/fdfs

# 拷贝文件
cp client.conf.sample client.conf

# 编辑文件
vim client.conf

8.2 修改配置文件

# Client 的数据和日志目录
base_path=/fastdfs/client
 
# Tracker端口
tracker_server=${公网IP}:22122

8.3 图片上传测试

上传图片:

# 切换目录
mkdir -p ~/data && cd /data

# 下载图片
wget https://sister-1306912104.cos.ap-shanghai.myqcloud.com/sister/test.jpg

# 上传图片
/usr/local/bin/fdfs_upload_file /etc/fdfs/client.conf test.jpg

# 上传成功就会返回一个ID:
`group1/M00/00/00/rBL5_1vZTlGANIJPAABqgmoDdSo292.jpg`

# 删除文件
/usr/local/bin/fdfs_delete_file /etc/fdfs/client.conf group1/M00/00/00/eE8CqGIwbs2AW8tjAAVTw7SzprA880.jpg

9 安装 fastdfs-nginx-module

9.1 解压文件

# 切换目录
cd ~/fastdfs

# 解压文件到指定目录
tar zxvf fastdfs-nginx-module-1.22.tar.gz -C /usr/local/fastdfs/

9.2 修改配置文件

# 切换目录
cd /usr/local/fastdfs/fastdfs-nginx-module-1.22/src

# 修改配置文件
vim config

这里是 5.2 修改了安装路径,所以这么改

如果没有修改安装路径,这直接删掉 local

image-20220315201438587

9.3 环境配置

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

9.4 解压 nginx

# 解压 nginx
tar zxvf ~/fastdfs/nginx-1.16.1.tar.gz  -C /usr/local/fastdfs/
# 切换目录
cd nginx-1.12.1

9.5 创建文件夹

mkdir -p /var/temp/nginx

9.6 编译安装

./configure \
--prefix=/usr/local/nginx \
--pid-path=/var/run/nginx/nginx.pid \
--lock-path=/var/lock/nginx.lock \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--with-http_gzip_static_module \
--http-client-body-temp-path=/var/temp/nginx/client \
--http-proxy-temp-path=/var/temp/nginx/proxy \
--http-fastcgi-temp-path=/var/temp/nginx/fastcgi \
--http-uwsgi-temp-path=/var/temp/nginx/uwsgi \
--http-scgi-temp-path=/var/temp/nginx/scgi \
--add-module=/usr/local/fastdfs/fastdfs-nginx-module-1.22/src
# 编译
make

image-20220315203349991

#  安装:
make install

image-20220315203438807

9.7 修改配置文件

# 切换目录
cd /usr/local/fastdfs/fastdfs-nginx-module-1.22/src/

# 拷贝文件
cp mod_fastdfs.conf /etc/fdfs/

# 切换目录
cd /etc/fdfs

# 修改配置文件
vim mod_fastdfs.conf
# ===== vim mod_fastdfs.conf ===== 
connect_timeout = 10

tracker_server = ${公网IP}:22122

url_have_group_name = true

store path0=/fastdfs/storage/store

9.8 拷贝 http 和 mime 文件

cp /usr/local/fastdfs/fastdfs-6.06/conf/http.conf /etc/fdfs
cp /usr/local/fastdfs/fastdfs-6.06/conf/mime.types /etc/fdfs

9.9 创建启动软连接

ln -s /usr/local/lib64/libfdfsclient.so /usr/lib64/libfdfsclient.so

9.10 创建网络服务软连接

ln -s /fastdfs/storage/store/data/ /fastdfs/storage/store/data/M00cd

9.11 修改nginx 的配置文件

# 切换目录
cd /usr/local/nginx/conf

# 修改文件
vim nginx.conf
user  root;
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       8888;
        server_name  localhost;
	location ~/group[0-9]/M00{
		ngx_fastdfs_module;
	}

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

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

        #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;
    #    }
    #}
}

9.12 启动 nginx

# 切换目录
cd /usr/local/nginx/sbin/

# 启动nginx
./nginx 

9.13 nginx其它命令

# 其它命令
./nginx -s stop
./nginx -s quit
./nginx -s reload

9.14 nginx启动失败

原因:

nginx: [emerg] open() "/var/run/nginx/nginx.pid" failed (2: No such file or directory)

因为nginx 缺少 nginx.pid 文件

解决方式 :

# 切换目录
cd /var/run

# 创建 nginx 文件夹
mkdir nginx

# 创建 nginx.pid 文件
touch nginx.pid

10 nginx 访问 FastDFS 测试

http://120.79.2.168:8888/group1/M00/00/00/eE8CqGJYs3iAaIurAAVTw7SzprA949.jpg

图片.png

11 开机重新启动FastDFS 服务

# 切换目录
 cd /etc/init.d/

# 启动 storaged 服务
./fdfs_storaged start

# 启动 trackerd 服务
./fdfs_trackerd start

# 切换nginx目录
cd /usr/local/nginx/sbin/
 
# 启动nginx
./nginx 
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值