FastDFS安装过程记录

1、安装准备
虚拟IP:192.168.133.145
虚拟机:VM
操作系统:CenOS 7
用户:root
数据目录:/data/fastdfs
2、开始安装
1.安装所需依赖包

[root@localhost ~]# yum install make cmake gcc gcc-c++

2.安装FastDFS三步走,把git上的文件都放到cd /usr/local/src中
git地址:https://github.com/happyfish100 和https://github.com/FRiCKLE/ngx_cache_purge

[root@localhost ~]# cd /usr/local/src
[root@localhost src]# ls

2.1安装libfastcommon

[root@localhost src]# cd libfastcommon
[root@localhost libfastcommon]# ./make.sh
[root@localhost libfastcommon]# ./make.sh install

执行以上3步,安装完毕,即完成第一步。
2.2安装FastDFS

[root@localhost libfastcommon]# cd ..
[root@localhost src]# cd fastdfs
[root@localhost fastdfs]# ./make.sh
[root@localhost fastdfs]# ./make.sh install

执行以上几步,若无报错,即安装完毕
3、配置Tracker服务
上述安装成功后,在/etc/目录下会有一个fdfs的目录,进入它。可以看到三个.sample后缀的文件,只是作者给我们的示例文件,我们需要把其中的tracker.conf.sample文件改为tracke.conf配置文件并修改它。命令如下:

[root@localhost fastdfs]# cd /etc/fdfs
[root@localhost fastdfs]# cd ls
client.conf.sample  storage.conf.sample  tracker.conf.sample
---
[root@localhost fast]# cp tracker.conf.sample tracker.conf
[root@localhost fast]# vim tracker.conf

打开tracker.conf文件,只需要找到这两个参数就可以了。base_path和http.server_port

# the base path to store data and log files
base_path=/data/fastdfs
# HTTP port on this tracker server
http.server_port=80

base_path:指定数据文件与日志的路径(需要先创建文件夹路径,如/data/fastdfs)
http.server-port:端口号
修改完成保存并退出vim,这时候我们可以使用/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf start来启动Tracker服务,也可使用ln -s建立软链接:

ln -s /usr/bin/fdfs_trackerd /usr/local/bin
ln -s /usr/bin/stop.sh /usr/local/bin
ln -s /usr/bin/restart.sh /usr/local/bin

这时候我们就可以使用service dfds_tracker start 来启动Tracker服务,启动服务后看一下端口是否在监听,命令:

启动服务:service fdfs_trackerd start
查看监听:netstat -unltp|grep fdfs

启动命令如下:

[root@localhost fdfs]# mkdir /data
[root@localhost fdfs]# mkdir /data/fastdfs
[root@localhost fdfs]# /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf start

看到22122端口正常被监听后,Tracker服务安装成功!!!给自己一朵小红花❀

[root@localhost fdfs]# netstat -unltp | grep fdfs
tcp        0      0 0.0.0.0:22122           0.0.0.0:*
LISTEN      22028/fdfs_trackerd  

4、配置Storage服务
开始配置Storage服务,此处为单机测试,把Storage服务放在多台服务器也是可以的,这里不再演示。
开始配置,进入/etc/fdfs的目录操作,进入后可以看到三个.sample后缀的文件,我们需要把其中的storage.conf.sample文件改为storage.conf配置文件并修改它。看命令:

cp storage.conf.sample storage.conf
vim storage.conf

指令操作:

[root@localhost fdfs]# cd /etc/fdfs
[root@localhost fdfs]# cp storage.conf.sample storage.conf
[root@localhost fdfs]# vim storage.conf

打开storage.conf文件后,修改三个参数

# the base path to store data and log files
base_path=/data/fastdfs/storage
# store_path#, based 0, if store_path0 not exists, it's value is base_path
# the paths must be exist
store_path0=/data/fastdfs/storage
#store_path1=/home/yuqing/fastdfs2
# tracker_server can ocur more than once, and tracker_server format is
#  "host:port", host can be hostname or ip address
tracker_server=192.168.133.145:22122

base_path:指定数据文件与日志的路径(需要先创建文件夹路径,如/data/fastdfs/storage)
store_path0:同上
tracker_server:本机IP+Tracker端口
修改完成后保存并退出,这时候我们依然想优雅地启动 Storage服务,带目录的命令不够优雅,这里还是使用ln -s 建立软链接:

ln -s /usr/bin/fdfs_storaged /usr/local/bin

执行命令启动服务:

service fdfs_storaged start

出现了一个大大的error啦!!!要仔细看,错误提示是找不到文件夹,这就好办了嘛。创建一个文件夹再次启动看看。

[root@localhost fdfs]# /usr/bin/fdfs_storaged start
[2019-10-01 15:58:58] ERROR - file: shared_func.c, line: 968, /etc/fdfs/start is not a regular file
[2019-10-01 15:58:58] ERROR - file: process_ctrl.c, line: 230, load conf file "start" fail, ret code: 22

重新启动若能够正常启动,便直接进入下一步;若不行直接使用命令

[root@localhost fdfs]# /usr/bin/fdfs_storaged /etc/fdfs/storage.conf start

查看监听:

[root@localhost fdfs]# netstat -unltp|grep fdfs
tcp        0      0 0.0.0.0:22122           0.0.0.0:*               LISTEN      22028/fdfs_trackerd  
tcp        0      0 0.0.0.0:23000           0.0.0.0:*               LISTEN      26659/fdfs_storaged  

5、服务监听测试
我们安装配置并启动了Tracker和Storage服务,也没有报错了。但是他们究竟是不是在通信呢?我们可以监视一下:

[root@localhost fdfs]# /usr/bin/fdfs_monitor /etc/fdfs/storage.conf
[2019-10-01 16:00:16] DEBUG - base_path=/data/fastdfs/storage, connect_timeout=30, network_timeout=60, tracker_server_count=1, anti_steal_token=0, anti_steal_secret_key length=0, use_connection_pool=0, g_connection_pool_max_idle_time=3600s, use_storage_id=0, storage server id count: 0

server_count=1, server_index=0

tracker server is 192.168.133.145:22122

group count: 1

Group 1:
group name = group1
disk total space = 17878 MB
disk free space = 10198 MB
trunk free space = 0 MB
storage server count = 1
active server count = 1
storage server port = 23000
storage HTTP port = 8888
store path count = 1
subdir count per path = 256
current write server index = 0
current trunk file id = 0

Storage 1:
    id = 192.168.133.145
    ip_addr = 192.168.133.145 (localhost.localdomain)  ACTIVE
    http domain = 
    version = 5.08
    join time = 2019-10-01 16:00:16
    up time = v2019-10-01 16:00:16

当看到ACTIVE就Ok了。
6、安装Nginx和fastdfs-nginx-module
Nginx模块的安装

# 下载解压包
wget -c https://nginx.org/download/nginx-1.9.9.tar.gz
# 解压包
tar -zxvf nginx-1.9.9.tar.gz

# fastdfs-nginx-module模块下载
wget https://github.com/happyfish100/fastdfs-nginx-module/archive/master.zip
# 解压astdfs-nginx-module模块
unzip master.zip

配置nginx安装,加入fastdfs-nginx-module模块。
此处和普通的nginx安装不太一样的,加载了模块

# 进入nginx
cd nginx-1.9.9


# configure编译时的缺失依赖(没有缺失可跳过此步骤)
yum install -y pcre-devel
yum install openssl openssl-devel

# 编译nginx
./configure  --with-http_ssl_module   --with-http_stub_status_module --with-ipv6  --with-http_ssl_module --with-http_realip_module --with-stream  --add-module=../fastdfs-nginx-module-master/src

# 默认执行make & make install 会报错
# 编辑fastdfs-nginx-module配置文件
vim /root/fastdfs-nginx-module-master/src/config

# 修改配置项
CORE_INCS="$CORE_INCS /usr/include/fastdfs /usr/include/fastcommon/"
CORE_LIBS="$CORE_LIBS -L/usr/lib -lfastcommon -lfdfsclient"
确保上述两个目录中有文件.h .o等

# make的时候如果提示common_defined.sh没有找到(没有此错误可跳过)
cp /usr/include/fastcommon/ /usr/indclude/fastdfs/

# 安装nginx
make & make install

这个时候,我们可以看一下Nginx下安装成功的版本及模块,命令:
配置fastdfs-nginx-module和Nginx
1.配置mod-fastdfs.conf,并拷贝到/etc/fdfs文件目录下

cd /usr/local/src/fastdfs-nginx-module/src/
vim mod_fastdfs.conf
cp mod_fastdfs.conf /etc/fdfs

修改一下三个地方的配置

# FastDFS tracker_server can ocur more than once, and tracker_server format is
#  "host:port", host can be hostname or ip address
# valid only when load_fdfs_parameters_from_tracker is true
tracker_server=192.168.198.129:22122
# if the url / uri including the group name
# set to false when uri like /M00/00/00/xxx
# set to true when uri like ${group_name}/M00/00/00/xxx, such as group1/M00/xxx
# default value is false
url_have_group_name = true
    # store_path#, based 0, if store_path0 not exists, it's value is base_path
# the paths must be exist
# must same as storage.conf
store_path0=/data/fastdfs/storage
#store_path1=/home/yuqing/fastdfs1

接着我们需要把fastdfs下面的配置中还没有存在/etc/fdfs中的拷贝进去,命令:

cd /usr/local/src/fastdfs/conf
cp anti-steal.jpg http.conf mime.types /etc/fdfs/

2.配置Nginx,编辑nginx.conf文件

cd /usr/local/nginx/conf
vi nginx.conf

在配置文件中加入:

location /group1/M00 {
    root /data/fastdfs/storage/;
    ngx_fastdfs_module;
}

由于我们配置了group2/M00的访问,我们需要建立一个group1文件夹,并建立M00到data的软链接。

mkdir /data/fastdfs/storage/data/group1
ln -s /data/fastdfs/storage/data /data/fastdfs/storage/data/group1/M00

启动Nginx,会打印出fastdfs模块的pid,可看看日志是否报错,正常不会报错的

/usr/local/nginx/sbin/nginx

打开浏览器,访问一下发现不能访问。地址:192.168.133.145:80/group1/M00
可能是没有关闭防火墙或开放80端口
开放80端口访问权限。在iptables中加入重启就行,或者你直接关闭防火墙,本地测试环境可以这么干,但到线上万万不能关闭防火墙的。

vi /etc/sysconfig/iptables
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT

重启防火墙,使设置生效

service iptables restart

7、上传测试
完成上面的步骤后,我们已经安装配置完成了全部工作,接下来就是测试了。因为执行文件全部在/usr/bin目录下,我们切换到这里,并新建一个test.txt文件,随便写一点什么,我写了text这个单词在里边。然后测试上传:

cp /etc/fdfs/client.conf.sample /etc/fdfs/client.conf 
vim /etc/fdfs/client.conf
cd /usr/bin
vim test.txt
fdfs_test /etc/fdfs/client.conf upload test.txt

最后访问:http:192.168.133.145/group1/M00/00/00/wKiFkV2THRGAB4FQAAAABTfs2ic879.txt
页面显示text,配置成功,撒花★,°:.☆( ̄▽ ̄)/$:.°★
开启服务指令:
1)/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf start
2)/usr/bin/fdfs_storaged /etc/fdfs/storage.conf start
3)/uer/local/nginx/sbin/nginx

参考文献:
1)https://blog.csdn.net/cs4380/article/details/97122578
2)https://www.cnblogs.com/jym-sunshine/p/6397470.html#4257496

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值