赞
踩
因为近期公司fastdfs集群要加2个storage节点,部署完成之后正好借这个机会把过程整理一下写一篇教程,本文会写得非常详细堪称保姆级教学。
`
首先,fastdfs有两个重要组成部分tracker和storage,可以部署在同一台服务器上也可以分为多节点部署,具体怎么部署根据实际情况来定,我这里把各个步骤都罗列出来,到时候可以根据情况灵活使用。
部署之前先要准备好安装包,我这里使用的版本是fastdfs-6.06、fastdfs-nginx-module-1.22、nginx-1.16.1、已经上传到csdn了可以直接下载使用,当然用其他的版本也可以。
storage节点执行:
接下来创建storage的base_path路径:
mkdir -p /home/fastdfs/storageg3/base
创建store_path路径,我这里是创建了8个,当然只创建一个也是可以的。
mkdir -p /home/fastdfs/storageg3
mkdir -p /home/source/
cd /home/fastdfs/storageg3
mkdir storage0 storage1 storage2 storage3 storage4 storage5 storage6 storage7
tracker节点执行:
创建tracker的base_path路径:
mkdir -p /home/fastdfs/tracker
因为我的是新机器所以还需要做点准备,更换yum源,安装必备软件,如果你已经做过了可以跳过这一步,但是gcc-c++、pcre-devel、 zlib-devel是必须要安装的,如果没有接下来编译fastdfs就会报错。
tracker和storage都执行:
yum -y install wget
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
yum clean all && yum makecache
yum update -y
yum -y install vim gcc gcc-c++ pcre-devel openssl openssl-devel gcc automake autoconf libtool make unzip
上面的步骤走完之后就把准备好的安装包传到服务器上,并解压到/home/source/。
unzip -d /home/source/ fastdfs-6.06.zip
unzip -d /home/source fastdfs-nginx-module-1.22.zip
unzip -d /home/source libfastcommon-1.0.43.zip
tar -zxf nginx-1.16.1.tar.gz -C /home/source/
现在开始安装,注意需要先安装libfastcommon再安装fastdfs。
tracker和storage都执行:
cd /home/source/libfastcommon-1.0.43
./make.sh
./make.sh install
cd /home/source/fastdfs-6.06
./make.sh clean
./make.sh
./make.sh install
cd /home/source/nginx-1.16.1
./configure --prefix=/usr/local/nginx --with-http_stub_status_module
./configure --add-module=/home/source/fastdfs-nginx-module-1.22/src
make
make install
安装完成之后就是做一些配置了,配置文件在/etc/fdfs目录下,配置文件storage.conf.sample需要把.sample去掉,也可以改成其他名字方便自己区分,特别是需要启动多个storage进程的时候。
storage节点执行:
cd /etc/fdfs
mv storage.conf.sample storageg3.conf
配置文件需要更改的地方主要就是下面几个:
指定你的group名称,配置自己的组名:
vim storageg3.conf
group_name = group3
指定存储数据和日志文件的目录,配置自己的路径:
base_path=/home/fastdfs/storageg/base
指定存储路径数量和具体路径:
store_path_count = 8
store_path0 = /home/fastdfs/storageg3/storage0
store_path1 = /home/fastdfs/storageg3/storage1
store_path2 = /home/fastdfs/storageg3/storage2
store_path3 = /home/fastdfs/storageg3/storage3
store_path4 = /home/fastdfs/storageg3/storage4
store_path5 = /home/fastdfs/storageg3/storage5
store_path6 = /home/fastdfs/storageg3/storage6
store_path7 = /home/fastdfs/storageg3/storage7
指定tracker地址:
tracker_server = 192.168.32.146:22122
我这里改了启动名称和启动的配置文件,如果配置文件没有改名字可以不用做这一步:
cd /etc/init.d/
cp fdfs_storaged fdfs_storaged.backup
vim fdfs_storageg3
PRG=/usr/bin/fdfs_storaged
CONF=/etc/fdfs/storageg3.conf
rhstatus() {
status storageg3
}
chkconfig fdfs_storageg3s2 on
启动命令:
systemctl start fdfs_storageg3s2
没改的话启动命令是:
systemctl start fdfs_storaged
或者:
fdfs_storaged /etc/fdfs/storage.conf start
tracker节点执行:
tracker的base_path路径改为规划的路径,store_group修改为自己的组名:
cd /etc/fdfs
mv tracker.conf.sample tracker.conf
vim tracker.conf
base_path = /home/fastdfs/tracker
store_group = group3
启动命令:
systemctl start fdfs_trackerd
或者:
fdfs_storaged /etc/fdfs/trcker.conf start
这一步完成启动之后就能看到storage连接上了,回到storage节点使用fdfs_monitor /etc/fdfs/storage.conf命令就可以看到返回fastdfs的信息:
fdfs_monitor /etc/fdfs/storage.conf server_count=1, server_index=0 tracker server is 192.168.32.146:22122 group count: 1 Group 1: group name = group3 disk total space = 65,424 MB disk free space = 47,176 MB trunk free space = 0 MB storage server count = 1 active server count = 0 storage server port = 23000 storage HTTP port = 8888 store path count = 8 subdir count per path = 256 current write server index = 0 current trunk file id = 0 Storage 1: id = 192.168.33.13 ip_addr = 192.168.33.13 OFFLINE
上面配置完成后就能够正常使用,但如果需要通过网页访问还需要整合nginx,下面就开始配置吧。
tracker和storage都执行:
把/home/source/fastdfs-nginx-module-1.22/src下的config文件中的/usr/local/include改成/usr/include:
cd /home/source/fastdfs-nginx-module-1.22/src/
vi config
ngx_module_incs="/usr/include"
CORE_INCS="$CORE_INCS /usr/include"
下面就是mod_fastdfs.conf的配置了,需要从/home/source/fastdfs-nginx-module-1.22/src目录复制到/etc/fdfs/下,mod_fastdfs.conf模块的配置需要更改的跟storage.conf一样。
cp mod_fastdfs.conf /etc/fdfs/ cp mod_fastdfs.conf mod_fastdfs.conf.backup ln -s /etc/fdfs/mod_fastdfs.conf mod_fastdfs.conf vim /etc/fdfs/mod_fastdfs.conf base_path=/home/fastdfs/storageg3/base tracker_server=192.168.32.146:22122 group_name=group3 url_have_group_name = true store_path_count=8 store_path0 = /home/fastdfs/storageg3/storage0 store_path1 = /home/fastdfs/storageg3/storage1 store_path2 = /home/fastdfs/storageg3/storage2 store_path3 = /home/fastdfs/storageg3/storage3 store_path4 = /home/fastdfs/storageg3/storage4 store_path5 = /home/fastdfs/storageg3/storage5 store_path6 = /home/fastdfs/storageg3/storage6 store_path7 = /home/fastdfs/storageg3/storage7
nginx的配置文件需要
cd /usr/local/nginx/conf cp mime.types /etc/fdfs/ cp http.conf /etc/fdfs vim nginx.conf server { listen 80; server_name localhost; location ~/group[3]/M[0-9][0-9] { ngx_fastdfs_module; } location / { root html; index index.html index.htm; } vim /usr/lib/systemd/system/nginx.service [Unit] Description=nginx stable last After=syslog.target network.target remote-fs.target nss-lookup.target [Service] Type=forking ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf ExecStop=/usr/local/nginx/sbin/nginx -s stop ExecReload=/usr/local/nginx/sbin/nginx -s reload #ExecQuit=/usr/local/nginx/sbin/nginx -s quit PrivateTmp=true [Install] WantedBy=multi-user.target cd /etc/init.d chkconfig nginx on systemctl status nginx systemctl start nginx systemctl enable nginx
内容完毕,有不明白的可以留言。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。