1、环境介绍:虚拟机A(tracker服务1 + nginx负载均衡 + keepalived双活)
虚拟机B(tracker服务2 + nginx负载均衡 + keepalived双活)
虚拟机C(storage服务1 + nginx http服务)
虚拟机D(storage服务2 + nginx http服务)
虚拟机E(storage服务3 + nginx http服务)
虚拟机F(storage服务4 + nginx http服务)
2、搭建FastDFS集群:将需要的安装包都拷贝到/usr/local/software文件夹
给虚拟机A和虚拟机B安装tracker服务(安装前置环境、安装libfastcommon-master、安装FastDFS-tracker)
给虚拟机C、D、E、F分别安装storage服务(差异、查看启动日志)
给虚拟机C、D、E、F分别安装nginx提供HTTP服务(安装nginx插件fastdfs-nginx-module、安装nginx)
3、安装分布式文件系统客户端FastDFS-client(任选一台tracker服务器搭建client)
注释:安装前置环境 - (1) 安装libfastcommon-master - (2) 安装FastDFS-tracker - (3)
差异 - (4) 查看启动日志 - (5)
安装nginx插件fastdfs-nginx-module - (6) 安装nginx - (7)
任选一台tracker服务器搭建client - (8)
(1)(安装前置环境)安装gcc 命令是:yum -y install gcc-c++ 安装libevent,命令是:yum -y install libevent
。
(2)(安装libfastcommon-master )解压:[root@localhost software]# tar -zxf libfastcommonV1.0.7.tar.gz 编译:命令:./make.sh 安装:命令:./make.sh instal
创建软链接:命令:ln -s /usr/lib64/libfastcommon.so /usr/lib/libfastcommom.so
。
(3)(安装FastDFS-tracker)解压:tar -zxf FastDFS_v5.05.tar,gz 编译:命令:先进入安装路径,cd FastDFS ,再进行编译:./make.sh 安装:命令:./make.sh install
将安装目录下的conf下的文件拷贝到/etc/fdfs下:cd FastDFS 、 cd conf 、 cp * /etc/fdfs 修改服务启动文件:vim /etc/init.d/fdfs_trackerd
执行命令,将local/ 替换成空 命令::%s/local\///g 也可以手动把local删掉 修改tracker配置文件: vim /etc/fdfs/tracker.conf
修改的内容:base_path=/usr/local/software/FastDFS/tracker store_lookup=0 看不懂可以看接下来的代码:
base_path=/usr/local/software/FastDFS/tracker
# the method of selecting group to upload files
# 0: round robin
# 1: specify group
# 2: load balance, select the max free space group to upload file
#0 - 轮询 1 - 指定组 2 - 负载均衡, 设置为0便于测试,工作环境应该设置为2
store_lookup=0
(4)(差异)修改服务启动文件:vim /etc/init.d/fdfs_storaged 执行命令,将local/ 替换成空 命令::%s/local\///g 也可以手动把local删掉
[root@localhost fdfs]# vim /etc fs/storage.conf
修改的内容:
#指定该storage所在的组名,另外E、F两个虚拟机应该设置为group2组
group_name=group1
# the base path to store data and log files
base_path=/usr/local/software/FastDFS/storage
# the paths must be exist
store_path0=/usr/local/software/FastDFS/storage
# tracker_server can ocur more than once, and tracker_server format is
# "host:port", host can be hostname or ip address
tracker_server= 192.168.101.137:22122
tracker_server= 192.168.101.138:22122
vim /etc/sysconfig/
加入:
-A INPUT -m state --state NEW -m tcp -p tcp --dport 23000 -j ACCEPT
重启防火墙:
service iptables restart
。
(5)(查看启动日志)/usr/local/software/FastDFS/storage/logs/storaged.log
。
(6)(安装nginx插件fastdfs-nginx-module) 解压:tar -zxf fastdfs-nginx-module_v1.16.tar.gz 修改配置文件: cd /usr/local/software/fastdfs-nginx-module/src
vim config 执行命令,将local/ 替换成空 命令::%s/local\///g 也可以手动把local删掉 复制配置文件:cp mod_fastdfs.conf /etc/fdfs
tracker_server= 192.168.101.137:22122
tracker_server= 192.168.101.138:22122
# 设置组名称,默认为group1,第二组的服务需要设置为group2
group_name=group1
#显示组名称
url_have_group_name=true
#
store_path0=/usr/local/software/FastDFS/storage
# 设置组的数量
group_count = 2
#添加组信息
[group1]
group_name=group1
storage_server_port=23000
store_path_count=1
store_path0=/usr/local/software/FastDFS/storage
[group2]
group_name=group2
storage_server_port=23000
store_path_count=1
store_path0=/usr/local/software/FastDFS/storage
。
(7)(安装nginx) 前置环境:安装gcc,命令:yum install -y gcc-c++ 安装pcre,命令:yum install -y pcre pcre-devel
安装zlib,命令:yum install -y zlib zlib-devel 安装openssl,命令:yum install -y openssl openssl-devel
安装nginx:安装包拷贝,将安装包放在/usr/local路径下。 解压:tar -zxf nginx-1.8.1.tar.gz 进入安装目录:cd nginx-1.8.1
创建软链接:ln -s /usr/lib64/libfdfsclient.so /usr/lib/libfdfsclient.so
配置:./configure --add-module=/usr/local/software/fastdfs-nginx-module/src
编译:make 安装:make install
配置nginx:vim /usr/local/nginx/conf/nginx.conf
location ~/group([0-9])/M00 {
ngx_fastdfs_module;
}
nobody 12101 0.0 0.0 5544 992 ? S 12:11 0:00 nginx: worker process
。
(8)(任选一台tracker服务器搭建client ) 修改配置文件:vim /etc/fdfs/client.conf
base_path=/usr/local/software/FastDFS/tracker
tracker_server=192.168.233.132:22122
tracker_server=192.168.233.133:22122
。