参考:
https://blog.youkuaiyun.com/u014230881/article/details/78537708
https://blog.youkuaiyun.com/hy245120020/article/details/78658081
1.下载并安装libevent http://libevent.org/
2.下载并安装libfastcommon https://github.com/happyfish100/libfastcommon.git
3.下载并安装fastdfs
https://sourceforge.net/projects/fastdfs/files/FastDFS%20Server%20Source%20Code/FastDFS%20Server%20with%20PHP%20Extension%20Source%20Code%20V5.08/
4.下载安装fastdfs-nginx-module
地址:https://sourceforge.net/projects/fastdfs/files/FastDFS%20Nginx%20Module%20Source%20Code/
5.复制相关文件
mod_fastdfs.conf在下载的fastdfs-nginx-module/src源码中
cp mod_fastdfs.conf /etc/fdfs
文件在解压FastDFS/conf下
cp anti-steal.jpg http.conf mime.types /etc/fdfs
环境:
2台服务器:
192.168.214.128
192.168.214.129
其中tracker server在128服务器上配置
命令参考:
一.安装libevent
解压;tar -zxvf libevent-2.0.22-stable.tar.gz
进入目录;
./configure --prefix=/usr 配置目录
make
make install
验证 ls -al /usr/lib |grep libevent
高版本编译报错时尝试
sudo apt-get install autoconf automake libtool
./autogen.sh
二.安装libfastcommon
unzip libfastcommon-master.zip
cd libfastcommon-master
./make.sh
./make.sh install
三.安装fastdfs
解压 tar -zxvf FastDFS.tar.gz
cd FastDFS
./make.sh
./make.sh install
四.配置 tracker.conf
cd /etc/fdfs/
cp tracker.conf.sample tracker.conf
vi tracker.conf
base_path=/home/ubuntu/fastdfs/tracker #设置 tracker 的数据文件和日志目录(需预先创建) mkdir -p /home/fastdfs/tracker
store_group=group1 #修改组名
五. 配置 storage.conf
cp storage.conf.sample storage.conf
vi storage.conf
group_name=group1 #组名,根据实际情况修改
base_path=/home/ubuntu/fastdfs/storage #设置 storage 的日志目录(需预先创建)mkdir -p /home/fastdfs/storage
store_path_count=1 #存储路径个数,需要和 store_path 个数匹配
store_path0=/home/ubuntu/fastdfs/storage/datas #存储路径(需预先创建)mkdir -p /home/fastdfs/storage/datas
tracker_server=192.168.214.128:22122 #tracker 服务器的 IP 地址和端口号(128和129都配置指向tracker server的 #ip:port(192.168.214.128:22122 )
六.配置 client.conf
cp client.conf.sample client.conf
vi client.conf
base_path=/home/ubuntu/fastdfs/fdfs_client # 日志路径
tracker_server=192.168.214.128:22122 # 追踪服务器的IP,有多个服务器可以另一行
启动
启动 fdfs_trackerd /etc/fdfs/tracker.conf
启动 fdfs_storaged /etc/fdfs/storage.conf
停止
直接kill即可让server进程正常退出,可以使用killall命令,例如:
killall fdfs_trackerd
killall fdfs_storaged
测试:
fdfs_test /etc/fdfs/client.conf upload /home/ubuntu/pic/test.jpg
七:安装fastdfs-nginx-module(安装之前已经安装好nginx)
tar -zxvf fastdfs-nginx-module_v1.16.tar.gz
进入解压目录下src目录,修改config设置,去掉路径中的local
然后进入nginx的源码安装(新增)fastdfs-nginx-module
/nginx/nginx-1.3.12# ./configure --prefix=/usr/local/nginx --add-module=/fastdfs-nginx/fastdfs-nginx-module/src(fastdfs-nginx-module/src所在目录)
八. fastdfs里nginx配置文件
cd /usr/local/src/fastdfs-nginx-module/src
cp mod_fastdfs.conf /etc/fdfs
cd /usr/local/src/FastDFS/conf/
cp anti-steal.jpg http.conf mime.types /etc/fdfs
九. 配置mod_fastdfs.conf
cd /etc/fdfs/
vim mod_fastdfs.conf
base_path=/home/ubuntu/fastdfs/storage #保存日志目录
tracker_server=192.168.214.128:22122 #tracker server
store_path0=/data/ubuntu/fastdfs/storage/datas
十.nginx.conf配置
usr/local/nginx/conf# vim nginx.conf
加入新server(192.168.214.128)
upstream fdfs_group1 {
server 192.168.214.128:8888 weight=1 max_fails=2 fail_timeout=30s;
server 192.168.214.129:8888 weight=1 max_fails=2 fail_timeout=30s;
}
server {
listen 8888;
server_name localhost;
location ~/group[0-9]/M00 {
ngx_fastdfs_module;
}
}
server {
listen 80;
server_name localhost;
location ~/group[0-9]/M00 {
proxy_next_upstream http_502 http_504 error timeout invalid_header;
proxy_pass http://fdfs_group1;
expires 30d;
}
}
192.168.214.129 nginx.conf配置
加入新server
server {
listen 8888;
server_name localhost;
location ~/group[0-9]/M00 {
ngx_fastdfs_module;
}
}
129服务器不用配置tracker server,
同步原理:
同步时由各个storage向tracker发起连接,tracker对各个storage进行分组,当新增storage或storage状态改变时,tracker将同步同组storage
当新增tracker时,再storage向tracker发起连接的时候,发现目标的storage server比本地的资源少,会将自身所在的tracker server上没有的storage同步给目标
fdfs_monitor /etc/fdfs/client.conf
netstat -unltp|grep fdfs