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

centos7下安装fastdfs+nginx

2017-09-02 18:11 519 查看

centos7下安装fastdfs和nginx环境配置

1.libfastcommon下载安装

git clone https://github.com/happyfish100/libfastcommon.git

cd libfastcommon

./make.sh

./make.sh install

2.fastdfs下载安装

git clone https://github.com/happyfish100/fastdfs.git

cd fastdfs

./make.sh

./make.sh install

cd conf

cp http.conf anti-steal.jpg mime.types /etc/fdfs/

3.修改配置文件

创建目录:

mkdir -p /var/lib/fast-dfs/tracker

mkdir -p /var/lib/fast-dfs/storage

mkdir -p /var/lib/fast-dfs/client

mkdir -p /var/lib/fast-dfs/nginx-module

创建配置文件:

cd /etc/fdfs/

cp tracker.conf.sample /etc/fdfs/tracker.conf

cp storage.conf.sample /etc/fdfs/storage.conf

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

修改tracker进程的配置文件/etc/fdfs/tracker.conf:

将:

base_path=/home/yuqing/fastdfs

改为:

base_path=/var/lib/fast-dfs/tracker #用于存放日志。

修改storage进程的配置文件/etc/fdfs/storage.conf:

将:

base_path=/home/yuqing/fastdfs

改为:

base_path=/var/lib/fast-dfs/storage #用于存放日志

将:

store_path0=/home/yuqing/fastdfs

改为:

store_path0=/var/lib/fast-dfs/storage #存放数据,若不设置默认为前面那个。

将:

tracker_server=192.168.209.121:22122

改为:

tracker_server=192.168.191.138:22122 #指定tracker服务器地址。

修改client进程的配置文件/etc/fdfs/client.conf:

将:

base_path=/home/yuqing/fastdfs

改为:

base_path=/var/lib/fast-dfs/client #用于存放日志

将:

tracker_server=192.168.0.197:22122

改为:

tracker_server=192.168.191.138:22122 #指定tracker服务器地址。

启动tracker进程:

fdfs_trackerd /etc/fdfs/tracker.conf start

fdfs_trackerd /etc/fdfs/tracker.conf stop

或者

systemctl enable fdfs_trackerd

systemctl stop fdfs_trackerd

systemctl start fdfs_trackerd

systemctl status fdfs_trackerd

启动storage进程:

fdfs_storaged /etc/fdfs/storage.conf start

fdfs_storaged /etc/fdfs/storage.conf stop

或者

systemctl enable fdfs_storaged

systemctl stop fdfs_storaged

systemctl start fdfs_storaged

systemctl status fdfs_storaged

检查进程:

ps -ef |grep fdfs



测试:

fdfs_monitor /etc/fdfs/storage.conf

fdfs_upload_file /etc/fdfs/client.conf local_filename

fdfs_download_file /etc/fdfs/client.conf remote_filename

fdfs_file_info /etc/fdfs/client.conf remote_filename



4.安装Nginx部分

安装fastdfs-nginx-module的依赖包:

yum -y install pcre pcre-devel zlib zlib-devel openssl openssl-devel

下载fastdfs-nginx-module、nginx

git clone https://github.com/happyfish100/fastdfs-nginx-module.git

wget http://nginx.org/download/nginx-1.12.0.tar.gz

tar -xzvf nginx-1.12.0.tar.gz

cd nginx-1.12.0

./configure –prefix=/usr/local/nginx-1.12.0 –add-module=path/fastdfs-nginx-module/src #(path为fastdfs-nginx-module的存放目录)

make

make install

cp path/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs/

#(path为fastdfs-nginx-module的存放目录)

修改配置文件/usr/local/nginx-1.12.0/conf/nginx.conf:

server {

listen 8888;

server_name localhost;

location ~ /group[0-9]/M00 {

ngx_fastdfs_module;

}

}

A、8888 端口值是要与/etc/fdfs/storage.conf 中的 http.server_port=8888 相对应, 因为 http.server_port 默认为 8888,如果想改成 80,则要对应修改过来。

B、Storage 对应有多个 group 的情况下,访问路径带 group 名,如/group1/M00/00/00/xxx, 对应的 Nginx 配置为:

location ~/group([0-9])/M00 {
ngx_fastdfs_module;


}

C、如查下载时如发现老报 404,将 nginx.conf 第一行 user nobody 修改为 user root 后重新启动。

cp path/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs/

vi /etc/fdfs/mod_fastdfs.conf #(path:fastdfs-nginx-module的目录)

修改配置文件/etc/fdfs/mod_fastdfs.conf:

将:

base_path=/tmp

改为:

base_path=/var/lib/fast-dfs/nginx-module

将:

tracker_server=tracker:22122

改为:

tracker_server=192.168.191.138:22122

将:

url_have_group_name = false

改为:

url_have_group_name = true

将:

store_path0=/home/yuqing/fastdfs

改为:

store_path0=/var/lib/fast-dfs/storage

防火墙中打开 Nginx 的 用到的端口

firewall-cmd –permanent –add-port=8888/tcp

firewall-cmd –permanent –add-port=8888/udp

firewall-cmd –permanent –add-port=22122/tcp

firewall-cmd –permanent –add-port=22122/udp

firewall-cmd –permanent –add-port=23000/tcp

firewall-cmd –permanent –add-port=23000/udp

firewall-cmd –reload

启动nginx:

/usr/local/nginx-1.12.0/sbin/nginx

浏览器访问:http://192.168.191.138:8888/



访问文件:



参考:http://blog.csdn.net/gzliudan/article/details/70881684
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: