Fastsfs+Nginx+centos7 文件服务器

Fastsfs+Nginx+centos7(单机配置)
系统系统 centos7.5
1台服务器:地址任意
安装包:
fastdfs-5.05.tar.gz
libfastcommon-1.0.36.zip
nginx-1.7.9.tar.gz
fastdfs-nginx-module_v1.16.tar

安装Fastdfs(全部)
安装依赖包
注意:FastDFS 5.x 取消了对 libevent 的依赖,添加了对 libfastcommon 的依
赖。
在安装FastDFS和Nginx之前,需确保gcc、gcc-c++、 libstdc+±
devel、make等依赖库和工具已经安装
#安装依赖软件
yum -y install gcc gcc-c++ libstdc+±devel pcre-devel zlib-devel wget make
yum -y groupinstall ‘Development Tools’
yum -y install vim
安装libfastcommon类库
安装FastDFS必须先安装libfastcommon类库,否则会导致报错,安装直接根据
如下几个步骤即可~
unzip libfastcommon-1.0.36.zip -d /usr/local
cd /usr/local/libfastcommon-1.0.36
./make.sh
./make.sh install
安装FastDFS
tar -xvzf fastdfs-5.05.tar.gz -C /usr/local
cd /usr/local/fastdfs-5.05
./make.sh
./make.sh install
安装好之后,在/usr/bin目录下,可以看fdfs开头的命令工具
FastDFS安装完成之后,所有配置文件在/etc/fdfs目录下,tracker需要
tracker.conf配置文件,storage需要storage.conf配置文件。
安装tracker
将tracker.conf.sample文件重命名为tracker.conf,然后修改配置文
件/etc/fdfs/tracker.conf

存储日志和数据的根目录

mkdir /root/fastdfs/tracker
cd /etc/fdfs
cp tracker.conf.sample tracker.conf
只需要修改 base_pash路径(文件存储路径)
vim tracker.conf
base_path=/root/fastdfs/tracker
配置文件中有这几个参数需要注意:
#启用配置文件
disabled=false
#设置tracker的端口号
port=22122
#设置tracker的数据文件和日志目录(需手动创建)
base_path=/root/fastdfs/tracker
#设置http端口号
http.server_port=9090
使用/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf start尝试启动tracker
[root@localhost ~]# fdfs_trackerd /etc/fdfs/tracker.conf restart
[root@localhost ~]#
没有报错,查看端口22122是否开始监听,确认启动是否成功。
[root@localhost ~]# ps -ef|grep fdfs
root 6078 1 0 11:59 ? 00:00:00 /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf start
root 6101 6054 0 12:01 pts/2 00:00:00 grep fdfs
[root@localhost ~]# netstat -unltp | grep fdfs
tcp 0 0 0.0.0.0:22122 0.0.0.0:* LISTEN 6078/fdfs_trackerd
也可以查看tracker的日志是否启动成功
[root@localhost ~]# cat /root/fastdfs/tracker/logs/trackerd.log
[2017-10-09 11:59:12] INFO - FastDFS v5.05, base_path=/root/fastdfs, run_by …
至此,一个简单的的tracker配置就完成了,Tracker也成功启动~, 接下来要做
的就是完成Storage的配置~
安装storage
安装storage
创建存储目录和配置文件
#存日志
mkdir /root/fastdfs/storage
#存数据
mkdir /root/fastdfs/storage_data
cd /etc/fdfs
cp storage.conf.sample storage.conf
修改配置
storage主要完成base_path,store_path以及tracker的连接地址以及storage
的http服务端口配置等。
主要有如下几个参数:
vi /etc/fdfs/storage.conf

内容

group_name=group1 # 组名(第一组为group1,第二组为group2,依次类推…)
base_path=/root/fastdfs/storage # 数据和日志文件存储根目录
store_path0=/root/fastdfs/storage_data #第一个存储目录,第二个存储目录起名为:
store_path1=xxx,其它存储目录名依次类推…
store_path_count=1 # 存储路径个数,需要和store_path个数匹配
tracker=$(ifconfig |grep broadcast |awk '{print KaTeX parse error: Expected 'EOF', got '}' at position 2: 2}̲') tracker_serv…(tracker):22122

tracker服务器IP和端口

启动Storage
启动storage,会根据配置文件的设置自动创建多级存储目录,查看端口23000是否
开始监听,确认启动是否成功。
[root@localhost fdfs]# fdfs_storaged /etc/fdfs/storage.conf restart
[root@localhost fdfs]# netstat -unltp | grep fdfs
tcp 0 0 0.0.0.0:23000 0.0.0.0:* LISTEN 5551/fdfs_storaged
也可以查看storage的日志是否启动成功。
[root@localhost logs]# cat /root/fastdfs/storage/logs/storaged.log
[2017-10-09 15:39:12] INFO - FastDFS v5.05, base_path=/root/fastdfs,
store_path_count=1 …
验证storage是否登记到tracker服务器
使用fdfs_monitor /etc/fdfs/storage.conf,运行fdfs_monitor查看storage服务
器是否已经登记到tracker服务器。
可以在任一存储节点上使用如下命令查看集群的状态信息
fdfs_monitor /etc/fdfs/storage.conf
如果出现ip_addr = Active, 则表明storage服务器已经登记到tracker服务器,
如下:
Storage 1:
id = 192.168.53.90
ip_addr = 192.168.53.90 (localhost) ACTIVE
至此,tracker、storage等配置都完成并成功启动
接下来,继续完成Nginx和fastdfs-nginx-module的安装和配置
在storage上安装nginx
注意:fastdfs-nginx-module模块只需要安装到storage上。
安装
解压安装包
tar -xvzf fastdfs-nginx-module_v1.16.tar.gz -C /usr/local
tar -zvxf nginx-1.7.9.tar.gz -C /usr/local
需要先配置软链接:
ln -sv /usr/include/fastcommon /usr/local/include/fastcommon
ln -sv /usr/include/fastdfs /usr/local/include/fastdfs
ln -sv /usr/lib64/libfastcommon.so /usr/local/lib/libfastcommon.so
安装nginx的时候,添加 fastdfs-nginx-module-master模块,
如: ./configure --add-module=…/fastdfs-nginx-module/src/
cd /usr/local/nginx-1.7.9
./configure --prefix=/usr/local/nginx --add-module=/usr/local/fastdfs-nginx-module/src
configure 成功输出结果:
checking for OS

  • Linux 2.6.32-431.el6.x86_64 x86_64
    checking for C compiler … found
  • using GNU C compiler
  • gcc version: 4.4.7 20120313 (Red Hat 4.4.7-18) (GCC)
    checking for gcc -pipe switch … found

    nginx http access log file: “/usr/local/nginx/logs/access.log”
    nginx http client request body temporary files: “client_body_temp”
    nginx http proxy temporary files: “proxy_temp”
    nginx http fastcgi temporary files: “fastcgi_temp”
    nginx http uwsgi temporary files: “uwsgi_temp”
    nginx http scgi temporary files: “scgi_temp”
    configure成功了
    接下来执行make和make install
    make
    确定编译没有出错,再进行install
    make install
    安装成功,查看版本信息
    /usr/local/nginx/sbin/nginx -V
    配置
    配置fastdfs-nginx-module
    进入fastdfs-nginx-module的src目录,将md_fastdfs.conf配置文件拷贝
    到/etc/fdfs/目录中
    cd /usr/local/fastdfs-nginx-module/src
    cp mod_fastdfs.conf /etc/fdfs/
    配置 mod_fastdfs.conf
    vim /etc/fdfs/mod_fastdfs.conf
    一般只需改动以下几个参数即可:
    base_path=/root/fastdfs/storage #保存日志目录
    tracker=$(ifconfig |grep broadcast |awk '{print KaTeX parse error: Expected 'EOF', got '}' at position 2: 2}̲') tracker_serv…(tracker):22122
    storage_server_port=23000 #storage服务器的端口号
    group_name=group1 #当前服务器的group名
    url_have_group_name = true #文件url中是否有group名
    store_path_count=1 #存储路径个数,需要和store_path个数匹配
    store_path0=/root/fastdfs/storage_data #存储路径
    group_count = 1 #设置组的个数
    在末尾增加3个组的具体信息:
    [group1]
    group_name=group1
    storage_server_port=23000
    store_path_count=1
    store_path0=/root/fastdfs/storage_data
    建立M00至存储目录的符号连接。
    ln -s /root/fastdfs/storage_data/data /root/fastdfs/storage_data/data/M00
    ll /root/fastdfs/storage_data/data/M00
    配置nginx
    编辑/usr/local/nginx/conf配置文件目录下的nginx.conf,设置添加storage信
    息并保存。
    vim /usr/local/nginx/conf/nginx.conf
    将server段中的listen端口号改为8080,启动用户使用root。
    user root
    listen 8080;
    在server段中添加:
    location ~/group1/M00 {
    root /root/fastdfs/storage_data/data;
    ngx_fastdfs_module;
    }
    复制fastdfs中的http.conf、mime.types文件到/etc/fdfs
    cp /usr/local/fastdfs-5.05/conf/http.conf /usr/local/fastdfs-5.05/conf/mime.types
    /etc/fdfs
    至此,nginx以及FastDFS插件模块设置完成。
    运行
    运行nginx之前,先要把防火墙中对应的端口打开(本例中为8080)。
    firewall-cmd --permanent --zone=public --add-port=8080/tcp
    firewall-cmd --reload
    启动nginx,确认启动是否成功。(查看是否对应端口8080是否开始监听)
    [root@localhost ~]# /usr/local/nginx/sbin/nginx
    ngx_http_fastdfs_set pid=12768
    [root@localhost ~]# netstat -unltp | grep nginx
    tcp 0 0 0.0.0.0:8080 0.0.0.0:* LISTEN 12769/nginx
    也可查看nginx的日志是否启动成功或是否有错误。
    cat /usr/local/nginx/logs/error.log
    在error.log中没有错误,既启动成功。可以打开浏览器,直接访问
    http://localhost:8080,查看是否弹出nginx欢迎页面。
    查看到欢迎页则说明,nginx运行成功。之后依次在其它storage上全部安装上
    nginx并确认运行正常。
    将nginx设置为开机启动:
    vim /etc/rc.d/rc.local
    将运行命令行添加进文件:/usr/local/nginx/sbin/nginx
    同理在其中添加:
    fdfs_trackerd /etc/fdfs/tracker.conf restart
    fdfs_storaged /etc/fdfs/storage.conf restart
    /usr/local/nginx/sbin/nginx
    firewall-cmd --permanent --zone=public --add-port=8080/tcp
    firewall-cmd --reload
    在tracker上安装nginx(单机无需配置)
    在tracker上安装的nginx主要为了提供http访问的反向代理、负载均衡以及缓存
    服务。
    安装
    解压
    tar -zvxf nginx-1.7.9.tar.gz -C /usr/local
    运行./configure进行安装前的设置,主要设置安装路径
    cd /usr/local/nginx-1.7.9
    ./configure --prefix=/usr/local/nginx
    运行make进行编译,确保编译成功。
    make
    运行make install进行安装。
    make install
    配置
    编辑/usr/local/nginx/conf配置文件目录下的nginx.conf,设置负载均衡
    vim /usr/local/nginx/conf/nginx.conf
    配置信息
    worker_processes 4; #根据CPU核心数而定
    events {
    worker_connections 65535; #最大链接数
    use epoll; #新版本的Linux可使用epoll加快处理性能
    }
    http {
    #设置group1的服务器
    upstream fdfs_group1 {
    server 192.168.53.90:8080 weight=1 max_fails=2 fail_timeout=30s;
    server 192.168.54.229:8080 weight=1 max_fails=2 fail_timeout=30s;
    }
    #设置group2的服务器
    upstream fdfs_group2 {
    server 192.168.54.233:8080 weight=1 max_fails=2 fail_timeout=30s;
    server 192.168.54.234:8080 weight=1 max_fails=2 fail_timeout=30s;
    }
    server {
    #设置服务器端口
    listen 8080;
    #设置group1的负载均衡参数
    location /group1/M00 {
    proxy_pass http://fdfs_group1;
    }
    #设置group2的负载均衡参数
    location /group2/M00 {
    proxy_pass http://fdfs_group2;
    }
    }
    }
    至此,nginx设置完成。
    运行
    运行nginx之前,先要把防火墙中对应的端口打开(本例中为8080)
    firewall-cmd --permanent --zone=public --add-port=8080/tcp
    firewall-cmd --reload
    启动nginx,确认启动是否成功。(查看是否对应端口8080是否开始监听)
    [root@localhost ~]# /usr/local/nginx/sbin/nginx
    ngx_http_fastdfs_set pid=12768
    [root@localhost ~]# netstat -unltp | grep nginx
    tcp 0 0 0.0.0.0:8080 0.0.0.0:* LISTEN 12769/nginx
    也可查看nginx的日志是否启动成功或是否有错误。
    cat /usr/local/nginx/logs/error.log
    尝试上传一个文件到FastDFS,然后访问试试。先配置client.conf文件。
    cp client.conf.sample client.conf
    vim /etc/fdfs/client.conf
    修改以下参数:
    base_path=/root/fastdfs/client #日志存放路径
    tracker=$(ifconfig |grep broadcast |awk '{print KaTeX parse error: Expected 'EOF', got '}' at position 2: 2}̲') tracker_serv…(tracker):22122
    http.tracker_server_port=8080
    使用/usr/local/bin/fdfs_upload_file上传一个文件,程序会自动返回文件的
    URL。
    [root@localhost fdfs]# fdfs_upload_file /etc/fdfs/client.conf /root/test.jpg
    group2/M00/00/00/wKg26VncfamAEqZ0AAu-4Kcs3QI677.jpg
    然后使用浏览器访问:
    http://localhost:8080/group2/M00/00/00/wKg26VncfamAEqZ0AAu-4Kcs3QI677.jpg
    看有查看到图片,说明集群搭建成功!
    在这里插入图片描述
    生产中可以将:/root/fastdfs 替换为:/fdfs/storage
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值