• FastDFS基础学习(二)之安装FastDFS


    一先安装libfastcommon-master

    首先需要安装一些东西

    首页FastDFS是C语言开发的安装必须使用make、cmake、gcc编译器

    1.安装依赖:

    1. yum install -y make cmake gcc gcc-c++
    2. yum install -y unzip zip

    2.上传并解压libfastcommon-master

    上传到/usr/local/fastdfs下。

    解压命令

    1. mkdir /usr/local/fastdfs
    2. cd /usr/local/fastdfs
    3. unzip libfastcommon-master.zip

    3.编译并安装

    进入解压之后的libfastcommon-master中

    cd libfastcommon-master

    编译

    ./make.sh

    安装

    ./make.sh install

    省事情的话可以

    ./make.sh && ./make.sh install

    有固定的默认安装位置。在/usr/lib64和/usr/include/fastcomoon俩个目录中

    4.创建软连接

    因为FastDFS主程序设置的lib目录是/usr/local/lib,所以需要软连接

    1. ln -s /usr/lib64/libfastcommon.so /usr/local/lib/libfastcommon.so
    2. ln -s /usr/local/lib64/libfdfsclient.so /usr/local/lib/libfdfsclient.so
    3. ls /usr/local/lib64/
    4. ls /usr/local/lib
    5. ls -l /usr/local/lib

    会看见红色的地方在闪后面在解决

    回到下面这个目录

    更改权限 

    chmod 755 HISTORY

    二.安装FastDFS主程序

    上传FastDFS_V5.08.tar.gz到/usr/local/fastdfs下后解压

    进入目录
    
    cd /usr/local/fastdfs
    解压
    
    1. #tar zxf FastDFS_v5.08.tar.gz
    2. #cd FastDFS

    需要提前安装很多运行环境才可以

    代码如下:

    yum -y install zlib zlib-devel pcre pcre-devel gcc gcc-c++ openssl openssl-devel libevent libevent-devel perl unzip net-tools wget 
    #./make.sh install

    若未安装以上运行环境,就运行./make.sh。需要清除编译,安装好以上运行环境,重新运行即可。

    清除编译代码: 
    
    ./make.sh clean
    编译
    
    #./make.sh
    安装
    

     安装后,FastDFS主程序所在位置是:

    1. /usr/bin 可执行文件所在位置。
    2. /etc/fdfs 配置文件所在位置。
    3. /usr/lib | /usr/lib64 主程序代码所在位置
    4. /usr/include/fastdfs 包含的一些插件组所在位置。
    5. ls /etc/init.d/ |grep fdfs

    FastDFS启动的是服务,服务的可执行文件在/etc/init.d目录中,命名是fdfs_trackerd和fdfs_storaged。在linux系统中,首页service命令启动服务是,service服务名start。服务器自动在/etc/init.d目录中查找,如果目录中没有这个可执行文件,抛出异常,如果存在,直接启动。

    启动FastDFS的命令有:service fdfs_trackerd start | /etc/init.d/fdfs_trackerd start

    1. cd /etc/fdfs
    2. cp tracker.conf.sample tracker.conf
    3. vi tracker.conf /vim tracker.conf

    修改:

    base_path=/fastdfs/tracker/base

    不能和Tomcat一样不然有冲突

    1. #http.server_port=7000
    2. :wq退出 

    创建文件夹

    mkdir -p /fastdfs/tracker/base

    #启动

    service fdfs_trackerd start

    #状态

    service fdfs_trackerd status

    出现下面这个就没有问题

    1.  #停止
    2. #service fdfs_trackerd stop
    3. #cd /etc/fdfs
    4. #cp storage.conf.sample storage.conf
    5. #mkdir -p /fastdfs/store/base
    6. #mkdir -p /fastdfs/store/storage
    7. # vi storage.conf
    8. #base_path=/fastdfs/store/base
    9. #store_path0=/fastdfs/store/storage
    10. #tracker_server=本机IP:22122
    11. :wq退出
    12. #service fdfs_storaged start
    13. #service fdfs_storaged status
    14. #cd /etc/fdfs
    15. #ls
    16. #cp client.conf.sample client.conf
    17. mkdir -p /fastdfs/client/base
    18. #vi client.conf
    19. base_path=/fastdfs/client/base
    20. tracker_server=本地IP:22122
    21. :wq退出
    22. ls /usr/bin | grep fdfs
    23. echo $PATH
    24. fdfs_upload_file /etc/fdfs/client.conf /usr/local/fastdfs/FastDFS_v5.08.tar.gz

     00在/fastdfs/store/storage/data

    配置静态IP地址

    vi /etc/sysconfig/network-scripts/ifcfg-ens33 

    新增

    最后一个设置参考 

    Nginx安装

    安装前先安装fastdfs-nginx-module

    先安装依赖

    1. #yum install -y gcc gcc-c++ make automake autoconf libtool pcre pcre-devel zlib zlib-devel openssl openssl-devel
    2. #cd /usr/local/fastdfs
    3. #tar xzf fastdfs-nginx-module_v1.16.tar.gz
    4. #cd fastdfs-nginx-module/
    5. #cd src
    6. #vi config
    7. #ls /usr/include/fastdfs
    8. #ls /usr/include/fastcommon/

    1. # ls /etc/fdfs
    2. #ls
    3. #cp mod_fastdfs.conf /etc/fdfs/
    4. #ls /etc/fdfs

    安装Nginx

    1. #cd /usr/local/fastdfs/
    2. #tar -zxf nginx-1.16.1.tar.gz
    3. #cd nginx-1.16.1/
    4. --add-module=/usr/local/fastdfs/fastdfs-nginx-module/src

    必须是

     fastdfs-nginx-module的src目录的绝对路径才可以

     绝对路径才可以

    在cd nginx-1.16.1/下使用以下命令

    1. ./configure \ --prefix=/usr/local/nginx \ --pid-path=/var/run/nginx/nginx.pid \ --lock-path=/var/Lock/nginx.lock \ --error-log-path=/var/log/nginx/error.log \
    2. --http-log-path=/var/log/nginx/access.log \ --with-http_gzip_static_module \ --http-client-body-temp-path=/var/temp/nginx/client \
    3. --http-proxy-temp-path=/var/temp/nginx/proxy \ --http-fastcgi-temp-path=/var/temp/nginx/fastcgi \ --http-uwsgi-temp-path=/var/emp/nginx/uwsg1 \
    4. --http-scgi-temp-path=/var/temp/nginx/scgi \ --add-module=/usr/local/fastdfs/fastdfs-nginx-module/src

    出现

    就说明没有问题

    1. #cd /etc/fdfs
    2. #ls
    3. #vi mod_fastdfs.conf

    修改下面这个

    1. #tracker_server=192.168.178.130:22122
    2. #url_have_group_name = true
    3. #store_path0=/fastdfs/store/storage
    4. :wq推出
    5. #cd /usr/local/fastdfs/nginx-1.16.1/
    6. #ls

    有Makefile就可以直接使用make命令

    1. #make
    2. #make install
    3. #cd /usr/local/nginx/
    4. #ls
    5. #sbin/nginx

    出现以下错误

     nginx: [emerg] mkdir() "/var/temp/nginx/client" failed (2: No such file or directory)

    解决

    1. #mkdir -p /var/temp/nginx
    2. #mkdir -p /var/emp/nginx/uwsg1

    查看nginx是否启动

    #ps aux | grep nginx

     启动成功

    关掉

    #sbin/nginx -s quit

    进入conf下

    1. #vi nginx.conf
    2. #user root;
    3. :wq推出
    4. #cd ..
    5. #sbin/nginx
    6. #ps aux | grep nginx

    1. #ls
    2. #ls /var/
    3. #ls /var/run/nginx/
    4. #more /var/log/nginx/error.log

    缺失配置文件

    1. #sbin/nginx -s quit
    2. #cd /usr/local/fastdfs/FastDFS/conf
    3. #ls
    4. #cp http.conf /etc/fdfs/
    5. #cp mime.types /etc/fdfs/
    6. #[root@localhost nginx]# pwd
    7. /usr/local/nginx
    8. #[root@localhost nginx]# ls /etc/fdfs
    9. client.conf mime.types storage.conf.sample
    10. client.conf.sample mod_fastdfs.conf tracker.conf
    11. http.conf storage.conf tracker.conf.sample
    12. #[root@localhost nginx]# sbin/nginx
    13. #[root@localhost nginx]# ps aux | grep nginx
    14. root 25412 0.0 0.0 28072 648 ? Ss 14:42 0:00 nginx: master process sbin/nginx
    15. root 25413 0.0 0.0 30744 1932 ? S 14:42 0:00 nginx: worker process
    16. root 25416 0.0 0.0 112824 988 pts/3 S+ 14:42 0:00 grep --color=auto nginx

    访问http://192.168.178.130/

    出现

    成功

    1. #[root@localhost nginx]# ls
    2. conf html sbi
    3. #[root@localhost nginx]# cd conf
    4. #[root@localhost conf]# ls
    5. fastcgi.conf koi-utf nginx.conf uwsgi_params
    6. fastcgi.conf.default koi-win nginx.conf.default uwsgi_params.default
    7. fastcgi_params mime.types scgi_params win-utf
    8. fastcgi_params.default mime.types.default scgi_params.default
    9. #[root@localhost conf]# vi nginx.conf

    新增一个server节点

    1. server{
    2. listen 8888;
    3. server_name localhost;
    4. location ~/group[1-9]/M00{
    5. ngx_fastdfs_module;
    6. }
    7. }

    listen是vi /etc/fdfs/storage.conf中的http.server_port中的

    1. #[root@localhost conf]# cd ..
    2. #[root@localhost nginx]# sbin/nginx
    3. ngx_http_fastdfs_set pid=25625
    4. nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
    5. nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
    6. nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
    7. nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
    8. nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
    9. nginx: [emerg] still could not bind()
    10. #[root@localhost nginx]# sbin/nginx -s quit
    11. ngx_http_fastdfs_set pid=25634
    12. #[root@localhost nginx]# sbin/nginx
    13. ngx_http_fastdfs_set pid=25635
    14. #[root@localhost conf]# cd /fastdfs/store/storage/data/00/00
    15. #[root@localhost 00]# ls
    16. wKiygmInAMeAPDuwAAVCLLrKVow.tar.gz wKiygmInGbmAfM-xABG0Rs4gJZI604.jpg
    17. wKiygmInFimAN67nABG0Rs4gJZI365.jpg wKiygmInGbmAfM-xABG0Rs4gJZI604.jpg-m
    18. wKiygmInFimAN67nABG0Rs4gJZI365.jpg-m

    访问地址:

    http://192.168.178.130:8888/group1/M00/00/00/wKiygmInFimAN67nABG0Rs4gJZI365.jpg

     虚拟机每次启动之后都要重新启动一下fastdfs 和 nginx服务,比较麻烦,所以增加开机自启动;

    编辑 /etc/rc.d/rc.local 文件,增加启动项;

    1、编辑文件

     vim /etc/rc.d/rc.local

     2、增加如下:

    1. # fastdfs start
    2. /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart
    3. /usr/bin/fdfs_storaged /etc/fdfs/storage.conf restart
    4. # nginx start
    5. /usr/local/nginx/sbin/nginx

    3、在centos7中, /etc/rc.d/rc.local 文件的权限被降低了,需要给rc.local 文件增加可执行的权限;

    chmod +x /etc/rc.d/rc.local

  • 相关阅读:
    Java 接口
    C++ Qt开发:QItemDelegate自定义代理组件
    微信小程序基本组件使用介绍
    ChatGPT can make mistakes. Consider checking important information.
    黑苹果引导介绍篇
    Vue怎么通过JSX动态渲染组件
    开源 SPL 助力 JAVA 处理公共数据文件(txt\csv\json\xml\xls)
    GO学习注意
    【Linux进程间通信】mmap共享存储映射
    持续进化,快速转录,Faster-Whisper对视频进行双语字幕转录实践(Python3.10)
  • 原文地址:https://blog.csdn.net/weixin_53998054/article/details/126088224