FastDFS集群部署
一、准备环境
名称 | 链接 | 备注 |
---|---|---|
CentOS7 | 操作系统 | |
libfastcommon | libfastcommon-1.0.39 | FastDFS分离出的C基础库 |
FastDFS | FastDFS-5.11 | FastDFS |
fastdfs-nginx-module | fastdfs-nginx-module-1.20 | FastDFS与Nginx的关联模块 |
Nginx | nginx-1.22.0 | Nginx |
二、服务器配置列表
名称 | IP地址 | 服务名称 | 端口 |
---|---|---|---|
.10服务器 | 192.168.232.10 | ||
libfastcommon | - | ||
tracker | 22122 | ||
storage-group1 | 23000 | ||
storage-group2 | 33000 | ||
fastdfs-nginx-module | - | ||
nginx | 8888 | ||
.20服务器 | 192.168.232.20 | ||
libfastcommon | - | ||
tracker | 22122 | ||
storage-group1 | 23000 | ||
storage-group2 | 33000 | ||
fastdfs-nginx-module | - | ||
nginx | 8888 | ||
.30服务器 | 192.168.232.30 | ||
libfastcommon | - | ||
tracker | 22122 | ||
storage-group1 | 23000 | ||
storage-group2 | 33000 | ||
fastdfs-nginx-module | - | ||
nginx | 8888 |
三、安装编译环境
yum groups install Development Tools –y
yum install perl –y
yum -y install redhat-rpm-config.noarch
yum -y install gd-devel
yum -y install perl-devel perl-ExtUtils-Embed
yum -y install pcre-devel
yum -y install openssl openssl-devel
yum -y install gcc-c++ autoconf automake
yum install -y zlib-devel
yum -y install libxml2 libxml2-dev
yum -y install libxslt-devel
yum -y install GeoIP GeoIP-devel GeoIP-data
yum install gperftools -y
四、安装服务
把下载好的文件分别放入系统中文件夹中(我放在了自己创建的/opt/fastdfs/文件夹下)
安装libfastcommon
解压安装libfastcommon
cd /opt/fastdfs/
tar -zxvf libfastcommon-1.0.39.tar.gz
cd libfastcommon-1.0.39/
./make.sh
./make.sh install
创建软连接
ln -s /usr/lib64/libfastcommon.so /usr/local/lib/libfastcommon.so
ln -s /usr/lib64/libfastcommon.so /usr/lib/libfastcommon.so
#
如果没有libfdfsclient.so可忽略
ln -s /usr/lib64/libfdfsclient.so /usr/local/lib/libfdfsclient.so
ln -s /usr/lib64/libfdfsclient.so /usr/lib/libfdfsclient.so
查看软连接是否创建成功
cd /usr/lib/
ls | grep libfastcommon
ls | grep libfdfsclient
cd /usr/local/lib/
ls | grep libfastcommon
ls | grep libfdfsclient
安装tracker
解压安装fastdfs
cd /opt/fastdfs/
tar -zxvf fastdfs-5.11.tar.gz
cd fastdfs-5.11/
./make.sh
./make.sh install
创建存储日志和数据的根目录
mkdir -p /data/fastdfs/tracker
修改tracker配置文件
cp /etc/fdfs/tracker.conf.sample /etc/fdfs/tracker.conf
vim /etc/fdfs/tracker.conf
# 最大连接数(默认256)
max_connections=1024
# 服务器端口(默认22122)
port=22122
# 存储日志和数据的根目录
base_path=/data/fastdfs/tracker
安装storage
安装tracker时已经解压安装过fastdfs文件了
配置group1、group2
mkdir -p /data/fastdfs/storage/group1
mkdir -p /data/fastdfs/storage/group2
mkdir -p /data/fastdfs/storage/group1/data/data01
mkdir -p /data/fastdfs/storage/group1/data/data02
mkdir -p /data/fastdfs/storage/group1/data/data03
mkdir -p /data/fastdfs/storage/group1/data/data04
mkdir -p /data/fastdfs/storage/group1/data/data05
mkdir -p /data/fastdfs/storage/group1/data/data06
mkdir -p /data/fastdfs/storage/group2/data/data01
mkdir -p /data/fastdfs/storage/group2/data/data02
mkdir -p /data/fastdfs/storage/group2/data/data03
mkdir -p /data/fastdfs/storage/group2/data/data04
mkdir -p /data/fastdfs/storage/group2/data/data05
mkdir -p /data/fastdfs/storage/group2/data/data06
cp /etc/fdfs/storage.conf.sample /etc/fdfs/storage-group1.conf
cp /etc/fdfs/storage.conf.sample /etc/fdfs/storage-group2.conf
修改group1文件
vim /etc/fdfs/storage-group1.conf
group_name=group1
# storage服务端口(默认23000)
port=23000
# 数据和日志文件存储根目录
base_path=/data/fastdfs/storage/group1
# group1的存储目录数量(默认一个,可选配)
store_path_count=6
# group1的存储目录(默认一个,可选配,需与存储目录数量一致)
store_path0=/data/fastdfs/storage/group1/data/data01
store_path1=/data/fastdfs/storage/group1/data/data02
store_path2=/data/fastdfs/storage/group1/data/data03
store_path3=/data/fastdfs/storage/group1/data/data04
store_path4=/data/fastdfs/storage/group1/data/data05
store_path5=/data/fastdfs/storage/group1/data/data06
# tracker的服务器IP和端口
tracker_server=192.168.232.10:22122
tracker_server=192.168.232.20:22122
tracker_server=192.168.232.30:22122
# 访问文件的端口(默认8888,和nginx端口保持一致)
http.server_port=8888
修改group2文件
vim /etc/fdfs/storage-group2.conf
group_name=group2
# storage 服务端口(默认23000,改为33000)
port=33000
# 数据和日志文件存储根目录
base_path=/data/fastdfs/storage/group2
# group2的存储目录数量(默认一个,可选配)
store_path_count=6
# group2的存储目录(默认一个,可选配,需与存储目录数量一致)
store_path0=/data/fastdfs/storage/group2/data/data01
store_path1=/data/fastdfs/storage/group2/data/data02
store_path2=/data/fastdfs/storage/group2/data/data03
store_path3=/data/fastdfs/storage/group2/data/data04
store_path4=/data/fastdfs/storage/group2/data/data05
store_path5=/data/fastdfs/storage/group2/data/data06
# tracker的服务器IP和端口
tracker_server=192.168.232.10:22122
tracker_server=192.168.232.20:22122
tracker_server=192.168.232.30:22122
# 访问文件的端口(默认8888,和nginx端口保持一致)
http.server_port=8888
配置客户端文件(测试用)
mkdir -p /data/fastdfs/client
cp /etc/fdfs/client.conf.sample /etc/fdfs/client.conf
vim /etc/fdfs/client.conf
base_path=/data/fastdfs/client
# tracker服务器IP和端口
tracker_server=192.168.232.10:22122
tracker_server=192.168.232.20:22122
tracker_server=192.168.232.30:22122
安装fastdfs-nginx-module
解压安装fastdfs-nginx-module
cd /opt/fastdfs/
tar -zxvf fastdfs-nginx-module-1.20.tar.gz
修改config文件
vim fastdfs-nginx-module-1.20/src/config
ngx_module_incs="/usr/include/fastdfs /usr/include/fastcommon/"
CORE_INCS="$CORE_INCS /usr/include/fastdfs /usr/include/fastcommon/"
创建并修改mod_fastdfs.conf文件
mkdir -p /data/fastdfs/ngx_mod
cp fastdfs-nginx-module-1.20/src/mod_fastdfs.conf /etc/fdfs/mod_fastdfs.conf
vim /etc/fdfs/mod_fastdfs.conf
connect_timeout=2
network_timeout=30
base_path=/data/fastdfs/ngx_mod
load_fdfs_parameters_from_tracker=true
storage_sync_file_max_delay = 86400
use_storage_id = false
storage_ids_filename = storage_ids.conf
# tracker服务器IP和端口
tracker_server=192.168.232.10:22122
tracker_server=192.168.232.20:22122
tracker_server=192.168.232.30:22122
# 当前本机服务器组全局(当前本机服务器配置多少group写多少group)
group_name=group1/group2
url_have_group_name = true
log_level=info
log_filename=
response_mode=proxy
if_alias_prefix=
flv_support = true
flv_extension = flv
group_count = 2
# group配置(按group顺序配置)
[group1]
group_name=group1
storage_server_port=23000
store_path_count=6
store_path0=/data/fastdfs/storage/group1/data/data01
store_path1=/data/fastdfs/storage/group1/data/data02
store_path2=/data/fastdfs/storage/group1/data/data03
store_path3=/data/fastdfs/storage/group1/data/data04
store_path4=/data/fastdfs/storage/group1/data/data05
store_path5=/data/fastdfs/storage/group1/data/data06
[group2]
group_name=group2
storage_server_port=33000
store_path_count=6
store_path0=/data/fastdfs/storage/group2/data/data01
store_path1=/data/fastdfs/storage/group2/data/data02
store_path2=/data/fastdfs/storage/group2/data/data03
store_path3=/data/fastdfs/storage/group2/data/data04
store_path4=/data/fastdfs/storage/group2/data/data05
store_path5=/data/fastdfs/storage/group2/data/data06
安装nginx
解压安装nginx
cd /opt/fastdfs/
tar -zxvf nginx-1.22.0.tar.gz
cd nginx-1.22.0
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --add-module=/opt/fastdfs/fastdfs-nginx-module-1.20/src
make
make install
配置nginx可以访问到storage服务
cp /opt/fastdfs/fastdfs-5.11/conf/http.conf /etc/fdfs/
cp /opt/fastdfs/fastdfs-5.11/conf/mime.types /etc/fdfs/
配置nginx.config
vim /usr/local/nginx/conf/nginx.conf
server {
listen 8888;
server_name localhost;
location /ok.htm {
return 200 "OK";
}
location ~/group[0-9]/ {
ngx_fastdfs_module;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
启动nginx
#
检查nginx配置
/usr/local/nginx/sbin/nginx -t
#
启动nginx
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
#
查看服务监听情况
netstat -tlunp | grep nginx
启动nginx失败解决方法(没出现下列错误可忽略)
如果出现这个错误:[emerg]: getpwnam(“nginx”) failed,表示没有nginx用户与nginx用户组,因此需要创建
useradd -s /sbin/nologin -M nginx
id nginx
五、防火墙
FastDFS服务端口放行
#
放行tracker
firewall-cmd --zone=public --add-port=22122/tcp --permanent
#
放行storage-group1
firewall-cmd --zone=public --add-port=23000/tcp --permanent
#
放行storage-group2
firewall-cmd --zone=public --add-port=33000/tcp --permanent
#
放行nginx
firewall-cmd --zone=public --add-port=8888/tcp --permanent
#
刷新防火墙规则
firewall-cmd --reload
防火墙相关命令
#
刷新防火墙规则
firewall-cmd --reload
#
查看所有放行的端口
firewall-cmd --zone=public --list-port
六、启动FastDFS文件服务
启动tracker
tracker启动命令
#
启动tracker
/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf start
#
关闭tracker
/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf stop
#
重启tracker
/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart
启动storage
storage-group1启动命令
#
启动
/usr/bin/fdfs_storaged /etc/fdfs/storage-group1.conf start
#
关闭
/usr/bin/fdfs_storaged /etc/fdfs/storage-group1.conf stop
#
重启
/usr/bin/fdfs_storaged /etc/fdfs/storage-group1.conf restart
storage-group2启动命令
#
启动
/usr/bin/fdfs_storaged /etc/fdfs/storage-group2.conf start
#
关闭
/usr/bin/fdfs_storaged /etc/fdfs/storage-group2.conf stop
#
重启
/usr/bin/fdfs_storaged /etc/fdfs/storage-group2.conf restart
查看集群状态
查看集群中各个节点的状态
#
INIT :初始化,尚未得到同步已有数据的源服务器
#
WAIT_SYNC :等待同步,已得到同步已有数据的源服务器
#
SYNCING :同步中
#
DELETED :已删除,该服务器从本组中摘除
#
OFFLINE :离线
#
ONLINE :在线,尚不能提供服务
#
ACTIVE :在线,可以提供服务
fdfs_monitor /etc/fdfs/client.conf
七、配置FastDFS开机重启
配置tracker
创建tracker启动文件
vim /usr/lib/systemd/system/fastdfs-tracker.service
[Unit]
Description=The FastDFS File server
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
ExecStart=/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf start
ExecStop=/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf stop
ExecRestart=/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart
[Install]
WantedBy=multi-user.target
加载并启动
systemctl daemon-reload
systemctl enable fastdfs-tracker.service
systemctl start fastdfs-tracker.service
查看状态和端口是否启动
systemctl status fastdfs-tracker.service
netstat -tulnp|grep 22122
配置storage
创建storage-group1启动文件
vim /usr/lib/systemd/system/fastdfs-storage-group1.service
[Unit]
Description=The FastDFS File server
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
ExecStart=/usr/bin/fdfs_storaged /etc/fdfs/storage-group1.conf start
ExecStop=/usr/bin/fdfs_storaged /etc/fdfs/storage-group1.conf stop
ExecRestart=/usr/bin/fdfs_storaged /etc/fdfs/storage-group1.conf restart
[Install]
WantedBy=multi-user.target
创建storage-group2启动文件
vim /usr/lib/systemd/system/fastdfs-storage-group2.service
[Unit]
Description=The FastDFS File server
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
ExecStart=/usr/bin/fdfs_storaged /etc/fdfs/storage-group2.conf start
ExecStop=/usr/bin/fdfs_storaged /etc/fdfs/storage-group2.conf stop
ExecRestart=/usr/bin/fdfs_storaged /etc/fdfs/storage-group2.conf restart
[Install]
WantedBy=multi-user.target
加载并启动
systemctl daemon-reload
systemctl enable fastdfs-storage-group1.service
systemctl start fastdfs-storage-group1.service
systemctl daemon-reload
systemctl enable fastdfs-storage-group2.service
systemctl start fastdfs-storage-group2.service
查看端口是否启动
netstat -tulnp|grep 23000
netstat -tulnp|grep 33000