目录
一.实验环境
二.集群部署
所有节点安装libfastcommon服务
所有节点安装FasDFS服务
配置storage存储端
在storage存储端安装nginx模块
在storage配置client
三.集群测试(client)
一.实验环境角色 | IP地址 | 安装的软件包 |
tracker(跟踪器) | 192.168.43.101/24 | libfastcommon、fastd |
storage(存储器) | 192.168.43.102/24 | libfastcommon、fastd、nginx、
fastdfs-nginx-module |
hostnamectl set-hostname tracker/storage
su
#关闭防火墙和核心防护
systemctl stop firewalld
setenforce 0
安装环境依赖包
yum -y install libevent libevent-devel perl \
make gcc zlib zlib-devel pcre pcre-devel \
gcc-c++ openssl-devel
安装libfastcommon
wget https://github.com/happyfish100/libfastcommon/archive/V1.0.38.tar.gz
tar zxf V1.0.38.tar.gz -C /opt/
cd /opt/libfastcommon-1.0.38/
编译安装
./make.sh && ./make.sh install
建立软件链接,便于系统识别
ln -s /usr/lib64/libfastcommon.so /usr/local/lib/libfastcommon.so
ln -s /usr/lib64/libfdfsclient.so /usr/local/lib/libfdfsclient.so
ln -s /usr/lib64/libfdfsclient.so /usr/lib/libfdfsclient.so
所有节点安装FasDFS服务
安装fastDFS
wget https://github.com/happyfish100/fastdfs/archive/V5.11.tar.gz
tar zxf V5.11.tar.gz -C /opt/
cd /opt/fastdfs-5.11/
#编译安装
./make.sh && ./make.sh install
复制模板文件
#切换配置文件模板路径
cd /etc/fdfs/
cp tracker.conf.sample tracker.conf //客户端上传配置文件
cp storage.conf.sample storage.conf //文件存储服务器配置文件
cp client.conf.sample client.conf //跟踪服务器配置文件
配置tracker跟踪端
建立数据文件、日志文件存储目录
#-m指定文件权限
[root@tracker ~]# mkdir -m 755 -p /opt/fastdfs
修改tracker的配置文件
[root@tracker ~]# vi /etc/fdfs/tracker.conf
port=22122 //tracker服务默认端口22122即可
base_path=/opt/fastdfs //tracker存储data和log的跟路径,必须提前创建好
http.server_port=8080 //tracker服务器上启动http服务进程
开启服务器并且设置开启自启
[root@tracker ~]# fdfs_trackerd /etc/fdfs/tracker.conf start
[root@tracker ~]# netstat -natp | grep 22122
tcp 0 0 0.0.0.0:22122 0.0.0.0:* LISTEN 2616/fdfs_trackerd
[root@tracker ~]# vi /etc/rc.local
#末行添加
fdfs_trackerd /etc/fdfs/tracker.conf start
配置storage存储端
建立数据、日志文件存储目录
[root@storage ~]# mkdir -m 755 -p /opt/fastdfs
编辑storage配置文件
vim /etc/fdfs/storage.conf
group_name=group1
#默认组名,根据实际情况修改,一个group内可以有多个storage
port=23000
#storge默认23000,同一个组的storage端口号必须一致
base_path=/opt/fastdfs
#storage日志文件的根路径
store_path_count=1
#与下面路径个数相同,默认为1
store_path0=/opt/fastdfs
#提供的存储路径(默认与日志文件存放在一起)
tracker_server=192.168.45.101:22122
#tracker服务器IP
http.server_port=80
#http访问文件的端口默认为8888,nginx中配置的监听端口保持一致
开启服务并且设置开启自启
[root@storage ~]# fdfs_storaged /etc/fdfs/storage.conf start
[root@storage ~]# netstat -atnp | grep 23000
tcp 0 0 0.0.0.0:23000 0.0.0.0:* LISTEN 2468/fdfs_storaged
[root@storage ~]#
检查storage是否与tracker端关联成功
[root@storage ~]# fdfs_monitor /etc/fdfs/storage.conf
[2020-04-22 00:13:31] DEBUG - base_path=/opt/fastdfs, connect_timeout=30, 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
server_count=1, server_index=0
tracker server is 192.168.43.101:22122
group count: 1
Group 1:
group name = group1
disk total space = 10230 MB
disk free space = 5427 MB
trunk free space = 0 MB
storage server count = 1
active server count = 1
storage server port = 23000
storage HTTP port = 80
store path count = 1
subdir count per path = 256
current write server index = 0
current trunk file id = 0
Storage 1:
id = 192.168.43.102
ip_addr = 192.168.43.102 (storage) ACTIVE
http domain =
version = 5.11
join time = 2020-04-21 21:48:49
up time = 2020-04-21 21:48:49
total storage = 10230 MB
free storage = 5427 MB
upload priority = 10
store_path_count = 1
subdir_count_per_path = 256
storage_port = 23000
storage_http_port = 80
current_write_path = 0
source storage id =
if_trunk_server = 0
connection.alloc_count = 256
connection.current_count = 0
connection.max_count = 1
total_upload_count = 2
success_upload_count = 2
total_append_count = 0
success_append_count = 0
total_modify_count = 0
success_modify_count = 0
total_truncate_count = 0
success_truncate_count = 0
total_set_meta_count = 0
success_set_meta_count = 0
total_delete_count = 2
success_delete_count = 2
total_download_count = 0
success_download_count = 0
total_get_meta_count = 0
success_get_meta_count = 0
total_create_link_count = 0
success_create_link_count = 0
total_delete_link_count = 0
success_delete_link_count = 0
total_upload_bytes = 811380
success_upload_bytes = 811380
total_append_bytes = 0
success_append_bytes = 0
total_modify_bytes = 0
success_modify_bytes = 0
stotal_download_bytes = 0
success_download_bytes = 0
total_sync_in_bytes = 0
success_sync_in_bytes = 0
total_sync_out_bytes = 0
success_sync_out_bytes = 0
total_file_open_count = 2
success_file_open_count = 2
total_file_read_count = 0
success_file_read_count = 0
total_file_write_count = 4
success_file_write_count = 4
last_heart_beat_time = 2020-04-22 00:13:27
last_source_update = 2020-04-21 23:13:15
last_sync_update = 1970-01-01 08:00:00
last_synced_timestamp = 1970-01-01 08:00:00
[root@storage ~]#
在storage存储端安装nginx模块
编译安装nginx和fastdfs-nginx-module
[root@storage]# tar zxvf nginx-1.12.0.tar.gz -C /opt
[root@storage]# tar zxvf fastdfs-nginx-module-1.20.tar.gz -C /opt
# 修改/opt/fastdfs-nginx-module-1.20/src/config文件
[root@storage fastDFS]# vim /opt/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/"
#编译安装
cd /opt/nginx-1.12.0/
[root@storage nginx-1.12.0]# ./configure \
--prefix=/usr/local/nginx \
--add-module=/opt/fastdfs-nginx-module-1.20/src/ //添加模块
make && make install
##复制模块
[root@storage nginx-1.12.0]# cd /opt/fastdfs-nginx-module-1.20/src
[root@storage src]# cp mod_fastdfs.conf /etc/fdfs/
#修改fastdfs-nginx-module模块配置文件mod-fasts.conf
[root@storage src]# cd /etc/fdfs/
[root@storage fdfs]# vim mod_fastdfs.conf
#检查一下配置
base_path=/opt/fastdfs //存放数据文件、日志的路径
tracker_server=192.168.45.101:22122 //tracker端的地址和端口
url_have_group_name = true //url是否包含group名称
storage_server_port=23000 //需要和storage配置的相同
store_path_count=1 //存储路径个数,需要和store_path个数匹配
store_path0=/opt/fastdfs //文件存储的位置
#修改nginx配置文件
[root@storage fdfs]# vim /usr/local/nginx/conf/nginx.conf
#server中空行处添加
location ~/M00 {
root /opt/fastdfs/data;
ngx_fastdfs_module;
}
#创建软链接
[root@storage fdfs]# ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/
#检测nginx的配置
[root@storage fdfs]# nginx -t
ngx_http_fastdfs_set pid=5285
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@storage fdfs]# nginx
ngx_http_fastdfs_set pid=5286
[root@storage fdfs]# netstat -natp | grep nginx
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 5287/nginx: master
#拷贝fastdfs解压目录中的http.conf和mime.types不做这步可能会导致报错
[root@storage fdfs]# cd /opt/fastdfs-5.11/conf/
[root@storage conf]# cp mime.types http.conf /etc/fdfs/
在storage配置client
正常集群中我们可以再开一台虚拟机作为client,本实验直接使用storage充当client
vim /etc/fdfs/client.conf
base_path=/opt/fastdfs
#tracker服务器文件路径
tracker_server=192.168.43.101:22122
#tracker服务器IP地址和端口号
http.tracker_server_port=8080
#tracker服务器的http端口号,必须和tracker的设置对应起来
#tracker服务器中的/etc/fdfs/tracker.conf的http.server_port=8080
三.集群测试(client)
上传文件
[root@storage ~]# ls
1.gif anaconda-ks.cfg fastdfs-nginx-module-1.20.tar.gz libfastcommon-1.0.39.tar.gz 公共 视频 文档 音乐
1.jpg fastdfs-5.11.tar.gz initial-setup-ks.cfg nginx-1.12.0.tar.gz 模板 图片 下载 桌面
[root@storage ~]# /usr/bin/fdfs_upload_file /etc/fdfs/client.conf 1.jpg
group1/M00/00/00/wKgrZl6fHp6AEXeNAAB-Lk5Q1rw893.jpg
[root@storage ~]#
测试结果
下载文件
[root@storage ~]# ls
anaconda-ks.cfg fastdfs-nginx-module-1.20.tar.gz libfastcommon-1.0.39.tar.gz 公共 视频 文档 音乐
fastdfs-5.11.tar.gz initial-setup-ks.cfg nginx-1.12.0.tar.gz 模板 图片 下载 桌面
[root@storage ~]# /usr/bin/fdfs_download_file /etc/fdfs/client.conf group1/M00/00/00/wKgrZl6fHp6AEXeNAAB-Lk5Q1rw893.jpg download.jpg
[root@storage ~]# ls
anaconda-ks.cfg fastdfs-5.11.tar.gz initial-setup-ks.cfg nginx-1.12.0.tar.gz 模板 图片 下载 桌面
download.jpg fastdfs-nginx-module-1.20.tar.gz libfastcommon-1.0.39.tar.gz 公共 视频 文档 音乐
[root@storage ~]#
删除文件
[root@storage ~]# /usr/bin/fdfs_delete_file /etc/fdfs/client.conf group1/M00/00/00/wKgrZl6fHp6AEXeNAAB-Lk5Q1rw893.jpg
[root@storage ~]#
作者:Mr.aaa