安装docker
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
sudo yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
sudo yum install docker-ce docker-ce-cli containerd.io
sudo systemctl start docker
# 开机自启动
sudo systemctl enable docker
docker安装MySQL
参考:https://juejin.cn/post/6844904122932871182
[mysql]
# mysql客户端默认字符集
default-character-set=utf8
[mysqld]
# 设置默认时区
default-time_zone='+8:00'
# 设置3306端口
port = 3306
# 就是将mysql回收空闲连接的时间变长,mysql默认回收时间是8小时
wait_timeout=86400
#日志时区为系统时间
log_timestamps=SYSTEM
# 设置mysql的安装目录
#basedir=
# 设置mysql数据的存放目录
datadir=/var/lib/mysql
# 允许最大连接数
max_connections=200
# 服务端使用的字符集默认为8比特编码的latin1字符集
character-set-server=utf8
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
# innodb缓存池的大小
innodb_buffer_pool_size=512M
# innodb重做日志的缓存池大小
innodb_log_buffer_size=10M
# 忽略大小写
lower_case_table_names = 1
# 日志部分
## 错误日志
log_error = /var/lib/mysql/mysql-error.log
# 二进制日志
# binlog过期的时间
expire_logs_days = 3
## 查询日志
#开启查询日志
general_log=ON
# 查询日志路径
general_log_file=/var/lib/mysql/mysql-query.log
# 慢查询日志
# 开启慢查询,0表示关闭
slow_query_log=1
# 指定慢查询日志路径
slow_query_log_file = /var/lib/mysql/mysql-slow-query.log
# 查询时间>=1秒才记录日志
long_query_time = 1
# 记录没有使用索引的 SQL 语句
# log_queries_not_using_indexes = 1
docker pull mysql:8.0
docker images |grep mysql
docker run --name mysql01 \
-p 3306:3306 \
-v /app/mysql/my.cnf:/etc/mysql/my.cnf \
-v /app/mysql/data:/var/lib/mysql \
-v /app/mysql/logs:/logs \
-v /app/mysql/mysql-files:/var/lib/mysql-files \
-v /etc/localtime:/etc/localtime \
-e MYSQL_ROOT_PASSWORD=root \
--restart=always \
--privileged=true \
-d mysql:8.0
-p 3306:3306:将容器的 3306 端口映射到主机的 3306 端口。
-v /app/mysql/conf.d:/etc/mysql/conf.d -v /app/mysql/logs:/logs -v /app/mysql/data:/var/lib/mysql:挂载文件
-e MYSQL_ROOT_PASSWORD=123456:初始化 root 用户的密码。
# 进入容器
docker exec -it mysql01 /bin/bash
开启慢日志后,日志的时间和容器的时间相差8小时
这里的log_timestamps
参数值为UTC,修改为SYSTEM系统时间就好
解决方法:
- show global variables like ‘log_timestamps’
- set global log_timestamps=SYSTEM;
注意:使用旧数据时,需要删除data中的mysql.sock
docker安装Redis
docker run -p 6379:6379 --name redis01 \
-v /app/redis/redis.conf:/etc/redis/redis.conf \
-v /app/redis:/data \
-v /etc/localtime:/etc/localtime:ro \
-d redis redis-server /etc/redis/redis.conf
docker安装nacos
新建文件夹 init.d logs
新建文件 custom.properties
server.contextPath=/nacos
server.servlet.contextPath=/nacos
server.port=8848
spring.datasource.platform=mysql
db.num=1
db.url.0=jdbc:mysql://bj-cynosdbmysql-grp-brlewqje.sql.tencentcdb.com:12306/study-nacos?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true
db.user=root
db.password=root
nacos.cmdb.dumpTaskInterval=3600
nacos.cmdb.eventTaskInterval=10
nacos.cmdb.labelTaskInterval=300
nacos.cmdb.loadDataAtStart=false
management.metrics.export.elastic.enabled=false
management.metrics.export.influx.enabled=false
server.tomcat.accesslog.enabled=true
server.tomcat.accesslog.pattern=%h %l %u %t "%r" %s %b %D %{User-Agent}i
nacos.security.ignore.urls=/,/**/*.css,/**/*.js,/**/*.html,/**/*.map,/**/*.svg,/**/*.png,/**/*.ico,/console-fe/public/**,/v1/auth/login,/v1/console/health/**,/v1/cs/**,/v1/ns/**,/v1/cmdb/**,/actuator/**,/v1/console/server/**
nacos.naming.distro.taskDispatchThreadCount=1
nacos.naming.distro.taskDispatchPeriod=200
nacos.naming.distro.batchSyncKeyCount=1000
nacos.naming.distro.initDataRatio=0.9
nacos.naming.distro.syncRetryDelay=5000
nacos.naming.data.warmup=true
nacos.naming.expireInstance=true
docker run --name nacos01 -d \
-p 8848:8848 \
-p 9848:9848 \
-p 9849:9849 \
--privileged=true \
--restart=always \
-e JVM_XMS=256m \
-e JVM_XMX=256m \
-e MODE=standalone \
-e PREFER_HOST_MODE=hostname \
-v /app/nacos/logs:/home/nacos/logs \
-v /app/nacos/conf:/home/nacos/config \
-v /etc/localtime:/etc/localtime:ro \
nacos/nacos-server:v2.1.2-slim
docker安装RabbitMQ
docker pull docker.io/rabbitmq:3.8-management
# 运行
docker run -d --name rabbitmq01 \
-p 5672:5672 -p 15672:15672 \
-v /app/rabbitmq:/var/lib/rabbitmq --hostname localhost \
-e RABBITMQ_DEFAULT_VHOST=localhost \
-e RABBITMQ_DEFAULT_USER=root \
-e RABBITMQ_DEFAULT_PASS=root \
-v /etc/localtime:/etc/localtime:ro \
rabbitmq:3.8-management
mac 安装docker环境(docker Desktop)
mac docker安装mysql
docker pull mysql:8.0.28-oracle
docker images |grep mysql
# 启动3306
docker run \
--privileged=true \
--name mysql3306 \
-p 3306:3306 \
--net=my_net \
-v /Users/lzq/docker/mysql/my.cnf:/etc/mysql/my.cnf \
-v /Users/lzq/docker/mysql/data:/var/lib/mysql \
-v /Users/lzq/docker/mysql/mysql-files:/var/lib/mysql-files \
-v /etc/localtime:/etc/localtime \
-e MYSQL_ROOT_PASSWORD=root \
-d mysql:8.0.28-oracle
#启动3307
docker run \
--privileged=true \
--name mysql3307 \
-p 3307:3306 \
-v /Users/lzq/docker/mysql3307/my.cnf:/etc/mysql/my.cnf \
-v /Users/lzq/docker/mysql3307/data:/var/lib/mysql \
-v /Users/lzq/docker/mysql3307/mysql-files:/var/lib/mysql-files \
-v /etc/localtime:/etc/localtime \
-e MYSQL_ROOT_PASSWORD=root \
-d mysql:8.0.28-oracle
docker安装redis
docker run -p 6379:6379 --name redis6379 \
-v /Users/lzq/docker/redis6379/redis.conf:/etc/redis/redis.conf \
-v /Users/lzq/docker/redis6379:/data \
-v /etc/localtime:/etc/localtime \
--net=my_net \
--ip 172.22.1.10 \
-d redis redis-server /etc/redis/redis.conf
docker run -p 6380:6379 --name redis6380 \
-v /Users/lzq/docker/redis6380/redis.conf:/etc/redis/redis.conf \
-v /Users/lzq/docker/redis6380:/data \
-v /etc/localtime:/etc/localtime \
--net=my_net \
--ip 172.22.1.11 \
-d redis redis-server /etc/redis/redis.conf
docker run -p 6381:6379 --name redis6381 \
-v /Users/lzq/docker/redis6381/redis.conf:/etc/redis/redis.conf \
-v /Users/lzq/docker/redis6381:/data \
-v /etc/localtime:/etc/localtime \
--net=my_net \
--ip 172.22.1.12 \
-d redis redis-server /etc/redis/redis.conf
docker run -p 16379:16379 --name sentinel16379 \
-v /Users/lzq/docker/redis6379/sentinel.conf:/etc/redis/sentinel.conf \
-v /Users/lzq/docker/redis6379:/data \
-v /etc/localtime:/etc/localtime \
--net=my_net \
--ip 172.22.1.20 \
-d redis redis-sentinel /etc/redis/sentinel.conf
docker run -p 16380:16379 --name sentinel16380 \
-v /Users/lzq/docker/redis6380/sentinel.conf:/etc/redis/sentinel.conf \
-v /Users/lzq/docker/redis6380:/data \
-v /etc/localtime:/etc/localtime \
--net=my_net \
--ip 172.22.1.21 \
-d redis redis-sentinel /etc/redis/sentinel.conf
docker run -p 16381:16379 --name sentinel16381 \
-v /Users/lzq/docker/redis6381/sentinel.conf:/etc/redis/sentinel.conf \
-v /Users/lzq/docker/redis6381:/data \
-v /etc/localtime:/etc/localtime \
--net=my_net \
--ip 172.22.1.22 \
-d redis redis-sentinel /etc/redis/sentinel.conf
创建一个网络:docker network create --driver bridge --subnet 172.22.1.0/24 --gateway 172.22.1.1 my_net
查询docker容器的虚拟ip:docker inspect 容器名称
主从复制 slaveof 172.22.1.10 6379
主从复制检查 info replication
进入redis中:
docker exec -it redis6379 /bin/bash
redis-sentinel /etc/redis/sentinel.conf
docker exec -it redis6380 /bin/bash
redis-sentinel /etc/redis/sentinel.conf
docker exec -it redis6381 /bin/bash
redis-sentinel /etc/redis/sentinel.conf
查看redis集群和sentinel状态:
redis-cli -h 172.22.1.10 -p 6379 info Replication
redis-cli -h 172.22.1.11 -p 6379 info Replication
redis-cli -h 172.22.1.12 -p 6379 info Replication
redis-cli -h 172.22.1.10 -p 16379 info Sentinel
redis-cli -h 172.22.1.11 -p 16379 info Sentinel
redis-cli -h 172.22.1.12 -p 16379 info Sentinel
docker安装RabbitMQ
如果是一开始安装的,不要挂载plugins文件夹,去掉这行命令启动后将plugins拷贝出来
docker pull rabbitmq:3.9.15-management
# 运行5672
docker run -d --name rabbitmq5672 \
-p 5672:5672 -p 15672:15672 \
-v /Users/lzq/docker/rabbitmq5672/data:/var/lib/rabbitmq \
-v /Users/lzq/docker/rabbitmq5672/log:/var/log/rabbitmq \
-v /Users/lzq/docker/rabbitmq5672/rabbitmq_delayed_message_exchange-3.9.0.ez:/opt/rabbitmq/plugins/rabbitmq_delayed_message_exchange-3.9.0.ez \
--hostname rabbitmq5672 \
-e RABBITMQ_DEFAULT_VHOST=localhost \
-e RABBITMQ_DEFAULT_USER=root \
-e RABBITMQ_DEFAULT_PASS=root \
--net=my_net \
-v /etc/localtime:/etc/localtime \
rabbitmq:3.9.15-management
# 运行5673
docker run -d --name rabbitmq5673 \
-p 5673:5672 -p 15673:15672 \
-v /Users/lzq/docker/rabbitmq5673/data:/var/lib/rabbitmq \
-v /Users/lzq/docker/rabbitmq5673/log:/var/log/rabbitmq \
-v /Users/lzq/docker/rabbitmq5673/rabbitmq_delayed_message_exchange-3.9.0.ez:/opt/rabbitmq/plugins/rabbitmq_delayed_message_exchange-3.9.0.ez \
--hostname rabbitmq5673 \
-e RABBITMQ_DEFAULT_VHOST=localhost \
-e RABBITMQ_DEFAULT_USER=root \
-e RABBITMQ_DEFAULT_PASS=root \
--net=my_net \
-v /etc/localtime:/etc/localtime \
rabbitmq:3.9.15-management
# 运行5674
docker run -d --name rabbitmq5674 \
-p 5674:5672 -p 15674:15672 \
-v /Users/lzq/docker/rabbitmq5674/data:/var/lib/rabbitmq \
-v /Users/lzq/docker/rabbitmq5674/log:/var/log/rabbitmq \
-v /Users/lzq/docker/rabbitmq5674/rabbitmq_delayed_message_exchange-3.9.0.ez:/opt/rabbitmq/plugins/rabbitmq_delayed_message_exchange-3.9.0.ez \
--hostname rabbitmq5674 \
-e RABBITMQ_DEFAULT_VHOST=localhost \
-e RABBITMQ_DEFAULT_USER=root \
-e RABBITMQ_DEFAULT_PASS=root \
--net=my_net \
-v /etc/localtime:/etc/localtime \
rabbitmq:3.9.15-management
docker安装Nacos
docker run --name nacos8848 -d \
-p 8848:8848 \
-p 9848:9848 \
-p 9849:9849 \
--privileged=true \
-e JVM_XMS=256m \
-e JVM_XMX=256m \
-e MODE=standalone \
--net=my_net \
-e PREFER_HOST_MODE=hostname \
-v /Users/lzq/docker/nacos/conf:/home/nacos/conf \
-v /Users/lzq/docker/nacos/logs:/home/nacos/logs \
-v /Users/lzq/docker/nacos/data:/home/nacos/data \
nacos/nacos-server:v2.1.2-slim
docker run --name nacos8848 -d \
-p 8848:8848 \
--privileged=true \
-e JVM_XMS=256m \
-e JVM_XMX=256m \
-e MODE=standalone \
-e TZ=Asia/Shanghai \
-e PREFER_HOST_MODE=hostname \
--net=my_net \
-v /Users/lzq/docker/nacos/conf:/home/nacos/conf \
-v /Users/lzq/docker/nacos/data:/home/nacos/data \
-v /Users/lzq/docker/nacos/logs:/home/nacos/logs \
xiaovcloud/nacos:1.4.5
docker安装Nginx
docker run \
-p 80:80 \
--name nginx \
--net=my_net \
-v /Users/lzq/docker/nginx/conf/nginx.conf:/etc/nginx/nginx.conf \
-v /Users/lzq/docker/nginx/conf/conf.d:/etc/nginx/conf.d \
-v /Users/lzq/docker/nginx/log:/var/log/nginx \
-v /Users/lzq/docker/nginx/html:/usr/share/nginx/html \
-d nginx
docker安装RocketMQ
docker run -d \
--name rocketmq-nameserv \
--privileged=true \
-p 9876:9876 \
--net=my_net \
-v /Users/lzq/docker/rocketmq/data/namesrv/logs:/home/rocketmq/logs \
-e "MAX_POSSIBLE_HEAP=100000000" \
-e "JAVA_OPT_EXT=-Xms512M -Xmx512M -Xmn128m" \
xiaovcloud/rocketmq:4.5.0 \
sh mqnamesrv
docker run -d \
--name rocketmq-broker \
--privileged=true \
--net=my_net \
-p 10911:10911 \
-p 10912:10912 \
-p 10909:10909 \
-v /Users/lzq/docker/rocketmq/data/broker/logs:/home/rocketmq/logs \
-v /Users/lzq/docker/rocketmq/data/broker/store:/home/rocketmq/store \
-v /Users/lzq/docker/rocketmq/conf/broker.conf:/home/rocketmq/rocketmq-4.5.0/conf/broker.conf \
-e "NAMESRV_ADDR=rocketmq-nameserv:9876" \
-e "JAVA_OPT_EXT=-Xms512M -Xmx512M -Xmn128m" \
-e "MAX_POSSIBLE_HEAP=200000000" \
xiaovcloud/rocketmq:4.5.0 \
sh mqbroker -c /home/rocketmq/rocketmq-4.5.0/conf/broker.conf
docker run -p 8888:8888 --name rocketmq-dashboard -d \
--net=my_net \
--network host \
-v /Users/lzq/docker/rocketmq/conf/dashboard.yml:/root/application.yml \
-t xiaovcloud/rocketmq-dashboard
docker rm -f rocketmq-nameserv
docker run -d --name rocketmq-nameserv \
-e TZ=Asia/Shanghai \
-e "JAVA_OPT_EXT=-Xms512M -Xmx512M -Xmn128m -Dfastjson.parser.safeMode=true" \
-p 9876:9876 \
--network my_net \
rocketmqinc/rocketmq:latest bash -c "sh mqnamesrv"
docker rm -f rocketmq-mqbroker
docker run -d --name rocketmq-mqbroker \
-e TZ=Asia/Shanghai \
-e "JAVA_OPT_EXT=-Xms512M -Xmx1024M -Xmn128m -Dfastjson.parser.safeMode=true" \
-p 10911:10911 -p 10912:10912 -p 10909:10909 \
rocketmqinc/rocketmq:latest bash -c "echo 'brokerIP1=10.60.57.62'>>../conf/broker.conf && echo 'namesrvAddr=10.60.57.62:9876'>>../conf/broker.conf && echo 'maxMessageSize=536870912'>>../conf/broker.conf && sh mqbroker -c ../conf/broker.conf"
docker安装Seata
docker run -d \
--name seata-server \
-p 8091:8091 \
-p 7091:7091 \
-v /Users/lzq/docker/seata/seata-server:/seata-server \
-v /Users/lzq/docker/seata/log:/root/logs/seata \
-e SEATA_IP=10.60.57.62 \
-e SEATA_PORT=8091 \
--net=my_net \
seataio/seata-server:1.6.0
docker run -d \
--name seata-server \
-p 8091:8091 \
-v /Users/lzq/docker/seata/seata-server:/seata-server \
-v /Users/lzq/docker/seata/log:/root/logs/seata \
-e SEATA_IP=10.60.56.46 \
-e SEATA_PORT=8091 \
--net=my_net \
seataio/seata-server:1.6.0
docker安装达梦数据库
docker run -d --platform linux/amd64 \
-p 5236:5236 \
--name=dm8 \
--privileged=true \
-e LD_LIBRARY_PATH=/opt/dmdbms/bin \
-e PAGE_SIZE=16 -e EXTENT_SIZE=32 -e LOG_SIZE=1024 -e UNICODE_FLAG=1 -e INSTANCE_NAME=dm8 \
--net=my_net \
-v /Users/lzq/docker/dameng:/opt/dmdbms/data dm8_single:dm8_20240715_rev232765_x86_rh6_64
m1安装docker环境(Orbstack)
#给docker中的容器建一个网段
docker network create --driver bridge --subnet 172.22.1.0/24 --gateway 172.22.1.1 my_net
#安装mysql3306
docker run \
--privileged=true \
--name mysql3306 \
-p 3306:3306 \
-v /Users/lzq/docker/mysql/my.cnf:/etc/mysql/my.cnf \
-v /Users/lzq/docker/mysql/data:/var/lib/mysql \
-v /Users/lzq/docker/mysql/mysql-files:/var/lib/mysql-files \
-e TZ=Asia/Shanghai \
-e MYSQL_ROOT_PASSWORD=root \
--net=my_net \
-d mysql:8.0.28-oracle
#安装nacos8848
docker run --name nacos8848 -d \
-p 8848:8848 \
--privileged=true \
-e JVM_XMS=256m \
-e JVM_XMX=256m \
-e MODE=standalone \
-e TZ=Asia/Shanghai \
-e PREFER_HOST_MODE=hostname \
--net=my_net \
-v /Users/lzq/docker/nacos/conf:/home/nacos/conf \
-v /Users/lzq/docker/nacos/data:/home/nacos/data \
-v /Users/lzq/docker/nacos/logs:/home/nacos/logs \
xiaovcloud/nacos:1.4.5
#安装mysql8849
docker run --name nacos8849 -d \
-p 8849:8848 -p 9849:9848 -p 9850:9849 \
--privileged=true \
-e JVM_XMS=256m \
-e JVM_XMX=256m \
-e MODE=standalone \
-e TZ=Asia/Shanghai \
-e PREFER_HOST_MODE=hostname \
--net=my_net \
-v /Users/lzq/docker/nacos2/conf:/home/nacos/conf \
-v /Users/lzq/docker/nacos2/data:/home/nacos/data \
-v /Users/lzq/docker/nacos2/logs:/home/nacos/logs \
xiaovcloud/nacos:2.2.1
#安装redis6379
docker run --name redis6379 \
-p 6379:6379 \
-v /Users/lzq/docker/redis6379/redis.conf:/etc/redis/redis.conf \
-v /Users/lzq/docker/redis6379:/data \
-e TZ=Asia/Shanghai \
--net=my_net \
-d redis redis-server /etc/redis/redis.conf
#docker安装rabbitmq
docker run -d --name rabbitmq5672 \
-p 5672:5672 -p 15672:15672 \
-v /Users/lzq/docker/rabbitmq:/var/lib/rabbitmq \
--hostname localhost \
-e RABBITMQ_DEFAULT_VHOST=localhost \
-e RABBITMQ_DEFAULT_USER=root \
-e RABBITMQ_DEFAULT_PASS=root \
-e TZ=Asia/Shanghai \
--net=my_net \
rabbitmq:3.9.15-management