1、拉取docker镜像(不指定版本号默认为最新版本)
docker pull redis
2、启动redis
docker run -p 6379:6379 redis
3、启动redis;映射端口(6379)、后台启动 -d、指定名称 --name、总是启动 --restart=always
redis支持内存数据持久化:
1)rdb持久化:快照 redis服务器将某一时刻数据以快照文件形式写入到磁盘
2)aof持久化:redis服务器将所有redis客户端的写操作以命令方式记录到日志文件中===AOF更加安全 everysec
3)docker启动redis;映射端口(6379)、后台启动 -d、指定名称 --name、总是启动 --restart=always、运行redis持久化 appendonly yes
docker run --name redis -d -p 6379:6379 --restart=always redis-server --appendonly yes
4)docker启动redis;开放端口(6379)、后台启动 -d、指定名称 --name、总是启动 --restart=always、开启持久化 appendonly yes、映射数据外部文件 -v 外部文件路径
docker run --name redis -d -p 6379:6379 --restart=always -v /Users/shenzw/devTools/docker/redis:/data redis redis-server --appendonly yes
4、如何自定义配置文件启动redis
1)如何获取redis配置文件
第一种方式:下载对应版本找到配置文件进行修改,使用完整配置文件启动
第二种方式:创建指定文件名称直接书写修改属性即可===>推荐(appendonly yes appendfilename “xxx.aof”)
2)上传配置文件到宿主机指定目录。/root/redisconf/redis.conf
3)数据卷挂载配置启动
docker run --name redis -d -p 6379:6379 --restart=always -v /Users/shenzw/devTools/docker/redis redis redis-server /data/redis.conf
1、dockerhub搜索nginx
2、下载nginx对应镜像(不带版本号默认最新版本)
docker pull nginx
3、运行nginx
1)启动nginx;映射端口(80)
docker run -p 80:80 nginx
2)启动nginx;映射端口(80)、后台启动 -d、总是启动 - restart=always、指定nginx名称 --name
docker run -p 80:80 -d --restart=always --name nginx nginx
3)启动nginx;映射端口(80)、后台启动 -d、总是启动 --restart=always、指定名称 --name、加载指定nginx配置启动 -v 容器(/etc/nginx/nginx.conf)
a、实现反向代理、负载均衡
拷贝文件:docker cp 容器id:/etc/nginx/nginx.conf /root/nginxconf
docker run -p 80:80 -d --restart=always --name nginx -v /Users/shenzw/devTools/docker/nginx/nginxconf/nginx.conf:/etc/nginx/nginx.conf nginx
b、nginx服务器、服务器
docker run -p 8080:80 -d --restart=always --name nginx -v /Users/shenzw/devTools/docker/nginx/html:/usr/share/nginx/html nginx
c、既实现反向代理、负载均衡;又当nginx服务器、服务器(-v 可以多个,灵活应用)
docker run -p 8080:80 -d --restart=always --name nginx -v /Users/shenzw/devTools/docker/nginx/html:/usr/share/nginx/html -v /Users/shenzw/devTools/docker/nginx/nginxconf/nginx.conf:/etc/nginx/nginx.conf nginx
Nacos单机部署步骤
初始化数据库脚本
脚本下载地址:https://github.com/alibaba/nacos/blob/master/config/src/main/resources/META-INF/nacos-db.sql
M1版本docker 安装nacos
截止当前 支持M1版本的镜像好像就一个zhusaidong/nacos-server-m1:2.0.3。
dockerhub镜像地址:
https://registry.hub.docker.com/r/zhusaidong/nacos-server-m1/tags
1、拉取镜像(要带上版本号,默认latest拉取不下来)
docker pull zhusaidong/nacos-server-m1:2.0.3
2、运行容器
docker run --name nacos2.0.3 -p 8091:8091 -d zhusaidong/nacos-server-m1:2.0.3
3、将容器的文件同步到宿主机
docker cp nacos2.0.3:/home/nacos/conf /Users/shenzw/devTools/docker/nacos/conf
4、停止并删除nacos容器
docker ps -a
docker stop nacos2.0.3
docker rm nacos2.0.3
5、重新生成新的nacos容器,这里以单例模式为例
我的配置
docker run \
--name nacos2.0.3 -d \
-p 8848:8848 \
--privileged=true \
--restart=always \
-e JVM_XMS=256m \
-e JVM_XMX=256m \
-e MODE=standalone \
-e PREFER_HOST_MODE=hostname \
-v /Users/shenzw/devTools/docker/nacos/standalone-logs:/home/nacos/logs \
-v /Users/shenzw/devTools/docker/nacos/init.d/custom.properties:/home/nacos/init.d/custom.properties \
-v /Users/shenzw/devTools/docker/nacos/conf/:/home/nacos/conf \
zhusaidong/nacos-server-m1:2.0.3
6、application.properties配置文件修改:(注意:配置ip地址时千万不要使用localhost和127.0.0.1,否则会报No DataSource set错误;这里用的是host.docker.internal—docker映射到宿主机)
# spring
server.servlet.contextPath=/nacos
server.contextPath=/nacos
server.port=8848
spring.datasource.platform=mysql
nacos.cmdb.dumpTaskInterval=3600
nacos.cmdb.eventTaskInterval=10
nacos.cmdb.labelTaskInterval=300
nacos.cmdb.loadDataAtStart=false
db.num=1
db.url.0=jdbc:mysql://host.docker.internal:3306/docker_nacos?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useSSL=false&allowPublicKeyRetrieval=true&rewriteBatchedStatements=true&serverTimezone=UTC
#db.url.1=jdbc:mysql://${MYSQL_SERVICE_HOST}:${MYSQL_SERVICE_PORT:3306}/${MYSQL_SERVICE_DB_NAME}?${MYSQL_SERVICE_DB_PARAM:characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useSSL=false}
db.user=root
db.password=root
### The auth system to use, currently only 'nacos' is supported:
#nacos.core.auth.system.type=${NACOS_AUTH_SYSTEM_TYPE:nacos}
### The token expiration in seconds:
#nacos.core.auth.default.token.expire.seconds=${NACOS_AUTH_TOKEN_EXPIRE_SECONDS:18000}
### The default token:
#nacos.core.auth.default.token.secret.key=${NACOS_AUTH_TOKEN:SecretKey012345678901234567890123456789012345678901234567890123456789}
### Turn on/off caching of auth information. By turning on this switch, the update of auth information would have a 15 seconds delay.
#nacos.core.auth.caching.enabled=${NACOS_AUTH_CACHE_ENABLE:false}
#nacos.core.auth.enable.userAgentAuthWhite=${NACOS_AUTH_USER_AGENT_AUTH_WHITE_ENABLE:false}
#nacos.core.auth.server.identity.key=${NACOS_AUTH_IDENTITY_KEY:serverIdentity}
#nacos.core.auth.server.identity.value=${NACOS_AUTH_IDENTITY_VALUE:security}
#server.tomcat.accesslog.enabled=${TOMCAT_ACCESSLOG_ENABLED:false}
server.tomcat.accesslog.pattern=%h %l %u %t "%r" %s %b %D
# default current work dir
server.tomcat.basedir=
## spring security config
### turn off security
nacos.security.ignore.urls=/,/error,/**/*.css,/**/*.js,/**/*.html,/**/*.map,/**/*.svg,/**/*.png,/**/*.ico,/console-fe/public/**,/v1/auth/**,/v1/console/health/**,/actuator/**,/v1/console/server/**
# metrics for elastic search
management.metrics.export.elastic.enabled=false
management.metrics.export.influx.enabled=false
nacos.naming.distro.taskDispatchThreadCount=10
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
7、重启容器
docker restart nacos2.0.3
8、通过查看日志验证是否启动成功
docker logs nacos2.0.3
9、打开网页就可以访问了
http://127.0.0.1:8848/nacos/index.html
验证是否用到docker部署的mysql
新增用户
M1版本docker 安装nacos
> dockerhub镜像地址:
https://hub.docker.com/r/fancyfong/seata/tags
1、拉取镜像
docker pull fancyfong/seata:1.4.1_arm64
2、启动容器
docker run --name seata-server1.4.1 -p 8091:8091 -d fancyfong/seata:1.4.1_arm64
3、将容器的文件同步到宿主机
docker cp seata-server1.4.1:/seata-server /Users/shenzw/devTools/docker/seata/seata-server
docker ps -a
docker stop seata-server1.4.1
docker rm seata-server1.4.1
5、重新生成seata容器(ps:-h指定映射到宿主机,不然注册服务一直是docker虚拟机的,贼坑)
docker run -d --restart=always --name seata-server1.4.1 -p 8091:8091 -h 宿主机IP -v /Users/shenzw/devTools/docker/seata/seata-server:/seata-server fancyfong/seata:1.4.1_arm64
注:解释下命令
registry {
# file 、nacos 、eureka、redis、zk、consul、etcd3、sofa
type = "nacos"
loadBalance = "RandomLoadBalance"
loadBalanceVirtualNodes = 10
nacos {
application = "seata-server"
serverAddr = "host.docker.internal:8848"
group = "DEFAULT_GROUP"
namespace = ""
cluster = "default"
username = "nacos"
password = "nacos"
}
eureka {
serviceUrl = "http://localhost:8761/eureka"
application = "default"
weight = "1"
}
redis {
serverAddr = "localhost:6379"
db = 0
password = ""
cluster = "default"
timeout = 0
}
zk {
cluster = "default"
serverAddr = "127.0.0.1:2181"
sessionTimeout = 6000
connectTimeout = 2000
username = ""
password = ""
}
consul {
cluster = "default"
serverAddr = "127.0.0.1:8500"
}
etcd3 {
cluster = "default"
serverAddr = "http://localhost:2379"
}
sofa {
serverAddr = "127.0.0.1:9603"
application = "default"
region = "DEFAULT_ZONE"
datacenter = "DefaultDataCenter"
cluster = "default"
group = "SEATA_GROUP"
addressWaitTime = "3000"
}
file {
name = "file.conf"
}
}
config {
# file、nacos 、apollo、zk、consul、etcd3
type = "file"
nacos {
serverAddr = "host.docker.internal:8848"
namespace = ""
group = "SEATA_GROUP"
username = ""
password = ""
}
consul {
serverAddr = "127.0.0.1:8500"
}
apollo {
appId = "seata-server"
apolloMeta = "http://192.168.1.204:8801"
namespace = "application"
apolloAccesskeySecret = ""
}
zk {
serverAddr = "127.0.0.1:2181"
sessionTimeout = 6000
connectTimeout = 2000
username = ""
password = ""
}
etcd3 {
serverAddr = "http://localhost:2379"
}
file {
name = "file.conf"
}
}
主要修改两处:(这里的IP地址用host.docker.internal同nacos)
type = "nacos"
serverAddr = "host.docker.internal:8848"
7、重启seata容器
docker restart seata-server1.4.1
8、通过查看日志验证是否启动成功
docker logs seata-server1.4.1
9、打开注册中心nacos看seata是否注册成功
http://127.0.0.1:8848/nacos/index.html
安装seata注意事项:
1、如果使用的是配置nacos,注意修改数据库连接信息;;同时部署在docker不同的容器时注意ip不能直接使用127.0.0.1
2、如果配置的事file.conf文件,修改file.conf文件