CentOS7安装FastDFS

#安装服务器
服务器IP
备注
10.155.31.51
tracker_server
10.155.31.52
storage
# 公共部分
cd /usr/local/src
yum -y install make cmake gcc gcc-c++
#wget https://github.com/happyfish100/libfastcommon/archive/V1.0.7.tar.gz libfastcommon是从 FastDFS 和 FastDHT 中提取出来的公共 C 函数库,基础环境
tar -zxvf V1.0.7.tar.gz
cd libfastcommon-1.0.7/
./make.sh
./make.sh install
ln -s /usr/lib64/libfastcommon.so /usr/local/lib/libfastcommon.so FastDFS主程序设置的lib目录是/usr/local/lib,所以需要创建软链接
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
cd ..
#wget https://github.com/happyfish100/fastdfs/archive/V5.05.tar.gz
tar -zxvf V5.05.tar.gz
cd fastdfs-5.05
./make.sh
./make.sh install
ln -s /usr/bin/fdfs_trackerd /usr/local/bin
#服务脚本内需要用到的命令(或者sed -ri s@/usr/local/bin@/usr/bin@ /etc/init.d/fdfs_storaged 修改两个服务脚本)
ln -s /usr/bin/fdfs_storaged /usr/local/bin
ln -s /usr/bin/stop.sh /usr/local/bin
ln -s /usr/bin/restart.sh /usr/local/bin
配置tracker跟踪器 在tracker机器上执行
cp /etc/fdfs/tracker.conf.sample /etc/fdfs/tracker.conf
vim /etc/fdfs/tracker.conf
store_lookup=2 集群上传文件时(0为轮询1为指定一个固定组2为向组空闲空间大的组上传文件
base_path=/home/iss/fastdfs/tracker 数据和日志目录地址
http.server_port=80
mkdir -pv /home/iss/fastdfs/tracker
systemctl daemon-reload
chkconfig –add fdfs_trackerd
systemctl start fdfs_trackerd
配置storage存储器 在storage机器上执行(我是和tracker机器安装在了一台机器上
cp /etc/fdfs/storage.conf.sample /etc/fdfs/storage.conf
vim /etc/fdfs/storage.conf
group_name=group1 组名,第一组为group1,第二组为group2因为只有两台机所以都是group1组一个组内可以有多个storage
base_path=/home/iss/fastdfs/storage 数据和日志目录地址
store_path0=/home/iss/fastdfs/storage 逐一配置 store_path_count 个路径,索引号基于 0如果不配置 store_path0,那它就和 base_path 对应的路径一样
tracker_server=10.155.31.51:22122 组内的storage会随机选择一个tracker当自己的主,当主tracker挂掉后会提升另外一个为自己的主原本主上线后抢占
http.server_port=80 与nginx整合时需要用到
mkdir -pv /home/iss/fastdfs/storage
systemctl daemon-reload
systemctl start fdfs_storaged 配置文件中定义的tracker必须启动
tail -f /home/iss/fastdfs/storage/logs/storaged.log 查看日志,选择哪个tracker当主以及和组内成员之间的通信信息
/usr/bin/fdfs_monitor /etc/fdfs/storage.conf 查看集群信息
与nginx整合storage节点上执行
wget https://jaist.dl.sourceforge.net/project/fastdfs/FastDFS%20Nginx%20Module%20Source%20Code/fastdfs-nginx-module_v1.16.tar.gz
tar -xvf fastdfs-nginx-module_v1.16.tar.gz 所需要添加的模块
vim fastdfs-nginx-module/src/config
修改第四行为这个
CORE_INCS=$CORE_INCS /usr/include/fastdfs /usr/include/fastcommon/”
yum -y install pcre-devel openssl-devel zlib-devel 编译安装nginx
useradd -r nginx
tar xzvf nginx-1.14.2.tar.gz 安装包在nginx官网下载(放在和上面下载的模块同一目录下
cd nginx-1.14.2/
./configure –prefix=/usr/local/nginx –conf-path=/etc/nginx/nginx.conf –error-log-path=/var/log/nginx/error.log –modules-path=/usr/lib64/nginx/modules –http-log-path=/var/log/nginx/access.log –pid-path=/var/run/nginx.pid –lock-path=/var/run/nginx.lock –user=nginx –group=nginx –with-http_ssl_module –with-http_v2_module –with-http_dav_module –with-http_stub_status_module –with-threads –with-file-aio –add-module=/usr/local/src/fastdfs-nginx-module/src/
make && make install
cp -rf /usr/local/nginx/sbin/nginx /usr/sbin/
cp /usr/local/src/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs/
vim /etc/fdfs/mod_fastdfs.conf
connect_timeout=10 连接超时时间
tracker_server=10.155.31.51:22122
tracker_server=10.155.31.52:22122
url_have_group_name = true 如果文件ID的uri中包含/group**,则要设置为true
store_path0=/home/iss/fastdfs/storage Storage 配置的store_path0路径,必须和storage.conf中的一致
group_name=group1 组名(在同一组内的storage的组名一致
group_count = 1 一共有几个组 (有几个组就写几个比如4台storage两两一组则数字就为2
[group1] 最后一行添加(若有多个组则添加多个
group_name=group1
storage_server_port=2300
store_path_count=1
store_path0=/home/iss/fastdfs/storage
cp /usr/local/src/fastdfs-5.05/conf/{http.conf,mime.types} /etc/fdfs/
ln -s /home/iss/fastdfs/storage/data/ /home/iss/fastdfs/storage/data/M00
vim /etc/nginx/nginx.conf listen 80 端口值是要与 /etc/fdfs/storage.conf 中的 http.server_port=80 (前面改成80了)相对应
location ~/group([0-9])/M00 {
ngx_fastdfs_module;
}
vim /usr/lib/systemd/system/nginx.service nginx启动服务配置
[Unit]
Description=The nginx HTTP and reverse proxy server
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/run/nginx.pid
ExecStartPre=/usr/bin/rm -f /run/nginx.pid
ExecStartPre=/usr/sbin/nginx -t
ExecStart=/usr/sbin/nginx
ExecReload=/bin/kill -s HUP $MAINPID
KillSignal=SIGQUIT
TimeoutStopSec=5
KillMode=process
PrivateTmp=true
[Install]
WantedBy=multi-user.target
systemctl daemon-reload
systemctl start nginx
测试上传文件以及访问在任意一个tracker端进行
cp /etc/fdfs/client.conf.sample /etc/fdfs/client.conf
vim /etc/fdfs/client.conf
base_path=/home/iss/fastdfs/client
tracker_server=10.155.31.51:22122
tracker_server=10.155.31.52:22122
mkdir -pv /home/iss/fastdfs/client
fdfs_upload_file /etc/fdfs/client.conf /root/653798961.jpg 命令+配置文件路径+上传的文件所在的路径
group1/M00/00/00/wKiDnV0AeCKAIKQ6AAAHq8MyJVo908.jpg 在同一group的storage节点的/fastdfs/storage/data/00/00/wKiDnV0AeCKAIKQ6AAAHq8MyJVo908.jpg 内
返回的文件ID由group存储目录两级子目录fileid文件后缀名由客户端指定主要用于区分文件类型拼接而成可在存储节点上查看
与nginx整合后在网页上可通过该storage节点的ip+路径访问
# 本文参考:https://www.cnblogs.com/zengpeng/p/11161159.html