nmt---Docker-compose自动化部署

1. 安装docker

source docker.sh

2. 安装pip

yum -y install python2-pip

3. 升级pip

pip install --upgrade pip==20.3 -i https://mirrors.aliyun.com/pypi/simple

4. 安装docker-compose

pip install docker-compose -i https://mirrors.aliyun.com/pypi/simple

5. 创建pes⽬录以及⼦⽬录

cd mkdir -p pes/{msyql,java,web}

6. 在pes⽬录下创建并且编辑dockerr-compose.yml⽂件

cd pes

vim docker-compose.yml

version: "3"

        servies:

        web: c

                ontainer_name: web0

                image: nginx:latest

                ports:

                - "80:80"

                expose:

                - 80

                volumes:

                - ./web/src/dist/:/usr/share/nginx/html/

                restart: "always"        

        java:

        mysql:

7. 添加web服务

web:

        container_name: web0         

        image: nginx:latest

        ports:

        - "80:80"

        expose:

        - 80

        volumes:

         - ./web/src/dist/:/usr/share/nginx/html/

        restart: "always"

8. docker-compose启动集群

cd pes

docker-compose up -d

9. docker-compose暂停集群

cd pes

docker-compose stop

10. docker-compose移除容器

docker-compose down

11. docker-compose多开容器

docker-compose up -d --scale web=5

使⽤docker-compose

docker-compose.yml

vim ./pes/docker-compose

version: "3"

        services:

        weba:

                container_name:

                web0 image: nginx:latest

                #ports:

                #- "80:80"

                expose:

                 - 80

                volumes: - ./web/src/dist/:/usr/share/nginx/html/

        webb:

                container_name: web1 i

                mage: nginx:latest

                #ports:

                #- "80:80"

               expose:

                - 80

                volumes:

                - ./web/src/dist/:/usr/share/nginx/html/

        webc:

                container_name: web2

                image: nginx:latest

                #ports:

                #- "80:80"

                expose:

                - 80

                volumes: - ./web/src/dist/:/usr/share/nginx/html/

        javaa:

                container_name: java0

                build: ./java #这个java⽬录下必须要有Dockerfile

                #ports:

                #- "8080:8080"

                expose:

                - 8080

                volumes: - ./java/src/:/java/src/

        javab:

                container_name: java1

                build: ./java #这个java⽬录下必须要有Dockerfile

                #ports:

                #- "8080:8080"

                expose: - 8080

                volumes: - ./java/src/:/java/src/

        mysql:

                container_name: mysql0

                image: mysql:5.7.44

                ports:

                - "3306:3306"

                expose:

                - 3306

                volumes: - ./mysql/data/:/var/lib/mysql/

        haproxy:

                container_name: haproxy0

                image: haproxy:latest

                ports:

                - "8888:8888"

                - "5000:5000"

                - "8080:8080"

                volumes: - ./haproxy/haproxy/haproxy.cfg:/usr/local/etc/haprox y/haproxy.cfg

                links:

                - web0

                - web1

                - web2

                - java0

                - java1

haproxy.cfg

######## 监控界⾯配置 #################

listen admin_status

        # 监控界⾯访问信息

       bind 0.0.0.0:8888

       mode http

        # URI相对地址

       stats uri /dbs

        # 统计报告格式

       stats realm Global\ statistics

        # 登录账户信息

       stats auth admin:123456

########frontend配置##############

######## 代理nginx服务 ###############

listen proxy-web

       bind 0.0.0.0:5000

       mode http

        # 负载均衡算法

        # static-rr 权重, leastconn 最少连接, source 请求IP, 轮询 roundrobin

       balance roundrobin

        # ⽇志格式

       option tcplog

        # 在 mysql 创建⼀个没有权限的haproxy⽤户,密码为空。 haproxy⽤户

        # create user 'haproxy'@'%' identified by''; FLUSH PRIVILEGES;

        #option mysql-check user haproxy

         # 这⾥是容器中的IP地址,由于配置的是轮询roundrobin,weight 权重其实没有⽣效

       server web0 web0:80 check weight 1 maxconn2000

       server web1 web1:80 check weight 1 maxconn2000

       server web2 web2:80 check weight 1 maxconn2000

        #server MYSQL_3 192.168.130.102:3306 checkweight 1 maxconn 2000

        # 使⽤keepalive检测死链

        # option tcpka

########################################

######## java的负载均衡配置 ###############

listen proxy-java

       bind 0.0.0.0:8080

       mode http

        # 负载均衡算法

        # static-rr 权重, leastconn 最少连接, source 请求IP, 轮询 roundrobin

       balance roundrobin

        # ⽇志格式

       option tcplog

        # 在 mysql 创建⼀个没有权限的haproxy⽤户,密码为空。 haproxy⽤户

        # create user 'haproxy'@'%' identified by''; FLUSH PRIVILEGES;

        #option mysql-check user haproxy

         # 这⾥是容器中的IP地址,由于配置的是轮询roundrobin,weight 权重其实没有⽣效

        server javaa java0:8080 check weight 1maxconn 200

        server javab java1:8080 check weight 1maxconn 2000

        #server MYSQL_3 192.168.130.102:3306 checkweight 1 maxconn 2000

        # 使⽤keepalive检测死链

        # option tcpka

#########################################

Application.properties

spring.datasource.url=jdbc:mysql://192.168.71.10:3306/project_exam_system

spring.datasource.username=zhangmin

spring.datasource.password=zhangmin

spring.datasource.driver-classname=com.mysql.cj.jdbc.Driver

你可能感兴趣的:(云计算学习,docker,自动化,容器,运维)