您的位置:首页 > 运维架构 > Linux

转载:分布式文件系统 - FastDFS 在 CentOS 下配置安装部署(2)

2018-01-22 17:05 1421 查看

原文:http://blog.mayongfa.cn/193.html

一、安装 Nginx 和 fastdfs-nginx-module

安装 Nginx 请看:从零开始学 Java - CentOS 下安装 Nginx,其实我只想放这一句话。但想想我还是一步一步写详细吧。

1.下载 Nginx 和 fastdfs-nginx-module ,这里是通过

wget
下载(我喜欢这种方式)。

wget -c https://nginx.org/download/nginx-1.10.1.tar.gz
wget https://github.com/happyfish100/fastdfs-nginx-module/archive/master.zip

2.解压 fastdfs-nginx-module ,记着这时候别用

tar
解压了,因为是
.zip
文件,正确命令:

unzip master.zip

3.配置 nginx 安装,加入

fastdfs-nginx-module
模块。这是和普通 Nginx 安装不一样的地方,因为加载了模块。

./configure --add-module=../fastdfs-nginx-module-master/src/

但是,万万没想到,报错啦!有些文件显示

not found
错误。更多看下图,都是错误:

比如这些

gcc、PCRE
这些没找到,说明我们服务器并未安装,所以,我们进行下安装即可了,我在 从零开始学 Java - CentOS 下安装 Nginx
gcc、 PCRE pcre-devel、 zlib、 OpenSSL
的安装命令,都安装一下之后我们再次进行 Nginx 的安装,显示下面的界面就是安装成功啦!

这时候,我们可以看一下 Nginx 下安装成功的版本及模块,命令:

/usr/local/nginx/sbin/nginx -V

二、配置 fastdfs-nginx-module 和 Nginx

1.配置

mod-fastdfs.conf
,并拷贝到
/etc/fdfs
文件目录下。

cd /software/fastdfs-nginx-module-master/src/
vim mod_fastdfs.conf

cp mod_fastdfs.conf /etc/fdfs

修改

mod-fastdfs.conf
配置只需要修改我标注的这三个地方就行了,其他不需要也不建议改变。

# 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-5.05
下面的配置中还没有存在
/etc/fdfs
中的拷贝进去

cd /software/fastdfs-5.05/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;
}

由于我们配置了

group1/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

打开浏览器,访问一下发现并不能访问,也并没有报错,但显示如下画面。糟糕了,怎么办?对了,我好像没关闭防火墙。

开放

80端口
访问权限。在
iptables
中加入重启就行,或者你直接关闭防火墙,本地测试环境可以这么干,但到线上万万不能关闭防火墙的。

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

重启防火墙,使设置生效:

service iptables restart

再次刷新浏览器,可以看到如下画面,说明我们 Nginx 结合 fastdfs-nginx-module 模块安装并配置成功啦!

我最后说一下怎么在已经安装过 Nginx 的服务器上安装配置 fastdfs-nginx-module 模块? 因为,一般我们线上服务器都是已经安装过 Nginx 的,所以这个时候,我们就直接进入 Nginx 的存放目录,进行配置后编译,就不需要执行最后安装

make install
这一步了,接着重启就行了。

上传测试

完成上面的步骤后,我们已经安装配置完成了全部工作,接下来就是测试了。因为执行文件全部在

/usr/bin
目录下,我们切换到这里,并新建一个
test.txt
文件,随便写一点什么,我写了
This is a test file. by:mafly
这句话在里边。然后测试上传:

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

很不幸,并没有成功,报错了。

ERROR - file: shared_func.c, line: 960, open file /etc/fdfs/client.conf fail, errno: 2, error info: No such file or directory
ERROR - file: ../client/client_func.c, line: 402, load conf file "/etc/fdfs/client.conf" fail, ret code: 2

一般什么事情第一次都不是很顺利,这很正常,通过错误提示我看到,好像没有找到

client.conf
这个文件,现在想起来的确没有配置这个文件,那我们现在去配置一下图中的两个参数:

cd /etc/fdfs
cp client.conf.sample client.conf
vim client.conf

怎么还依然报错阿???

upload file fail, error no: 2, error info: No such file or directory

哈哈,你是不是测试上传命令中要上传的

test.txt
文件路径有问题,嗯,那我改一下命令:

/usr/bin/fdfs_test /etc/fdfs/client.conf upload /usr/bin/test.txt

成功啦!!! 返回文件信息及上传后的文件 HTTP 地址,你打开浏览器访问一下试试

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: