fastDFS安装
(1.)安装必要的工具库
yum install lrzsz -y
yum install wget -y
yum install vim -y
yum instsll unzip -y
yum install net-tools -y
(2.)安装nginx以及fastdfs依赖库
yum install gcc perl openssl openssl-devel pcre pcre-devel zlib zlib-devel libevent libevent-devel
(3.) 安装fastdfs
a.上传fastdfs和libfastcommon安装包,包括:fastdfs-5.11.tar.gz,fastdfs-nginx-module-master.zip,libfastcommon-1.0.36.tar.gz
,并进行解压,安装
b.拷贝fastdfs目录中的http.conf和mime.types到/etc/fdfs目录
(4.)部署两个tracer服务器
a.修改tracker配置文件
vim tracker.conf
base__path=/opt/fastdfs/tracker # tracker的数据目录,需要提前创建
b.启动
fdfs_trackerd /etc/fdfs/tracker.conf
(5.)修改storage配置文件
vim storage.conf
group_name=group1 #组名,如果有两个,group1,group2
base_path=/opt/fastdfs/storage # storage的日志目录,提前创建
store_path0=/opt/fastdfs/storage/files #存储路径 提前创建
tracker_server=192.168.1.135:22122 # tracker的服务器地址和端口
tracker_server=192.168.1.136:22122
启动
fdfs_trackerd /etc/fdfs/tracker.conf
说明:fastdfs默认的负载均衡策略是选择磁盘空间优先存放,可以在tracker.conf中修改store_lookup=1
,0:随机存储策略 1:指定组 2:选择磁盘空间的优先存放 默认值
(6.)安装Nginx,使用nginx对fastdfs进行负载均衡
a.上传nginx-1.12.2.tar.gz和fastdfs-nginx-module-master.zip
b.安装nginx依赖
yum install gcc openssl openssl-devel pcre pcre-devel zlib zlib-devel -y
解压nginx,fastdfs扩展模块
unzip fastdfs-nginx-module-master.zip
tar -zxvf nginx-1.12.2.tar
./configure --prefix=/usr/local/nginx # 两台tracker上执行,不需要fastdfs模块
./configure --prefix=/usr/local/nginx --add-module=/root/fastdfs-nginx-module-master/src # storage上执行,需要fastdfs模块
./make
./make install
---------------------------------------------
# storage的服务器需要拷贝mod_fastdfs文件
cp /root/fastdfs-nginx-module-master/src/mod_fastdfs.conf /etc/fdfs/
(7.)配置tracker服务器上的nginx
cd /opt/local/nginx
vim nginx.conf
location ~/grouop[0-9]/M0[0-9] {
proxy_pass http://fastdfs_group_server
}
upstream fastdfs_group_server {
server 192.168.1.137:80
server 192.168.1.138:80
server 192.168.1.139:80
server 192.168.1.140:80
}
(8.)修改storage服务器的mod_fastdfs.conf文件
vim /etc/fdfs/mod_fastdfs.conf
base_path=/opt/fastdfs/nginx # 日志目录,提前创建
tracker_server=192.168.1.135:22122
tracker_server=192.168.1.136:22122
storage_server_port=23000
group_name=group1
url_have_group_name=true # 访问URL中需要带group
store_path0=/opt/fastdfs/storage/files # 存储路径,提前创建
storage_path_count=1
group_count = 2 # 设置组的个数
[group1]
group_name=group1
storage_server_port=23000
storage_path_count=1
storage_path0=/opt/fastdfs/storage/files
(9.)部署前端用户访问的入口服务器,访问该服务器负载到后端两个tracker上。
vim nginx.conf
location ~/group[1-9]/M)[1-9]{
proxy_pass http://fastdfs_group_server
}
upstream fastdfs_group_server {
server 192.168.1.135:80
server 192.168.1.136:80
}
(10) 关于防火墙的操作
systemctl status firewalld # 查看防火墙状态
systemctl disable firewalld # 禁用防火墙
systemctl stop firewalld # 停止
systemctl start firewalld # 启动