yum -y install make cmake gcc gcc-c++ 在/usr/local/src/下放文件 wget https://github.com/happyfish100/libfastcommon/archive/V1.0.7.tar.gz libfastcommon是从 FastDFS 和 FastDHT 中提取出来的公共 C 函数库,基础环境 tar -zxvf V1.0.7.tar.gz cd libfastcommon-1.0.7/ ./make.sh ./make.sh install ln -s /usr/lib64/libfastcommon.so /usr/local/lib/libfastcommon.so FastDFS主程序设置的lib目录是/usr/local/lib,所以需要创建软链接 ln -s /usr/lib64/libfastcommon.so /usr/lib/libfastcommon.so ln -s /usr/lib64/libfdfsclient.so /usr/local/lib/libfdfsclient.so ln -s /usr/lib64/libfdfsclient.so /usr/lib/libfdfsclient.so cd .. wget https://github.com/happyfish100/fastdfs/archive/V5.05.tar.gz tar -zxvf V5.05.tar.gz cd fastdfs-5.05 ./make.sh ./make.sh install ln -s /usr/bin/fdfs_trackerd /usr/local/bin 服务脚本内需要用到的命令(或者sed -ri [email protected]/usr/local/[email protected]/usr/[email protected] /etc/init.d/fdfs_storaged 修改两个服务脚本) ln -s /usr/bin/fdfs_storaged /usr/local/bin ln -s /usr/bin/stop.sh /usr/local/bin ln -s /usr/bin/restart.sh /usr/local/bin 配置tracker跟踪器 在tracker机器上执行 cp /etc/fdfs/tracker.conf.sample /etc/fdfs/tracker.conf vim /etc/fdfs/tracker.conf base_path=/fastdfs/tracker 数据和日志目录地址 http.server_port=80 mkdir -pv /fastdfs/tracker systemctl daemon-reload chkconfig --add fdfs_trackerd systemctl start fdfs_trackerd storage 配置storage存储器 在storage机器上执行(我是和tracker机器安装在了一台机器上) cp /etc/fdfs/storage.conf.sample /etc/fdfs/storage.conf vim /etc/fdfs/storage.conf group_name=group1 组名,第一组为group1,第二组为group2(因为只有两台机所以都是group1组,一个组内可以有多个storage) base_path=/fastdfs/storage 数据和日志目录地址 store_path0=/fastdfs/storage 逐一配置 store_path_count 个路径,索引号基于 0。如果不配置 store_path0,那它就和 base_path 对应的路径一样 tracker_server=192.168.131.156:22122 组内的storage会随机选择一个tracker当自己的主,当主tracker挂掉后会提升另外一个为自己的主(原本主上线后抢占) tracker_server=192.168.131.157:22122 http.server_port=80 与nginx整合时需要用到 mkdir -pv /fastdfs/storage chkconfig --add fdfs_storaged systemctl daemon-reload systemctl start fdfs_storaged 配置文件中定义的tracker必须启动 tail -f /fastdfs/storage/logs/storaged.log 查看日志,选择哪个tracker当主,以及和组内成员之间的通信信息 usr/bin/fdfs_monitor /etc/fdfs/storage.conf 查看集群信息 与nginx整合(storage节点上执行) wget https://jaist.dl.sourceforge.net/project/fastdfs/FastDFS%20Nginx%20Module%20Source%20Code/fastdfs-nginx-module_v1.16.tar.gz tar -xvf fastdfs-nginx-module_v1.16.tar.gz 所需要添加的模块 vim fastdfs-nginx-module/src/config 修改第四行为这个 CORE_INCS="$CORE_INCS /usr/include/fastdfs /usr/include/fastcommon/" nginx 安装包在nginx官网下载(放在和上面下载的模块同一目录下) groupadd -g 666 nginx useradd -u666 -g666 nginx yum -y install gcc gcc-c++ autoconf automake make yum -y install openssl openssl-devel libxml2-devel libxslt-devel perl-devel perl-ExtUtils-Embed libtool zlib zlib-devel pcre pcre-devel patch gd-devel yum install gperftools-devel redhat-rpm-config GeoIP-devel -y cd /usr/local/src/ wget http://nginx.org/download/nginx-1.16.1.tar.gz cd nginx-1.16.1 ./configure --prefix=/usr/local/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/usr/local/nginx/conf/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt=‘-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC‘ --with-ld-opt=‘-Wl,-z,now -pie‘ --add-module=/usr/local/src/fastdfs-nginx-module/src make -j 8 make install cp /usr/local/nginx/sbin/nginx /usr/bin/ useradd -s /sbin/nologin -M nginx mdir -p /var/cache/nginx/client_temp cp /usr/local/rsc/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs/ vim /etc/fdfs/mod_fastdfs.conf connect_timeout=10 连接超时时间 tracker_server=192.168.131.156:22122 #tracker_server=192.168.131.157:22122 url_have_group_name = true 如果文件ID的uri中包含/group**,则要设置为true store_path0=/fastdfs/storage Storage 配置的store_path0路径,必须和storage.conf中的一致 group_name=group1 组名(在同一组内的storage的组名一致) group_count = 1 一共有几个组 (有几个组就写几个,比如4台storage两两一组则数字就为2) [group1] 最后一行添加(若有多个组则添加多个) group_name=group1 storage_server_port=2300 store_path_count=1 store_path0=/fastdfs/storage cp /usr/loca/src/fastdfs-5.05/conf/{http.conf,mime.types} /etc/fdfs/ ln -s /fastdfs/storage/data/ /fastdfs/storage/data/M00 vim /usr/local/src/nginx/nginx.conf listen 80 端口值是要与 /etc/fdfs/storage.conf 中的 http.server_port=80 (前面改成80了)相对应。 location ~/group([0-9])/M00 { ngx_fastdfs_module; } vim /usr/lib/systemd/system/nginx.service nginx启动服务配置 [Unit] Description=nginx After=network.target remote-fs.target nss-lookup.target [Service] Type=forking PIDFile=/var/run/nginx.pid ExecStartPost=/bin/sleep 0.1 ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf ExecReload=/bin/kill -s HUP $MAINPID ExecStop=/bin/kill -s QUIT $MAINPID PrivateTmp=true [Install] WantedBy=multi-user.target systemctl daemon-reload ystemctl start nginx 测试上传文件以及访问(在任意一个tracker端进行) cp /etc/fdfs/client.conf.sample /etc/fdfs/client.conf vim /etc/fdfs/client.conf base_path=/fastdfs/client tracker_server=192.168.131.156:22122 tracker_server=192.168.131.157:22122 mkdir -pv /fastdfs/client fdfs_upload_file /etc/fdfs/client.conf /root/653798961.jpg 命令+配置文件路径+上传的文件所在的路径 group1/M00/00/00/wKiDnV0AeCKAIKQ6AAAHq8MyJVo908.jpg 在同一group的storage节点的/fastdfs/storage/data/00/00/wKiDnV0AeCKAIKQ6AAAHq8MyJVo908.jpg 内 返回的文件ID由group、存储目录、两级子目录、fileid、文件后缀名(由客户端指定,主要用于区分文件类型)拼接而成。可在存储节点上查看 与nginx整合后在网页上可通过该storage节点的ip+路径访问 比如我上面上传的文件 http://192.168.131.156/group1/M00/00/00/wKiDnV0AeCKAIKQ6AAAHq8MyJVo908.jpg 在前端的nginx代理下的配置 参考文档是https://blog.csdn.net/qq_39170130/article/details/91813775
原文地址:https://www.cnblogs.com/hao-guo/p/12164997.html
时间: 2024-11-25 20:26:22