- 安装FastDFS
- 安装FastDFS
- 安装nginx
- 安装前请先升级gcc:
- 安装nginx依赖:gcc套件和升级后可不安装
- http://www.openssl.org/">SL功能需要openssl库,下载地址:http://www.openssl.org/
- http://www.zlib.net/">gzip模块需要zlib库,下载地址:http://www.zlib.net/
- http://www.pcre.org/">pcre库,下载地址:http://www.pcre.org/
- gcc-c++ 编译器
- http://nginx.org/en/download.html">Nginx的安装包:下载地址为:http://nginx.org/en/download.html
- 安装软件
- 安装Nginx
- 安装fastdfs-nginx-module
安装FastDFS
安装libfastcommon
安装FastDFS之前要先安装它的依赖库libfastcommon,
下载地址:https://github.com/happyfish100/libfastcommon.git
git clone https://github.com/happyfish100/libfastcommon.git
cd libfastcommon; git checkout V1.0.48
./make.sh clean && ./make.sh && ./make.sh install
或使用压缩包:解压libfastcommon-master压缩包
unzip libfastcommon-master.zip
或者
tar -zxvf libfastcommon-master.tar.gz
进入libfastcommon目录
cd libfastcommon
编译libfastcommon
./make.sh
安装libfastcommon
./make.sh install
安装FastDFS
安装FastDFS
下载地址:https://github.com/happyfish100/fastdfs.git
FastDFS may be copied only under the terms of the GNU General
Public License V3, which may be found in the FastDFS source kit.
Please visit the FastDFS Home Page for more detail.
Chinese language: http://www.fastken.com/
# step 1. download libfastcommon source codes and install it,
# github address: https://github.com/happyfish100/libfastcommon.git
# gitee address: https://gitee.com/fastdfs100/libfastcommon.git
# command lines as:
git clone https://github.com/happyfish100/libfastcommon.git
cd libfastcommon; git checkout V1.0.43
./make.sh clean && ./make.sh && ./make.sh install
# step 2. download fastdfs source codes and install it,
# github address: https://github.com/happyfish100/fastdfs.git
# gitee address: https://gitee.com/fastdfs100/fastdfs.git
# command lines as:
git clone https://github.com/happyfish100/fastdfs.git
cd fastdfs; git checkout V6.06
./make.sh clean && ./make.sh && ./make.sh install
# step 3. setup the config files
# the setup script does NOT overwrite existing config files,
# please feel free to execute this script (take easy :)
./setup.sh /etc/fdfs
# step 4. edit or modify the config files of tracker, storage and client
such as:
vi /etc/fdfs/tracker.conf
vi /etc/fdfs/storage.conf
vi /etc/fdfs/client.conf
and so on ...
# step 5. run the server programs
# start the tracker server:
/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart
# start the storage server:
/usr/bin/fdfs_storaged /etc/fdfs/storage.conf restart
# (optional) in Linux, you can start fdfs_trackerd and fdfs_storaged as a service:
/sbin/service fdfs_trackerd restart
/sbin/service fdfs_storaged restart
# step 6. (optional) run monitor program
# such as:
/usr/bin/fdfs_monitor /etc/fdfs/client.conf
# step 7. (optional) run the test program
# such as:
/usr/bin/fdfs_test <client_conf_filename> <operation>
/usr/bin/fdfs_test1 <client_conf_filename> <operation>
# for example, upload a file for test:
/usr/bin/fdfs_test /etc/fdfs/client.conf upload /usr/include/stdlib.h
tracker server config file sample please see conf/tracker.conf
storage server config file sample please see conf/storage.conf
client config file sample please see conf/client.conf
Item detail
1. server common items
---------------------------------------------------
| item name | type | default | Must |
---------------------------------------------------
| base_path | string | | Y |
---------------------------------------------------
| disabled | boolean| false | N |
---------------------------------------------------
| bind_addr | string | | N |
---------------------------------------------------
| network_timeout | int | 30(s) | N |
---------------------------------------------------
| max_connections | int | 256 | N |
---------------------------------------------------
| log_level | string | info | N |
---------------------------------------------------
| run_by_group | string | | N |
---------------------------------------------------
| run_by_user | string | | N |
---------------------------------------------------
| allow_hosts | string | * | N |
---------------------------------------------------
| sync_log_buff_interval| int | 10(s) | N |
---------------------------------------------------
| thread_stack_size | string | 1M | N |
---------------------------------------------------
memo:
* base_path is the base path of sub dirs:
data and logs. base_path must exist and it's sub dirs will
be automatically created if not exist.
$base_path/data: store data files
$base_path/logs: store log files
* log_level is the standard log level as syslog, case insensitive
# emerg: for emergency
# alert
# crit: for critical
# error
# warn: for warning
# notice
# info
# debug
* allow_hosts can ocur more than once, host can be hostname or ip address,
"*" means match all ip addresses, can use range like this: 10.0.1.[1-15,20]
or host[01-08,20-25].domain.com, for example:
allow_hosts=10.0.1.[1-15,20]
allow_hosts=host[01-08,20-25].domain.com
2. tracker server items
---------------------------------------------------
| item name | type | default | Must |
---------------------------------------------------
| port | int | 22000 | N |
---------------------------------------------------
| store_lookup | int | 0 | N |
---------------------------------------------------
| store_group | string | | N |
---------------------------------------------------
| store_server | int | 0 | N |
---------------------------------------------------
| store_path | int | 0 | N |
---------------------------------------------------
| download_server | int | 0 | N |
---------------------------------------------------
| reserved_storage_space| string | 1GB | N |
---------------------------------------------------
memo:
* the value of store_lookup is:
0: round robin (default)
1: specify group
2: load balance (supported since V1.1)
* store_group is the name of group to store files.
when store_lookup set to 1(specify group),
store_group must be set to a specified group name.
* reserved_storage_space is the reserved storage space for system
or other applications. if the free(available) space of any stoarge
server in a group <= reserved_storage_space, no file can be uploaded
to this group (since V1.1)
bytes unit can be one of follows:
# G or g for gigabyte(GB)
# M or m for megabyte(MB)
# K or k for kilobyte(KB)
# no unit for byte(B)
3. storage server items
-------------------------------------------------
| item name | type | default | Must |
-------------------------------------------------
| group_name | string | | Y |
-------------------------------------------------
| tracker_server | string | | Y |
-------------------------------------------------
| port | int | 23000 | N |
-------------------------------------------------
| heart_beat_interval | int | 30(s) | N |
-------------------------------------------------
| stat_report_interval| int | 300(s) | N |
-------------------------------------------------
| sync_wait_msec | int | 100(ms) | N |
-------------------------------------------------
| sync_interval | int | 0(ms) | N |
-------------------------------------------------
| sync_start_time | string | 00:00 | N |
-------------------------------------------------
| sync_end_time | string | 23:59 | N |
-------------------------------------------------
| store_path_count | int | 1 | N |
-------------------------------------------------
| store_path0 | string |base_path| N |
-------------------------------------------------
| store_path# | string | | N |
-------------------------------------------------
|subdir_count_per_path| int | 256 | N |
-------------------------------------------------
|check_file_duplicate | boolean| 0 | N |
-------------------------------------------------
| key_namespace | string | | N |
-------------------------------------------------
| keep_alive | boolean| 0 | N |
-------------------------------------------------
| sync_binlog_buff_interval| int | 60s | N |
-------------------------------------------------
memo:
* tracker_server can ocur more than once, and tracker_server format is
"host:port", host can be hostname or ip address.
* store_path#, # for digital, based 0
* check_file_duplicate: when set to true, must work with FastDHT server,
more detail please see INSTALL of FastDHT. FastDHT download page:
http://code.google.com/p/fastdht/downloads/list
* key_namespace: FastDHT key namespace, can't be empty when
check_file_duplicate is true. the key namespace should short as possible
或使用压缩包:解压FastDFS压缩包
tar -xzf FastDFS_v5.08.tar.gz
或者
unzip fastdfs-master.zip
进入FastDFS目录
cd FastDFS
编译FastDFS
./make.sh
安装FastDFS
./make.sh install
修改配置文件
cd /etc/fdfs/
会看到三个配置文件:
client.conf.sample, tracker.conf.sample,storage.conf.sample
复制,然后配置:
cp client.conf.sample client.conf
cp tracker.conf.sample tracker.conf
cp storage.conf.sample storage.conf
配置storage.conf
注意:同一个组内的不同的storage的配置要相同(方便同步文件)
配置storage属于哪个group:
group_name=group1 (因为现在先只是配一个组,所以这里就为group1)
配置base_path:
原来 base_path=/home/yuqing/fastdfs 这里需要改为自己的文件路径,
如:base_path=/home/xxx/fastdfs (这里的文件目录如果没有,要自己新建,不然会报错)
配置store_path0:
这里 store_path0=/home/yuqing/fastdfs 也要改为自己的文件路径
如: store_path0=/home/xxx/fastdfs (建议与bast_path一样)
配置tracker_server:
还有:tracker_server要改为自己的trakcer_server的ip
如:tracker_server=172.16.36.245:22122 (若有特殊要求可查看文档根据实际情况配置)
配置tracker.conf
配置base_path:
原来 base_path=/home/yuqing/fastdfs 这里需要改为自己的文件路径,
如:base_path=/home/xxx/fastdfs (这里的文件目录如果没有,要自己新建,不然会报错)
(若有特殊要求可查看文档根据实际情况配置)
配置client.conf
配置base_path:
原来 base_path=/home/yuqing/fastdfs 这里需要改为自己的文件路径,
如:base_path=/home/xxx/fastdfs (这里的文件目录如果没有,要自己新建,不然会报错)
启动服务程序
启动tracker server
/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart
启动storage server
/usr/bin/fdfs_storaged /etc/fdfs/storage.conf restart
启动测试程序
上传文件测试:
/usr/bin/fdfs_test /etc/fdfs/client.conf upload tff.jpeg
上传成功会返回信息如:
This is FastDFS client test program v5.08
Copyright (C) 2008, Happy Fish / YuQing
……(此处省略很多字)
example file url:
http://172.16.36.245/group1/M00/00/00/rBAk9VhH11aAQznLAACgiYdLO3c42_big.jpeg
安装nginx
安装前请先升级gcc:
1、安装gcc套装:
yum install cpp
yum install binutils
yum install glibc
yum install glibc-kernheaders
yum install glibc-common
yum install glibc-devel
yum install gcc
yum install make
2、升级gcc
yum -y install centos-release-scl
yum -y install devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutils
scl enable devtoolset-9 bash
安装nginx依赖:gcc套件和升级后可不安装
SL功能需要openssl库,下载地址:http://www.openssl.org/
gzip模块需要zlib库,下载地址:http://www.zlib.net/
pcre库,下载地址:http://www.pcre.org/
gcc-c++ 编译器
Nginx的安装包:下载地址为:http://nginx.org/en/download.html
安装软件
安装SSL功能需要的openssl库插件
注意:安装过程是按照我在linux下设置的文件路径来安装的,命令如下:
tar -zxvf soft/openssl-SNAP-20160104
cd cd openssl-SNAP-20160104/
./config
make
make install
安装 pcre-8.39.zip
- 进入目录:
cd pcre-8.39
- 执行命令:
./configure
- 执行命令:
make
- 执行命令:
sudo make install
安装 zlib-1.2.8.tar.xz
- 进入目录:
cd zlib-1.2.8
- 执行命令:
./configure
- 执行命令:
make
- 执行命令:
sudo make install
安装 gcc-c++
yum install -y gcc gcc-c++
安装Nginx
下载:
从官方网址上下载稳定版本nginx,网址为:https://nginx.org/en/download.html
用ftp或sftp工具将nginx-1.18.0.tar.gz拷贝到linux操作系统
安装:
解压
tar -zxvf nginx-1.18.0.tar.gz
编译 安装
cd nginx-1.18.0
指定目录安装nginx
./configure --prefix=/data/nginx
make && make install
启动
cd /data/nginx/sbin
./nginx
服务化 以下步骤可跳过
- 服务化:新增文件 vim /usr/lib/systemd/system/nginx.service,文件编码如下:
[Unit]
Description=nginx
After=network.target
[Service]
Type=forking
ExecStart=/data/nginx/sbin/nginx
ExecReload=/data/nginx/sbin/nginx -s reload
ExecStop=/data/nginx/sbin/nginx -s quit
PrivateTmp=true
[Install]
WantedBy=multi-user.target
将nginx加入到开机启动
systemctl enable nginx.service
安装fastdfs-nginx-module
下载
下载地址:https://github.com/happyfish100/fastdfs-nginx-module/
fastdfs-nginx_module作用:在storage之间同步数据时候,还没同步完全时候就发生下载时,直接从源数据storage下载
将fastdfs-nginx-module压缩包解压,并记录下它的路径,因为安装的时候要用到
进入nginx的安装包的源目录,然后编译和安装fastdfs-nginx-module
命令如下:
注意:要先关闭所有的nginx进程,在进行下面这一步骤
cd nginx
./configure --add-module=/home/ningqijun/fastdfs-nginx-module/src
(/home/ningqijun/fastdfs-nginx-module/src根据自己的文件目录来配)
make
make install
配置nginx.conf
(默认nginx.conf是在目录/usr/local/nginx/conf/ 里面的)
命令:
cd /usr/local/nginx/conf/
vi nginx.conf
只有一个group默认配置
最简单的配置:当mod_fastdfs.conf 配置文件中只有一个group1, 且配置了 url_have_group_name = false 时,即访问地址不使用分组名称,那么只需在nginx的配置文件中增加以下配置即可:
在nginx.conf里面的server{里面添加location /M00……},添加下面的几行:
location /M00 {
root /home/ningqijun/fastdfs/data;
ngx_fastdfs_module;
}
多个group的配置
当配置多个组,且mod_fastdfs.conf 里面指定了url_have_group_name= true 时,配置方式:
location ~ /group([0-9]) /M00 {
root /home/ningqijun/fastdfs/data;
ngx_fastdfs_module;
}
比如:在group1上的 nginx 的nginx.conf 配置是
location /group1 /M00 {
root /home/ningqijun/fastdfs/data;
ngx_fastdfs_module;
}
比如:在group2上的 nginx 的nginx.conf 配置是
location /group2 /M00 {
root /home/ningqijun/fastdfs/data;
ngx_fastdfs_module;
}
创建/M00软连接
命令:
ln -s /home/ningqijun/fastdfs/data /home/ningqijun/fastdfs/data/M00
修改mod_fastdfs.conf
将/home/…/fastdfs-nginx-module-master/src(位置看自己将解压到哪里)
里面的mod_fastdfs.conf复制到/etc/fdfs/里面
1. 更改tracker_server的IP如:tracker_server=172.16.36.245:22122
2. 更改store_path0这个要与storaged的配置一致,如:store_path0=/home/ningqijun/fastdfs
重新启动Nginx
将FastDFS配置目录下的2个文件复制到/etc/fdfs目录下:
cp /usr/local/fastdfs/conf/http.conf /etc/fdfs/
cp /usr/local/fastdfs/conf/mime.types /etc/fdfs/
命令:
/usr/local/nginx/sbin/nginx -s stop
/usr/local/nginx/sbin/nginx
注意:要实现HTTP下载必须要求Nginx和fastdfs-nginx-module起来
测试:
/usr/bin/fdfs_test /etc/fdfs/client.conf upload test.png
假设返回链接如下:
http://192.168.1.100/group1/M00/00/00/aIBdvl5Th7iAM1PwAACLyBo1AoQ37510.png
浏览器输入下面的URL(即去掉 group1):
http://192.168.1.100/M00/00/00/aIBdvl5Th7iAM1PwAACLyBo1AoQ37510.png
能查看刚上传的 png 文件即 OK.