一、安装Docker

环境:CentOS7

安装官方给的方法进行安装,首先先卸载旧版本的环境:

  1. $ sudo yum remove docker \
  2. docker-client \
  3. docker-client-latest \
  4. docker-common \
  5. docker-latest \
  6. docker-latest-logrotate \
  7. docker-logrotate \
  8. docker-engine

2.png
没找到,没找到正常,因为服务器从来没安装过docker,哈哈哈哈

然后第二步,安装需要的依赖:

  1. $ sudo yum install -y yum-utils
  2. $ sudo yum-config-manager \
  3. --add-repo \
  4. https://download.docker.com/linux/centos/docker-ce.repo

然后安装最新的Docker:

  1. $ sudo yum install docker-ce docker-ce-cli containerd.io

安装完成后,我们启动docker:

  1. systemctl start docker

查看docker是否安装成功:

  1. docker -v

3.png
docker下载源默认是国外的,我们需要切换到国内源:

我这里选用的是网易的源,首先修改或新增 /etc/docker/daemon.json,修改内容为:

  1. vi /etc/docker/daemon.json
  2. {
  3. "registry-mirrors": ["http://hub-mirror.c.163.com"]
  4. }
  5. systemctl restart docker

二、安装Docker-Compose

  1. sudo curl -L "https://github.com/docker/compose/releases/download/1.27.4/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

下载慢可以用这个:

  1. curl -L https://get.daocloud.io/docker/compose/releases/download/1.27.4/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose

赋予可执行权限:

  1. sudo chmod +x /usr/local/bin/docker-compose

然后查看版本:

  1. docker-compose --version

1.png
说明docker-compose已经安装成功

三、用Docker-Compose搭建MinIO集群

查看官方文档,下载docker-compose.yaml与nginx.conf

docker-compose.yaml

  1. version: '3.7'
  2. # starts 4 docker containers running minio server instances.
  3. # using nginx reverse proxy, load balancing, you can access
  4. # it through port 9000.
  5. services:
  6. minio1:
  7. image: minio/minio:RELEASE.2020-11-19T23-48-16Z
  8. volumes:
  9. - data1-1:/data1
  10. - data1-2:/data2
  11. expose:
  12. - "9000"
  13. environment:
  14. MINIO_ACCESS_KEY: minio
  15. MINIO_SECRET_KEY: minio123
  16. command: server http://minio{1...4}/data{1...2}
  17. healthcheck:
  18. test: ["CMD", "curl", "-f", "http://localhost:9000/minio/health/live"]
  19. interval: 30s
  20. timeout: 20s
  21. retries: 3
  22. minio2:
  23. image: minio/minio:RELEASE.2020-11-19T23-48-16Z
  24. volumes:
  25. - data2-1:/data1
  26. - data2-2:/data2
  27. expose:
  28. - "9000"
  29. environment:
  30. MINIO_ACCESS_KEY: minio
  31. MINIO_SECRET_KEY: minio123
  32. command: server http://minio{1...4}/data{1...2}
  33. healthcheck:
  34. test: ["CMD", "curl", "-f", "http://localhost:9000/minio/health/live"]
  35. interval: 30s
  36. timeout: 20s
  37. retries: 3
  38. minio3:
  39. image: minio/minio:RELEASE.2020-11-19T23-48-16Z
  40. volumes:
  41. - data3-1:/data1
  42. - data3-2:/data2
  43. expose:
  44. - "9000"
  45. environment:
  46. MINIO_ACCESS_KEY: minio
  47. MINIO_SECRET_KEY: minio123
  48. command: server http://minio{1...4}/data{1...2}
  49. healthcheck:
  50. test: ["CMD", "curl", "-f", "http://localhost:9000/minio/health/live"]
  51. interval: 30s
  52. timeout: 20s
  53. retries: 3
  54. minio4:
  55. image: minio/minio:RELEASE.2020-11-19T23-48-16Z
  56. volumes:
  57. - data4-1:/data1
  58. - data4-2:/data2
  59. expose:
  60. - "9000"
  61. environment:
  62. MINIO_ACCESS_KEY: minio
  63. MINIO_SECRET_KEY: minio123
  64. command: server http://minio{1...4}/data{1...2}
  65. healthcheck:
  66. test: ["CMD", "curl", "-f", "http://localhost:9000/minio/health/live"]
  67. interval: 30s
  68. timeout: 20s
  69. retries: 3
  70. nginx:
  71. image: nginx:1.19.2-alpine
  72. volumes:
  73. - ./nginx.conf:/etc/nginx/nginx.conf:ro
  74. ports:
  75. - "9000:9000"
  76. depends_on:
  77. - minio1
  78. - minio2
  79. - minio3
  80. - minio4
  81. ## By default this config uses default local driver,
  82. ## For custom volumes replace with volume driver configuration.
  83. volumes:
  84. data1-1:
  85. data1-2:
  86. data2-1:
  87. data2-2:
  88. data3-1:
  89. data3-2:
  90. data4-1:
  91. data4-2:

nginx.conf

  1. user nginx;
  2. worker_processes auto;
  3. error_log /var/log/nginx/error.log warn;
  4. pid /var/run/nginx.pid;
  5. events {
  6. worker_connections 1024;
  7. }
  8. http {
  9. include /etc/nginx/mime.types;
  10. default_type application/octet-stream;
  11. log_format main '$remote_addr - $remote_user [$time_local] "$request" '
  12. '$status $body_bytes_sent "$http_referer" '
  13. '"$http_user_agent" "$http_x_forwarded_for"';
  14. access_log /var/log/nginx/access.log main;
  15. sendfile on;
  16. #tcp_nopush on;
  17. keepalive_timeout 65;
  18. #gzip on;
  19. # include /etc/nginx/conf.d/*.conf;
  20. upstream minio {
  21. server minio1:9000;
  22. server minio2:9000;
  23. server minio3:9000;
  24. server minio4:9000;
  25. }
  26. server {
  27. listen 9000;
  28. listen [::]:9000;
  29. server_name localhost;
  30. # To allow special characters in headers
  31. ignore_invalid_headers off;
  32. # Allow any size file to be uploaded.
  33. # Set to a value such as 1000m; to restrict file size to a specific value
  34. client_max_body_size 0;
  35. # To disable buffering
  36. proxy_buffering off;
  37. location / {
  38. proxy_set_header Host $http_host;
  39. proxy_set_header X-Real-IP $remote_addr;
  40. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  41. proxy_set_header X-Forwarded-Proto $scheme;
  42. proxy_connect_timeout 300;
  43. # Default is HTTP/1, keepalive is only enabled in HTTP/1.1
  44. proxy_http_version 1.1;
  45. proxy_set_header Connection "";
  46. chunked_transfer_encoding off;
  47. proxy_pass http://minio;
  48. }
  49. }
  50. }

然后执行命令

  1. docker-compose pull
  2. docker-compose up -d /*-d代表后台运行*/

然后查看docker状态

  1. docker ps

4.png
这样,用docker-compose搭建minio集群就完成了

查看日志:
5.png
这样利用docker-compose搭建minio分布式就成功了