当前位置:   article > 正文

docker+k3s部署GZCTF

gzctf



k3s官网

gzctf官方部署文档地址

gzctf官网

一、准备工作

1、准备三台服务器(gzctfweb、k3s-master、k3s-slave)

nameip
gzctfweb192.168.8.100
k3s-master192.168.8.101
k3s-slave192.168.8.102

2、修改用户名

  1. hostnamectl set-hostname gzctfweb  # gzctfweb服务器执行
  2. hostnamectl set-hostname k3s-master
  3. hostnamectl set-hostname k3s-slave

3、关闭防火墙、清空iptables规则、(所有机器执行)

  1. systemctl disable firewalld && systemctl stop firewalld
  2. iptables -F

4、关闭swap分区,关闭selinux(k3s-master和k3s-slave机器执行)

  1. sed -ri 's#(SELINUX=).*#\1disabled#' /etc/selinux/config
  2. setenforce 0
  3. swapoff -a
  4. sed -i ' / swap / s/^\(.*\)$/#\1/g' /etc/fstab

5、配置hosts解析(k3s-master和k3s-slave机器执行)

  1. cat >>/etc/hosts<<EOF
  2. 192.168.8.101 k3s-master
  3. 192.168.8.102 k3s-slave
  4. EOF

二、安装docker(k3s-master和k3s-slave机器执行)

  1. curl https://releases.rancher.com/install-docker/20.10.sh | sh
  2. systemctl enable --now docker  # docker开启自启

三、安装k3s集群

1、k3s-master节点执行:

curl -sfL https://rancher-mirror.rancher.cn/k3s/k3s-install.sh | INSTALL_K3S_MIRROR=cn INSTALL_K3S_EXEC="--docker --kube-controller-manager-arg=node-cidr-mask-size=18" sh -

systemctl enable --now k3s  # k3sserver自启

注意:在安装slave节点时,先在master节点用如下命令查看token

cat /var/lib/rancher/k3s/server/node-token

2、k3s-slave节点执行:

curl -sfL https://rancher-mirror.rancher.cn/k3s/k3s-install.sh | INSTALL_K3S_MIRROR=cn INSTALL_K3S_EXEC="--docker" K3S_URL=https://myserver:6443 K3S_TOKEN=mytoken sh -  

# myserver:master节点的ip、mytoken就是在master节点查看到的内容

systemctl enable --now k3s.agent   # 开启自启

3、更改 NodePort 端口范围(k3s-master机器执行)

vim /etc/systemd/system/k3s.service

在ExecStart=/usr/local/bin/k3s最后写入如下内容
 

    --kube-apiserver-arg service-node-port-range=20000-50000

4、更改 K3s 的容器数量限制(k3s-master和k3s-slave机器执行)

①:

vim /etc/rancher/k3s/kubelet.config


编写如下内容:
 

  1. apiVersion: kubelet.config.k8s.io/v1beta1
  2. kind: KubeletConfiguration
  3. maxPods: 500  # 容器数量限制

②:

vim /etc/systemd/system/k3s.service

在ExecStart=/usr/local/bin/k3s最后写入如下内容:

--kubelet-arg=config=/etc/rancher/k3s/kubelet.config

5、添加容器镜像仓库(k3s-master机器执行)

vim /etc/rancher/k3s/registries.yaml


写入以下内容(我用的是docker仓库,这里可以根据自己的实际情况更改):
 

  1. mirrors:
  2.   "docker.io":
  3.     endpoint:
  4.       - "https://hub.docker.com"

6、重启k3s集群  

  1. systemctl daemon-reload && systemctl restart k3s  # master节点
  2. systemctl daemon-reload && systemctl restart k3s-agent # slave节点

四、搭建gzctf(在gzctfweb机器上执行)

1、准备文件

docker-compose.yml  #在k3s官网下载

  1. version: '3.0'
  2. services:
  3. gzctf:
  4. image: gztime/gzctf:latest
  5. restart: always
  6. environment:
  7. - "GZCTF_ADMIN_PASSWORD=myctfpassword" # gzctf管理员初始密码
  8. ports:
  9. - "8080:80"
  10. networks:
  11. default:
  12. volumes:
  13. - "./data/files:/app/uploads"
  14. - "./appsettings.json:/app/appsettings.json:ro"
  15. - "./logs:/app/log"
  16. # - "./data/keys:/root/.aspnet/DataProtection-Keys"
  17. - "./k8sconfig.yaml:/app/k8sconfig.yaml:ro"
  18. # - "/var/run/docker.sock:/var/run/docker.sock"
  19. depends_on:
  20. - db
  21. db:
  22. image: postgres:alpine
  23. restart: always
  24. environment:
  25. - "POSTGRES_PASSWORD=mydbpassword" # 数据库的密码
  26. networks:
  27. default:
  28. volumes:
  29. - "./data/db:/var/lib/postgresql/data"
  30. networks:
  31. default:
  32. driver: bridge
  33. ipam:
  34. config:
  35. - subnet: 192.168.12.0/24


appsettings.json  # 在k3s官网下载

  1. {
  2. "AllowedHosts": "*",
  3. "ConnectionStrings": {
  4. "Database": "Host=db:5432;Database=gzctf;Username=postgres;Password=mydbpassword" //数据库的信息
  5. // redis is optional
  6. //"RedisCache": "cache:6379,password=<Redis Password>"
  7. },
  8. "Logging": {
  9. "LogLevel": {
  10. "Default": "Information",
  11. "Microsoft": "Warning",
  12. "Microsoft.Hosting.Lifetime": "Information"
  13. }
  14. },
  15. "EmailConfig": {
  16. "SendMailAddress": "a@a.com",
  17. "UserName": "",
  18. "Password": "",
  19. "Smtp": {
  20. "Host": "localhost",
  21. "Port": 587
  22. }
  23. },
  24. "XorKey": "<Random Key Str>",
  25. "ContainerProvider": {
  26. "Type": "Kubernetes", // or "Kubernetes"
  27. "PublicEntry": "192.168.100.101", // or "xxx.xxx.xxx.xxx" //这里可以写k3s-master的ip
  28. "DockerConfig": {
  29. // optional
  30. "SwarmMode": false,
  31. "Uri": "unix:///var/run/docker.sock"
  32. }
  33. },
  34. "RequestLogging": false,
  35. "DisableRateLimit": false,
  36. "RegistryConfig": {
  37. "UserName": "",
  38. "Password": "",
  39. "ServerAddress": ""
  40. },
  41. "GoogleRecaptcha": {
  42. "VerifyAPIAddress": "https://www.recaptcha.net/recaptcha/api/siteverify",
  43. "Sitekey": "",
  44. "Secretkey": "",
  45. "RecaptchaThreshold": "0.5"
  46. }
  47. }


k8sconfig.yaml  # 在master节点获取:cat /etc/rancher/k3s/k3s.yaml 保存为k8sconfig.yaml,
    修改k8sconfig.yaml中的server字段,将ip地址改为master节点ip,端口号不变

2. 将以上三个文件置于同一文件夹下

3、启动gzctf

docker compose -f docker-compose.yml up  # 前台运行,加-d参数可后台运行
docker compose -f docker-compose.yml stop  # 停止

docker compose -f docker-compose.yml rm  # 删除

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Gausst松鼠会/article/detail/559848
推荐阅读
相关标签
  

闽ICP备14008679号