企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
[TOC] ## 1. FastDFS安装(ubuntu) 需要准备: nginx、fastdfs、libfastcommon、gcc、git ~~~ apt-get update apt-get -y install make gcc git ~~~ ### 1.1 下载安装libfastcommon(项目通用函数库) 1)git克隆 ~~~ git clone https://github.com/happyfish100/libfastcommon.git ~~~ 2)编译安装 ~~~ cd libfastcommon/ ./make.sh ./make.sh install ~~~ ### 1.2 安装FastDFS 1)编译安装FastDFS ~~~ git clone https://github.com/happyfish100/fastdfs.git cd fastdfs ./make.sh ./make.sh install ~~~ 服务脚本在: ~~~ /etc/init.d/fdfs_storaged /etc/init.d/fdfs_trackerd ~~~ #### 1.2.1 配置tracker 1. 修改Tracker配置文件 ~~~ cp /etc/fdfs/tracker.conf.sample /etc/fdfs/tracker.conf vim /etc/fdfs/tracker.conf ~~~ 做以下配置 ~~~ bind_addr=192.168.56.10 # 所在服务器IP地址 base_path=/data/fastdfs/tracker ~~~ 2. 创建对应的数据存储目录 ~~~ mkdir -p /data/fastdfs/tracker ~~~ 3. 启动Tracker ~~~ mv /etc/init.d/fdfs_trackerd /etc/init.d/tracker service tracker start ~~~ 4. 查看tracker是否启动 ~~~ ps -ef |grep fdfs ~~~ ![](https://box.kancloud.cn/8675a229b2c2eedff31238621b5d0d4a_1145x90.png) #### 1.2.2 配置storage 1. 修改Storage配置文件 ~~~ cp /etc/fdfs/storage.conf.sample /etc/fdfs/storage.conf vim /etc/fdfs/storage.conf ~~~ 修改以下配置 ~~~ group_name=group1 bind_addr=192.168.56.10 # 所在服务器IP地址 base_path=/data/fastdfs/storage store_path0=/data/fastdfs/storage tracker_server=192.168.56.10:22122 # tracker的ip:port http.server_port=8888 # http监听端口 ~~~ 2. 创建对应的数据存储目录 ~~~ mkdir -p /data/fastdfs/storage ~~~ 3. 启动storage ~~~ mv /etc/init.d/fdfs_storaged /etc/init.d/storage service storage start ~~~ 4. 查看是否启动 ~~~ ps -ef |grep storage ~~~ ![](https://box.kancloud.cn/c18b0447aac73cb724948998bd715a7f_1061x62.png) ### 1.3 配置Client ~~~ cp /etc/fdfs/client.conf.sample /etc/fdfs/client.conf vim /etc/fdfs/client.conf ~~~ 做下面修改 ~~~ base_path=/data/fastdfs/client tracker_server=192.168.56.10:22122 ~~~ 创建client目录 ~~~ mkdir -p /data/fastdfs/client ~~~ 测试上传文件 ~~~ fdfs_upload_file /etc/fdfs/client.conf ./client.conf ~~~ ![](https://box.kancloud.cn/2016f428722c385f6cba02a9701d942d_870x72.png) 如上图上传成功后,返回`group1/M00/00/00/wKg4ClsiIoOAHAWxAAAFtZDs6iQ79.conf`这样的一串,这个是以后访问这个文件的凭借。其中/00/00/上传后文件是storage存储目录下的目录,上传的文件就在这个目录下边。 在storage配置的base_path下,是这样的目录: ![](https://box.kancloud.cn/451006498fc117d72760d57242d2fc1a_1685x168.png) ~~~ cd 00/00 ls ~~~ 可以看到刚刚上传的文件 ![](https://box.kancloud.cn/75590c7a309e24e8cff719facd71b041_1159x47.png) ### 1.4整合nginx #### 1.4.1 下载fastdfs-nginx-module模块 ~~~ git clone https://github.com/happyfish100/fastdfs-nginx-module.git ~~~ #### 14.2 安装nginx 1.下载nginx nginx版本为:nginx-1.14.0 http://nginx.org/en/download.html 2.编译安装nginx ~~~ tar -xzvf nginx-1.14.0.tar.gz apt-get -y install libpcre3 libpcre3-dev openssl libssl-dev cd nginx-1.14.0/ ./configure \ --prefix=/usr \ --sbin-path=/usr/sbin/nginx \ --conf-path=/etc/nginx/nginx.conf \ --error-log-path=/var/log/nginx/error.log \ --http-log-path=/var/log/nginx/access.log \ --pid-path=/var/run/nginx/nginx.pid \ --lock-path=/var/lock/nginx.lock \ --user=root \ --group=root \ --with-http_ssl_module \ --with-http_flv_module \ --with-http_stub_status_module \ --with-http_gzip_static_module \ --with-pcre \ --add-module=/root/fastdfs-nginx-module/src && make && sudo make install ~~~ 3.复制fastdfs-ngin-module中的配置文件,到/etc/fdfs目录中 ~~~ cp /root/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs/ ~~~ 4.修改mod_fastdfs.conf文件 ~~~ vim /etc/fdfs/mod_fastdfs.conf ~~~ 修改以下配置 ~~~ group_name=group1 connect_timeout=10 tracker_server=192.168.56.10:22122 url_have_group_name = true store_path0=/data/fastdfs/storage log_filename=mod_fastdfs.log ~~~ 5.复制FastDFS里的2个文件,到/etc/fdfs目录中 ~~~ cp /root/fastdfs/conf/http.conf /root/fastdfs/conf/mime.types /etc/fdfs/ ~~~ 6.修改Nginx配置文件 ~~~ vim /etc/nginx/nginx.conf ~~~ 做以下配置 ~~~ server { listen 8888; # 与storage.conf文件中的http.server_port一致 server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; location ~/group([0-9])/M00 { root /data/fastdfs/storage/data; ngx_fastdfs_module; } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } ... } ~~~ 7.启动Nginx ~~~ nginx ~~~ 8.测试 上传一张图片 ~~~ root@ubuntu01:~# fdfs_upload_file /etc/fdfs/client.conf ./2.png group1/M00/00/00/wKg4ClsiKj6AOv3sAAoHBffgMgw082.png ~~~ 访问地址为就是nginx所在服务器地址+storage配置的http端口+上传文件返回的一串字符串,如: http://192.168.56.10:8888/group1/M00/00/00/wKg4ClsiKj6AOv3sAAoHBffgMgw082.png ![](https://box.kancloud.cn/355032cea80ac01ef7eab07d0bc8f936_1784x931.png) ## 2. 集群搭建 在上边讲述了如何搭建了只有一个tracker server、storage server,接下来说明如何配置集群 ### 2.1 tracker集群 将tracker部署为多节点集群模式: 1.安装tracker 按照1.1~1.2.1步骤执行 2.修改client、storage配置 ~~~ # 修改client端配置,加入tracker vim /etc/fdfs/client.conf tracker_server=tracker1_ip:22122 # 有几个tracker就添加几个这个配置 tracker_server=tracker2_ip:22122 # 修改nginx整合模块配置 vim /etc/fdfs/mod_fastdfs.conf tracker_server=tracker1_ip:22122 # 有几个tracker就添加几个这个配置 tracker_server=tracker2_ip:22122 # 修改storage配置 vim /etc/fdfs/storage.conf tracker_server=tracker2_ip:22122 # 有几个tracker就添加几个这个配置 tracker_server=tracker2_ip:22122 ~~~ 重启storage,不建议用restart ~~~ service storage stop service storage start ~~~ 执行命令`/usr/bin/fdfs_monitor /etc/fdfs/storage.conf`查看是否成功,如下图现在tracker server数量为2两个 ![](https://box.kancloud.cn/03b092a2e7cce92657d35b6b27ae611d_1830x427.png) ### 2.2 storage集群 #### 2.2.1 多volume/group 1.搭建多group 执行1.1~1.2,此时只要group_name配置不同即为不同的组,如下是两个分组的配置。如果想在一个group下配置多个storage的话,指定相同的group_name即可。 group1的storage.conf ~~~ group_name=group1 bind_addr=192.168.56.10 base_path=/data/fastdfs/storage store_path0=/data/fastdfs/storage tracker_server=192.168.56.10:22122 tracker_server=192.168.56.11:22122 http.server_port=8888 ~~~ group2的storage.conf ~~~ group_name=group2 bind_addr=bind_addr=192.168.56.11 base_path=/data/fastdfs/storage store_path0=/data/fastdfs/storage tracker_server=192.168.56.10:22122 tracker_server=192.168.56.11:22122 http.server_port=8888 ~~~ 在任意的服务器上执行命令执行命令`/usr/bin/fdfs_monitor /etc/fdfs/storage.conf`,如下如现在tracker数量为2个,group数量为2个。 ![](https://box.kancloud.cn/344de339a8928ef90ac3927b17d53403_736x377.png) 此时,默认fastdfs会以load balance(负载均衡)的方式,即挑选资源较为富足的group进行文件上传。 ~~~ root@ubuntu01:~# fdfs_upload_file /etc/fdfs/client.conf ./2.png group2/M00/00/00/wKg4C1soeX-AJvj9AAoHBffgMgw417.png root@ubuntu01:~# fdfs_upload_file /etc/fdfs/client.conf ./2.png group2/M00/00/00/wKg4C1soeZWADUQ8AAoHBffgMgw073.png root@ubuntu01:~# fdfs_upload_file /etc/fdfs/client.conf ./2.png group2/M00/00/00/wKg4C1soeZaABSmhAAoHBffgMgw325.png root@ubuntu01:~# fdfs_upload_file /etc/fdfs/client.conf ./2.png group2/M00/00/00/wKg4C1soeZeADGZmAAoHBffgMgw797.png root@ubuntu01:~# fdfs_upload_file /etc/fdfs/client.conf ./2.png group2/M00/00/00/wKg4C1soeZiAO3rNAAoHBffgMgw093.png root@ubuntu01:~# fdfs_upload_file /etc/fdfs/client.conf ./2.png group2/M00/00/00/wKg4C1soeZiAVjmdAAoHBffgMgw961.png root@ubuntu01:~# fdfs_upload_file /etc/fdfs/client.conf ./2.png group2/M00/00/00/wKg4C1soeZmAExMRAAoHBffgMgw515.png ~~~ 因为group2的资源比group1要充足,所以都文件上传到了group2,fastdfs提供了文件上传负载策略一共有三种 > 1. round robin: > 以轮询的方式依次的向各个group存储文件,对应配置值0 > 2. specify group: > 指定某一group存储文件,对应配置值1,此时需要配合配置store_group=group_name来指定特定的组 > 3. load balance: > 选择资源充足的组来存储文件,为FastDFS默认配置 >