1. Install and start the software
Go-fastdfs limits one IP address to one service for high availability (can you have multiple servers on one machine?). ; We can start multiple Go-Fastdfs services using a Docker installation that specifies the IP of the container
Start the two Go-FastdFS services and set the internal IP address to 10.88.0.3 and 10.88.0.5 respectively
$docker run --name fastdfs1 --network bridge -- IP 10.88.0.3 -d -v /opt/fastdfs_data1:/data -p 10001:8080-e GO_FASTDFS_DIR=/data sjqzhang/go-fastdfs $docker run --name fastDFS2 --network bridge -- IP 10.88.0.5 -d -v /opt/fastdfs_data2:/data -p 10002:8080 -e GO_FASTDFS_DIR=/data sjqzhang/go-fastdfsCopy the code
If external access is not required, the port is not mapped
$docker run --name fastdfs1 --network bridge -- IP 10.88.0.3 -d -v /opt/fastdfs_data1:/data -e GO_FASTDFS_DIR=/data Sjqzhang /go-fastdfs $docker run --name fastdfs2 --network bridge -- IP 10.88.0.5 -d -v /opt/fastdfs_data2:/ data-e GO_FASTDFS_DIR=/data sjqzhang/go-fastdfsCopy the code
2. Modify the configuration and restart
10.88.0.3 Modifying the Configuration file in /opt/fastdfs_data1/conf/cfg.json. The main parameters are as follows:
"PeerID": "Unique in the cluster. Use a single character from 0 to 9." is automatically generated by default. "Peer_id ": "3"," local host address ": "Local HTTP address, automatically generated by default (note that the port must be the same as the port in addr). The segment must be internal network. If it is not internal network, change it by yourself. ", "host": "http://10.88.0.3:8080"," cluster ": "List of peers, note that IP addresses must not be the same for high availability, cannot be automatically backed up, cannot be 127.0.0.1, and must be internal IP addresses, automatically generated by default ", "peers": [" http://10.88.0.3:8080 ", "http://10.88.0.5:8080"),Copy the code
10.88.0.5 Modifying the configuration file in /opt/fastdfs_data2/conf/cfg.json. The following parameters are modified:
"PeerID": "Unique in the cluster. Use a single character from 0 to 9." is automatically generated by default. "peer_id": "5", "local host address ": "Local HTTP address, automatically generated by default (note that the port must be the same as the port in addr). The segment must be internal network. If it is not internal network, change it by yourself. ", "host": "http://10.88.0.5:8080"," cluster ": "List of peers, note that IP addresses must not be the same for high availability, cannot be automatically backed up, cannot be 127.0.0.1, and must be internal IP addresses, automatically generated by default ", "peers": [" http://10.88.0.3:8080 ", "http://10.88.0.5:8080"),Copy the code
restart
$ docker restart fastdfs1 fastdfs2
Copy the code
3. Local test
Open the browser at http://10.88.0.3:8080 and upload the file, for example, demo-subpackes.b42a3adB.zip
Upload result:
{" data ": {" domain" : "http://10.88.0.3:8080", "md5" : "b42a3adbf89bd645d94a2d5834720843", "mtime:" 1597546859, "path" : "/group1/default/20200816/11/00/4/demo-subpackages.b42a3adb.zip", "retcode": 0, "retmsg": "", "scene": "default", "scenes": "default", "size": 242389, "src": "/group1/default/20200816/11/00/4/demo-subpackages.b42a3adb.zip", "url": "Http://10.88.0.3:8080/group1/default/20200816/11/00/4/demo-subpackages.b42a3adb.zip"}, "message" : ""," status ":" ok "}Copy the code
Test and http://10.88.0.3:8080/group1/default/20200816/11/00/4/demo-subpackages.b42a3adb.zip http://10.88.0.5:8080/group1/default/20200816/11/00/4/demo-subpackages.b42a3adb.zip no problem.
4. Nginx single-cluster configuration
Modify the nginx configuration by setting server_name and other configurations as required, such as mapping to the domain name file.izqy.top
worker_processes 1; events { worker_connections 1024; } http { include mime.types; default_type application/html; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access.log main; error_log /var/log/nginx/error.log error; sendfile on; keepalive_timeout 65; client_max_body_size 0; proxy_redirect ~/big/upload/(.*) /big/upload/$1; Upstream go-fastdfs {server 10.88.0.3:8080; Server 10.88.0.5:8080; ip_hash; #notice:very important} server {listen 80; server_name localhost file.izqy.top; location / { proxy_set_header Host $host; #notice:very important proxy_set_header x-real-ip $remote_addr; [notice: this item is forwarded_forwarded_for $FORWARded_forwarded_forwarded_for; #notice:very important proxy_pass http://go-fastdfs; }}}Copy the code
After restarting nginx, visit http://file.izqy.top to test and upload the download, Check whether the uploaded file is saved to /opt/fastdfs_data1/files/default and /opt/ fastDFs_data2 /files/default.