1、环境所需的所有依赖包,百度云盘下载:
链接:https://pan.baidu.com/s/1LCBukP5BbdRvZyFnTmjJPw 提取码:7gxy
2、创建好tracker和storage文件夹
mkdir -p /home/mm/fastdfs/tracker
mkdir -p /home/mm/fastdfs/storage
3、我是把所有的文件都上传到/usr/local里了,大家随意
(1)安装libfastcommon
unzip libfastcommon-master.zip
cd libfastcommon-master
执行编译 ./make.sh
执行安装./make.sh install
执行软链接
ln -s /usr/lib64/libfastcommon.so /usr/local/lib/libfastcommon.so
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
(2)安装FastDFS
cd /usr/local
执行 tar -zxvf fastdfs-5.11.tar.gz
cd fastdfs-5.11
./make.sh
./make.sh install
查看可执行命令
ls -la /usr/bin/fdfs*
接下来,继续
[root@localhost sbin]# cd /etc/fdfs/
[root@localhost fdfs]# ll
-rw-r--r--. 1 root root 1461 6月 24 13:19 client.conf.sample
-rw-r--r--. 1 root root 7927 6月 24 13:19 storage.conf.sample
-rw-r--r--. 1 root root 7389 6月 24 13:19 tracker.conf.sample
cp client.conf.sample client.conf
cp storage.conf.sample storage.conf
cp tracker.conf.sample tracker.conf
到此~FastDFS安装结束。
(3)配置Tracker服务
编辑tracker.conf:vi tracker.conf,修改相关参数
base_path=/home/mm/fastdfs/tracker #tracker存储data和log的跟路径,必须提前创建好
http.server_port=80 #http端口,需要和nginx相同
启动 tracker 命令如下。
/启动tracker
/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart
保存,然后 查看tracker端口监听情况
[root@localhost fastdfs_tracker]# netstat -unltp|grep fdfs
tcp 0 0 0.0.0.0:22122 0.0.0.0:* LISTEN 7850/fdfs_trackerd
到此22122端口监听成功
(4)配置Storage服务
vi /etc/fdfs/storage.conf,修改相关参数:
base_path=/home/mm/fastdfs/storage #storage存储data和log的跟路径,必须提前创建好
store_path0=/home/mm/fastdfs/storage #如果为空,则使用base_path
tracker_server=192.168.1.134:22122 #配置该storage监听的tracker的ip和port
保存之后 创建软引用
ln -s /usr/bin/fdfs_storaged /usr/local/bin
// 启动storage
/usr/bin/fdfs_storaged /etc/fdfs/storage.conf restart
同样查看服务是否启动
[root@localhost 00]# netstat -unltp | grep fdfs
tcp 0 0 0.0.0.0:22122 0.0.0.0:* LISTEN 7850/fdfs_trackerd
tcp 0 0 0.0.0.0:23000 0.0.0.0:* LISTEN 8077/fdfs_storaged
安装Nginx和fastdfs-nginx-module模块
(1)解压 nginx 和 fastdfs-nginx-module-master
cd /usr/local
tar -zxvf nginx-1.12.0.tar.gz
unzip fastdfs-nginx-module-master.zip
(2)在安装nginx之前要安装nginx所需的依赖lib
sudo apt-get install libpcre3 libpcre3-dev
sudo apt-get install zlib1g-dev
sudo apt-get install openssl libssl-dev
(3)修改fastdfs-nginx-module-master/src/config文件
vi /usr/local/fastdfs-nginx-module-master/src/config
ngx_module_incs="/usr/include/fastdfs /usr/include/fastcommon/"
CORE_INCS="$CORE_INCS /usr/include/fastdfs /usr/include/fastcommon/"
(4)配置,并加载fastdfs-nginx-module模块
cd nginx-1.12.0
./configure --prefix=/usr/local/nginx --add-module=/usr/local/fastdfs-nginx-module-master/src/
编译和安装
make
make install
(5)查看安装路径:whereis nginx
(6)配置mod-fastdfs.conf,并拷贝到/etc/fdfs文件目录下
cd /usr/local/fastdfs-nginx-module-master/src/
cp mod_fastdfs.conf /etc/fdfs
(7)进入/etc/fdfs修改mod-fastdfs.conf
base_path=/home/mm/fastdfs
tracker_server=192.168.1.134:22122 #tracker的地址
url_have_group_name=true #url是否包含group名称
store_path0=/home/mm/fastdfs/storage #文件存储的位置
(8)配置nginx,80端口server增加location如图
cd /usr/local/nginx/conf/
vi nginx.conf
location ~/M00 {
root /home/mm/fastdfs/storage/data;
nginx_fastdfs_module;
}
(9)最后需要拷贝fastdfs解压目录中的http.conf和mime.types
cd /usr/local/src/fastdfs-5.11/conf
cp mime.types http.conf /etc/fdfs/
(10)nginx启动、停止:
cd /usr/local/nginx/sbin/
./nginx
./nginx -s stop #此方式相当于先查出nginx进程id再使用kill命令强制杀掉进程
./nginx -s quit #此方式停止步骤是待nginx进程处理任务完毕进行停止
./nginx -s reload
(11)查看此时的nginx版本:发现fastdfs模块已经安装好了
[root@localhost conf]# /usr/local/nginx/sbin/nginx -V
nginx version: nginx/1.12.0
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC)
configure arguments: --prefix=/usr/local/nginx --add-module=/usr/local/fastdfs-nginx-module-master/src
FastDFS常用命令测试
上传文件
进入/etc/fdfs目录,有cp命令拷贝client.conf.sample,删除.sample后缀作为正式文件;
修改client.conf相关配置:
base_path=/home/mm/fastdfs/tracker //tracker服务器文件路径
tracker_server=192.168.1.134:22122 //tracker服务器IP地址和端口号
http.tracker_server_port=80 # tracker服务器的http端口号,必须和tracker的设置对应起来
上传测试 /usr/bin/fdfs_upload_file /etc/fdfs/client.conf /usr/local/girl.jpg
[root@localhost ~]# /usr/bin/fdfs_upload_file /etc/fdfs/client.conf /usr/local/girl.jpg
group1/M00/00/00/wKgBhl0Qm-SAfhCXAAhj4DKKH4E003.jpg
通过浏览器访问成功:http://192.168.1.134/group1/M00/00/00/wKgBhl0Qm-SAfhCXAAhj4DKKH4E003.jpg
注意事项:
1、ubuntu系统中安装nginx所需的依赖lib指令为:
sudo apt-get install libpcre3 libpcre3-dev
sudo apt-get install zlib1g-dev
sudo apt-get install openssl libssl-dev
2、安装nginx报错
报错1:“src/os/unix/ngx_user.c:26:7: error: ‘struct crypt_data’ has no member named ‘current_salt’”
解决:https://www.jiweichengzhu.com/article/cc4ed4eeb4644586b81e9070a96c0bda
报错2:src/core/ngx_murmurhash.c:37:11: error: this statement may fall through [-Werror=implicit-fallthroug
解决:https://www.91mszl.com/zhangwuji/article/details/1286
3、云服务器需要在安全组中开放3个端口:22122、23000、80