首先需要安装一些东西
首页FastDFS是C语言开发的安装必须使用make、cmake、gcc编译器
1.安装依赖:
- yum install -y make cmake gcc gcc-c++
-
- yum install -y unzip zip
2.上传并解压libfastcommon-master
上传到/usr/local/fastdfs下。
解压命令
- mkdir /usr/local/fastdfs
-
- cd /usr/local/fastdfs
-
- 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,所以需要软连接
- ln -s /usr/lib64/libfastcommon.so /usr/local/lib/libfastcommon.so
-
- ln -s /usr/local/lib64/libfdfsclient.so /usr/local/lib/libfdfsclient.so
-
- ls /usr/local/lib64/
-
- ls /usr/local/lib
-
- ls -l /usr/local/lib
会看见红色的地方在闪后面在解决
回到下面这个目录

更改权限
chmod 755 HISTORY
二.安装FastDFS主程序
上传FastDFS_V5.08.tar.gz到/usr/local/fastdfs下后解压
进入目录
cd /usr/local/fastdfs
解压
-
- #tar zxf FastDFS_v5.08.tar.gz
-
- #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主程序所在位置是:
- /usr/bin 可执行文件所在位置。
-
- /etc/fdfs 配置文件所在位置。
-
- /usr/lib | /usr/lib64 主程序代码所在位置
-
- /usr/include/fastdfs 包含的一些插件组所在位置。
-
- 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
- cd /etc/fdfs
-
- cp tracker.conf.sample tracker.conf
-
- vi tracker.conf /vim tracker.conf
修改:
base_path=/fastdfs/tracker/base
不能和Tomcat一样不然有冲突
- #http.server_port=7000
- :wq退出
创建文件夹
mkdir -p /fastdfs/tracker/base
#启动
service fdfs_trackerd start
#状态
service fdfs_trackerd status
出现下面这个就没有问题

- #停止
-
- #service fdfs_trackerd stop
-
- #cd /etc/fdfs
-
- #cp storage.conf.sample storage.conf
-
- #mkdir -p /fastdfs/store/base
-
- #mkdir -p /fastdfs/store/storage
-
- # vi storage.conf
-
- #base_path=/fastdfs/store/base
-
- #store_path0=/fastdfs/store/storage
-
- #tracker_server=本机IP:22122
- :wq退出
-
- #service fdfs_storaged start
-
- #service fdfs_storaged status
- #cd /etc/fdfs
- #ls
- #cp client.conf.sample client.conf
- mkdir -p /fastdfs/client/base
- #vi client.conf
- base_path=/fastdfs/client/base
- tracker_server=本地IP:22122
- :wq退出
-
- ls /usr/bin | grep fdfs
-
- echo $PATH
-
- 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
先安装依赖
- #yum install -y gcc gcc-c++ make automake autoconf libtool pcre pcre-devel zlib zlib-devel openssl openssl-devel
- #cd /usr/local/fastdfs
- #tar xzf fastdfs-nginx-module_v1.16.tar.gz
- #cd fastdfs-nginx-module/
- #cd src
- #vi config
- #ls /usr/include/fastdfs
- #ls /usr/include/fastcommon/

- # ls /etc/fdfs
- #ls
- #cp mod_fastdfs.conf /etc/fdfs/
- #ls /etc/fdfs
安装Nginx
- #cd /usr/local/fastdfs/
- #tar -zxf nginx-1.16.1.tar.gz
- #cd nginx-1.16.1/
- --add-module=/usr/local/fastdfs/fastdfs-nginx-module/src
必须是
fastdfs-nginx-module的src目录的绝对路径才可以
绝对路径才可以
在cd nginx-1.16.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 \
- --http-log-path=/var/log/nginx/access.log \ --with-http_gzip_static_module \ --http-client-body-temp-path=/var/temp/nginx/client \
- --http-proxy-temp-path=/var/temp/nginx/proxy \ --http-fastcgi-temp-path=/var/temp/nginx/fastcgi \ --http-uwsgi-temp-path=/var/emp/nginx/uwsg1 \
- --http-scgi-temp-path=/var/temp/nginx/scgi \ --add-module=/usr/local/fastdfs/fastdfs-nginx-module/src
出现

就说明没有问题
- #cd /etc/fdfs
- #ls
- #vi mod_fastdfs.conf
修改下面这个
- #tracker_server=192.168.178.130:22122
- #url_have_group_name = true
- #store_path0=/fastdfs/store/storage
- :wq推出
- #cd /usr/local/fastdfs/nginx-1.16.1/
- #ls
有Makefile就可以直接使用make命令
- #make
- #make install
- #cd /usr/local/nginx/
- #ls
- #sbin/nginx
出现以下错误
nginx: [emerg] mkdir() "/var/temp/nginx/client" failed (2: No such file or directory)
解决
- #mkdir -p /var/temp/nginx
- #mkdir -p /var/emp/nginx/uwsg1
查看nginx是否启动
#ps aux | grep nginx

启动成功
关掉
#sbin/nginx -s quit
进入conf下

- #vi nginx.conf
- #user root;
- :wq推出
- #cd ..
- #sbin/nginx
- #ps aux | grep nginx

- #ls
- #ls /var/
- #ls /var/run/nginx/
- #more /var/log/nginx/error.log
缺失配置文件

- #sbin/nginx -s quit
- #cd /usr/local/fastdfs/FastDFS/conf
- #ls
- #cp http.conf /etc/fdfs/
- #cp mime.types /etc/fdfs/
-
- #[root@localhost nginx]# pwd
- /usr/local/nginx
-
- #[root@localhost nginx]# ls /etc/fdfs
- client.conf mime.types storage.conf.sample
- client.conf.sample mod_fastdfs.conf tracker.conf
- http.conf storage.conf tracker.conf.sample
-
- #[root@localhost nginx]# sbin/nginx
-
- #[root@localhost nginx]# ps aux | grep nginx
- root 25412 0.0 0.0 28072 648 ? Ss 14:42 0:00 nginx: master process sbin/nginx
- root 25413 0.0 0.0 30744 1932 ? S 14:42 0:00 nginx: worker process
- root 25416 0.0 0.0 112824 988 pts/3 S+ 14:42 0:00 grep --color=auto nginx
访问http://192.168.178.130/
出现

成功
- #[root@localhost nginx]# ls
- conf html sbi
- #[root@localhost nginx]# cd conf
- #[root@localhost conf]# ls
- fastcgi.conf koi-utf nginx.conf uwsgi_params
- fastcgi.conf.default koi-win nginx.conf.default uwsgi_params.default
- fastcgi_params mime.types scgi_params win-utf
- fastcgi_params.default mime.types.default scgi_params.default
- #[root@localhost conf]# vi nginx.conf
新增一个server节点
- server{
- listen 8888;
- server_name localhost;
- location ~/group[1-9]/M00{
- ngx_fastdfs_module;
- }
- }
listen是vi /etc/fdfs/storage.conf中的http.server_port中的
- #[root@localhost conf]# cd ..
-
- #[root@localhost nginx]# sbin/nginx
- ngx_http_fastdfs_set pid=25625
- nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
- nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
- nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
- nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
- nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
- nginx: [emerg] still could not bind()
-
- #[root@localhost nginx]# sbin/nginx -s quit
- ngx_http_fastdfs_set pid=25634
-
- #[root@localhost nginx]# sbin/nginx
- ngx_http_fastdfs_set pid=25635
-
- #[root@localhost conf]# cd /fastdfs/store/storage/data/00/00
-
- #[root@localhost 00]# ls
- wKiygmInAMeAPDuwAAVCLLrKVow.tar.gz wKiygmInGbmAfM-xABG0Rs4gJZI604.jpg
- wKiygmInFimAN67nABG0Rs4gJZI365.jpg wKiygmInGbmAfM-xABG0Rs4gJZI604.jpg-m
- 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、增加如下:
- # fastdfs start
- /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart
- /usr/bin/fdfs_storaged /etc/fdfs/storage.conf restart
-
- # nginx start
- /usr/local/nginx/sbin/nginx

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