fastdfs+nginx 的集群搭建
一、环境部署安排
192.168.230.130 nginx tracker
192.168.230.131 nginx tracker
192.168.230.132 nginx storage1 group1
192.168.230.133 nginx storage2 group1
192.168.230.134 nginx storage3 group2
192.168.230.135 nginx storage4 group2
二、环境搭建前的准备------>【所有的机器都执行】
1.基本部署工具的安装
安装lrzsz:
安装wget:
安装unzip:
安装ifconfig:
安装vim:
yum install lrzsz wget unzip vim net-tools -y
2.安装nginx和fastdfs所需要的的依赖库及组件包
yum -y install cmake bison git ncurses-devel gcc gcc-c++ autoconf automake zlib zlib-devel openssl openssl-devel pcre-devel pcre libevent
3.上传fastdfs需要的软件包
1)上传文件
V1.0.7.tar.gz 和 V5.05.tar.gz这2个包
pwd : ---> /root/
2)解压文件包并进行编译安装依赖包和fastdfs的组件包
cd libfastcommon-1.0.7
./make.sh
./make.sh install
tar -zxvf V5.05.tar.gz
cd fastdfs-5.0
./make.sh
./make.sh install
3)nginx的配置文件的移动
cd fastdfs-5.0/conf
cp http.conf mime.types /etc/fdfs/
三、配置文件并启动
1.修改2个tracker服务器的tracker.conf的配置文件
192.168.230.131
192.168.230.130
1)进入 /etc/fdfs,复制 FastDFS 跟踪器样例配置文件 tracker.conf.sample,并重命名为 tracker.conf
cd /etc/fdfs
cp tracker.conf.sample tracker.conf
2)Tracker 数据和日志目录地址(根目录必须存在,子目录会自动创建)
sed -i 's#/home/yuqing/fastdfs#/home/fastdfs/tracker#g' tracker.conf
3)HTTP 服务端口
sed -i 's#http.server_port=8080#http.server_port=80#g' tracker.conf
4)创建tracker基础数据目录,即base_path对应的目录
mkdir -p /home/fastdfs/tracker
5)启动tracker
/etc/init.d/fdfs_storaged start
2.部署两个组中的4台storage的storage.conf文件
第一个组:
192.168.230.132
192.168.230.133
1)进入 /etc/fdfs 目录,复制 FastDFS 存储器样例配置文件 storage.conf.sample,并重命名为 storage.conf
cd /etc/fdfs
cp storage.conf.sample storage.conf
2)Storage 数据和日志目录地址(根目录必须存在,子目录会自动生成)
sed -i 's#base_path=/home/yuqing/fastdfs#base_path=/home/fastdfs/storage#g' storage.conf
3)Storage 数据和日志目录地址(根目录必须存在,子目录会自动生成)
sed -i 's#store_path0=/home/yuqing/fastdfs#store_path0=/home/fastdfs/file#g' storage.conf
4)访问端口
sed -i 's#http.server_port=8888#http.server_port=80#g' storage.conf
5)编写tracker的地址
vim storage.conf
tracker_server=192.168.230.130:22122
tracker_server=192.168.230.131:22122
group_name=group1
6)创建Storage基础数据目录,对应base_path目录
mkdir -p /home/fastdfs/storage
7)这是配置的store_path0路径
mkdir -p /home/fastdfs/file
第二个组:
192.168.230.134
192.168.230.135
1)进入 /etc/fdfs 目录,复制 FastDFS 存储器样例配置文件 storage.conf.sample,并重命名为 storage.conf
cd /etc/fdfs
cp storage.conf.sample storage.conf
2)Storage 数据和日志目录地址(根目录必须存在,子目录会自动生成)
sed -i 's#base_path=/home/yuqing/fastdfs#base_path=/home/fastdfs/storage#g' storage.conf
3)Storage 数据和日志目录地址(根目录必须存在,子目录会自动生成)
sed -i 's#store_path0=/home/yuqing/fastdfs#store_path0=/home/fastdfs/file#g' storage.conf
4)访问端口
sed -i 's#http.server_port=8888#http.server_port=80#g' storage.conf
5)编写tracker的地址
vim storage.conf
tracker_server=192.168.230.130:22122
tracker_server=192.168.230.131:22122
group_name=group2
6)创建Storage基础数据目录,对应base_path目录
mkdir -p /home/fastdfs/storage
7)这是配置的store_path0路径
mkdir -p /home/fastdfs/file
mkdir /home/fastdfs/client -p
3.安装nginx
192.168.230.130 、192.168.230.131 ---->nginx做为负载均衡的作用
192.168.230.132、192.168.230.133 ----->nginx的扩展模块
192.168.230.134、192.168.230.135 ----->nginx的扩展模块
1)192.168.230.130、192.168.230.131这2台直接上 传nginx 的安装包
pwd : ---> /root/
上传nginx-1.14.2.tar.gz
tar -zxvf nginx-1.14.2.tar.gz
cd nginx-1.14.2
./configure --prefix=/usr/local/nginx_fdfs
make
make install
2)192.168.230.132、192.168.230.133、192.168.230.134、192.168.230.135,这4台上传nginx的扩展模块
pwd : ---> /root/
#下载模块
wget -c https://github.com/happyfish100/fastdfs-nginx-module/archive/5e5f3566bbfa57418b5506aaefbe107a42c9fcb1.zip
# 解压
unzip 5e5f3566bbfa57418b5506aaefbe107a42c9fcb1.zip
# 重命名
mv fastdfs-nginx-module-5e5f3566bbfa57418b5506aaefbe107a42c9fcb1 fastdfs-nginx-module-master
#
cd nginx-1.14.2
./configure --prefix=/usr/local/nginx_fdfs --add-module-/root/fastdfs-nginx-module-master/src
make
make install
4.为这6台机器配置nginx
1)nginx的负载均衡的机器: 192.168.230.130、192.168.230.131
cd /usr/local/nginx_fdfs/conf
vim nginx.conf
添加的内容
upstream fast_group_server{
server 192.168.115.132:80;
server 192.168.115.133:80;
server 192.168.115.134:80;
server 192.168.115.135:80;
}
location ~/group([0-9])/M[0-9] {
proxy_pass http://fastdfs_group_server;
}
启动:
检查语法:/usr/local/nginx_fdfs/sbin/nginx -c /usr/local/nginx_fdfs/conf/nginx.conf -t
/usr/local/nginx_fdfs/sbin/nginx -c /usr/local/nginx_fdfs/conf/nginx.conf
2)nginx扩展模块的配置:192.168.230.132、192.168.230.133、192.168.230.134、192.168.230.135
a.配置nginx的扩展模块192.168.230.132、192.168.230.133、192.168.230.134、192.168.230.135
cd /usr/local/nginx_fdfs/conf
添加一个location对请求进行拦截,配置一个正则规则,拦截fastdfs的文件路径
vim nginx.conf
location ~/group([0-9])/M[0-9] {
ngx_fastdfs_module;
}
b.配置mod_fastdfs.conf:192.168.230.132、192.168.230.133
cd /etc/fdfs
vim mod_fastdfs.conf
base_path=/home/fastdfs/nginx_mod
tracker_server=192.168.230.130:22122
tracker_server=192.168.230.131:22122
group_name=group1
# 如果文件ID的uri中包含/group**,则要设置为true
url_have_group_name = true
# Storage 配置的store_path0路径,必须和storage.conf中的一致
store_path0= /home/fastdfs/file
#组的数量有几个写几
group_count = 2
[group1]
group_name=group1
storage_server_port=23000
storage_path_count=1
storage_path0=/home/fastdfs/file
[group2]
group_name=group2
storage_server_port=23000
storage_path_count=1
storage_path0=/home/fastdfs/file
mkdir /home/fastdfs/nginx_mod
c. 配置mod_fastdfs.conf:192.168.230.134、192.168.230.135
cd /etc/fdfs
vim mod_fastdfs.conf
base_path=/home/fastdfs/nginx_mod
tracker_server=192.168.230.130:22122
tracker_server=192.168.230.131:22122
group_name=group2
# 如果文件ID的uri中包含/group**,则要设置为true
url_have_group_name = true
# Storage 配置的store_path0路径,必须和storage.conf中的一致
store_path0= /home/fastdfs/file
#组的数量有几个写几
group_count = 2
[group1]
group_name=group1
storage_server_port=23000
storage_path_count=1
storage_path0=/home/fastdfs/file
[group2]
group_name=group2
storage_server_port=23000
storage_path_count=1
storage_path0=/home/fastdfs/file
mkdir /home/fastdfs/nginx_mod
d.启动:
检查语法:/usr/local/nginx_fdfs/sbin/nginx -c /usr/local/nginx_fdfs/conf/nginx.conf -t
/usr/local/nginx_fdfs/sbin/nginx -c /usr/local/nginx_fdfs/conf/nginx.conf
5.配置客户访问的一个ip进行访问文件
tar -zxvf nginx-1.14.2.tar.gz
cd nginx-1.14.2
./configure --prefix=/usr/local/nginx_fdfs
make
make install
cd nginx-1.14.2/conf
vim nginx.conf
upstream fast_group_server{
server 192.168.115.130:80;
server 192.168.115.131:80;
}
location ~/group([0-9])/M[0-9] {
proxy_pass http://fastdfs_group_server;
}
d.启动:
检查语法:/usr/local/nginx_fdfs/sbin/nginx -c /usr/local/nginx_fdfs/conf/nginx.conf -t
/usr/local/nginx_fdfs/sbin/nginx -c /usr/local/nginx_fdfs/conf/nginx.conf