docker-compose文件

//安装docker和docker—compose

yum install -y yum-utils

yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo



yum install -y docker

yum list installed | grep docker

//启动docker
systemctl start docker

//设置开机自启
systemctl enable docker


sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
    "registry-mirrors": ["http://hub-mirror.c.163.com"]
}
EOF

systemctl daemon-reload
//重新启动docker
systemctl restart docker.service




###  docker-compose 安装
curl -L https://get.daocloud.io/docker/compose/releases/download/1.25.5/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose


## 授权
chmod +x /usr/local/bin/docker-compose

# 验证安装
docker-compose -v



#重启防火墙
service firewalld restart

# 重启docker服务
systemctl daemon-reload
systemctl restart docker.service



#卸载docker
yum remove docker  docker-common docker-selinux docker-engine
rm -rf /var/lib/docker

sudo rm /usr/local/bin/docker-compose
version : '3.8'
services:
  cxcsp-canal:
    container_name: cxcsp-canal
    image: canal/canal-server:v1.1.4
    ports:
    - "11111:11111"
    volumes:
    - ./canal/conf/canal.properties:/home/admin/canal-server/conf/canal.properties
    - ./canal/conf/instance.properties:/home/admin/canal-server/conf/example/instance.properties
    - ./canal/log:/home/admin/canal-server/logs
    depends_on:
      - cxcsp-mysql
    links:
      - cxcsp-mysql
  cxcsp-mysql:
    container_name: cxcsp-mysql
    image: mysql:5.7
    build:
      context: ./mysql
      dockerfile: dockerfile
    ports:
      - "3306:3306"
    volumes:
      - ./mysql/conf:/etc/mysql/conf.d
      - ./mysql/logs:/logs
      - ./mysql/data:/var/lib/mysql
    command: [
          'mysqld',
          '--innodb-buffer-pool-size=80M',
          '--character-set-server=utf8mb4',
          '--collation-server=utf8mb4_unicode_ci',
          '--default-time-zone=+8:00',
          '--lower-case-table-names=1',
          '--log-bin=mysql-bin',
          '--binlog-format=ROW',
          '--server-id=1'
        ]
    environment:
      MYSQL_DATABASE: 'cxcsp'
      MYSQL_ROOT_PASSWORD: go6mcYM!rO%nU!8I
  cxcsp-nginx:
    container_name: cxcsp-nginx
    image: nginx
    build:
      context: ./nginx
    ports:
      - "80:80"
    volumes:
      - ./nginx/html/cxcsp-guide:/home/cxcsp/cxcsp-guide
      - ./nginx/conf/nginx.conf:/etc/nginx/nginx.conf
      - ./nginx/cert:/etc/nginx/cert
      - ./nginx/conf.d:/etc/nginx/conf.d
      - ./nginx/logs:/var/log/nginx
  cxcsp-redis:
    container_name: cxcsp-redis
    image: redis
    build:
      context: ./redis
    ports:
      - "6379:6379"
    volumes:
      - ./redis/conf/redis.conf:/home/cxcsp/redis/redis.conf
      - ./redis/data:/data
    command: redis-server /home/cxcsp/redis/redis.conf
  cxcsp-rmq-namesrv:
    container_name: cxcsp-rmq-namesrv
    image: apache/rocketmq:4.9.1
    ports:
    - "9876:9876"
    volumes:
    - ./rocketmq/namesrv/logs:/root/logs
    - ./rocketmq/namesrv/store:/root/store
    environment:
      MAX_POSSIBLE_HEAP: 100000000
    command:
      sh mqnamesrv
  cxcsp-rmq-broker:
    container_name: cxcsp-rmq-broker
    image: apache/rocketmq:4.9.1
    ports:
    - "10911:10911"
    - "10909:10909"
    volumes:
    - ./rocketmq/broker/logs:/root/logs
    - ./rocketmq/broker/store:/root/store
    - ./rocketmq/conf/broker.conf:/opt/rocketmq-4.9.1/conf/broker.conf
    environment:
      NAMESRV_ADDR: namesrv:9876
      MAX_POSSIBLE_HEAP: 200000000
    command:
      sh mqbroker -c /opt/rocketmq-4.9.1/conf/broker.conf
    links:
      - cxcsp-rmq-namesrv
  cxcsp-rmq-console:
    container_name: cxcsp-rmq-console
    image: styletang/rocketmq-console-ng
    ports:
    - "19999:8080"
    environment:
      JAVA_OPTS: "-Drocketmq.namesrv.addr=cxcsp-rmq-namesrv:9876 -Dcom.rocketmq.sendMessageWithVIPChannel=false"
    links:
      - cxcsp-rmq-namesrv
  cxcsp-main:
    container_name: cxcsp-main
    build:
      context: starter/cxcsp
      dockerfile: dockerfile
    ports:
      - "9900:9900"
    depends_on:
      - cxcsp-mysql
      - cxcsp-redis
      - cxcsp-rmq-namesrv
    links:
      - cxcsp-mysql
      - cxcsp-redis
      - cxcsp-rmq-namesrv
  cxcsp-api:
    container_name: cxcsp-api
    build:
      context: starter/cxcsp-api
      dockerfile: dockerfile
    ports:
      - "9901:9901"
    depends_on:
      - cxcsp-mysql
      - cxcsp-redis
      - cxcsp-rmq-namesrv
    links:
      - cxcsp-mysql
      - cxcsp-redis
      - cxcsp-rmq-namesrv
  cxcsp-canal-monitor:
    container_name: cxcsp-canal-monitor
    build:
      context: starter/cxcsp-canal
      dockerfile: dockerfile
    ports:
      - "8971:8971"
    depends_on:
      - cxcsp-mysql
      - cxcsp-redis
      - cxcsp-canal
    links:
      - cxcsp-mysql
      - cxcsp-redis
      - cxcsp-canal
  cxcsp-cmpp:
    container_name: cxcsp-cmpp
    build:
      context: starter/cxcsp-cmpp
      dockerfile: dockerfile
    ports:
      - "8090:8090"
    depends_on:
      - cxcsp-mysql
      - cxcsp-redis
      - cxcsp-rmq-namesrv
    links:
      - cxcsp-mysql
      - cxcsp-redis
      - cxcsp-rmq-namesrv
  cxcsp-oc:
    container_name: cxcsp-oc
    build:
      context: starter/cxcsp-oc
      dockerfile: dockerfile
    ports:
      - "9903:9903"
    depends_on:
      - cxcsp-mysql
      - cxcsp-redis
      - cxcsp-rmq-namesrv
    links:
      - cxcsp-mysql
      - cxcsp-redis
      - cxcsp-rmq-namesrv

shell命令

#!/bin/sh

# 使用说明,用来提示输入参数
usage() {
    echo "Usage: sh 执行脚本.sh [port|base|modules|stop|rm]"
    exit 1
}

# 开启所需端口
port(){
    firewall-cmd --add-port=80/tcp --permanent    # nginx
    firewall-cmd --add-port=11111/tcp --permanent # canal
    firewall-cmd --add-port=3306/tcp --permanent  # mysql
    firewall-cmd --add-port=6379/tcp --permanent  # redis
    firewall-cmd --add-port=9876/tcp --permanent  # rmq-namesrv
    firewall-cmd --add-port=10911/tcp --permanent # rmq-broker
    firewall-cmd --add-port=10909/tcp --permanent # rmq-broker
    firewall-cmd --add-port=19999/tcp --permanent # rmq-console-ng
    firewall-cmd --add-port=9900/tcp --permanent  # cxcsp-main
    firewall-cmd --add-port=8971/tcp --permanent  # cxcsp-canal
    firewall-cmd --add-port=9901/tcp --permanent  # cxcsp-api
    firewall-cmd --add-port=8090/tcp --permanent  # cxcsp-cmpp
    firewall-cmd --add-port=9903/tcp --permanent  # cxcsp-oc
    service firewalld restart
}

# 启动基础环境(必须)
base(){
    docker-compose up -d cxcsp-canal cxcsp-mysql cxcsp-redis cxcsp-nginx cxcsp-rmq-namesrv cxcsp-rmq-broker cxcsp-rmq-console
}

# 启动程序模块(必须)
starter(){
    docker-compose up -d cxcsp-main cxcsp-api cxcsp-cmpp cxcsp-oc cxcsp-canal-monitor
}

# 关闭所有环境/模块
stop(){
    docker-compose stop
}

# 删除所有环境/模块
rm(){
    docker-compose rm
}

# 根据输入参数,选择执行对应方法,不输入则执行使用说明
case "$1" in
"port")
    port
;;
"base")
    base
;;
"starter")
    starter
;;
"stop")
    stop
;;
"rm")
    rm
;;
*)
    usage
;;
esac
docker-compose文件_第1张图片

你可能感兴趣的:(docker,数据库,nginx)