How to build the FastDFS distributed file system cluster environment?

Seven linux are required.
Insert picture description here

To build a FastDFS distributed file system cluster, it is recommended to deploy at least 6 server nodes;
==Build a FastDFS cluster
Step 1: Install 6 mini versions of Linux. The mini version of Linux has no graphical interface and takes up little disk and resources. The Linux used in the enterprise is Linux without a graphical interface;

Step 2: As the mini version of Linux lacks some commonly used tool libraries, it is inconvenient to operate. It is recommended to install the following tool libraries:
1. Install lrzsz, yum install lrzsz -y
2. Install wget, yum install wget -y
4. Install vim, yum install vim -y
5. Install unzip, yum install unzip -y
6. Install ifconfig, yum install net-tools -y

yum install lrzsz wget vim unzip net-tools -y

7. Install the library dependencies required by nginx and fastdfs:
yum install gcc perl openssl openssl-devel pcre pcre-devel zlib zlib-devel libevent libevent-devel -y

The third step is to install fastdfs
1. Upload the installation package of fastdfs and libfastcommon
2. Decompress libfastcommon and install libfastcommon
3. Decompress fastdfs and install fastdfs
4. Copy http.conf and mime.types in the fastdfs directory to the /etc/fdfs directory
Note: All 6 machines perform these operations

Step 4: Deploy two tracker server servers, the work that needs to be done:

修改两个tracker服务器的配置文件:
tracker.conf: 修改一个地方:
base_path=/opt/fastdfs/tracker   #设置tracker的数据文件和日志目录(需预先创建)
启动tracker服务器 fdfs_trackerd /etc/fdfs/tracker.conf

The fifth step is to modify the storage.conf file in the four storages in the two groups. The
first storage server of the first group of group1 (modify the storage.conf configuration file):
group_name=group1 #group name, modify it according to the actual situation, the value is group1 or group2
base_path=/opt/fastdfs/storage #Set storage log directory (need to be created in advance)
store_path0=/opt/fastdfs/storage/files
#Storage path tracker_server=192.168.171.135:22122 #tracker server IP address and port No.
tracker_server = 192.168.171.136: 22122

第二组group2的第一个storage server(修改storage.conf配置文件):
group_name=group2   #组名,根据实际情况修改,值为 group1 或 group2
base_path=/opt/fastdfs/storage   #设置storage的日志目录(需预先创建)
store_path0=/opt/fastdfs/storage/files    #存储路径
tracker_server=192.168.171.135:22122  #tracker服务器的IP地址以及端口号
tracker_server=192.168.171.136:22122

启动storage服务器
使用之前的Java代码测试FastDFS的6台机器是否可以上传文件

Note: FastDFS is a load balancing strategy by default. You can modify the tracker.conf file on the 2 machines of the tracker
store_lookup=1

0 随机存放策略
1 指定组
2 选择磁盘空间的优先存放 默认值

修改后重启服务
fdfs_trackerd /etc/fdfs/tracker.conf restart

Use Nginx for load balancing========

The sixth step is to install nginx and use nginx to load balance fastdfs.
Upload nginx-1.12.2.tar.gz and nginx's fastdfs extension module installation package fastdfs-nginx-module-master.zip to
add nginx installation dependency
yum install gcc openssl openssl -devel pcre pcre-devel zlib zlib-devel -y
Unzip nginx
tar -zxvf nginx-1.12.2.tar.gz
Unzip fastdfs extension module
unzip fastdfs-nginx-module-master.zip
Configure nginx installation information for
2 tracker servers Configuration information (fastdfs module is not required)
./configure --prefix=/usr/local/nginx_fdfs
The configuration information of 4 storage servers (fastdfs module is required)
./configure --prefix=/usr/local/nginx_fdfs - add-module=/root/fastdfs-nginx-module-master/src
compile and install nginx
./make
./make install

4台storage的服务器需要拷贝mod_fastdfs文件
将/root/fastdfs-nginx-module-master/src目录下的mod_fastdfs.conf文件拷贝到 /etc/fdfs/目录下,这样才能正常启动Nginx;

The seventh step is to configure the nginx of the two tracker machines
into the installation directory
cd /usr/local/nginx_fdfs

添加一个location 对请求进行拦截,配置一个正则规则 拦截fastdfs的文件路径, 并将请求转发到其余的4台storage服务器(修改 conf目录下nginx.conf 文件)
#nginx拦截请求路径:
location ~ /group[1-9]/M0[0-9] {   
    proxy_pass http://fastdfs_group_server; 
}



添加一个upstream 执行服务的IP为 另外的4台stroage 的地址
#部署配置nginx负载均衡:
upstream fastdfs_group_server {  
    server 192.168.171.137:80;  
    server 192.168.171.138:80;
    server 192.168.171.139:80;  
    server 192.168.171.140:80;  
}

The eighth step is to configure another 4 storage nginx to add http access request path interception.
Enter the installation directory
cd /usr/local/nginx_fdfs to
add a location to intercept the request, configure a regular rule to intercept the file path of fastdfs, and use the nginx module of fastdfs Forward the request (modify the nginx.conf file in the conf directory)
#nginx intercept request path:
location ~ /group[1-9]/M0[0-9] { ngx_fastdfs_module; }

The ninth step is to modify the mod_fasfdfs.conf file (/etc/fdfs/mod_fastdfs.conf) of the 4 storage servers respectively #Modify the
base path and create the corresponding folder in the specified path
base_path=/opt/fastdfs/nginx_mod #Save log directory
# Specify the ip and port of the two tracker servers
tracker_server=192.168.171.135:22122 #The IP address and port number of the tracker server tracker_server=192.168.171.136:22122 #Specify the port number of the storage server storage_server_port=23000
#No need to modify in general #Specify The name of the group to which the current storage server belongs (the current cases 03 and 04 are group1 05 and 06 are group2) group_name=group1 #The group name of the current server #Specify whether the group name is included in the url path (the current case url contains the group name) url_have_group_name= true # Whether there is a group name in the file url store_path_count=1 #The number of storage paths, need to match the number of store_path (generally do not need to change) store_path0=/opt/fastdfs/storage/files #Storage path # Specify the number of groups, according to the actual Configuration decision, (the current case has 2 groups group1 and group2) group_count = 2 #Set the number of groups









在末尾增加2个组的具体信息:
[group1]
group_name=group1
storage_server_port=23000
store_path_count=1
store_path0=/opt/fastdfs/storage/files

[group2]
group_name=group2
storage_server_port=23000
store_path_count=1
store_path0=/opt/fastdfs/storage/files

第一个组的第二个storage按照相同的步骤操作;

另外一个组的两个storage也按照相同的步骤操作;

#测试nginx的配置文件是否正确(测试全部6台服务器)
   /usr/local/nginx_fdfs/sbin/nginx -c /usr/local/nginx_fdfs/conf/nginx.conf -t
#启动nginx服务器(全部6台服务器)
  /usr/local/nginx_fdfs/sbin/nginx -c /usr/local/nginx_fdfs/conf/nginx.conf

Test: Use a browser to access the fastdfs files in the 6 servers respectively

Step 10: Deploy front-end users to access the entry server, that is, access Nginx on 192.168.230.128. The Nginx is load balanced to the back-end 2 tracker servers;
configure the nginx.conf file
location ~ /group[1-9]/M0[0 -9] { proxy_pass http://fastdfs_group_server; }

添加一个upstream 执行服务的IP为 2台tracker 的地址
#部署配置nginx负载均衡:
upstream fastdfs_group_server {  
    server 192.168.171.135:80;  
    server 192.168.171.136:80; 
}

Test: Use a browser to access the fastdfs file in the 128 (the only entry nginx server) server.
Note: Since the previous 128 nginx may have static resource interception, the file cannot be accessed. At this time, you can comment or delete these static resource interceptors.

additional materials==============
Finally, in order for the service to connect to the tracker normally, please turn off the firewalls of all machines:
systemctl status firewalld View the firewall status
systemctl disable firewalld Disable the startup firewall
systemctl stop firewalld Stop the firewall
systemctl restart network restart network
systemctl start network start network
systemctl stop network stop network

It is possible that the installed linux (without graphics) does not have the network card service enabled, you can modify the network card configuration file under /etc/sysconfig/network-scripts to set ONBOOT=yse to
start the network card, and then start the network service.

Keepalived is a software that will automatically switch to the standby nginx server when the main nginx fails, usually by operation and maintenance personnel

Guess you like

Origin blog.csdn.net/qq_36905956/article/details/105227041