同学们很多和我反馈,现在在找工作的时候好多企业要求会懂fastdfs的内容,并且熟悉部署及相关错误拍错的技能,这里就总结下之前在项目上部署的fastdfs的搭建步骤,供大家学习参考。
文章目录
1. FastDFS集群运行环境
1.1 集群架构
本文档部署的FastDFS集群包含3台机器,一台为trackerServer,其余两台为storageServer。FastDFS集群架构如下图所示(IP地址根据实际情况进行修改),请注意fastdfs的奇偶内容!!!。
简单描述机构图:
1.1.1环境介绍:
操作系统版本 | centos6.5 |
---|---|
common版本 | 1.0.7 |
fastdfs版本 | 5.05 |
依赖包内容 | zlib、zlib-devel、pcre、pcre-devel、gcc、gcc-c++、openssl 、openssl-devel 、libevent、 libevent-devel 、perl、 unzip |
1.1.2 安装libfastcommon-1.0.7
下载地址
https://github.com/happyfish100/libfastcommon/archive/V1.0.7.zip
安装
[root@fastdfs shell]#
yum install zlib zlib-devel pcre pcre-devel gcc gcc-c++ openssl openssl-devel libevent libevent-devel perl unzip
unzip V1.0.7.zip
[root@fastdfs shell]#
cd libfastcommon-1.0.7
[root@fastdfs shell]#
./make.sh
[root@fastdfs shell]#
./make.sh install
上述操作安装完毕后的路径在/usr/lib64/,但是FastDFS主程序设置的lib目录是/usr/local/lib,所以需要创建软连接如下
[root@fastdfs shell]#
ln -s /usr/lib64/libfastcommon.so /usr/local/lib/libfastcommon.so
[root@fastdfs shell]#
ln -s /usr/lib64/libfastcommon.so /usr/lib/libfastcommon.so
[root@fastdfs shell]#
ln -s /usr/lib64/libfdfsclient.so /usr/local/lib/libfdfsclient.so
[root@fastdfs shell]#
ln -s /usr/lib64/libfdfsclient.so /usr/lib/libfdfsclient.so
1.1.3 安装fastdfs-5.05
下载地址
https://github.com/happyfish100/fastdfs/archive/V5.05.zip
安装
[root@fastdfs shell]#
unzip V5.05.zip
[root@fastdfs shell]#
cd fastdfs-5.05/
[root@fastdfs shell]#
./make.sh
[root@fastdfs shell]#
./make.sh install
1.2 配置trackerServer
IP地址:192.168.1.206
1.2.1 创建tracker的数据文件和日志目录
[root@fastdfs shell]#
mkdir -p /fdfs/tracker
1.2.2 拷贝配置文件
[root@fastdfs shell]#
cd /etc/fdfs
[root@fastdfs shell]#
cp tracker.conf.sample tracker.conf
1.2.3 编辑配置文件
[root@fastdfs shell]#
vi tracker.conf
disabled=false #启用配置文件
port=22122 #设置tracker的端口号,一般采用22122这个默认端口
base_path=/fdfs/tracker #设置tracker的数据文件和日志目录(预先创建)
http.server_port=8080 #设置http端口号注意,这个配置在fastdfs5.05这个版本中已经不用配置!
1.2.4 启动tracker
[root@fastdfs shell]#
fdfs_trackerd /etc/fdfs/tracker.conf restart
1.2.5 查看启动情况
[root@fastdfs shell]#
netstat -unltp|grep fdfs
1.2.6 查看日志
[root@fastdfs shell]#
cat /fdfs/tracker/logs/trackerd.log
1.2.7 设置开机自启动
[root@fastdfs shell]#
vi /etc/rc.d/rc.local
#增加:
fdfs_trackerd /etc/fdfs/tracker.conf restart
至此,trackerServer安装并检测完成。
1.3 配置storageServer
IP地址:192.168.1.208、192.168.1.209
以192.168.1.208机器安装为例,其余机器安装过程重复以下步骤即可。
1.3.1 创建storage的数据文件和日志目录
mkdir -p /fdfs/storage
1.3.2 拷贝配置文件
cd /etc/fdfs
cp storage.conf.sample storage.conf
1.3.3 编辑配置文件
vi storage.conf
disabled=false #启用配置文件
group_name=group1 #组名,根据实际情况修改
port=23000 #设置storage的端口号,默认是23000,同一个组的storage端口号必须一致
base_path=/fdfs/storage #设置storage的日志目录(需预先创建)
store_path_count=1 #存储路径个数,需要和store_path个数匹配
store_path0=/fdfs/storage #存储路径(需要预先创建)
tracker_server=172.17.186.206:22122 #tracker服务器的IP地址和端口号
http.server_port=8080 #设置http端口号 注意,这个配置在fastdfs5.05这个版本中已经不用配置!
1.3.4 启动storage
fdfs_storaged /etc/fdfs/storage.conf restart
1.3.5 查看启动情况
netstat -unltp|grep fdfs
1.3.6 查看日志
cat /fdfs/storage/logs/storaged.log
1.3.7 设置开机自启动
vi /etc/rc.d/rc.local
#增加:
fdfs_storaged /etc/fdfs/storage.conf restart
至此,storageServer安装完成。
1.4 查看storage登记状态
登录任意一台storageServer,在此以服务器192.168.1.208为例。
运行fdfs_monitor查看storage服务器是否已经登记到tracker服务器。
fdfs_monitor /etc/fdfs/storage.conf
看到“192.168.1.208 ACTIVE”、“192.168.1.209 ACTIVE“即可确认storage运行正常。
1.5 验证文件传输
1.5.1 拷贝Tracker服务器中的客户端配置文件
所有需要进行验证的群组内的机器均要进行如下操作:
[root@fastdfs shell]# cd /etc/fdfs
[root@fastdfs shell]# cp client.conf.sample client.conf
1.5.2 编辑配置文件
vi client.conf
base_path=/tmp #设置client的日志目录(需预先创建)
tracker_server=192.168.1.206:22122 #tracker服务器的IP地址和端口号
1.5.3 执行上传命令
fdfs_upload_file /etc/fdfs/client.conf fastdfs-5.05.zip
返回ID号,证明文件上传成功
group0/M00/00/00/rBG61VjJ6imAaA_bAAZ6ZSv5MEk.05.zip
1.5.4 执行下载命令
创建文件
touch /tmp/fastdfs-5.05.zip
此时文件大小为0
执行下载
fdfs_download_file /etc/fdfs/client.conf group0/M00/00/00/rBG61VjJ6imAaA_bAAZ6ZSv5MEk.05.zip /tmp/fastdfs-5.05.zip
此时文件大小为上传文件的大小。读取文件内容,判断下载成功。
查看文件信息
1.6 编辑trackerServer、storageServer启动脚本
1.6.1 在206服务器上编辑trackerServer启动、停止脚本
个人习惯,所有启动脚本都编写在/shells下,所以使用请自行确定。
mkdir /shells
cd /shells
编辑启动脚本:
vi start_fdfstrack.sh
#输入如下命令:
fdfs_trackerd /etc/fdfs/tracker.conf start
#保存文件并退出,给脚本可执行权限:
chmod 755 start_fdfstrack.sh
编辑停止脚本:
vi stop_fdfstrack.sh
#输入如下命令:
fdfs_trackerd /etc/fdfs/tracker.conf stop
保存文件并退出,给脚本可执行权限:
chmod 755 stop_fdfstrack.sh
1.6.2 在208、209服务器上编辑storageServer启动、停止脚本
cd /shells
编辑启动脚本:
vi start_fdfstorage.sh
#输入如下命令内容:
fdfs_storaged /etc/fdfs/storage.conf start
保存文件并退出,给脚本可执行权限:
chmod 755 start_fdfstorage.sh
编辑停止脚本:
vi stop_fdfstorage.sh
输入如下命令:
fdfs_storaged /etc/fdfs/storage.conf stop
保存文件并退出,给脚本可执行权限:
chmod 755 stop_fdfstorage.sh
好的。fastdfs搭建就到此结束了,大家在搭建的时候可以参考下,很简单的内容,我为了方便启停服务在这里编写了启停脚本。
欢迎喜欢实施运维的小伙伴加入群进行谈论!
运维技术群:263859509