FastDFS 安装及部署
版本说明:
- Centos 7.5
- Nginx-1.15.6
- FastDFS-6.0.6
- FastDFS-module-1.22
- libfastcommon-1.0.43
一、将Centos的iso文件挂载到服务器上,并连接成yum源
cd /etc/yum.repos.d
mkdir bak
mv ./*.repo bak
vi cdrom .repo
- 在vi中写入yum源地址
[cdrom]
name=cdrom
baseurl=file:///mnt
gpgcheck=0
enabled=1
- 挂载iso文件
mount /x/Centos*.iso /mnt
- 清空yum源
yum cleanup
- 加载CenOS中的yum源
yum makecache
二、安装需要的lib
- 安装gcc
yum -y install gcc
- 安装perl
yum -y install perl
- 安装net-tools
yum -y install net-tools
如需要安装nginx则进行下面lib的安装,否则可以跳过
- 安装perl-devel
yum -y install pcre-devel
- 安装zlib-devel
yum -y install zlib-devel
三、安装libfastcommon
1.下载安装包,并解压
wget https://github.com/happyfish100/libfastcommon/archive/V1.0.43.tar.gz
或从互联网下载该包后考入服务器
解压:
tar -zxvf V1.0.43.tar.gz
2.编译安装
1 | cd libfastcommon-1.0.43 |
四、安装FastDFS
- 下载fastdfs V6.0.6
wget https://github.com/happyfish100/fastdfs/archive/V6.06.tar.gz
或将下载好的包考入服务器
- 编译、安装
cd fastdfs-6.0.6
./make.sh && ./make.sh install
- 检验是否安装成功
ls -la /usr/bin/fdfs*
安装成功后的截图
可能会出现的问题:
1 | /root/fastdfs-6.06/storage/fdfs_storaged.c:151: undefined reference to `g_exe_name' |
解决方法:
1 | ./make.sh clean |
五、配置Tracker服务
修改tracker.conf
1
2
3cd /etc/fdfs
cp tracker.conf.sample tracker.conf
vim tracker.conf需要修改tracker.conf的内容为:
base_path=/x/fastdfs/tracker #设置tracker文件存储位置,注意需要提前创建好该目录
port=22122 #tracker 端口
http.server_port=80 #http访问端口
启动tracker(命令支持start|stop|restart)
/user/bin/fdfs_trackerd /etc/fdfs/tracker.conf start
在安装fastdfs的时候会将fdfs的基础命令注册到shell里可以直接调用:
fdfs_trackerd /etc/fdfs/tracker.conf start
- 查看日志
cat /x/fastdfs/tracker/logs/tracker.log
- 查看端口
netstat -apn | grep fdfs
六、配置Storage服务
- 创建storage.conf
1 | cp /etc/fdfs/storage.conf.sample /etc/fdfs/storage.conf |
- 修改storage.conf
base_path=/usr/local/fastdfs/stroage #storage文件路径 需要提前创建路径文件夹
port=23000 #storage端口
group_name=group1 #配置group名
store_path_count=1
store_path0=/usr/local/fastdfs/storage/file # storage存储路径,需提前创建文件夹
tracker_server=192.168.0.1:22122 #配置tracker地址 如有多个tracker就写几个
- 启动storage(命令支持start|stop|restart)
1 | fdfs_storage /etc/fdfs/storage.conf start |
- 查看日志
1 | cat /usr/local/fastdfs/storage/logs/storage.log |
- 查看端口
1 | netstat -apn|grep fdfs |
- 通过monitor查看storage是否与tracker连接成功
[root@FastDFS1 ~]# fdfs_monitor /etc/fdfs/storage.conf
[2020-04-24 12:09:02] DEBUG - base_path=/usr/local/fastdfs/storage, connect_timeout=5, network_timeout=60, tracker_server_count=1, anti_steal_token=0, anti_steal_secret_key length=0, use_connection_pool=1, g_connection_pool_max_idle_time=3600s, use_storage_id=0, storage server id count: 0server_count=1, server_index=0
tracker server is 10.211.55.7:22122
group count: 1
Group 1:
group name = group1
disk total space = 41,947 MB
disk free space = 40,193 MB
trunk free space = 0 MB
storage server count = 2
active server count = 2
storage server port = 23000
storage HTTP port = 8888
store path count = 1
subdir count per path = 256
current write server index = 0
current trunk file id = 0Storage 1:
id = 10.211.55.7
ip_addr = 10.211.55.7 ACTIVE
http domain =
version = 6.06
join time = 2020-04-12 01:54:08
up time = 2020-04-24 12:04:20
total storage = 41,947 MB
free storage = 40,193 MB
upload priority = 10
store_path_count = 1
subdir_count_per_path = 256
storage_port = 23000
storage_http_port = 8888
current_write_path = 0
source storage id =
if_trunk_server = 0
connection.alloc_count = 256
connection.current_count = 1
connection.max_count = 1
total_upload_count = 29
success_upload_count = 29
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 = 0
success_delete_count = 0
total_download_count = 29
success_download_count = 29
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 = 21855103
success_upload_bytes = 21855103
total_append_bytes = 0
success_append_bytes = 0
total_modify_bytes = 0
success_modify_bytes = 0
stotal_download_bytes = 26501695
success_download_bytes = 26501695
total_sync_in_bytes = 19704008
success_sync_in_bytes = 19704008
total_sync_out_bytes = 0
success_sync_out_bytes = 0
total_file_open_count = 84
success_file_open_count = 84
total_file_read_count = 113
success_file_read_count = 113
total_file_write_count = 191
success_file_write_count = 191
last_heart_beat_time = 2020-04-24 12:06:21
last_source_update = 2020-04-23 09:01:43
last_sync_update = 2020-04-22 19:55:17
last_synced_timestamp = 2020-04-22 19:56:15 (0s delay)
七、安装Nginx和fastdfs-nginx-module模块
- 下载安装包,并解压
执行下载命令
wget http://nginx.org/download/nginx-1.16.1.tar.gz
wget https://github.com/happyfish100/fastdfs-nginx-module/archive/V1.22.tar.gz
解压 tar -zxvf nginx-1.16.1.tar.gz
解压 tar -zxvf V1.22.tar.gz
- 编译、安装
依次执行以下命令
1 | ./configure --prefix=/usr/local/nginx --add-module=/root/fastdfs-nginx-module-1.22/src |
注:- -add-module的值为fastdfs-nginx-module的路径
3、启动、验证是否启动成功
查看nginx的安装路径
1 | whereis nginx |
切换到nginx的sbin目录
1 | cd /usr/local/nginx/sbin/ |
启动命令
1 | ./nginx |
停止命令
1 | ./nginx -s quit |
验证启动状态
1 | wget "http://127.0.0.1" |
4、查看fastdfs模块是否安装成功
1 | /usr/local/nginx/sbin/nginx -V |
问题1:
执行wget “http://127.0.0.1"未响应
查看nginx目录下的log文件
解决方案
1 | cp /root/fastdfs-nginx-module-1.22/src/mod_fastdfs.conf /etc/fdfs/ |
修改/etc/fdfs/mod_fastdfs.conf
base_path=/tmp
tracker_server=192.168.0.1:22122
url_have_group_name=true
storage_server_port=23000
store_path_count=1
store_path0=/usr/local/fastdfs/storage/file
注:
base_path 默认为/tmp
tracker_server 为tracker的地址
url_have_group_name url 是否包含group名称
storage_server_port 需要和storage配置的相同
store_path_count 存储路径个数,需要和store_path个数匹配
store_path0 文件存储的位置
八、配置Nginx
切换到nginx目录
1 | cd /usr/local/nginx/conf/ |
编辑nginx.conf文件,增加一个location
location ~/M00{
root /usr/local/fastdfs/storage/file;
ngx_fastdfs_module;
}
九、fastdfs常用命令测试
1、上传文件
(1). 进入/etc/fdfs目录,cp一个client.conf.sample,去掉.sample后缀作为正式文件
(2).修改client.conf配置
base_path=/usr/local/fastdfs/client
tracker_server=192.168.0.1:22122
http.tracker_server_port=80
注:
base_path client的日志文件存储位置
tracker_server tracker的IP和port
http.tracker_server_port tracker服务器的http端口号,必须和tracker的设置对应起来
(3)上传文件
/usr/bin/fdfs_upload_file /etc/fdfs/client.conf a.txt
2、下载文件
/usr/bin/fdfs_download_file /etc/fdfs/client.conf group1/M00/00/00/wKgggF6NiFOAUhYsAAAADwjU0j8530.txt a.txt
3、删除文件
/usr/bin/fdfs_delete_file /etc/fdfs/client.conf group1/M00/00/00/wKgggF6NiFOAUhYsAAAADwjU0j8530.txt