FastDFS Install & Configuration
FastDFS Install & Configuration
1. Environment
作者的GitHub地址:https://github.com/happyfish100(本次所需的工具大部分都可以找到)
所需要的工具
fastdfs-6.06.tar.gz
fastdfs-nginx-module-1.22.tar.gz
libfastcommon-1.0.43.tar.gz
2. Install FastDFS
-
安装工具
yum -y install zlib zlib-devel pcre pcre-devel gcc gcc-c++ openssl openssl-devel libevent libevent-devel perl unzip net-tools wget
-
安装rz命令
yum install lrzsz -y
-
将安装包通过SFTP上传至Centos7 服务器中指定目录,这里放在/opt目录下
cd /opt ls -l
-
创建安装目录
mkdir -pv /home/libfastcommon
-
将libfastcommon解压至安装目录
tar -zxvf libfastcommon-1.0.43.tar.gz -C /home/libfastcommon cd /home/libfastcommon/libfastcommon-1.0.43 ./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 ln -s /usr/lib64/libfdfsclient.so /usr/local/lib/libfdfsclient.so ln -s /usr/lib64/libfdfsclient.so /usr/lib/libfdfsclient.so
-
创建安装目录
mkdir -pv /home/fastdfs
-
将fastdfs解压至安装目录
cd tar -zxvf /opt/fastdfs-6.06.tar.gz -C /home/fastdfs cd /home/fastdfs/fastdfs-6.06 ./make.sh ./make.sh install
-
FastDFS安装成功,查看安装目录
cd /etc/fdfs/ ll
-
备份实例文件
cd /etc/fdfs/ cp client.conf.sample client.conf cp storage.conf.sample storage.conf cp tracker.conf.sample tracker.conf
3. Install tracker
-
为tracker创建工作目录
mkdir -pv /home/aeuportal/fastdfs
-
配置tracker
cd /etc/fdfs/ ll vim /etc/fdfs/tracker.conf
-
修改tracker配置文件,并保存
disabled=false # tracker服务器端口(默认22122,一般不修改) port=22122 # 存储日志和数据的根目录 刚刚创建的tracker工作目录 base_path=/home/aeuportal/fastdfs
-
启动tracker
systemctl start fdfs_trackerd systemctl enable fdfs_trackerd systemctl status fdfs_trackerd systemctl stop fdfs_trackerd
-
查看tracker的data和log
cd /home/aeuportal/fastdfs ll tail -f /home/aeuportal/fastdfs/logs/trackerd.log
-
查看tracker端口
netstat -lnptu | grep fdfs
4. Install storage
-
为storage创建工作目录
mkdir -pv /home/fastdfs_storaged/ mkdir -pv /home/fastdfs_storaged_data/
-
配置storage
cd /etc/fdfs/ ll vim /etc/fdfs/storage.conf
-
修改storage配置文件,并保存
disabled=false # 组名,根据实际情况修改 group_name=group1 # storage服务端口(默认23000,一般不修改) port=23000 # 数据和日志文件存储根目录 刚刚创建的tracker工作目录 base_path=/home/aeuportal/fastdfs # 设置storage的端口号,默认是23000,同一个组的storage端口号必须一致 http.server_port=23000 # 存储路径个数,需要和store_path个数匹配 store_path_count=1 # 第一个存储目录 store_path0=/home/aeuportal/fastdfs # tracker服务器IP和端口 tracker_server=<HOST>:22122 # http访问文件的端口(默认8888,看情况修改,和nginx中保持一致) http.server_port=80
-
创建软链接
ln -s /usr/bin/fdfs_storaged /usr/local/bin
-
启动storage
systemctl start fdfs_storaged systemctl enable fdfs_storaged systemctl status fdfs_storaged systemctl stop fdfs_storaged
-
查看storage的data和log
cd /home/fastdfs_storaged/ ll tail -f /home/aeuportal/fastdfs/logs/storaged.log
-
查看storage端口
netstat -lnptu | grep fdfs
-
确认storage是否注册到了tracker中去
/usr/bin/fdfs_monitor /etc/fdfs/storage.conf
-
成功后可以看到:
ip_addr = <HOST> ACTIVE 的字样
-
删除group
/usr/bin/fdfs_monitor /etc/fdfs/storage.conf delete <groupname> <storageid>
5. 配置客户端
-
为client创建工作目录
mkdir -pv /home/fastdfs_client
-
配置client
cd /etc/fdfs/ ll vim /etc/fdfs/client.conf
-
修改client配置文件,并保存
base_path=/home/fastdfs_client #tracker服务器文件路径 tracker_server=<HOST>:22122 #tracker服务器IP地址和端口号 http.tracker_server_port=22088 # tracker 服务器的 http端口号,必须和tracker的设置对应起来
6. 为nginx安装fastdfs-nginx-module
-
进入目录
cd /usr/local/nginx/nginx-1.18.0
-
将fastdfs-nginx-module解压至nginx安装目录
tar -zxvf /opt/fastdfs-nginx-module-1.22.tar.gz -C /usr/local/nginx/nginx-1.18.0
-
查看nginx原有的模块
/usr/local/nginx/sbin/nginx -V
-
执行编译安装命令
./configure --prefix=/usr/local/nginx --add-module=/usr/local/nginx/nginx-1.18.0/fastdfs-nginx-module-1.22/src
-
配置完成后,运行命令
make make install
-
将刚刚编译好的nginx覆盖掉原有的nginx(这个时候nginx要停止状态)
cp ./objs/nginx /usr/local/nginx/sbin/
-
启动nginx,仍可以通过命令查看是否已经加入成功
systemctl start nginx systemctl stop nginx /usr/local/nginx/sbin/nginx -V
6. 配置fastdfs-nginx-module
-
为fastdfs-nginx-module创建工作目录
mkdir -pv /home/aeuportal/fastdfs_nginx_module/
-
把
fastdfs-nginx-module
安装目录中src
目录下的mod_fastdfs.conf
也拷贝到/usr/local/nginx/nginx-1.18.0/conf
目录下cp /usr/local/nginx/nginx-1.18.0/fastdfs-nginx-module-1.22/src/mod_fastdfs.conf /etc/fdfs
-
修改
mod_fastdfs.conf
配置文件,并保存vim /etc/fdfs/mod_fastdfs.conf
# 保存日志目录 base_path=/home/fastdfs_storaged/ # tracker服务器IP和端口 tracker_server=<HOST>:22122 # storage服务器的端口号 port=22122 # 文件url中是否有group名 url_have_group_name=true # 第一个存储目录 store_path0=/home/fastdfs_storage_data # 设置组的个数,事实上这次只使用了 group_count=1
-
创建M00至storage存储目录的符号链接
ln -s /home/fastdfs_storage_data/data /home/fastdfs_storage_data/data/M00
-
进入FastDFS安装时的解压过的目录
/home/fastdfs/fastdfs-6.06/conf
,将http.conf
和mime.types
拷贝到/etc/fdfs
目录下cd /home/fastdfs/fastdfs-6.06/conf ls cp /home/fastdfs/fastdfs-6.06/conf/http.conf /etc/fdfs/ cp /home/fastdfs/fastdfs-6.06/conf/mime.types /etc/fdfs/
-
创建M00至storage存储目录的符号连接
ln -s /home/fastdfs_storage_data/data/ /home/fastdfs_storage_data/data/M00
-
配置nginx
server { listen 80; server_name localhost; location ~/group[0-9]/ { ngx_fastdfs_module; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } }
-
查看nginx日志
tail -f /usr/local/nginx/logs/error.log
7. Configuration 防火墙
-
查使用端口 23000
netstat -lnpt
-
开放端口,这里使用 23000端口
firewall-cmd --permanent --zone=public --add-port=22122/tcp firewall-cmd --permanent --zone=public --add-port=23000/tcp firewall-cmd --permanent --zone=public --add-port=80/tcp firewall-cmd --permanent --zone=public --add-port=81/tcp
-
重启防火墙
firewall-cmd --reload
-
查看防火墙,已开放端口列表
firewall-cmd --list-ports