软件下载

# 已经事先把所需软件下载好并上传到/usr/local/src目录了
https://github.com/happyfish100/libfastcommon/archive/V1.0.43.tar.gz
https://github.com/happyfish100/fastdfs-nginx-module/archive/V1.22.tar.gz
https://github.com/happyfish100/fastdfs/archive/V6.06.tar.gz
https://github.com/happyfish100/fastdfs-client-java/archive/V1.28.tar.gz
https://openresty.org/download/openresty-1.15.8.3.tar.gz

文件下载地址:https://files.cnblogs.com/files/sanduzxcvbnm/FastDFS软件包.7z

基础环境设置

安装依赖组件

yum -y install  gcc gcc-c++ libevent
yum -y groupinstall 'Development Tools'

<escape><!-- more --></escape>

安装libfastcommon

cd /usr/local/src
tar -zxvf libfastcommon-1.0.43.tar.gz
cd libfastcommon-1.0.43
./make.sh
./make.sh install # 检查文件是否存在
[root@bogon libfastcommon-1.0.43]# ll /usr/lib64 | grep "libfastcommon.so"
-rwxr-xr-x 1 root root 1035264 Apr 2 10:07 libfastcommon.so
[root@bogon libfastcommon-1.0.43]# ll /usr/lib | grep "libfastcommon.so"
lrwxrwxrwx 1 root root 27 Apr 2 10:07 libfastcommon.so -> /usr/lib64/libfastcommon.so

安装fastdfs

cd /usr/local/src
tar -zxvf fastdfs-6.06.tar.gz
cd fastdfs-6.06
./make.sh
./make.sh install # 安装成功后将解压目录下的conf下的俩文件拷贝到/etc/fdfs/下
cd conf
cp http.conf mime.types /etc/fdfs/
cd /etc/fdfs/
[root@bogon fdfs]# ll
total 68
-rw-r--r-- 1 root root 1909 Apr 2 10:15 client.conf.sample
-rw-r--r-- 1 root root 965 Apr 2 10:16 http.conf
-rw-r--r-- 1 root root 31172 Apr 2 10:16 mime.types
-rw-r--r-- 1 root root 10246 Apr 2 10:15 storage.conf.sample
-rw-r--r-- 1 root root 620 Apr 2 10:15 storage_ids.conf.sample
-rw-r--r-- 1 root root 9138 Apr 2 10:15 tracker.conf.sample

fdfs_trackerd配置并启动

cd /etc/fdfs/
cp tracker.conf.sample tracker.conf
mkdir -p /opt/{fdfs_tracker,fdfs_storage,fdfs_storage_data}
vim tracker.conf
base_path = /opt/fdfs_tracker # 启动fdfs_trackerd
/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf start
# 查看端口号,验证启动情况
[root@bogon fdfs]# ps -ef | grep fdfs
root 2119 1 0 10:22 ? 00:00:00 /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf start
[root@bogon fdfs]# ss -tulnp | grep 22122
tcp LISTEN 0 128 *:22122 *:* users:(("fdfs_trackerd",pid=2119,fd=5)) # 命令行选项
Usage: /usr/bin/fdfs_trackerd <config_file> [start|stop|restart] # 注意:在/opt/fdfs_data目录下生成两个目录,一个是数据,一个是日志.
# 设置开机自启动
echo "/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart" | tee -a /etc/rc.d/rc.local

fdfs_storaged配置并启动

cd /etc/fdfs/
cp storage.conf.sample storage.conf
vim storage.conf
base_path = /opt/fdfs_storage # 注意,这个目录最好有大于50G的磁盘空间
store_path0 = /opt/fdfs_storage_data # 若配置这个参数,则该目录为实际保存文件的路径
tracker_server = 192.168.75.5:22122
# 启动fdfs_storaged
/usr/bin/fdfs_storaged /etc/fdfs/storage.conf start
[root@bogon fdfs]# ps -ef | grep "fdfs_storaged"
root 2194 1 7 10:36 ? 00:00:01 /usr/bin/fdfs_storaged /etc/fdfs/storage.conf start
[root@bogon fdfs]# ss -tulnp | grep "fdfs"
tcp LISTEN 0 128 *:23000 *:* users:(("fdfs_storaged",pid=2194,fd=5))
tcp LISTEN 0 128 *:22122 *:* users:(("fdfs_trackerd",pid=2119,fd=5)) # 命令行选项
Usage: /usr/bin/fdfs_trackerd <config_file> [start|stop|restart]
# 设置开机自启动
echo "/usr/bin/fdfs_storaged /etc/fdfs/storage.conf restart" | tee -a /etc/rc.d/rc.local

校验整合

要确定一下,storage是否注册到了tracker中去

/usr/bin/fdfs_monitor /etc/fdfs/storage.conf

成功后可以看到:ip_addr = 192.168.75.5 ACTIVE

使用FastDFS自带工具测试

cd /etc/fdfs/
cp client.conf.sample client.conf
vim client.conf
base_path = /opt/fdfs_tracker #tracker服务器文件路径
tracker_server = 192.168.75.5:22122 #tracker服务器IP地址和端口号
http.tracker_server_port = 8080 # tracker服务器的http端口号,必须和tracker的设置对应起来

上传一张图片1.jpg到Centos服务器上的 /tmp 目录下,进行测试,命令如下:

/usr/bin/fdfs_test /etc/fdfs/client.conf upload /tmp/1.jpg
This is FastDFS client test program v6.06 Copyright (C) 2008, Happy Fish / YuQing FastDFS may be copied only under the terms of the GNU General
Public License V3, which may be found in the FastDFS source kit.
Please visit the FastDFS Home Page http://www.fastken.com/
for more detail. [2020-04-02 10:47:57] DEBUG - base_path=/opt/fdfs_tracker, connect_timeout=5, network_timeout=60, tracker_server_count=1, anti_steal_token=0, anti_steal_secret_key length=0, use_connection_pool=0, g_connection_pool_max_idle_time=3600s, use_storage_id=0, storage server id count: 0 tracker_query_storage_store_list_without_group:
server 1. group_name=, ip_addr=192.168.75.5, port=23000 group_name=group1, ip_addr=192.168.75.5, port=23000
storage_upload_by_filename
group_name=group1, remote_filename=M00/00/00/wKhLBV6FUl6AA0eTACSnIi51C7k037.jpg
source ip address: 192.168.75.5
file timestamp=2020-04-02 10:47:58
file size=2402082
file crc32=779422649
example file url: http://192.168.75.5:8080/group1/M00/00/00/wKhLBV6FUl6AA0eTACSnIi51C7k037.jpg
storage_upload_slave_by_filename
group_name=group1, remote_filename=M00/00/00/wKhLBV6FUl6AA0eTACSnIi51C7k037_big.jpg
source ip address: 192.168.75.5
file timestamp=2020-04-02 10:47:58
file size=2402082
file crc32=779422649
example file url: http://192.168.75.5:8080/group1/M00/00/00/wKhLBV6FUl6AA0eTACSnIi51C7k037_big.jpg

以上图中的文件地址:http://192.168.75.5:8080/group1/M00/00/00/wKhLBV6FUl6AA0eTACSnIi51C7k037.jpg对应storage服务器上的/opt/fdfs_storage_data/data/00/00/wKhLBV6FUl6AA0eTACSnIi51C7k037.jpg文件;

注意图片路径中的8080端口,这个是tracker的端口,

但是查看该目录,会有四个图片文件:

[root@bogon 00]# pwd
/opt/fdfs_storage_data/data/00/00
[root@bogon 00]# ll
total 4704
-rw-r--r-- 1 root root 2402082 Apr 2 10:47 wKhLBV6FUl6AA0eTACSnIi51C7k037_big.jpg
-rw-r--r-- 1 root root 49 Apr 2 10:47 wKhLBV6FUl6AA0eTACSnIi51C7k037_big.jpg-m
-rw-r--r-- 1 root root 2402082 Apr 2 10:47 wKhLBV6FUl6AA0eTACSnIi51C7k037.jpg
-rw-r--r-- 1 root root 49 Apr 2 10:47 wKhLBV6FUl6AA0eTACSnIi51C7k037.jpg-m

FastDFS和nginx结合使用

在tracker上安装 nginx

在每个tracker上安装nginx的主要目的是做负载均衡及实现高可用。如果只有一台tracker服务器可以不配置nginx.

一个tracker对应多个storage,通过nginx对storage负载均衡;

在storage上安装nginx(openresty)

cd /usr/local/src/
tar -zxvf fastdfs-nginx-module-1.22.tar.gz
cd fastdfs-nginx-module-1.22/src
cp mod_fastdfs.conf /etc/fdfs/
vim /etc/fdfs/mod_fastdfs.conf
base_path=/opt/fdfs_storage
tracker_server=192.168.75.5:22122
url_have_group_name = true #url中包含group名称
store_path0=/opt/fdfs_storage_data #与storage.conf中的路径保持一致
yum -y install pcre pcre-devel openssl openssl-devel
cd /usr/local/src
tar -zxvf openresty-1.15.8.3.tar.gz
cd openresty-1.15.8.3
./configure \
--with-luajit \
--with-http_stub_status_module \
--with-http_ssl_module \
--with-http_realip_module \
--with-http_gzip_static_module \
--add-module=/usr/local/src/fastdfs-nginx-module-1.22/src
gmake
gmake install # 启动
vim /usr/local/openresty/nginx/conf/nginx.conf
error_log logs/error.log;
pid logs/nginx.pid;
server{
server_name 192.168.75.5;
}
/usr/local/openresty/nginx/sbin/nginx -c /usr/local/openresty/nginx/conf/nginx.conf
# 浏览器访问,出现openresty欢迎页面 # 设置nginx开机启动
echo "/usr/local/openresty/nginx/sbin/nginx -c /usr/local/openresty/nginx/conf/nginx.conf" | tee -a /etc/rc.d/rc.local vim /usr/local/openresty/nginx/conf/nginx.conf
server{
location /group1/M00/ {
root /opt/fdfs_storage/data;
ngx_fastdfs_module;
}
} /usr/local/openresty/nginx/sbin/nginx -s reload # 参考上面测试的那一步图片url地址:http://192.168.75.5:8080/group1/M00/00/00/wKhLBV6FUl6AA0eTACSnIi51C7k037.jpg
使用nginxf访问的话,实际地址是:http://192.168.75.5/group1/M00/00/00/wKhLBV6FUl6AA0eTACSnIi51C7k037.jpg
需要把tracker使用的8080端口去掉,否则无法访问
# 进一步完善nginx配置文件
# 这个server设置的是storage nginx
server {
listen 9991;
server_name localhost; location / {
root html;
index index.html index.htm;
} location ~/group1/M00 {
root /opt/fastdfs_storage/data;
ngx_fastdfs_module;
} location = /50x.html {
root html;
}
} # 若访问不到图片需要配置这个软连接
# ln -s /opt/fastdfs_storage_data/data/ /opt/fastdfs_storage_data/data/M00 # 这个server设置的是tracker nginx
upstream fdfs_group1 {
server 127.0.0.1:9991;
} server {
listen 80;
server_name localhost; location /group1/M00 {
proxy_pass http://fdfs_group1;
} error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}

CentOS7部署FastDFS+nginx模块的更多相关文章

  1. 详细说明-CentOS7部署FastDFS+nginx模块(包含集群方式)

    软件下载 # 已经事先把所需软件下载好并上传到/usr/local/src目录了 https://github.com/happyfish100/libfastcommon/archive/V1.0. ...

  2. 在虚拟机中配置FastDFS+Nginx模块

    先上部署图 提示一下, ip 192.168.72.138 上面部署了两个group, 分别为 group1和g2. 另外, 同组之内的 port 要保持一致. 一.安装准备 1. #每台机器都添加两 ...

  3. Ansible + shell 实现部署fastdfs+nginx 实现图片服务器并提供动态缩放功能;

    因为公司阿里服务器变动几次,手动部署了好几次fastdfs+nginx,于是就想到了自动化部署,以下为脚本内容,由于只是想把着功能实现,并未有完完整的判断逻辑: 以下为ansible-playbook ...

  4. CentOS7搭建FastDFS+Nginx

    1. FastDFS 介绍 FastDFS是一个开源的分布式文件系统,她对文件进行管理,功能包括:文件存储.文件同步.文件访问(文件上传.文件下载)等,解决了大容量存储和负载均衡的问题.特别适合以文件 ...

  5. 使用passenger在Centos7部署Puma+Nginx+Ruby on Rails

    安装ruby环境 RVM(ruby版本管理工具)安装 gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A170311 ...

  6. CentOS7部署Django,nginx,uwsgi,redis

    前期准备 把所有的软件都传到这个tools文件夹 cd - mkdir tools cd tools/ mkdir /application 安装nginx yum install pcre pcre ...

  7. centos7 install fastdfs nginx

    https://github.com/judasn/Linux-Tutorial/blob/master/markdown-file/FastDFS-Nginx-Lua-GraphicsMagick. ...

  8. centos7配置fastdfs集群(5.09)

    centos7配置fastdfs集群(5.09) 2017年03月10日 23:34:26 带鱼兄 阅读数 1564    版权声明:本文为博主原创文章,转载请注明出处. https://blog.c ...

  9. FastDFS+Nginx+fastdfs-nginx-module集群搭建

    一.实验环境说明 操作系统: Centos 6.6 x64 FastDFS 相关版本: fastdfs-5.05 fastdfs-nginx-module-v1.16 libfastcommon-v1 ...

随机推荐

  1. 07 MySQL_事务

    事务 事务( transaction) 是数据库中执行同一业务多条SQL语句 工作单元,事务可以保证多条SQL语句全部执行成功或全部执行失败 和事务相关的SQL语句: 验证事务: 1. 创建表: cr ...

  2. 5.1 从C到C++

    在前4章中介绍了C语言的主要内容,已经足以应付许多算法竞赛的题目了,然而能写不代表好写,有些虽然能够用C语言实现,但是使用C++写起来往往会更快,并且不容易出错 从c到c++ C语言是一门很有用的语言 ...

  3. 平衡树——splay 一

    splay 一种平衡树,同时也是二叉排序树,与treap不同,它不需要维护堆的性质,它由Daniel Sleator和Robert Tarjan(没错,tarjan,又是他)创造,伸展树是一种自调整二 ...

  4. TCP/IP协议三次握手、四次断开

    1.tcp报文格式 1行代表一个字节: 第一行:代表源端口和目的端口,分别占16位: 第二行:32位序列号:表示客户端向服务端发送的报文的序号是多少,这个序号是计算机随机生成的一个代表该报文的唯一标示 ...

  5. Vxe-table 高亮当前行

    需求 1 :设置初始高亮 子组件: 父组件 需求 2 :高亮行的变化,需要把数据传递到兄弟组件中 解决办法:EventBus 参考链接: http://t.csdn.cn/iwOJc main.js ...

  6. Odoo4 tree视图左上角新增Button

    # 一.直接在tree根元素中新增.这种有个限制就是必须要勾选一或多条记录的时候按钮才会显示 <tree> <header> <button type="obj ...

  7. Apache DolphinScheduler 1.3.6 功能发布说明

    参与人员 @chengshiwen.@hailin0.@wanghong1314.@ruanwenjun.@xxjingcd.@zhangguohao.@zhuangchong.@syb8535531 ...

  8. Linux 基于源码安装 Redis

    1.下载 Redis: 前往 Redis 官网复制 Redis 相应版本的下载链接,到终端下载 2. 进入到指定目录, 下载 redis.tar.gz 包,运行 wget + 复制的下载链接  例如: ...

  9. 一、JDK和JRE

    JDK和JRE JDK=JRE+开发工具包: JRE=JVM+核心类库 如果只是运行Java程序,安装JRE即可:开发Java程序并运行则需要安装JDK.目前最稳定版本是JDK8.0,并且马上部分企业 ...

  10. 通过cpu热插拔解决rcu stall的问题

    在linux 3.10环境一次故障处理中,发现有类似如下打印: NFO: rcu_sched_state detected stalls on CPUs/tasks: {15 } (detected ...