Basic Configuration mounted FasterDFS practical operation --------

I. Introduction

1, FastDFS is a lightweight open source distributed file system, its file management features include: file storage, file synchronization, file access (file upload, file download), etc., to solve the high-capacity storage and load balancing problem. Particularly suitable for the carrier to file online services, such as photo album sites, video sites, and more.
2, FastDFS tailor-made for the Internet, full account of redundancy, load balancing, and other mechanisms linear expansion, and focus on high availability, high performance and other indicators, it is easy to use FastDFS to build a high-performance file server clusters provide file upload , downloads and other services.
3, FastDFS is constituted by the tracking server (Tracker Server), the storage server (Storage Server) and a client (Client). Tracker main job scheduling work, since load balancing role in access.

4, tracking and storage nodes may be constituted by one or more servers. Tracker server and storage node can be increased at any time without affecting the online or offline service. Wherein the tracker servers are all equal, the pressure may be increased or decreased according to the server at any time.

5, the server is increased in volume, the existing file synchronization is completed automatically by the system, after synchronization is complete, the system automatically switches to the new server online service.

Basic Configuration mounted FasterDFS practical operation --------

Second, the basic deployment steps

First, the experimental preparation
centos7-1: Tracker 192.168.142.66
centos7-2: Storage 192.168.142.77 nginx +
II to start the installation
(1) Installation libfastcommon service (all nodes are installed)
installed base environment package

yum -y install libevent  libevent-devel perl  make gcc zlib  zlib-devel pcre pcre-devel  gcc-c++  openssl-devel

Installation libfastcommon

[root@storage ~]# wget https://github.com/happyfish100/libfastcommon/archive/V1.0.38.tar.gz
[root@storage ~]# tar zxf V1.0.38.tar.gz -C /opt/
[root@storage ~]# cd /opt/libfastcommon-1.0.38/

Compile and build soft links to facilitate system identification

[root@storage libfastcommon-1.0.38]# ./make.sh && ./make.sh install
[root@storage libfastcommon-1.0.38]# ln -s /usr/lib64/libfastcommon.so /usr/local/lib/libfastcommon.so
[root@storage libfastcommon-1.0.38]# ln -s /usr/lib64/libfdfsclient.so /usr/local/lib/libfdfsclient.so
[root@storage libfastcommon-1.0.38]# ln -s /usr/lib64/libfdfsclient.so /usr/lib/libfdfsclient.so

(2) Installation FastDFS service (all nodes are installed)
to download and install

[root@storage ~]# wget https://github.com/happyfish100/fastdfs/archive/V5.11.tar.gz
[root@storage ~]# tar zxf V5.11.tar.gz -C /opt/
[root@storage ~]# cd /opt/fastdfs-5.11/

Compile

[root@storage fastdfs-5.11]# ./make.sh && ./make.sh install

The template file changes

[root@storage fastdfs-5.11]# cd /etc/fdfs/              //配置文件模板路径
[root@storage fdfs]# cp tracker.conf.sample tracker.conf
[root@storage fdfs]# cp storage.conf.sample storage.conf
[root@storage fdfs]# cp client.conf.sample client.conf

(3) tracker monitoring side configuration
set up a data file, the log file storage directory

mkdir -m 755 -p /opt/fastdfs

Modify the configuration file tracker

[root@tracker ~]# vim /etc/fdfs/tracker.conf
#修改以下配置
port=22122         //tracker服务默认端口22122即可
base_path=/opt/fastdfs      //tracker存储data和log的跟路径,必须提前创建好
http.server_port=8080 //tracker服务器上启动http服务进程,没装忽略

Open service

[root@tracker ~]# fdfs_trackerd /etc/fdfs/tracker.conf start
[root@tracker ~]# netstat -atnp | grep 22122
tcp        0      0 0.0.0.0:22122           0.0.0.0:*               LISTEN      43776/fdfs_trackerd

[root@tracker ~]# systemctl stop firewalld
[root@tracker ~]# setenforce 0

(4) storage server modify
establish data files, log file storage directory

mkdir -m 755 -p /opt/fastdfs

Modify the configuration file storage

[root@storage ~]# vim /etc/fdfs/storage.conf
#修改以下配置
group_name=group1        //默认组名,根据实际情况修改
port=23000       //storge默认23000,同一个组的storage端口号必须一致
base_path=/opt/fastdfs          //storage日志文件的根路径
store_path_count=1              //与下径个数相同,默认为1
store_path0=/opt/fastdfs       //提供的存储路径(默认与日志文件存放在一起)
tracker_server=192.168.142.66:22122      //自己的tracker服务器IP(重点!!!)
http.server_port=80            //http访问文件的端口默认为8888,nginx中配置的监听端口保持一致

Open service

#开启服务(命令支持start|stop|restart)
[root@storage ~]# fdfs_storaged  /etc/fdfs/storage.conf start
[root@storage ~]# netstat -atnp | grep 23000
tcp        0      0 0.0.0.0:23000           0.0.0.0:*               LISTEN      40430/fdfs_storaged

[root@storage ~]# systemctl stop firewalld
[root@storage ~]# setenforce 0

Check whether associated with a tracker monitoring client success

[root@storage ~]# fdfs_monitor /etc/fdfs/storage.conf
Storage 1:
                id = 192.168.142.77
                ip_addr = 192.168.142.77 (storage)  ACTIVE
                http domain =
                ......省略

(5) Installation nginx services (storage: 192.168.142.77)
here in order to reduce the number of virtual machines on, nginx will be installed in the storage end

Install nginx and its components

[root@storage ~]# tar zxf nginx-1.12.0.tar.gz -C /opt/

#下载fastdfs-nginx-module安装包
[root@storage ~]# wget https://github.com/happyfish100/fastdfs-nginx-module/archive/V1.20.tar.gz
[root@storage ~]# tar zxf V1.20.tar.gz -C /opt/

Compile & installation

[root@storage ~]# cd /opt/nginx-1.12.0
[root@storage nginx-1.12.0]# ./configure \
--prefix=/usr/local/nginx \
--add-module=/opt/fastdfs-nginx-module-1.20/src/             //fastdfs-nginx-module模块
[root@storage nginx-1.12.0]# make && make install

note

可能的报错:
/usr/include/fastdfs/fdfs_define.h:15:27: fatal error: common_define.h: No such file or directory

解决方案:
修改fastdfs-nginx-module-1.20/src/config文件,然后重新配置、编译及安装
ngx_module_incs="/usr/include/fastdfs /usr/include/fastcommon/"
CORE_INCS="$CORE_INCS /usr/include/fastdfs /usr/include/fastcommon/"

Fastdfs-nginx-module configuration module

[root@storage nginx-1.12.0]# cd fastdfs-nginx-module-1.20/src
[root@storage nginx-1.12.0]# cp mod_fastdfs.conf /etc/fdfs/           //移动其配置文件至fdfs目录下

#修改fastdfs-nginx-module模块配置文件mod-fasts.conf
[root@storage nginx-1.12.0]# cd /etc/fdfs
[root@storage fdfs]# vim mod_fastdfs.conf
#检查一下配置
base_path=/opt/fastdfs         //存放数据文件、日志的路径
tracker_server=192.168.142.66:22122    //tracker端的地址(重点!!!)
url_have_group_name = true  //url是否包含group名称
storage_server_port=23000           //需要和storage配置的相同
store_path_count=1              //存储路径个数,需要和store_path个数匹配
store_path0=/opt/fastdfs               //文件存储的位置

Nginx modify configuration files

[root@storage fdfs]# vim /usr/local/nginx/conf/nginx.conf
#空行处添加
location ~/M00 {
                root /opt/fastdfs/data;
                ngx_fastdfs_module;
}

Fastdfs decompressed copy directory and mime.types http.conf

#不做这步可能会导致报错
[root@storage fdfs]# cd /opt/fastdfs-5.11/conf/
[root@storage conf]# cp mime.types http.conf /etc/fdfs/

(6) to modify the client-side (in this experiment is the end of storage)
modify the configuration file

[root@storage ~]# vim /etc/fdfs/client.conf
#检查以下配置
base_path=/opt/fastdfs     //tracker服务器文件路径
tracker_server=192.168.142.66:22122            //tracker服务器IP地址和端口号
http.tracker_server_port=8080                  // tracker服务器的http端口号,必须和tracker的设置对应起来

Third, the test

Upload test file abc.txt

/usr/bin/fdfs_upload_file /etc/fdfs/client.conf   abc.txt

Download file abc.txt

/usr/bin/fdfs_download_file /etc/fdfs/client.conf group1/M00/00/00/wKiOTV354W2AIf7GAAAAEh3TEws726.txt abc.txt

Delete files abc.txt

fdfs_delete_file /etc/fdfs/client.conf group1/M00/00/00/wKiOTV354W2AIf7GAAAAEh3TEws726.txt

Thank you for watching, constantly updated ing! ! !

Guess you like

Origin blog.51cto.com/14475593/2460595