项目环境docker及docker-compose文档
1、Linux环境介绍
-
centos7.6
-
16G以上内存空间(至少8G)
1、找到配置文件 cd /etc/sysconfig/network-scripts/ vi ifcfg-ens33 ---------------------------- TYPE=Ethernet PROXY_METHOD=none BROWSER_ONLY=no BOOTPROTO=static DEFROUTE=yes IPADDR=192.168.200.188 NETMASK=255.255.255.0 GATEWAY=192.168.200.2 DNS1=114.114.114.114 DNS2=8.8.8.8 IPV4_FAILURE_FATAL=no IPV6INIT=yes IPV6_AUTOCONF=yes IPV6_DEFROUTE=yes IPV6_FAILURE_FATAL=no IPV6_ADDR_GEN_MODE=stable-privacy NAME=ens33 UUID=b8fd5718-51f5-48f8-979b-b9f1f7a5ebf2 DEVICE=ens33 ONBOOT=yes ----------------------------------- 重启网卡 service network restart 测试网卡 ping www.baidu.com 如果有字节输出,则表示网络正常
# jdk镜像仓库:https://repo.huaweicloud.com/java/jdk/8u171-b11/ #下载wget命令 yum install wget # 下载、解压jdk wget https://repo.huaweicloud.com/java/jdk/8u171-b11/jdk-8u171-linux-x64.tar.gz #解压 tar -zxf jdk-8u171-linux-x64.tar.gz #移动文件夹中 mv jdk1.8.0_171 /usr/local # 配置环境 vi /etc/profile # 添加内容: export JAVA_HOME=/usr/local/jdk1.8.0_171 export PATH=$JAVA_HOME/bin:$PATH # 配置生效命令 source /etc/profile #查看j版本命令 java -version
4、Docker安装
安装docker
设置镜像加速器
# 执行如下命令: mkdir /etc/docker 表示创建一个文件夹 #如果有该文件则进入编辑状态,如果没有,则创建该文件然后进入编辑状态 vi /etc/docker/daemon.json #编写以下内容 { "registry-mirrors": ["https://7oc12mqc.mirror.aliyuncs.com"] }
注意:[“自己的镜像加速器地址”]
5、Docker-compose安装
#国内资源(建议) curl -L https://get.daocloud.io/docker/compose/releases/download/1.25.4/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose # 设置文件可执行权限 chmod +x /usr/local/bin/docker-compose # 查看版本信息 docker-compose -version
6、Nacos安装
-
创建一个文件夹
mkdir nacos
进入该文件夹中
cd nacos
vi docker-compose.yml
编写docker-compose.yml文件
version: "2" services: nacos: image: nacos/nacos-server:1.4.1 container_name: nacos environment: - MODE=standalone volumes: - /root/nacos/logs:/home/nacos/logs - /root/nacos/init.d/custom.properties:/home/nacos/init.d/custom.properties ports: - "8848:8848" restart: always
创建文件夹及文件
cd nacos
mkdir init.d
cd init.d
touch custom.properties
在nacos目录下执行脚本
docker-compose up -d
7、MySQL安装
mkdir mysql
进入mysql文件夹中创建一个docker-compose.yml文件
cd mysql
vi docker-compose.yml
在docker-compose.yml中加入以下内容
version: '3' services: mysql: container_name: mysql environment: TZ: Asia/Shanghai MYSQL_ROOT_PASSWORD: "root" image: "mysql:5.7" restart: always volumes: - "./conf/my.cnf:/etc/my.cnf" - "./data:/var/lib/mysql" ports: - "3306:3306"
创建文件(在mysql文件夹下)
mkdir conf
cd conf
touch my.cnf
在mysql文件夹下执行脚本
docker-compose up -d
mkdir es
进入es文件夹中创建一个docker-compose.yml文件
vi docker-compose.yml
在docker-compose.yml中加入以下内容
version: '3' services: elasticsearch: image: elasticsearch:7.12.1 container_name: elasticsearch restart: always environment: - bootstrap.memory_lock=true - http.cors.enabled=true - http.cors.allow-origin=* - "discovery.type=single-node" - "ES_JAVA_OPTS=-Xms512m -Xmx512m" ulimits: memlock: soft: -1 hard: -1 volumes: - /root/es/plugins:/usr/share/elasticsearch/plugins ports: - 9200:9200 - 9300:9300 kibana: image: kibana:7.12.1 container_name: kibana environment: - SERVER_NAME=kibana - ELASTICSEARCH_URL=http://192.168.200.145:9200 - XPACK_MONITORING_ENABLED=true ports: - 5601:5601 depends_on: - elasticsearch external_links: - elasticsearch
es文件夹下执行脚本
docker-compose up -d
在去选择ik分词器的时候,需要与elasticsearch的版本好对应上
把资料中的elasticsearch-analysis-ik-7.12.1.zip
上传到服务器上,放到对应目录(plugins)解压
下面我们需要把课前资料中的ik分词器解压缩,重命名为ik
在重新启动es,进行测试
docker restart elasticsearch
连接kibana,测试iK分词器
# ik_max_word中文分词器 GET _analyze { "analyzer": "ik_max_word", "text":"中国人民真好看" } # ik_smart中文分词器 GET _analyze { "analyzer": "ik_smart", "text":"中国人民真好看" } # 默认分词器 GET _analyze { "analyzer": "standard", "text":"中国人民真好看" }
mkdir minio
进入文件夹
cd minio
创建docker-compose.yml
vi docker-compose.yml
编写以下内容
version: '3' services: minio: image: minio/minio:RELEASE.2021-04-18T19-26-29Z container_name: myminio ports: - 9000:9000 volumes: - /var/minio/data:/data - /var/minio/config:/root/.minio environment: MINIO_ACCESS_KEY: "minio" MINIO_SECRET_KEY: "minio123" command: server /data restart: always
执行命令
在docker-compose.yml所在的目录之下执行
docker-compose up -d
10、Redis安装创建一个文件夹
创建一个文件夹
mkdir redis
进入redis文件夹中创建一个docker-compose.yml文件
cd redis
vi docker-compose.yml
在docker-compose.yml中加入以下内容
version: '3' services: redis: container_name: redis image: redis:5.0.7 restart: always ports: - 6379:6379 volumes: - ./conf/redis.conf:/etc/redis/redis.conf:rw - ./data:/data:rw command: redis-server /etc/redis/redis.conf --appendonly yes environment: - TZ=Asia/Shanghai
redis文件夹下执行脚本
docker-compose up -d
mkdir kafka
进入kafka文件夹中创建一个docker-compose.yml文件
cd kafka
vi docker-compose.yml
在docker-compose.yml中加入以下内容
version: '3' services: zookeeper-kafka: image: wurstmeister/zookeeper restart: unless-stopped hostname: zookeeper-kafka container_name: zookeeper-kafka ports: - 2777:2181 volumes: - ./data:/data - ./datalog:/datalog kafka: image: wurstmeister/kafka:2.12-2.4.1 depends_on: - zookeeper-kafka container_name: kafka ports: - 9092:9092 environment: KAFKA_ADVERTISED_HOST_NAME: kafka KAFKA_BROKER_ID: 0 KAFKA_ZOOKEEPER_CONNECT: 192.168.200.145:2777 KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://192.168.200.145:9092 KAFKA_LISTENERS: PLAINTEXT://0.0.0.0:9092 restart: unless-stopped volumes: - ./docker.sock:/var/run/docker.sock
KAFKA_ZOOKEEPER_CONNET:IP:zookeeper的端口号
IP要改成自己服务器的ip地址
在kafka文件夹下执行以下命令
docker-compose up -d
#拉取镜像 docker pull sheepkiller/kafka-manager #创建容器 docker run -di --name=kafka-manager -p 9001:9000 --restart=always -e ZK_HOSTS=192.168.200.145:2777 sheepkiller/kafka-manager
ZK_HOSTS=192.168.200.129:2777
表示关联zookeeper的地址及端口号, 2777是zookeeper的对外端口号
13、MongoDB安装
创建一个文件夹
mkdir mongo
进入mongo文件夹中创建一个docker-compose.yml文件
cd mongo
vi docker-compose.yml
在docker-compose.yml中加入以下内容
version: '3.1' services: mongo: image: mongo:5.0.2 restart: always container_name: mongo hostname: mongo environment: #用户名密码 MONGO_INITDB_ROOT_USERNAME: root MONGO_INITDB_ROOT_PASSWORD: root ports: - 27017:27017 volumes: - ./data:/data/db networks: mongo: aliases: - mongo1 networks: mongo: driver: bridge
mongo文件夹下执行脚本
docker-compose up -d
安装完后,要对mongo进行认证操作cls
进入mongo内部 [root@localhost ~]# docker exec -it mongo /bin/bash root@mongo:/# mongo MongoDB shell version v4.4.5 connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb Implicit session: session { "id" : UUID("f7c7c594-d5dd-473a-9ded-43609ac16a28") } MongoDB server version: 4.4.5 > use admin switched to db admin > db.auth("root","root") 1 > show dbs admin 0.000GB config 0.000GB local 0.000GB
mkdir xxljob
进入xxljob文件夹中创建一个docker-compose.yml文件
cd xxljob
vi docker-compose.yml
在docker-compose.yml中加入以下内容
version: '3' services: xxl-job: image: xuxueli/xxl-job-admin:2.3.0 container_name: xxl-job environment: PARAMS: "--spring.datasource.url=jdbc:mysql://192.168.200.145:3306/xxl_job?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&serverTimezone=Asia/Shanghai --spring.datasource.username=root --spring.datasource.password=root" ports: - 8888:8080 volumes: - /data/docker/xxl-job/logs/:/data/applogs/xxl-job/
xxljob文件夹下执行脚本
docker-compose up -d
15、seata安装
1、安装
创建文件夹
mkdir seata
进入文件夹,然后创建docker-compose.yml
cd seata
vi docker-compose.yml
写入以下内容
version: "3" services: seata-server: image: seataio/seata-server:1.4.2 hostname: seata-server container_name: seata restart: always ports: - "8091:8091" environment: - SEATA_PORT=8091 - SEATA_IP=192.168.40.131 volumes: - /root/seata/config:/root/seata-config
生成容器
docker-compose up -d
查看容器是否启动
docker ps
2、修改参数
1、进入容器内部
docker exec -it seata sh
2、进入resources文件夹下
cd resources
3、修改registry.conf配置
vi registry.conf
注册中心配置:
配置中心:
具体详情:(也可参考windwos环境中的registry.conf文件)
registry { # file ...nacos ...eureka...redis...zk...consul...etcd3...sofa type = "nacos" nacos { application = "seata-tc-server" serverAddr = "192.168.200.104:8848" group = "SEATA_GROUP" namespace = "" cluster = "SH" username = "nacos" password = "nacos" } } config { # file...nacos ...apollo...zk...consul...etcd3 type = "nacos" nacos { serverAddr = "192.168.200.104:8848" namespace = "" group = "SEATA_GROUP" username = "nacos" password = "nacos" dataId = "seataServer.properties" } }
exit
docker restart seata
docker logs -f seata
docker cp mysql:/etc/mysql/mysql.conf.d/mysqld.cnf /root/mysqld.cnf wait_timeout=86400 docker cp mysqld.cnf mysql:/etc/mysql/mysql.conf.d/mysqld.cnf