Ubuntu下安装FastDFS并配置Nginx
1. 压缩包下载
1 2 3
| wget https://github.com/happyfish100/fastdfs/archive/V5.11.tar.gz wget https://github.com/happyfish100/libfastcommon/archive/V1.0.36.tar.gz wget https://github.com/libevent/libevent/releases/download/release-2.1.12-stable/libevent-2.1.12-stable.tar.gz
|
2. 环境配置
2.1 依赖
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| apt-get install make apt-get install unzip apt-get install gcc apt-get install libevent-dev
#nginx 依赖 #安装gcc g++的依赖库 sudo apt-get install build-essential sudo apt-get install libtool
#安装pcre依赖库(http://www.pcre.org/) sudo apt-get update sudo apt-get install libpcre3 libpcre3-dev
#安装zlib依赖库(http://www.zlib.net) sudo apt-get install zlib1g-dev sudo apt-get install libssl-dev
#安装SSL依赖库(16.04默认已经安装了) sudo apt-get install openssl
|
1 2 3 4 5 6 7 8 9 10 11 12
| tar -zxvf libevent-2.1.12-stable.tzr.gz cd libevent-2.1.12-stable
#配置安装库的目标路径: ./configure --prefix=/usr
#编译安装libevent库: make sudo make install
#检测安装是否成功 ls -al /usr/lib | grep libevent
|
2.2 下载安装ibfastcommon
libfastcommon是从 FastDFS 和 FastDHT 中提取出来的公共 C 函数库,
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| wget https://github.com/happyfish100/libfastcommon/archive/V1.0.36.tar.gz or git clone https://github.com/happyfish100/libfastcommon.git #新建目录 mkdir -p /usr/local/libfastcommon #将下载V1.0.36.tar.gz压缩包拷贝到新建的目录下然后解压 cp V1.0.36.tar.gz /usr/local/libfastcommon cd /usr/local/libfastcommon tar -zxvf V1.0.36.tar.gz cd libfastcommon-1.0.36
#编译、安装 ./make.sh ./make.sh install
|
3. 下载安装FastDFS
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| wget https://github.com/happyfish100/fastdfs/archive/V5.11.tar.gz mkdir -p /usr/local/fastdfs cp V5.11.tar.gz /usr/local/fastdfs cd /usr/local/fastdfs tar -zxvf V5.11.tar.gz cd fastdfs-5.11 ./make.sh ./make.sh install
#创建libfastcommon.so软链接 ln -s /usr/lib64/libfastcommon.so /usr/local/lib/libfastcommon.so
#创建libfdfsclient.so软链接 ln -s /usr/lib64/libfdfsclient.so /usr/local/lib/libfdfsclient.so
#建立 /usr/bin 到 /usr/local/bin 的软链接 ln -s /usr/bin/fdfs_trackerd /usr/local/bin 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
mkdir -p /data/fastdfs/tracker #用于存储tracker server的数据和日志 mkdir -p /data/fastdfs/storage #用于存储storage server的数据和日志 mkdir -p /data/fastdfs/res #用于存储上传的资源文件 mkdir -p /data/fastdfs/client #用于存储client server的数据和日志 mkdir -p /data/fastdfs/temp # //临时目录
|
3.1 1. 配置跟踪服务器(tracker server)
1 2 3
| cd /etc/fdfs cp tracker.conf.sample tracker.conf vim tracker.conf
|
1 2 3 4 5 6 7 8
| # 启用配置 disabled=false # tracker服务器端口(默认22122) port=22122 # Tracker 存储数据和日志根目录(根目录必须存在,子目录会自动创建) base_path=/data/fastdfs/tracker # HTTP 服务端口 http.server_port=80
|
3.1 2. 配置存储服务器(storage server)
1 2 3 4 5
| cd /etc/fdfs cp storage.conf.sample storage.conf
#2. 编辑storage.conf vim storage.conf
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| # 启用配置文件 disabled=false # storage服务器端口(默认23000) port=23000 # 将base_path路径改为刚新建的storage目录 # 数据和日志存储的根目录 base_path=/data/fastdfs/storage # 指定第一存储目录 # 逐一配置 store_path_count 个路径,索引号基于 0。 # 如果不配置 store_path0,那它就和 base_path 对应的路径一样 store_path0=/data/fastdfs/res # 指定tracker服务器地址,此处是上面预定好的IP tracker_server=192.168.103.4:22122 # HTTP 访问文件的端口,此处需要与后面Nginx监听的端口保持一致 http.server_port=80
|
3.1 3. 配置客户端服务器(client server)
1 2 3 4 5 6
| #1. 切换路径,复制一份client.conf.sample文件并修改文件名 cd /etc/fdfs cp client.conf.sample client.conf #2. 编辑client.conf
vim client.conf
|
1 2 3 4
| # 将base_path路径改为刚新建的client目录 base_path=/data/fastdfs/client # 指定tracker服务器地址(虚拟机本机ip和端口号) tracker_server=192.168.103.4:22122
|
3.1 4. 启动tracker和storage
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| #启动tracker和storage /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf /usr/bin/fdfs_storaged /etc/fdfs/storage.conf
#也可以通过以下命令启动 /etc/init.d/fdfs_trackerd start /etc/init.d/fdfs_storaged start
#查看tracker和storage启动是否成功 tail -f /data/fdfs/storage/logs/storaged.log tail -f /data/fdfs/tracker/logs/trackerd.log
#也可以通过这个命令查看 端口正在被监听,则算是服务安装成功 netstat -unltp |grep fdfs
|
3.1 5. 测试文件上传
1 2 3
| # 上传Downloads文件夹中的avatar.png cd Downloads /usr/bin/fdfs_test /etc/fdfs/client.conf upload avatar.png
|
4. 安装Nginx并添加fastdfs 模块
1
| wget https://nginx.org/download/nginx-1.12.1.tar.gz
|