美文网首页
FastDFS Ubuntu 16.04安装

FastDFS Ubuntu 16.04安装

作者: retamia | 来源:发表于2019-04-16 14:50 被阅读0次

FastDFS Ubuntu 16.04安装

参考地址

安装依赖库

mkdir /usr/local/src
mkdir /home/dfs/
cd /usr/local/src
sudo apt install git gcc make automake autoconf libtool libpcre3 libpcre3-dev zlib1g-dev openssl libssl-dev

安装libfastcommon


cd /usr/local/src
git clone https://github.com/happyfish100/libfastcommon.git --depth 1

cd libfastcommon/
./make.sh         #编译可执行文件和链接库文件
./make.sh install #拷贝头文件和库文件到系统目录可能要是用sudo

安装FastDFS

cd /usr/local/src
git clone https://github.com/retamia/fastdfs.git --depth 1 #原作者的fastdfs在Mac上编译PHP扩展会编译错误
cd fastdfs
./make.sh         #编译可执行文件和链接库文件
./make.sh install #拷贝头文件和库文件到系统目录可能要是用sudo

cp /etc/fdfs/tracker.conf.sample /etc/fdfs/tracker.conf  #tracker服务器需要拷贝该文件
cp /etc/fdfs/storage.conf.sample /etc/fdfs/storage.conf  #storage服务器需要拷贝该文件

cp /etc/fdfs/client.conf.sample /etc/fdfs/client.conf #客户端配置

cp /usr/local/src/fastdfs/conf/http.conf /etc/fdfs/ #如果需要提供http访问的需要拷贝该文件,storage服务器和tracker服务器都需要拷贝
cp /usr/local/src/fastdfs/conf/mime.types /etc/fdfs/ #同上

安装FastDFS-Nginx-Module扩展(不需要Http Client的话可以跳过)

cd /usr/local/src
git clone https://github.com/happyfish100/fastdfs-nginx-module.git --depth 1
cp /usr/local/src/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs

安装Nginx(不需要Http Client的话可以跳过)

如果已经安装Nginx,请先卸载以前的Nginx

cd /usr/local/src

sudo apt install wget

wget http://nginx.org/download/nginx-1.15.4.tar.gz #下载nginx压缩包

tar -zxvf nginx-1.15.4.tar.gz #解压

cd nginx-1.15.4/

./configure --add-module=/usr/local/src/fastdfs-nginx-module/src/ #Nginx编译环境设置 添加fastdfs-nginx-module模块

make
make install # 可能需要sudo

部署

以下配置可在单机或多机上进行

tracker服务器配置

vim /etc/fdfs/tracker.conf # 修改之前安装FastDFS环节时候拷贝的配置文件

# 以下内容修改不是在Shell终端执行,而是vim里的文本内容
port = 22122            # tracker 默认端口,未被占用的话一般不修改
base_path = /home/dfs   # 日志和文件的根目录,由之前安装依赖库环节创建
# 保存

storage服务器配置


vim /etc/fdfs/storage.conf # 修改之前安装FastDFS环节时候拷贝的配置文件

# 以下内容修改不是在Shell终端执行,而是vim里的文本内容
port=23000           # storage默认端口,未被占用的话一般不修改
base_path = /home/dfs   # 日志和文件的根目录,由之前安装依赖库环节创建

store_path_count=1    # 硬盘的数量
store_path0=/home/dfs # 0的存储目录
#store_path1=/other/dfs # 如果有其他硬盘的话 store_path_count=2,再新增store_path1,有几个count就写几个store_path

tracker_server=192.168.1.1:22122 # trackerker服务器IP和端口
tracker_server=192.168.1.2:22122 # 有几个trackerker就配置几个

http.server_port=8888 # 默认8888,不支持Http访问的话可以不配置(跟Nginx配置的端口号保持一致)
# 保存

client 测试配置

vim /etc/fdfs/client.conf # 修改之前安装FastDFS环节时候拷贝的配置文件

# 以下内容修改不是在Shell终端执行,而是vim里的文本内容
base_path=/home/dfs
tracker_server=192.168.1.1:22122 # trackerker服务器IP和端口
tracker_server=192.168.1.2:22122 # 有几个trackerker就配置几个
# 保存

# 以下内容是vim保存后在Shell终端执行的
fdfs_upload_file /etc/fdfs/client.conf /usr/local/src/nginx-1.15.4.tar.gz # 把刚才下Nginx压缩包上传到FastDFS上

#执行fdfs_upload_file会得到一个文件的ID 用以下载该文件或者在Http中访问该文件

Nginx.conf配置(不需要Http Client的话可以跳过)


vim /etc/fdfs/mod_fastdfs.conf
# 以下内容修改不是在Shell终端执行,而是vim里的文本内容
tracker_server=192.168.1.1:22122 # trackerker服务器IP和端口
tracker_server=192.168.1.2:22122 # 有几个trackerker就配置几个
url_have_group_name=true
store_path0=/home/dfs
# 保存

# 以下内容在Shell终端执行
vim /usr/local/nginx/conf/nginx.conf #配置nginx.config
# 以下内容修改不是在Shell终端执行,而是vim里的文本内容
# Nginx中添加如下配置,Storage服务器和Tracker服务器都需要配置Nginx
server {
    listen       8888;    # 该端口为storage.conf中的http.server_port相同
    server_name  localhost;
    location ~/group[0-9]/ {
        ngx_fastdfs_module;
    }
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
    root   html;
    }
}

# 测试下载,用外部浏览器访问刚才已传过的nginx安装包返回的文件ID 
# http://192.168.1.1:8888/group1/M00/00/00/wKgAQ1pysxmAaqhAAA76tz-dVgg.tar.gz

启动服务

tracker

/etc/init.d/fdfs_trackerd start
/etc/init.d/fdfs_trackerd restart
/etc/init.d/fdfs_trackerd stop
chkconfig fdfs_trackerd on # 自启动

storage

/etc/init.d/fdfs_storaged start
/etc/init.d/fdfs_storaged restart
/etc/init.d/fdfs_storaged stop
chkconfig fdfs_storaged on # 自启动

nginx

/usr/local/nginx/sbin/nginx 
/usr/local/nginx/sbin/nginx -s reload
/usr/local/nginx/sbin/nginx -s stop

PHP 扩展安装


cd /usr/local/src/fastdfs/php_client
phpize
./configure
make 
make install

# 拷贝到PHP扩展的目录下
# 拷贝到pecl的路径下,例如pecl install redis后,拷贝到跟redis.so的相同目录下
cp modules/fastdfs_client.so /usr/local/Cellar/php/7.2.10/pecl/20170718/


# 拷贝fastdfs_client.ini配置文件到 /etc/php
cp fastdfs_client.ini /usr/local/etc/php/7.2/conf.d # 这是MAC上的
# 或者
php --ini # 得到php.ini的文件地址,然后可以直接将fastdfs_client.ini的文本内容直接拷贝到 php.ini文件里面

# 修改文本内容,内容设置跟配置Client环节差不多,这里就不赘述了
vi /usr/local/etc/php/7.2/conf.d/fastdfs_client.ini

# 执行测试文件

php fastdfs_test.php

# 由于每个人的系统和PHP环境不一致,上述的路径可能需要改动较大,请自行确定调整

相关文章

网友评论

      本文标题:FastDFS Ubuntu 16.04安装

      本文链接:https://www.haomeiwen.com/subject/wvsbwqtx.html