|
1. 虚拟机环境 centos7
安装gcc
yum install -y gcc gcc-c++

2. 安装 libevent
yum -y install libevent
3. 安装 lrzsz vim
yum install lrzsz
yum install vim


4. 安装libfastcommon
tar -zxvf libfastcommon-1.0.7.tar.gz -C /usr/local/ // 把压缩包解压到/usr/local/
cd /usr/local/libfastcommon-1.0.7/ // 进入到目录
./make.sh //编译
./make.sh install //安装



安装完成后,进入到/usr/lib64/ 目录 查看 libfastcommon.so 文件
cd /usr/lib64
ls | grep libfastcommon.so
*********由于FastDFS程序引用usr/lib目录所以需要将/usr/lib64下的库文件拷贝至/usr/lib下
cp libfastcommon.so /usr/lib

5. 安装tracker
cd /usr/local/src
tar -zxvf fastdfs-5.05.tar.gz -C /usr/local/
mv /usr/local/fastdfs-5.05/ /usr/local/fastdfs
cd /usr/local/fastdfs/
./make.sh && ./make.sh install
出现下图代表安装成功!!!

6.安装成功将安装目录下的conf下的文件拷贝到/etc/fdfs/下;
[root@localhost fastdfs]# cp /usr/local/fastdfs/conf/* /etc/fdfs/
[root@localhost fastdfs]#

6. 配置和启动tracker
base_path=/home/yuqing/fastdfs 改为: base_path=/home/fastdfs
http.server_port=8080 改为: http.server_port=80

7. 创建文件夹和启动tracker
[root@localhost fdfs]# mkdir /home/fastdfs
[root@localhost fdfs]# /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart
[root@localhost fdfs]#
在/home/fastdfs/ 目录下生成两个目录, 一个是数据,一个是日志;

8.配置和启动storage
修改storage.conf ; vim storage.conf
group_name=group1 #配置组名
base_path=/home/yuqing/fastdfs 改为: base_path=/home/fastdfs
#store存放文件的位置(store_path)
store_path0=/home/yuqing/fastdfs 改为: store_path0=/home/fdfs_storage
#如果有多个挂载磁盘则定义多个store_path,如下
#store_path1=.....
#store_path2=......
#配置tracker服务器:IP
tracker_server=192.168.172.20:22122
#如果有多个则配置多个tracker
#tracker_server=192.168.101.4:22122
#配置http端口
http.server_port=88

8. 创建、/home/fdfs_storage 目录文件 和启动storage
[root@localhost fdfs]# mkdir /home/fdfs_storage
[root@localhost fdfs]# /usr/bin/fdfs_storaged /etc/fdfs/storage.conf restart
[root@localhost fdfs]# cd /home/fdfs_storage/data/
[root@localhost data]# ls 00 0C 18 24 30 3C 48 54 60 6C 78 84 90 9C A8 B4 C0
[root@localhost data]#

9. 使用FastDFS自带工具测试
[root@localhost data]# cd /etc/fdfs/
[root@localhost fdfs]# cp client.conf.sample client.conf
[root@localhost fdfs]# vim client.conf
编辑如下内容

10. 创建文件夹
[root@localhost /]# mkdir files
[root@localhost /]# cd files/
上传一张图片到该文件夹

[root@localhost files]# ls
100.jpg
[root@localhost files]#
11. 进行测试,运行如下:(运行测试程序,读取/etc/fdfs/client.conf 文件,上传/files目录下的100.jpg文件
[root@localhost files]# /usr/bin/fdfs_test /etc/fdfs/client.conf upload /files/100.jpg
This is FastDFS client test program v5.05
Copyright (C) 2008, Happy Fish / YuQing
...............
group_name=group1, remote_filename=M00/00/00/wKhIhFx6JlWAUNmcAAg5ifGdEFI185.jpg
source ip address: 192.168.72.132
............
file crc32=4053602386 example file url: http://192.168.72.132/group1/M00/00/00/wKhIhFx6JlWAUNmcAAg5ifGdEFI185.jpg
.......
.............. example file url: http://192.168.72.132/group1/M00/00/00/wKhIhFx6JlWAUNmcAAg5ifGdEFI185_big.jpg
[root@localhost files]#

由于没有nginx 或apache 无法提供下载和访问
12. 在fasdfs 安装nginx
[root@localhost files]# cd /usr/local/src/
[root@localhost src]# rz
[root@localhost src]# ls
fastdfs-5.05.tar.gz fastdfs-nginx-module_v1.16.tar.gz libfastcommon-1.0.7.tar.gz
[root@localhost src]# tar -zxvf fastdfs-nginx-module_v1.16.tar.gz -C /usr/local/
[root@localhost src]# cd /usr/local/fastdfs-nginx-module/src/
[root@localhost src]# ls
common.c common.h config mod_fastdfs.conf ngx_http_fastdfs_module.c
[root@localhost src]# vim config
[root@localhost src]# cp mod_fastdfs.conf /etc/fdfs
[root@localhost src]# vim /etc/fdfs/mod_fastdfs.conf
需要修改的内容如下:
base_path=/home/fastdfs
tracker_server=192.168.72.133:22122
url_have_group_name=true
store_path0=/home/fdfs_storage #指定文件存储路径(上面配置的store路径)
13. 将libfdfsclient.so 复制到/usr/lib/
[root@localhost src]# cp /usr/lib64/libfdfsclient.so /usr/lib/
[root@localhost src]# mkdir -p /var/temp/nginx/client
14. 安装nginx
安装nginx 依赖库
yum install pcre
yum install pcre-devel
yum install zlib
yum install zlib-devel
yum install openssl
yum install openssl-devel
使用 rz命令 选者上传安装包nginx-1.8.0.tar.gz
解压压缩包
[root@localhost src]# tar -zxvf fastdfs-nginx-module_v1.16.tar.gz -C /usr/local/
[root@localhost src]#cd /usr/local/nginx-1.8.0/
[root@localhost src]# ./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/temp/nginx/uwsgi \
--http-scgi-temp-path=/var/temp/nginx/scgi \
--add-module=/usr/local/fastdfs-nginx-module/src

make && make install
查看/usr/local/nginx/conf/目录

[root@localhost conf]# cd /usr/local/fastdfs/conf/
[root@localhost conf]# cp http.conf mime.types /etc/fdfs/
[root@localhost conf]# mkdir /usr/local/nginx/logs
[root@localhost conf]# cd /usr/local/nginx/conf/
[root@localhost conf]# cp nginx.conf nginx.conf.bak
[root@localhost conf]# vim nginx.conf
编辑内容如下:
pid /usr/local/nginx/logs/nginx.pid;
server_name 192.168.72.132; //你的ip
#location / {
# root html;
# index index.html index.htm;
#}
把以上内容改成以下内容
location /group1/M00/ {
root /home/fdfs_storage/data;
ngx_fastdfs_module;
}
注释:
(a.) server_name指定本机ip;
(b.) location /group1/M00/:group1为nginx 服务FastDFS的分组名称,M00是FastDFS自动生成编号,对应store_path0=/home/fdfs_storage,如果FastDFS定义store_path1,这里就是M01
15. 启动nginx
[root@localhost conf]# cd /usr/local/nginx/sbin/
[root@localhost sbin]# ./nginx
ngx_http_fastdfs_set pid=23270
[root@localhost sbin]# ps -ef | grep nginx

16. 关闭防火墙
CentOS 7.0默认使用的是firewall作为防火墙;若没有启用iptables 作为防火墙,则使用以下方式关闭防火墙:
[root@localhost sbin]# systemctl stop firewalld.service
[root@localhost sbin]# systemctl disable firewalld.service
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@localhost sbin]# firewall-cmd --state
not running
[root@localhost sbin]#
若已经启用iptables作为防火墙,则使用以下方式关闭:
[root@localhost sbin]# service iptables stop #临时关闭防火墙
[root@localhost sbin]# chkconfig iptables off #永久关闭防火墙
17. 浏览器访问图片:
cd /usr/loca/nginx/sbin/
命令:./nignx 启动nginx
./nginx -s reload //重启
url: http://192.168.72.132/group1/M00/00/00/wKhIhFx6JlWAUNmcAAg5ifGdEFI185_big.jpg
|