When developing spring cloud Alibaba microservice application, mysql, redis and Nacos should be set up first. In this paper, docker is used;
There are many ways to deploy Nacos. See the official document: Nacos docker, which uses the stand-alone mode and MySQL mode, so it will be associated with MySQL;
docker- compose.yaml The definition file is as follows:
version: "3.6"
services:
mysql:
image: mysql:${MYSQL_VERSION}
container_name: mysql
ports:
- "${MYSQL_HOST_PORT}:3306"
volumes:
- ${MYSQL_CONF_FILE}:/etc/mysql/conf.d/mysql.cnf:ro
- ${MYSQL_DATA_DIR}:/var/lib/mysql/:rw
restart: on-failure
networks:
- default
environment:
MYSQL_ROOT_PASSWORD: "${MYSQL_ROOT_PASSWORD}"
TZ: Asia/Shanghai
redis:
image: redis:${REDIS_VERSION}
container_name: redis
environment:
TZ: Asia/Shanghai
volumes:
- ${REDIS_LOG_DIR}:/var/log/redis/:rw
- ${REDIS_CONF_FILE}:/usr/local/etc/redis/redis.conf:ro
- ${REDIS_DIR}:/var/lib/redis/6379/:rw
command:
- /usr/local/etc/redis/redis.conf
restart: on-failure
networks:
- default
ports:
- "${REDIS_HOST_PORT}:6379"
nacos:
image: nacos/nacos-server:${NACOS_VERSION}
container_name: nacos
environment:
- "PREFER_HOST_MODE=${PREFER_HOST_MODE}"
- "MODE=${MODE}"
- "SPRING_DATASOURCE_PLATFORM=${SPRING_DATASOURCE_PLATFORM}"
- "MYSQL_SERVICE_HOST=${MYSQL_SERVICE_HOST}"
- "MYSQL_SERVICE_DB_NAME=${MYSQL_SERVICE_DB_NAME}"
- "MYSQL_SERVICE_PORT=${MYSQL_SERVICE_PORT}"
- "MYSQL_SERVICE_USER=${MYSQL_SERVICE_USER}"
- "MYSQL_SERVICE_PASSWORD=${MYSQL_SERVICE_PASSWORD}"
volumes:
- ${NACOS_LOG_DIR}:/home/nacos/logs:rw
- ${NACOS_PROPERTIES}:/home/nacos/init.d/custom.properties
depends_on:
- mysql
ports:
- 8848:8848
restart: on-failure
networks:
default:
Environment variable. Env:
################################################
### environment config file ###
################################################
#################### MySQL #####################
MYSQL_VERSION=5.7.24
MYSQL_HOST_PORT=3306
MYSQL_ROOT_PASSWORD=123456
MYSQL_DATA_DIR=./mysql
MYSQL_CONF_FILE=./conf/mysql.cnf
#################### Redis #####################
REDIS_VERSION=5.0.9
REDIS_HOST_PORT=6379
REDIS_CONF_FILE=./conf/redis.conf
REDIS_LOG_DIR=./log/redis
REDIS_DIR=./redis
#################### NACOS #####################
NACOS_VERSION=1.2.1
NACOS_LOG_DIR=./log/nacos
PREFER_HOST_MODE=hostname
MODE=standalone
SPRING_DATASOURCE_PLATFORM=mysql
MYSQL_ SERVICE_ Host = MySQL # the main thing here is to write the host of MySQL service, not 127.0.0.1; just write MySQL directly;
MYSQL_SERVICE_DB_NAME=nacos
MYSQL_SERVICE_PORT=3306
MYSQL_SERVICE_USER=root
MYSQL_SERVICE_PASSWORD=123456
NACOS_PROPERTIES=./conf/custom.properties
The file tree structure is as follows:
├── conf
│ ├── conf.d
│ ├── custom.properties
│ ├── mysql.cnf
│ ├── nginx.conf
│ └── redis.conf
├── docker-compose.yml
├── log
│ ├── nacos
│ └── redis
├── mysql
│ ├── auto.cnf
│ ├── ca-key.pem
│ ├── ca.pem
│ ├── client-cert.pem
│ ├── client-key.pem
│ ├── ib_buffer_pool
│ ├── ib_logfile0
│ ├── ib_logfile1
│ ├── ibdata1
│ ├── ibtmp1
│ ├── mysql
│ ├── mysql.error.log
│ ├── mysql.slow.log
│ ├── nacos
│ ├── performance_schema
│ ├── private_key.pem
│ ├── public_key.pem
│ ├── server-cert.pem
│ ├── server-key.pem
│ └── sys
├── redis
│ ├── dump.rdb
│ └── test.txt
└── www
It is worth noting that the Nacos version here is 1.2.1, and the initialized SQL script Nacos MySQL can be obtained from the Nacos MySQL script;
Start service:
docker-compose -f docker-compose.yml up -d
Starting redis ... done
Starting mysql ... done
Starting nacos ... done
View the service and port status:
lsof -nP|grep LISTEN
idea 411 bigticket 122u IPv4 0xf5b8d5ea88576b3b 0t0 TCP 127.0.0.1:6942 (LISTEN)
idea 411 bigticket 744u IPv4 0xf5b8d5ea89a9225b 0t0 TCP 127.0.0.1:63342 (LISTEN)
idea 411 bigticket 1049u IPv4 0xf5b8d5ea8b092cfb 0t0 TCP 127.0.0.1:49427 (LISTEN)
privoxy 656 bigticket 3u IPv4 0xf5b8d5ea896a4503 0t0 TCP 127.0.0.1:1087 (LISTEN)
ss-local 663 bigticket 8u IPv4 0xf5b8d5ea86d77ecb 0t0 TCP 127.0.0.1:1086 (LISTEN)
com.docke 1141 bigticket 7u IPv4 0xf5b8d5ea808b6de3 0t0 TCP 127.0.0.1:49948 (LISTEN)
com.docke 1145 bigticket 14u IPv4 0xf5b8d5ea8976d25b 0t0 TCP 127.0.0.1:6443 (LISTEN)
com.docke 1145 bigticket 21u IPv6 0xf5b8d5ea88f29063 0t0 TCP *:6379 (LISTEN)
com.docke 1145 bigticket 24u IPv6 0xf5b8d5ea88f26ba3 0t0 TCP *:3306 (LISTEN)
com.docke 1145 bigticket 25u IPv6 0xf5b8d5ea88f25943 0t0 TCP *:8848 (LISTEN)
MySQL and redis use the client to test the connection and connect smoothly;
Browser input http://127.0.0.1 : 8848 / Nacos /, initial account password: Nacos / Nacos
reference resources:
https://github.com/nacos-grou…