美文网首页docker
docker-compose 部署cmdb

docker-compose 部署cmdb

作者: _str_ | 来源:发表于2019-11-21 20:30 被阅读0次

首先需要创建一下目录

image.png
按照这个目录一次创建文件
首先看看docker-compose.yml文件
注意:mysql默认只能普通用户访问 root不能外部访问
version: '3.2'

services:

  mysql:
    #build: ./docker-cmdb/mysql
    #image: mysql_db
    image: mysql/mysql-server:5.7
    container_name: mysql-cmdb
    expose:
      - "3306"
    volumes:
    #  - ./docker-cmdb/data/mysql/data:/var/lib/mysql    --不能挂载出去 默认是root用户数据 挂出去不能用
      - ./docker-cmdb/mysql/init:/docker-entrypoint-initdb.d/   -- compose编排的时候进行给普通用户创建并授权 
      - ./docker-cmdb/mysql/data:/var/lib/mysql
    networks:
      - jumpserver-test
    environment:
      MYSQL_ROOT_PASSWORD: QFedu123!

  redis:
    build: ./docker-cmdb/redis
    container_name: redis-cmdb
    expose:
      - "6379"
    restart: always
    volumes:
      - ./docker-cmdb/data/redis/data:/var/lib/redis
    networks:
      - jumpserver-test
   
  
  nginx:
    image: nginx:alpine3.8
   # build: ./docker-cmdb/nginx
    restart: always
    container_name: nginx-cmdb
    ports:
      - "9090:80"
    networks:
      - jumpserver-test
    volumes:
       - ./docker-cmdb/nginx/conf.d:/etc/nginx/conf.d
       - ./docker-cmdb/nginx/allstatic:/allstatic
    depends_on:
       - cmdb    

  rabbitmq:
     image: rabbitmq_rabbitmq 
     #build: ./docker-cmdb/rabbitmq
     container_name: rabbitmq-cmdb
     expose: 
       - "5672"
     networks: 
       - jumpserver-test
     volumes:
       - ./docker-cmdb/data/rabbitmq/data:/var/lib/rabbitmq

  cmdb:
    build: ./docker-cmdb/cmdb
    container_name: cmdb-server
    expose:
      - "8000"
    tty: true
    restart: always
    networks:
      - jumpserver-test
    volumes:
      - ./docker-cmdb/cmdb/auth_cmdb:/opt/auth_cmdb
    depends_on:
      - mysql
      - redis
      - rabbitmq
    command:
      - /bin/bash
      - -c 
      - | 
        cd /opt/auth_cmdb
        pip3 install uwsgi
        python3 manage.py makemigrations
        python3 manage.py migrate
        uwsgi --ini /opt/auth_cmdb/conf/auth_cmdb.ini
   
networks:
  jumpserver-test:

redis和rabbitmq只需要到官方docker仓库去找dockerfile就可以在compose里执行构建了

cmdb

把那个项目目录文件拷到这个文件夹下面


image.png

auth_cmdb 是项目文件
requirements.txt 是项目依赖环境

Dockefile
以本地镜像centos-python3.7为基础镜像

FROM centos7-python3.7:latest
ADD . /opt
RUN pip3 install -r /opt/requirements.txt 

compose中编排的时候直接就吧项目拷贝进去 然后把项目依赖环境给安装好

需要注意的是的 在nginx的文件夹中需要改conf.d的配置文件 具体如下

upstream django {
    server cmdb-server:8000;     ---cmdb-server 是容器名
}

server {
    listen      80;
    
    server_name  nginx-cmdb;     ---nginx-cmdb是容器名
    charset     utf-8;

   
    client_max_body_size 75M;  

    
    location /static {
        alias /allstatic; 
    }

    
    location / {
        uwsgi_pass  django; 
        include     uwsgi_params;
    }
}

在cmdb中的项目下的conf文件中的auth_cmdb.ini文件中修改

[uwsgi]
# 切换到工作目录
chdir = /opt/auth_cmdb
socket = cmdb-server:8000
#http = 172.21.0.2:80
#static-map = /static=/opt/cmdb-server/Auth_CMDB/auth_cmdb/allstatic
module = auth_cmdb.wsgi

master = true
processes = 6

# clear environment on exit
vacuum          = true

# 虚拟环境路径,按自己项目的虚拟环境路径填写,不要照抄!!!
#virtualenv = /root/.local/share/virtualenvs/Auth_CMDB-VyyRWCBC

logto = /tmp/auth_cmdb.log

相关文章

网友评论

    本文标题:docker-compose 部署cmdb

    本文链接:https://www.haomeiwen.com/subject/jptcictx.html