一,查看本地centos的版本
[root@localhost lib]# cat /etc/redhat-release
CentOS Linux release 8.1.1911 (Core)
说明:架构森林是一个专注架构的博客,地址:https://www.cnblogs.com/architectforest
对应的源码可以访问这里获取: https://github.com/liuhongdi/
说明:作者:刘宏缔 邮箱: 371125307@qq.com
二,fastdfs的下载与安装
请参见 centos8安装fastdfs6.06集群方式一之:软件下载与安装
地址: https://www.cnblogs.com/architectforest/p/12388972.html
三,tracker的安装/配置/运行
请参见 centos8安装fastdfs6.06集群方式二之:tracker的安装/配置/运行
地址: https://www.cnblogs.com/architectforest/p/12389095.html
四,四台storage上:生成启动fastdfs默认的配置文件
[root@localhost fastdfs-6.06]# cd /etc/fdfs/
[root@localhost fdfs]# cp storage.conf.sample storage.conf
[root@localhost fdfs]# cp client.conf.sample client.conf
说明:不需要生成tracker.conf,因为storage上不再运行tracker服务
五,四台storage上:安装nginx及fastdfs-nginx-module
1,解压nginx:
[root@localhost source]# tar -zxvf nginx-1.17.8.tar.gz
3,解压fastdfs-nginx-module
[root@localhost source]# tar -zxvf V1.22.tar.gz
4,修改config文件,把/usr/local 替换成 /usr
[root@localhost source]# cd fastdfs-nginx-module-1.22/
[root@localhost fastdfs-nginx-module-1.22]# cd src
[root@localhost src]# vi config
5,nginx配置,添加fastdfs-nginx-module和http_stub_status_module 模块
[root@localhost fdfs]# cd /usr/local/source/nginx-1.17.8/
[root@localhost nginx-1.17.8]# ./configure --prefix=/usr/local/soft/nginx --with-http_stub_status_module --add-module=/usr/local/source/fastdfs-nginx-module-1.22/src/
6,编译安装nginx
[root@localhost nginx-1.17.8]# make && make install
7,检查安装是否成功?
[root@localhost nginx-1.17.8]# ls /usr/local/soft/ | grep nginx
nginx
查看指定的编译参数是否起作用?
[root@localhost fdfs]# /usr/local/soft/nginx/sbin/nginx -V
nginx version: nginx/1.17.8
built by gcc 8.3.1 20190507 (Red Hat 8.3.1-4) (GCC)
configure arguments: --prefix=/usr/local/soft/nginx --with-http_stub_status_module --add-module=/usr/local/source/fastdfs-nginx-module-1.22/src/
六,四台storage上:配置并启动storage服务
1,创建storage服务所需的目录
[root@localhost fdfs]# mkdir /data/fastdfs/storage
[root@localhost fdfs]# chmod 777 /data/fastdfs/storage/
2, 配置storage服务
编辑storage的配置文件:
[root@localhost fdfs]# vi /etc/fdfs/storage.conf
各配置项包括:
group_name = group1
base_path = /data/fastdfs/storage
//配置base_path为上面所创建的storage目录
store_path0 = /data/fastdfs/storage
//上面的store_path :存储所在的目录,可以设置多个,注意从0开始
tracker_server = 172.17.0.2:22122
tracker_server = 172.17.0.3:22122
//上面是tracker_server的ip和端口
http.server_port = 80
//上面是指定http服务的端口
说明://后面是我加的注释,不要写到配置文件中
说明:配置的不同之处:
172.17.0.4 group_name = group1
172.17.0.5 group_name = group1
172.17.0.6 group_name = group2
172.17.0.7 group_name = group2
说明:从上面我们可以看到,storage_server在启动时要注册到tracker_server,
从而实现由tracker_server对其进行调度
3,启动storage服务
[root@localhost fdfs]# /etc/init.d/fdfs_storaged start
正在启动 fdfs_storaged (via systemctl): [ 确定 ]
4,检查storage服务启动是否成功?
[root@localhost fdfs]# ps auxfww | grep fdfs
root 15630 0.0 0.0 12320 972 pts/0 S+ 15:46 0:00 | | \_ grep --color=auto fdfs
root 15026 0.0 0.1 155696 6964 ? Sl 15:13 0:00 /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf
root 15573 2.7 1.7 150736 66292 ? Sl 15:45 0:02 /usr/bin/fdfs_storaged /etc/fdfs/storage.conf
说明:看到fdfs_storaged,表示storage服务启动成功
5,检查storage服务是否已绑定到端口:23000?
[root@localhost fdfs]# netstat -anp | grep 23000
tcp 0 0 0.0.0.0:23000 0.0.0.0:* LISTEN 15573/fdfs_storaged
说明:23000 端口是在配置文件 /etc/fdfs/storage.conf中定义的,如下:
# the storage server port
port = 23000
七,四台存储服务器上:配置fastdfs-nginx-module
1,生成配置文件:
[root@localhost nginx-1.17.8]# cp /usr/local/source/fastdfs-nginx-module-1.22/src/mod_fastdfs.conf /etc/fdfs/
2,编辑配置文件:
[root@localhost nginx-1.17.8]# vi /etc/fdfs/mod_fastdfs.conf
配置以下几项
group_name=group1
connect_timeout=10
tracker_server=172.17.0.2:22122
tracker_server=172.17.0.3:22122
url_have_group_name = true
store_path0=/data/fastdfs/storage
group_count = 2 [group1] group_name=group1
storage_server_port=23000
store_path_count=1
store_path0=/data/fastdfs/storage [group2] group_name=group2
storage_server_port=23000
store_path_count=1
store_path0=/data/fastdfs/storage
说明: 最上面的group_name
当机器属于group1这组时,值为group1
当机器属于group2这组时,值为group2
说明:url_have_group_name = true
这一项不要漏掉,会导至nginx不正常工作
3,复制另两个web访问用到配置文件到fdfs配置目录下:
[root@d5d19e99e782 /]# cp /usr/local/source/fastdfs-6.06/conf/http.conf /etc/fdfs/
[root@d5d19e99e782 /]# cp /usr/local/source/fastdfs-6.06/conf/mime.types /etc/fdfs/
八,四台存储服务器上:配置nginx
编辑nginx的配置文件:
[root@localhost conf]# vi /usr/local/soft/nginx/conf/nginx.conf
在server listen 80 的这个server配置下面,
增加一个location
location ~/group([0-9]) {
root /data/fastdfs/storage/data;
ngx_fastdfs_module; }
九,四台存储服务器上:启动nginx
1,启动
[root@localhost storage]# /usr/local/soft/nginx/sbin/nginx
2,检查nginx是否已成功启动
[root@localhost storage]# ps auxfww | grep nginx
root 24590 0.0 0.0 12320 980 pts/0 S+ 16:44 0:00 | | \_ grep --color=auto nginx
root 24568 0.0 0.0 41044 428 ? Ss 16:44 0:00 \_ nginx: master process /usr/local/soft/nginx/sbin/nginx
nobody 24569 0.0 0.1 74516 4940 ? S 16:44 0:00 \_ nginx: worker process