您的位置:首页 > 运维架构 > Linux

CentOS 7 搭建单机版fastdfs(多分组模式)

2020-08-21 21:06 239 查看

环境准备

fastdfs-5.05.tar.gz
fastdfs-nginx-module_v1.16.tar.gz
libfastcommon-1.0.7.tar.gz
nginx-1.12.0.tar.gz

以上tar包上传至 /home/software 目录下

安装c++等一系列运行环境

yum install gcc-c++
# 如果安装过会提示已经安装插件,依次往下无脑安装
yum install pcre pcre-devel
yum install zlib zlib-devel
yum install openssl openssl–devel

安装完后我们先安装 nginx,进入 /home/software 目录

[root@all software]# cd /home/software/

解压nginx-1.12.0.tar.gz

[root@all software]# tar -zxvf nginx-1.12.0.tar.gz

进入源码包编译安装

[root@all software]# cd nginx-1.12.0/
[root@all nginx-1.12.0]# ./configure
[root@all nginx-1.12.0]# make
[root@all nginx-1.12.0]# make install

安装完成之后默认目录会在 /usr/local/nginx 下面,进入目录

[root@all nginx-1.12.0]# cd /usr/local/nginx/

sbin目录为nginx的命令目录,conf是配置文件,html是他的静态页面,logs是运行的日志文件

进入 sbin/ 目录启动 nginx

[root@all nginx]# cd sbin/
[root@all sbin]# ./nginx

启动完毕,在浏览器访问服务器ip地址,看到这个页面就表示nginx安装完毕

开始安装fastDFS

首先安装下环境 yum -y install libevent 确保安装完毕

进入文件目录,解压文件 libfastcommon-1.0.7.tar.gz

[root@all sbin]# cd /home/software/
[root@all software]# tar -zxvf libfastcommon-1.0.7.tar.gz

进入目录编译安装

[root@all software]# cd libfastcommon-1.0.7/
# 编译
[root@all libfastcommon-1.0.7]# ./make.sh
# 安装
[root@all libfastcommon-1.0.7]# ./make.sh install

然后安装Tracker服务,storage服务,进入 /home/software,解压文件 fastdfs-5.05.tar.gz

[root@all libfastcommon-1.0.7]# cd /home/software/
[root@all software]# tar -zxvf fastdfs-5.05.tar.gz

解压成功后进入 fastdfs-5.05/ 目录编译安装

[root@all software]# cd fastdfs-5.05/
# 编译
[root@all fastdfs-5.05]# ./make.sh
# 安装
[root@all fastdfs-5.05]# ./make.sh install

由于安装的文件默认再 /usr/bin 中,配置文件在 /etc/fdfs 中,所以我们将配置文件拷贝到 /etc/fdfs 中
进入 conf/ 目录,拷贝文件到 /etc/fdfs

[root@all fastdfs-5.05]# cd conf/
[root@all conf]# cp * /etc/fdfs/

修改tracker配置文件 vim /etc/fdfs/tracker.conf

# 修改 base_path=/home/yuqing/fastdfs 日志文件存放路径
base_path=/home/fastdfs/tracker

# 修改 http.server_port=8080 端口号
http.server_port=80

:wq保存退出

进入 /home/ 目录下递归创建 tracker 目录,把 storage 和 client 也创建好

# -p 参数会递归创建文件夹
[root@all home]# mkdir fastdfs/tracker -p
[root@all home]# mkdir fastdfs/storage -p
[root@all home]# mkdir fastdfs/client -p

然后可以启动 tracker 服务了

[root@all home]# /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart

检测是否启动成功

[root@all home]# ps aux|grep tracker


安装storage服务

进入 /etc/fdfs/ 目录,拷贝 storage.conf 文件 重命名为 storage1.conf

[root@all ~]# cd /etc/fdfs/
[root@all fdfs]# cp storage.conf storage1.conf

修改 storage1.conf 配置文件

[root@all fdfs]# vim storage1.conf
# 修改 port=23000 端口号
port=23001
# 修改 base_path=/home/yuqing/fastdfs 日志文件存放路径
base_path=/home/fastdfs/storage/group1
# 修改 store_path0=/home/yuqing/fastdfs 资源文件存放路径
store_path0=/home/fastdfs/storage/group1
# 修改 tracker 服务ip地址
# tracker_server=192.168.209.121:22122
# tracker 服务装在哪台服务器就是哪台服务器的ip地址
tracker_server=192.168.50.100:22122

:wq保存退出

进入 /home/fastdfs/storage/ 目录创建分组1目录 group1/

[root@all ~]# cd /home/fastdfs/storage/
[root@all storage]# mkdir group1

启动分组一的 storage 服务

[root@all storage]# /usr/bin/fdfs_storaged /etc/fdfs/storage1.conf restart

检测是否启动成功

[root@all storage]# ps aux|grep storage


然后可以通过 client 进行测试,进入 /etc/fdfs/ 目录,修改配置文件

[root@all storage]# cd /etc/fdfs/
[root@all fdfs]# vim client.conf

修改日志文件的存放路径和 tracker 服务的IP地址

# 修改 base_path=/home/yuqing/fastdfs 日志文件路径
base_path=/home/fastdfs/client
# 修改 tracker_server=192.168.0.197:22122 IP地址

整合Nginx

进入 /home/software/ 目录,解压 fastdfs-nginx-module_v1.16.tar.gz 文件

[root@all fdfs]# cd /home/software/
[root@all software]# tar -zxvf fastdfs-nginx-module_v1.16.tar.gz

解压完成后进入

[root@all software]# cd fastdfs-nginx-module/src/

修改 config 文件

[root@all src]# vim config
ngx_addon_name=ngx_http_fastdfs_module
HTTP_MODULES="$HTTP_MODULES ngx_http_fastdfs_module"
NGX_ADDON_SRCS="$NGX_ADDON_SRCS
$ngx_addon_dir/ngx_http_fastdfs_module.c"
CORE_INCS="$CORE_INCS /usr/include/fastdfs /usr/include/fastcommon/"
CORE_LIBS="$CORE_LIBS -L/usr/lib -lfastcommon -lfdfsclient"
CFLAGS="$CFLAGS -D_FILE_OFFSET_BITS=64 -DFDFS_OUTPUT_CHUNK_SIZE='256*1024' -DFDFS_MOD_CONF_FILENAME='\"/etc/fdfs/mod_fastdfs.conf\"'"
: wq保存退出

进入nginx源代码目录编译安装整合

[root@all src]# cd /home/software/nginx-1.12.0/
# FastDFS 加载模块
./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=/home/software/fastdfs-nginx-module/src

# HTTPS + FastDFS 加载模块
./configure \
--prefix=/usr/local/nginx \
--with-http_realip_module \
--with-http_image_filter_module=dynamic \
--with-http_ssl_module \
--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=/home/software/fastdfs-nginx-module/src

加载完毕编译安装

# 编译
[root@all nginx-1.12.0]# make
# 安装
[root@all nginx-1.12.0]# make install

安装完成进入目录,拷贝 mod_fastdfs.conf 到 /etc/fdfs/ 系统配置文件目录

[root@all nginx-1.12.0]# cd /home/software/fastdfs-nginx-module/src/
[root@all src]# cp mod_fastdfs.conf /etc/fdfs/

修改 mod_fastdfs.conf 配置文件

[root@all src]# vim /etc/fdfs/mod_fastdfs.conf

# 修改 tracker_server=tracker:22122 IP地址
tracker_server=192.168.50.100:22122
# 修改 url_have_group_name = false
url_have_group_name = true
# 修改 store_path0=/home/yuqing/fastdfs 资源文件存放路径

:wq保存退出

进入nginx安装目录,修改nginx配置文件

[root@all src]# cd /usr/local/nginx/conf/
[root@all conf]# vim nginx.conf
server {
listen       80;
server_name  192.168.50.100;

location /group1/M00 {
ngx_fastdfs_module;
}
}

启动nginx

启动报错,说没有这个文件,创建他

[root@all conf]# sudo mkdir -p /var/temp/nginx


启动报错,说没有这个文件,修改nginx配置文件

再次启动成功

通过 FIleZilla 工具上传一张图片上去
浏览器输入 http://192.168.50.100/group1/M00/00/00/3919139cbae96f90ec387d3a7a4ee0b.jpg

nginx报错404的,重启服务器或虚拟机

多分组配置

进入 /etc/fdfs/ 拷贝 storage1.conf 文件(要配置多少组就拷贝多少份文件)
我们只需修改组名称、端口号、日志存放路径和资源存放路径即可

[root@all ~]# cd /etc/fdfs/
[root@all fdfs]# cp storage1.conf storage2.conf
[root@all fdfs]# cp storage1.conf storage3.conf
[root@all fdfs]# cp storage1.conf storage4.conf
[root@all fdfs]# cp storage1.conf storage5.conf
[root@all fdfs]# cp storage1.conf storage6.conf
[root@all fdfs]# cp storage1.conf storage7.conf
[root@all fdfs]# cp storage1.conf storage8.conf
[root@all fdfs]# cp storage1.conf storage9.conf
[root@all fdfs]# cp storage1.conf storage10.conf
...............................................

逐一修改组名称、端口号、日志存放路径和资源存放路径

# 组名称
group_name=group1 ~ group10
# 端口号
port=23002 ~ port=23010
# 日志存放路径
base_path=/home/fastdfs/storage/group2 ~ base_path=/home/fastdfs/storage/group10
# 资源存放路径
store_path0=/home/fastdfs/storage/group2 ~ base_path=/home/fastdfs/storage/group10
# 最下面的 HTTP 服务端口保持一致 80
http.server_port=80

:wq保存退出

其余的 storage.conf 分组文件逐一修改

修改 mod_fastdfs.conf 配置文件,修改组名和组个数配置,多个组名称用 " / " 分隔

[root@all fdfs]# vim mod_fastdfs.conf
# connect_timeout 组个数
# group_name 组名,有多少个写多少个
# group_count 组个数

[group1]
group_name=group1
storage_server_port=23001
store_path_count=1
store_path0=/home/fastdfs/storage/group1

[group2]
group_name=group2
storage_server_port=23002
store_path_count=1
store_path0=/home/fastdfs/storage/group2
........................................
有多少个配置多少个


配置完成后进入 /home/fastdfs/storage/ 创建分组目录

[root@all software]# cd /home/fastdfs/storage/
[root@all storage]# mkdir group2
[root@all storage]# mkdir group3
[root@all storage]# mkdir group4
...............................
有多少组创建多少个

创建完后回到 /etc/fdfs/ 目录启动 storage 服务

[root@all storage]# cd /etc/fdfs/
[root@all fdfs]# /usr/bin/fdfs_storaged /etc/fdfs/storage2.conf restart
[root@all fdfs]# /usr/bin/fdfs_storaged /etc/fdfs/storage3.conf restart
[root@all fdfs]# /usr/bin/fdfs_storaged /etc/fdfs/storage4.conf restart
.................................................
有多少个启动多少个

启动完后进入nginx安装目录,修改配置文件

[root@all conf]# vim /usr/local/nginx/conf/nginx.conf
####################################################
server {
listen       80;
server_name  192.168.50.100;

location ~/group([0-10]|1[0-10])/M00 {
ngx_fastdfs_module;
}
}

启动nginx

[root@all conf]# /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

配置 fastdfs 开机自启,编辑 /etc/rc.d/rc.local 文件

:wq保存退出

给 rc.local 文件增加可执行的权限

[root@all ~]# chmod +x /etc/rc.d/rc.local

END

启动 nginx+fast

/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart
/usr/bin/fdfs_storaged /etc/fdfs/storage.conf restart
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

重载配置文件

cd /usr/local/nginx/sbin/
./nginx -s stop

启动nginx

/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: