赞
踩
sudo yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine
sudo yum install -y yum-utils
sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
sudo yum install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
sudo systemctl start docker
docker --version
sudo systemctl status docker
获取加速器地址:https://cr.console.aliyun.com/cn-hangzhou/instances/mirrors
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["加速器地址"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
参考:https://docs.docker.com/engine/install/centos/
docker pull mysql
docker images
mkdir ~/mysql
cd ~/mysql
docker run -id \
-p 3306:3306 \
--name mysql \
-v $PWD/conf:/etc/mysql/conf.d \
-v $PWD/logs:/logs \
-v $PWD/data:/var/lib/mysql \
-e MYSQL_ROOT_PASSWORD=root \
mysql
参数 | 说明 |
---|---|
-v $PWD/conf:/etc/mysql/conf.d | 配置目录,将主机当前目录下的 conf/my.cnf 挂载到容器的 /etc/mysql/my.cnf |
-v $PWD/logs:/logs | 日志目录,将主机当前目录下的 logs 目录挂载到容器的 /logs |
-v $PWD/data:/var/lib/mysql | 数据目录,将主机当前目录下的data目录挂载到容器的 /var/lib/mysql |
docker ps -a
docker pull nacos/nacos-server
docker images
mkdir ~/nacos
cd ~/nacos
docker run -d \
-e MODE=standalone \
-e PREFER_HOST_MODE=hostname \
-e SPRING_DATASOURCE_PLATFORM=mysql \
-e MYSQL_SERVICE_HOST=192.168.120.1 \
-e MYSQL_SERVICE_PORT=3306 \
-e MYSQL_SERVICE_USER=root \
-e MYSQL_SERVICE_PASSWORD=root \
-e MYSQL_SERVICE_DB_NAME=nacos_config \
-p 8848:8848 \
--name nacos \
--restart=always \
nacos/nacos-server
参数说明:https://nacos.io/en-us/docs/quick-start-docker.html
192.168.120.1 为 Mysql 容器 ip 地址,获取 docker 所有容器 ip 地址命令:
docker inspect -f '{{.Name}} - {{.NetworkSettings.IPAddress }}' $(docker ps -aq)
mkdir ~/nacos/conf
docker cp nacos:/home/nacos/conf/application.properties ~/nacos/conf/
docker cp nacos:/home/nacos/conf/nacos-logback.xml ~/nacos/conf/
# spring server.servlet.contextPath=${SERVER_SERVLET_CONTEXTPATH:/nacos} server.contextPath=/nacos server.port=${NACOS_APPLICATION_PORT:8848} # 修改此行,将SPRING_DATASOURCE_PLATFORM的默认值""改为mysql spring.datasource.platform=${SPRING_DATASOURCE_PLATFORM:mysql} nacos.cmdb.dumpTaskInterval=3600 nacos.cmdb.eventTaskInterval=10 nacos.cmdb.labelTaskInterval=300 nacos.cmdb.loadDataAtStart=false db.num=${MYSQL_DATABASE_NUM:1} # 修改此行,添加MYSQL_SERVICE_HOST的默认值为192.168.120.1,MYSQL_SERVICE_DB_NAME的默认值为nacos_config,修改MYSQL_SERVICE_DB_PARAM时区 db.url.0=jdbc:mysql://${MYSQL_SERVICE_HOST:192.168.120.1}:${MYSQL_SERVICE_PORT:3306}/${MYSQL_SERVICE_DB_NAME:nacos}?${MYSQL_SERVICE_DB_PARAM:characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useUnicode=true&useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true} # 修改此行,添加MYSQL_SERVICE_HOST的默认值为192.168.120.1,MYSQL_SERVICE_DB_NAME的默认值为nacos_config,修改MYSQL_SERVICE_DB_PARAM时区 db.url.1=jdbc:mysql://${MYSQL_SERVICE_HOST:192.168.120.1}:${MYSQL_SERVICE_PORT:3306}/${MYSQL_SERVICE_DB_NAME:nacos}?${MYSQL_SERVICE_DB_PARAM:characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useUnicode=true&useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true} # 修改此行,添加MYSQL_SERVICE_USER的默认值为root db.user=${MYSQL_SERVICE_USER:root} # 修改此行,添加MYSQL_SERVICE_PASSWORD的默认值为root db.password=${MYSQL_SERVICE_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=${NACOS_SECURITY_IGNORE_URLS:/,/error,/**/*.css,/**/*.js,/**/*.html,/**/*.map,/**/*.svg,/**/*.png,/**/*.ico,/console-fe/public/**,/v1/auth/**,/v1/console/health/**,/actuator/**,/v1/console/server/**}
采用添加默认值的方式,这样不会影响指定命令行的参数。
运行之前先删除之前启动的容器
docker stop nacos
docker rm nacos
重新运行容器
docker run -d \
-e MODE=standalone \
-e JVM_XMS=256m -e JVM_XMX=256m \
-p 8848:8848 \
-v ~/nacos/conf:/home/nacos/conf \
-v ~/nacos/logs:/home/nacos/logs \
-v ~/nacos/data:/home/nacos/data \
--name nacos \
--restart=always \
nacos/nacos-server
http://ip:8848/nacos
数据库写入登录用户名&密码
INSERT INTO users (username, password, enabled)
VALUES ('nacos', '${new_password}', TRUE);
将 ${new_password} 替换为经过 BCrypt 加密的新密码。加密工具可使用 Nacos 提供的 PasswordEncoderUtil 类,通过运行 Java 代码获取加密后的密码。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。