APISIX Docker 部署

2024-07-27 690 0

3.6 集成apisix-dashboard, 之后版本则没有
https://github.com/apache/apisix-docker/blob/release/apisix-3.6.0/example/docker-compose.yml
可参考

下载Apisix Docker源码

root@apisix:~# git clone -b release/apisix-3.6.0 https://github.com/apache/apisix-docker.git
root@apisix:~# cd apisix-docker
root@apisix:~# cp example/apisix_conf/config.yaml{,.bak}

root@apisix:~# vim example/apisix_conf/config.yaml

apisix:
  node_listen: 
    - 9080 # APISIX 默认HTTP端口, 可以删除
    - 80
  ssl: # 添加ssl模块,开启https
    enable: true
    listen:
      - port: 443
      - port: 9443 # APISIX 默认HTTPS端口, 可以删除
  enable_ipv6: false

  enable_control: true # API管理端口
  control:
    ip: "0.0.0.0"
    port: 9092

deployment:
  admin:
    allow_admin:               # https://nginx.org/en/docs/http/ngx_http_access_module.html#allow
      - 0.0.0.0/0              # admin用户可以执行key的网段.

    admin_key:
      - name: "admin"
        key: edd1c9xxxxxxxxxxxxxxxxxxxxx # # 修改admin用户key, 生产不要用默认
        role: admin                 # admin: manage all configuration data

      - name: "viewer"
        key: 4054f7cf07e344346cd3f287985e76a2
        role: viewer

  etcd:
    host:                           # it's possible to define multiple etcd hosts addresses of the same etcd cluster.
      - "http://etcd:2379"          # multiple etcd address
    prefix: "/apisix"               # apisix configurations prefix
    timeout: 30                     # 30 seconds

plugin_attr:
  prometheus:
    export_addr:
      ip: "0.0.0.0"
      port: 9091

docker-compose.yaml配置调整

  • 开启80、443为默认端口
  • 删除docker-compose.yaml中不需要的web-01、web-02、Prometheus、Grafana
root@apisix:~/apisix-docker/example# cat docker-compose.yml

version: "3"

services:
  apisix-dashboard:
    image: apache/apisix-dashboard:3.0.1-alpine
    restart: always
    volumes:
    - ./dashboard_conf/conf.yaml:/usr/local/apisix-dashboard/conf/conf.yaml
    ports:
    - "9000:9000"
    networks:
      apisix:

  apisix:
    image: apache/apisix:${APISIX_IMAGE_TAG:-3.6.0-debian}
    restart: always
    volumes:
      - ./apisix_conf/config.yaml:/usr/local/apisix/conf/config.yaml:ro
    depends_on:
      - etcd
    ##network_mode: host
    ports:
      - "9180:9180/tcp"
      - "9080:9080/tcp"
      - "9091:9091/tcp"
      - "9443:9443/tcp"
      - "9092:9092/tcp"
      - "80:80/tcp" #开启apisix 80 443端口映射
      - "443:443/tcp" 
    networks:
      apisix:

  etcd:
    image: bitnami/etcd:3.4.15
    restart: always
    volumes:
      - etcd_data:/bitnami/etcd
    environment:
      ETCD_ENABLE_V2: "true"
      ALLOW_NONE_AUTHENTICATION: "yes"
      ETCD_ADVERTISE_CLIENT_URLS: "http://etcd:2379"
      ETCD_LISTEN_CLIENT_URLS: "http://0.0.0.0:2379"
    ports:
      - "2379:2379/tcp"
    networks:
      apisix:

#这里删除web-01 web-02 prometheus grafana相关镜像

networks:
  apisix:
    driver: bridge

volumes:
  etcd_data:
    driver: local

启动测试

root@apisix:~/apisix-docker/example# docker compose up -d
WARN[0000] /root/apisix-docker/example/docker-compose.yml: the attribute `version` is obsolete, it will be ignored, please remove it to avoid potential confusion 
[+] Running 4/4
 ✔ Network example_apisix                Created                                                                                                   0.2s 
 ✔ Container example-apisix-dashboard-1  Started                                                                                                   1.4s 
 ✔ Container example-etcd-1              Started                                                                                                   1.4s 
 ✔ Container example-apisix-1            Started  服务 http服务会返回404
root@apisix:~/apisix-docker/example# curl http://localhost
{"error_msg":"404 Route Not Found"}
root@apisix:~/apisix-docker/example# curl https://localhost
curl: (35) error:0A000438:SSL routines::tlsv1 alert internal error

dashboard

http://ip:9000
默认用户密码为admin:admin

root@apisix:~# vim apisix-docker/example/dashboard_conf/conf.yaml

...
authentication:
  secret:
    secret 
  expire_time: 3600     # jwt token expire time, in second
  users:                # yamllint enable rule:comments-indentation
    - username: admin   # username and password for login `manager api`
      password: admin  # 修改密码
    - username: user
      password: user
...

相关文章

发布评论