[转]Centos7 fastdfs/nginx 安装与配置

https://blog.csdn.net/alex_bean/article/details/78625131

 

参考文章

服务器环境

  • CentOS7
  • IP: 192.168.219.21

FastDFS安装与配置

安装开发环境

yum groupinstall "Development Tools" "Server platform Development"
  • 1

安装 libfastcommon

cd /usr/local/
git clone https://github.com/happyfish100/libfastcommon.git
cd libfastcommon/
./make.sh
./make.sh install

安装 fastdfs

cd /usr/local/
git clone https://github.com/happyfish100/fastdfs.git
cd fastdfs/
./make.sh
./make.sh install

配置 tracker

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

disabled=false(默认为false,表示是否无效)
port=22122(默认为22122)
base_path=/data/fdfs/tracker

配置 client.conf

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

base_path=/data/fdfs/tracker
tracker_server=192.168.219.21:22122  #不要写localhost

创建 tracker 目录

mkdir -pv /data/fdfs/tracker

启动 tracker

centos6 启动方式

service fdfs_trackerd start

centos7 启动方式

/etc/init.d/fdfs_trackerd start

查看端口

ss -lntup|grep 22122
tcp LISTEN 0 128 :22122 :* users:((“fdfs_trackerd”,3785,5))

关闭tracker

/etc/init.d/fdfs_trackerd stop

注意:虽然FastDFS区分tracker和storage服务器,但是安装的软件及步骤均相同,只是不同的配置文件而已,因此以上安装适用tracker server和storage server

配置 storage

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

disabled=false(默认为false,表示是否无效)
port=23000(默认为23000)
group_name=group1 #指定组名
base_path=/data/fdfs/storage # 用于存储数据
store_path_count=2 # 设置设备数量
store_path0=/data/fdfs/storage/m0 #指定存储路径0
store_path1=/data/fdfs/storage/m1 #指定存储路径1
注意:同一组内存储路径不能冲突,例如:下一个节点的存储路径就是m2,m3….等
tracker_server=192.168.219.21:22122 #指定tracker 不要写localhost,否则起不来
http.server_port=8888(默认为8888,nginx中配置的监听端口那之一致)

mkdir -pv /data/fdfs/storage/{m0,m1} # 创建数据目录

启动 storage

必须先启动tracker,再启动storage

// centos6 启动方式

service fdfs_storaged start

// centos7 启动方式

/etc/init.d/fdfs_storaged start

// 查看端口

ss -lntup|grep 23000
LISTEN 0 128 :23000 :*

// 关闭storage

/etc/init.d/fdfs_storaged stop

文件上传测试

/usr/bin/fdfs_upload_file /etc/fdfs/client.conf /home/alex/test.png
group1/M00/00/00/wKjbFVoXuUqALADZAAdIM2UokFM563.png
返回文件ID即说明文件已经上传成功

存储服务器(storage server)安装并配置nginx

安装 fastdfs-nginx-module 模块

cd /root
git clone https://github.com/happyfish100/fastdfs-nginx-module
cp /root/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs/
vim /etc/fdfs/mod_fastdfs.conf

connect_timeout=10
base_path=/tmp(默认为/tmp)
tracker_server=192.168.219.21:22122
storage_server_port=23000(默认配置为23000)
url_have_group_name = true
store_path_count=2 # 设置设备数量
store_path0=/data/fdfs/storage/m0
store_path0=/data/fdfs/storage/m1
group_name=group1(默认配置为group1)

安装 nginx 依赖库

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

安装 nginx

 cd /root
 wget http://nginx.org/download/nginx-1.8.1.tar.gz
 tar xf nginx-1.8.1.tar.gz 
 cd nginx-1.8.1
 ./configure --prefix=/application/nginx/ --add-module=../fastdfs-nginx-module/src/
 make && make install

 

cp /usr/local/fastdfs/conf/http.conf /etc/fdfs/
cp /usr/local/fastdfs/conf/mime.types /etc/fdfs/

配置 nginx

vim /application/nginx/conf/nginx.conf

user  root;    
 worker_processes  1;
events {
    worker_connections  1024;
}
    http {
        include       mime.types;
        default_type  application/octet-stream;
        sendfile        on;
        keepalive_timeout  65;
        server {
            listen       8888;
            server_name  localhost;
            location ~/group[0-9]/ {
                ngx_fastdfs_module;
            }
            error_page   500 502 503 504  /50x.html;
            location = /50x.html {
            root   html;
            }
        }
    }

 

启动 nginx

cp /application/nginx/sbin/nginx /etc/init.d/
/etc/init.d/nginx

ss -lntup|grep 8888
tcp LISTEN 0 128 :8888 :* users:((“nginx”,7308,6),(“nginx”,7309,6))

配置 firewalld-cmd

yum -y install firewalld

Failed to start firewalld.service: Unit is masked.

systemctl unmask firewalld 

开启8888端口

添加
firewall-cmd --zone=public --add-port=8888/tcp --permanent (–permanent永久生效,没有此参数重启后失效)

firewall-cmd --zone=public --add-port=23000/tcp --permanent (–permanent永久生效,没有此参数重启后失效)

firewall-cmd --zone=public --add-port=22122/tcp --permanent (–permanent永久生效,没有此参数重启后失效)
重新载入
firewall-cmd --reload

访问图片

这里写图片描述

posted @ 2018-07-03 16:30  胜强  阅读(193)  评论(0编辑  收藏  举报