centos7下的FastDFS5.11的安装与使用

FastDFS是一款开源的轻量级分布式文件系统,纯C实现,支持Linux、FreeBSD等Unix系统。

类google FS,不是通用的文件系统,只能通过专有API访问。

FastDFS服务端有两种角色:跟踪器(tracker)和存储节点(storage)。

tracker主要做调度工作,在访问上起负载均衡的作用,在内存中记录集群中group和storage的状态信息,是连接client和storage的枢纽。

storage存储服务器,文件和文件属性都保存到存储服务器上。

FastDFS是C语言开发,建议在linux上运行,本教程使用Centos6.4作为安装环境。
    安装FastDFS需要先将官网下载的源码进行编译,编译依赖gcc环境,

如果没有gcc环境,需要安装gcc:

yum install -y gcc gcc-c++

如果没有make命令

yum -y install gcc automake autoconf libtool make

安装libevent
FastDFS依赖libevent库,需要安装:
yum -y install libevent

安装libfastcommon包

最新下载地址 
https://github.com/happyfish100/libfastcommon/releases

tar -zxvf libfastcommon-1.0.38.tar.gz -C /usr/local/
cd /usr/local/libfastcommon-1.0.38/
./make.sh           #编译
./make.sh install   #安装

libfastcommon安装好后会在/usr/lib64 目录下生成  libfastcommon.so 库文件;

注意:由于FastDFS程序引用usr/lib目录所以需要将/usr/lib64下的库文件拷贝至/usr/lib下。cp libfastcommon.so /usr/lib

不过最新的libfastcommon-1.0.38.tar安装后已经不需要往 /usr/lib拷贝了

安装fastdfs

https://github.com/happyfish100/fastdfs/releases
tar -zxvf fastdfs-5.11.tar.gz
cd fastdfs-5.11
./make.sh && ./make.sh install 

安装成功将安装目录下的conf下的文件拷贝到/etc/fdfs/下;
cp /usr/local/FastDFS/conf/* /etc/fdfs/

安装成功后进入/etc/fdfs目录:
 
修改tracker.conf
vi tracker.conf
base_path=/home/yuqing/FastDFS   
改为:
base_path=/home/server/fastdfs

启动tracker,运行如下命令:
/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart

设置开机自动启动。
vim /etc/rc.d/rc.local
将运行命令行添加进文件:/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart

配置和启动storage

由于上面已经安装过FastDFS,这里只需要配置storage就好了;
切换目录到: /etc/fdfs/ 目录下;

修改storage.conf
vi storage.conf
group_name=group1
base_path=/home/yuqing/FastDFS改为:base_path=/home/FastDFS
store_path0=/home/yuqing/FastDFS改为:store_path0=/home/FastDFS/fdfs_storage
#如果有多个挂载磁盘则定义多个store_path,如下
#store_path1=.....
#store_path2=......
tracker_server=192.168.101.3:22122   #配置tracker服务器:IP
#如果有多个则配置多个tracker
tracker_server=192.168.101.4:22122

启动storage,配置开机启动同trackerserver

/usr/bin/fdfs_storaged /etc/fdfs/storage.conf restart

FastDFS 和nginx整合

配置fastdfs-nginx-module

将FastDFS-nginx-module_v1.16.tar.gz传至/usr/local/下
cd /usr/local
tar -zxvf FastDFS-nginx-module_v1.16.tar.gz
cd FastDFS-nginx-module/src
修改config文件

CORE_INCS="$CORE_INCS /usr/include/fastdfs /usr/include/fastcommon/"
CORE_LIBS="$CORE_LIBS -L/usr/lib -lfastcommon -lfdfsclient"

将fastdfs-nginx-module/src下的mod_fastdfs.conf拷贝至/etc/fdfs/下

cp mod_fastdfs.conf /etc/fdfs/
并修改 /etc/fdfs/mod_fastdfs.conf 的内容;
vi /etc/fdfs/mod_fastdfs.conf

 base_path=/tmp 修改为 base_path=/home/fastdfs

base_path=/home/fastdfs
tracker_server=192.168.172.20:22122 
#tracker_server=192.168.172.20:22122 #(多个tracker配置多行)
url_have_group_name=true        #url中包含group名称
store_path0=/home/fdfs_storage  #指定文件存储路径(上面配置的store路径)
 

安装nginx

上传 nginx-1.14.0.tar.gz 到Centos服务器上;

解压 tar -zxvf nginx-1.14.0.tar.gz 

./configure \
--prefix=/home/server/nginx \
--conf-path=/home/server/nginx/conf/nginx.conf \
--pid-path=/home/server/nginx/conf/nginx.pid \
--lock-path=/home/server/nginx/lock/nginx.lock \
--error-log-path=/home/server/nginx/logs/error.log \
--http-log-path=/home/server/nginx/logs/access.log \
--with-http_gzip_static_module \
--http-client-body-temp-path=/home/server/nginx/temp/client \
--http-proxy-temp-path=/home/server/nginx/temp/proxy \
--http-fastcgi-temp-path=/home/server/nginx/temp/fastcgi \
--http-uwsgi-temp-path=/home/server/nginx/temp/uwsgi \
--http-scgi-temp-path=/home/server/nginx/temp/scgi \
--add-module=/home/server/fastdfs/fastdfs-nginx-module/src

make && make install

修改配置文件ningx.config

user root;
worker_processes  1;

pid        logs/nginx.pid;

events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;

    server {
        listen       7777;
        server_name  localhost;

        location / {
            root   html;
            index  index.html index.htm;
        }

        location ~ /group([0-9])/M00/{
                root /home/amm/server/fastdfs/fdfs_storage/data;
                ngx_fastdfs_module;
        }
    }

}

创建nginx/client目录
mkdir -p /var/temp/nginx/client

启动nginx

/home/server/nginx/sbin/nginx -c /home/server/nginx/conf/nginx.conf -s reload

查询端口是否有进程守护用如下命令grep对应端口,如80为端口号
例:netstat -nalp|grep 7777

查看某个程序用到的端口

例: netstat -unltp|grep nginx

查看开放端口

例:/sbin/iptables -L -n

参考资料:

https://www.cnblogs.com/yufeng218/p/8111961.html

https://blog.csdn.net/luckyzsion/article/details/75581834

猜你喜欢

转载自blog.csdn.net/ieflex/article/details/81514217