docker-compose服务编排(mysql、redis、mongo、nacos、rabbitmq、kafka、fastdfs、minio、es、seata、yapi、jenkins)

centos安装

JDK(√)

  1. 安装jdk

    • 去http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html中下载jdk的安装文件。由于我的Linux是64位的,因此我下载jdk-8u311-linux-x64.tar.gz文件。
    • 新建/data/java文件夹,将jdk-8u311-linux-x64.tar.gz放到该文件夹中,并将工作目录切换到/data/java目录下。
    • 执行命令tar -zxvf jdk-8u311-linux-x64.tar.gz 进行解压,解压后发现/data/java多了一个jdk1.8.0_311文件夹。
    • 通过以上步骤,jdk就已经全部安装完成了。下面,就是环境变量的配置。
  2. 配置环境变量/data/java/jdk1.8.0_311

    • 使用vi /etc/profile编辑profile文件

    • 在/etc/profile底部加入如下内容

      JAVA_HOME=/data/software/jdk1.8.0_361
      CLASSPATH=$JAVA_HOME/lib/

      PATH= P A T H : PATH: PATH:JAVA_HOME/bin
      export PATH JAVA_HOME CLASSPATH

    • 以上,环境变量配置完成。**需要注意的是,PATH在配置的时候,一定要把 J A V A H O M E / b i n 放在前面 ∗ ∗ ,不然使用 j a v a 命令时,系统会找到以前的 j a v a ,再不往下找了。这样 j a v a 这个可执行文件运行的目录其实不在 JAVA_HOME/bin放在前面**,不然使用java命令时,系统会找到以前的java,再不往下找了。这样java这个可执行文件运行的目录其实不在 JAVAHOME/bin放在前面,不然使用java命令时,系统会找到以前的java,再不往下找了。这样java这个可执行文件运行的目录其实不在JAVA_HOME/bin下,而在其它目录下,会造成很大的问题。

    • 还要注意,以前其它教程写的CLASSPATH=$JAVA_HOME/lib.tools.jar,不知道以前的版本是怎么样的,现在的版本是没有这样的jar包的

    • 最后使用source /etc/profile让profile文件立即生效。

  3. 测试

    • java -version
    • javac

docker服务编排

Mysql(√)

version: "3.5"
services:
  mysql:
    image: mysql:8.0.21
    container_name: mysql
    ports:
      - 3306:3306
    volumes:
      - /data/mysql:/var/lib/mysql
    environment:
      MYSQL_ROOT_PASSWORD: root
    networks:
      dream:
        aliases:
          - mysql
networks:
  dream:
    name: dream
    driver: bridge

Redis(√)

version: '3.5'
services:
myredis:
 container_name: redis
 image: redis:6.0.6
 restart: always
 ports:
   - 6379:6379
 privileged: true
 command: redis-server /etc/redis/redis.conf --appendonly yes --requirepass "redis"
 volumes:
   - /data/redis/data:/data
   - /data/redis/conf/redis.conf:/etc/redis/redis.conf
 networks:
   dream:
     aliases:
       - redis
networks:
  dream:
    name: dream
    driver: bridge

Mongo(√)

version: "3.5"
services:
  mongo:
    image: mongo:4.0.3
    container_name: mongo
    ports:
      - 27017:27017
    volumes:
      - /data/mongodb/db:/data/db
	environment:
      #MongoDB账户
	  MONGO_INITDB_ROOT_USERNAME: root
      #MongoDB密码
      MONGO_INITDB_ROOT_PASSWORD: root
    networks:
      dream:
        aliases:
          - mongo
networks:
  dream:
    name: dream
    driver: bridge

Nacos(√)

version: "3.5"
services:
  nacos:
    image: nacos/nacos-server:2.0.2
    container_name: nacos
    volumes:
      - /data/nacos/logs:/home/nacos/logs
    ports:
      - 8848:8848
    environment:
      - MODE=standalone
    networks:
      dream:
        aliases:
          - nacos
networks:
  dream:
    name: dream
    driver: bridge

http://114.116.1.116:8848/nacos nacos nacos

RabbitMQ(√)

version: '3.5'
services:
 rmqnamesrv:
    image: rabbitmq:3.9-management
    container_name: rabbitmq
    ports:
      - 5672:5672
      - 15672:15672
    volumes:
      - /data/rabbitmq/:/var/lib/rabbitmq
    networks:
      dream:
        aliases:
          - rabbitmq
networks:
  dream:
    name: dream
    driver: bridge

http://114.116.1.116:15672 guest guest

Kafka(√)

version: '2'
services:
  zookeeper:
    image: wurstmeister/zookeeper
    container_name: zookeeper
    ports:
      - "2181:2181"
    networks:
      - dream
  kafka:
    image: wurstmeister/kafka:2.12-2.3.0
    container_name: kafka
    ports:
      - "9092:9092"
    environment:
      KAFKA_ADVERTISED_HOST_NAME: 114.116.1.116
      KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
    networks:
      - dream
  kafdrop:
    image: obsidiandynamics/kafdrop
    container_name: kafdrop
    ports:
      - "9080:9000"
    environment:
      KAFKA_BROKERCONNECT: kafka:9092
      JVM_OPTS: "-Xms32M -Xmx64M"
      SERVER_SERVLET_CONTEXTPATH: "/"
    networks:
      - dream
networks:
  dream:
    driver: bridge

http://114.116.1.116:9080/

FastDFS(√)

version: '3.5'
services:
 tracker:
    image: delron/fastdfs
    container_name: tracker
    volumes:
      - /data/fastdfs/tracker:/var/fdfs
    command: tracker
    networks:
      dream:
        aliases:
          - tracker
  storage:
    image: delron/fastdfs
    container_name: storage
    volumes:
      - /data/fastdfs/storage:/var/fdfs
    environment:
      - TRACKER_SERVER=114.116.1.116:22122
      - GROUP_NAME=group1
    command: storage
    depends_on:
      - tracker
    networks:
      dream:
        aliases:
          - storage
networks:
  dream:
    name: dream
    driver: bridge
# 路径/opt/docker/fdfs/storage下创建test.txt文件
vi /data/fastdfs/storage/test.txt
# 进入storage容器
docker exec -it storage bash
# 进入/var/fdfs目录
cd /var/fdfs/
# 上传test.txt文件
/usr/bin/fdfs_upload_file /etc/fdfs/client.conf test.txt
# 返回文件下载路径
group1/M00/00/00/wKgshWBR2fqAEh8WAAAAC8CJ-Us546.txt
# 浏览器输入ip:port/下载路径(XXX.XXX.XXX.XXX为storage所在服务器的IP,页面将显示文件内容)
XXX.XXX.XXX.XXX:8888/group1/M00/00/00/wKgshWBR2fqAEh8WAAAAC8CJ-Us546.txt

MinIO(√)

version: '2'
services:
minio:
 image: minio/minio
 container_name: minio
 command: server --console-address ":9001" /data
 ports:
      - "9000:9000"
      - "9001:9001"
    environment:
      MINIO_ROOT_USER: minio
      MINIO_ROOT_PASSWORD: minio123
    volumes:
      - /data/minio/data:/data
      - /data/minio/config:/root/.minio
    networks:
      - dream
networks:
  dream:
    driver: bridge

http://192.168.31.34:9001/minio/ minio minio123

Elasticsearch + Kibana(√)

version: '2'
services:
  elasticsearch:
    image: elasticsearch:7.17.5
    container_name: es-elasticsearch
    ports:
      - "9200:9200"
      - "9300:9300"
    environment:
      - discovery.type=single-node
    volumes:
      - /data/elasticsearch/plugins:/usr/share/elasticsearch/plugins
    networks:
      - dream
  kibana:
    image: kibana:7.17.5
    container_name: es-kibana
    ports:
      - "5601:5601"
    environment:
      ELASTICSEARCH_HOSTS: http://114.116.1.116:9200
    networks:
      - dream
networks:
  dream:
    driver: bridge

安装ik分词器与py分词器

# 进入容器
docker exec -it es-elasticsearch /bin/bash
# 在线下载并安装
./bin/elasticsearch-plugin  install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v7.15.5/elasticsearch-analysis-ik-7.17.5.zip

# 退出并重启镜像
exit
docker restart elasticsearch

es-elasticsearch:http://114.116.1.116:9200

es-kibana:http://114.116.1.116:5601

Seata(√)

# 地址为seata官方提供
https://seata.io/zh-cn/docs/ops/deploy-by-docker-compose.html
# 准备registry.conf文件

registry {
type = "nacos"

nacos {
# seata服务注册在nacos上的别名,客户端通过该别名调用服务
 application = "seata-server"
# 请根据实际生产环境配置nacos服务的ip和端口
 serverAddr = "114.116.1.116:8848"
# nacos上指定的namespace
 namespace = ""
 cluster = "default"
 username = "nacos"
 password = "nacos"
}
}

config {
type = "nacos"

nacos {
 # 请根据实际生产环境配置nacos服务的ip和端口
 serverAddr = "127.0.0.1:8848"
 # nacos上指定的namespace
 namespace = "seata-db-config"
 group = "SEATA_GROUP"
 username = "nacos"
 password = "nacos"
# 从v1.4.2版本开始,已支持从一个Nacos dataId中获取所有配置信息,你只需要额外添加一个dataId配置项
 dataId: "seata_db_config"
}
}
# 准备nacos配置中心配置

# 存储模式
store.mode=db

store.db.datasource=druid
store.db.dbType=mysql
# 需要根据mysql的版本调整driverClassName
# mysql8及以上版本对应的driver:com.mysql.cj.jdbc.Driver
# mysql8以下版本的driver:com.mysql.jdbc.Driver
store.db.driverClassName=com.mysql.cj.jdbc.Driver
# 注意根据生产实际情况调整参数host和port
store.db.url=jdbc:mysql://127.0.0.1:3306/AAA_seata-server?serverTimezone=UTC&useUnicode=true&characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useSSL=false
# 数据库用户名
store.db.user=root
# 用户名密码
store.db.password=root
# 准备docker-compose.yaml文件
version: "3.1"
services:
seata-server:
 image: seataio/seata-server:1.5.1
 container_name: seata
 ports:
      - "8091:8091"
    environment:
      # 指定seata服务启动端口
      - SEATA_PORT=8091
      # 注册到nacos上的ip。客户端将通过该ip访问seata服务。
      # 注意公网ip和内网ip的差异。
      - SEATA_IP=114.116.1.116
      - SEATA_CONFIG_NAME=file:/root/seata-config/registry
    volumes:
    # 因为registry.conf中是nacos配置中心,只需要把registry.conf放到./seata-server/config文件夹中
      - "/data/seata/config:/root/seata-config"
    networks:
      - dream
networks:
  dream:
    driver: bridge

xxl-job(√)

version: '2'
services:
 mysql:
    image: centos/mysql-57-centos7
    ports:
      - "3306:3306"
    environment:
      MYSQL_ROOT_PASSWORD: root
    networks:
      - dream
  xxljob:
    image: xuxueli/xxl-job-admin:2.2.0
    ports:
      - "8080:8080"
    environment:
      PARAMS: "--spring.datasource.url=jdbc:mysql://mysql:3306/xxl_job?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&serverTimezone=Asia/Shanghai --spring.datasource.password=root"
    volumes:
      - /tmp:/data/applogs
    networks:
      - dream
networks:
  dream:
    driver: bridge

yapi(类似swagger)(√)

version: "3.5"
services:
  mongo:
    image: mongo:4.0.3
    container_name: mongo
    ports:
      - 27017:27017
    volumes:
      - /data/mongodb/db:/data/db
    networks:
      dream:
        aliases:
          - mongo
  yapi:
    image: mrjin/yapi:latest
    container_name: yapi
    environment:
      - VERSION=1.5.6
      - LOG_PATH=/tmp/yapi.log
      - HOME=/home
      - PORT=3000
      - [email protected]
      - DB_SERVER=mongo
      - DB_NAME=yapi
      - DB_PORT=27017
    ports:
      - 3000:3000
    volumes:
      - /data/yapi/log/:/home/vendors/log
    depends_on:
      - mongo
    entrypoint: "bash /wait-for-it.sh mongo:27017 -- entrypoint.sh"
    networks:
      dream:
        aliases:
          - yapi
networks:
  dream:
    name: dream
    driver: bridge

账号: [email protected]
默认密码是:ymfe.org,安装成功后进入后台修改
Http://114.116.1.116:3000

GitLab(√)

version: '3.5'
services:
   gitlab:
       image: 'twang2218/gitlab-ce-zh:11.1.4'
       restart: always
       hostname: 'gitlab.example.com'
       environment:
           TZ: 'Asia/Shanghai'
           GITLAB_OMNIBUS_CONFIG: |
               external_url 'http://gitlab.example.com'
               gitlab_rails['time_zone'] = 'Asia/Shanghai'
               # 需要配置到 gitlab.rb 中的配置可以在这里配置,每个配置一行,注意缩进。
               # 比如下面的电子邮件的配置:
               # gitlab_rails['smtp_enable'] = true
               # gitlab_rails['smtp_address'] = "smtp.exmail.qq.com"
               # gitlab_rails['smtp_port'] = 465
               # gitlab_rails['smtp_user_name'] = "[email protected]"
               # gitlab_rails['smtp_password'] = "成功开启POP3/SMTP服务后对应的授权码,写入此处"
               # gitlab_rails['smtp_authentication'] = "login"
               # gitlab_rails['smtp_enable_starttls_auto'] = true
               # gitlab_rails['smtp_tls'] = true
               # gitlab_rails['gitlab_email_from'] = '[email protected]'
       ports:
           - '8888:80'
           - '4443:443'
           - '2222:22'
       volumes:
           - /data/docker/gitlab/config:/etc/gitlab
           - /data/docker/gitlab/data:/var/opt/gitlab
           - /data/docker/gitlab/logs:/var/log/gitlab
	   networks:
			dream:
        		aliases:
					 - gitlab
networks:
  dream:
    name: dream
    driver: bridge

Jenkins–部署springboot项目(√)

version: "3"
services:
  jenkins:
    image: jenkins/jenkins:lts
    ports:
      - 8080:8080
      - 50000:50000
    restart: "always"
    container_name: jenkins
    environment:
      JAVA_OPTS: -Duser.timezone=Asia/Shanghai
    volumes:
      - /data/jenkins/home:/var/jenkins_home
      - /data/software/jdk1.8.0_351:/user/local/jdk1.8
      - /data/software/apache-maven-3.8.4:/user/local/apache-maven-3.8.4
      - /var/run/docker.sock:/var/run/docker.sock
      - /usr/bin/docker:/usr/bin/docker
    privileged: true
    user: root
    networks:
      dream:
        aliases:
          - jenkins
networks:
  dream:
    driver: bridge

docker运行(想用此文必看)

将上面的复制到 docker-compose.yml 文件后再上传至linux中运行

  1. 使用docker-compose启动容器

    docker-compose up #前台启动,会打印日志
    docker-compose up -d #后台启动

    docker-compose down # 关闭

  2. 压缩、解压docker镜像压缩包

    docker load -i 压缩包名字 # 解压

    docker commit 容器id 镜像名称:版本号 # 制作镜像(容器->镜像)

    docker save -o 要打镜像包名称 镜像 # 压缩

  3. 开启启动 docker 服务

    systemctl enable docker

  4. 设置容器随docker自启动

    docker update 容器名 --restart=always

  5. 开放端口

    firewall-cmd --zone=public --permanent --add-port=端口号/tcp

  6. 安装ping

    apt-get update
    apt-get install iputils-ping

  7. 安装ifconfig命令

    apt-get update
    apt-get install net-tools

  8. 安装vim命令

    apt-get update
    apt-get install vim

  9. 创建网桥

    docker network create dream

  10. 查看网桥详情 – 查看容器的ip地址

docker network inspect dream

vim 快捷命令

# vim快捷命令
# 光标至文件末尾
shift + g
# 光标至文件开头
gg
# 光标至指定行
行数 + gg
# 显示行数
:set number
# 光标至行尾
shift + 4
# 光标至行首
0
# 搜索
/搜索内容 -> enter  -> n下一个,N上一个
# 删除一行
dd
# 删除整个文件内容
:%d

你可能感兴趣的:(docker,docker)