创建数据挂载目录
mkdir -p /home/nacos/{conf,nacos-1/{logs},nacos-2/{logs,nginx}}
增加公共配置custom.properties
cd /home/nacos/conf
vim custom.properties
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| nacos.naming.empty-service.auto-clean=true nacos.naming.empty-service.clean.initial-delay-ms=50000 nacos.naming.empty-service.clean.period-time-ms=30000
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
server.tomcat.basedir=
nacos.security.ignore.urls=/,/error,/**/*.css,/**/*.js,/**/*.html,/**/*.map,/**/*.svg,/**/*.png,/**/*.ico,/console-fe/public/**,/v1/auth/**,/v1/console/health/**,/actuator/**,/v1/console/server/**
nacos.core.auth.system.type=nacos
nacos.core.auth.enabled=false
nacos.core.auth.default.token.expire.seconds=18000
nacos.core.auth.default.token.secret.key=SecretKey012345678901234567890123456789012345678901234567890123456789
nacos.core.auth.caching.enabled=true
nacos.istio.mcp.server.enabled=false
|
编写dockerc-compose.yml
cd /home/nacos
vim docker-compose.yml
单机环境
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| version: '3' services: nacos-server: image: nacos/nacos-server:1.4.2 container_name: nacos-standalone ports: - 8848:8848 restart: always networks: - nacos_net privileged: true environment: MODE: standalone PREFER_HOST_MODE: 172.16.10.233 #如果支持主机名可以使用hostname,否则使用ip,默认也是ip SPRING_DATASOURCE_PLATFORM: mysql #数据源平台 仅支持mysql或不保存empty MYSQL_SERVICE_HOST: 172.16.10.233 MYSQL_SERVICE_PORT: 3306 MYSQL_SERVICE_DB_NAME: nacos MYSQL_SERVICE_USER: root MYSQL_SERVICE_PASSWORD: root #JVM调优参数 JVM_XMS: 512m #-Xms default :2g JVM_MMS: 320m JVM_XMX: 512m #-Xmx default :2g JVM_XMN: 320m #-Xmn default :1g #挂载目录 volumes: - /home/unit/nacos/nacos-standalone/logs:/home/nacos/logs - /home/unit/nacos/conf/custom.properties:/home/nacos/init.d/custom.properties networks: nacos_net: driver: bridge
|
集群环境
这里指定了docker内网的号段,需要提前创建好network,docker network create –driver=bridge –subnet=10.1.1.0/24 test-network
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
| version: '3' networks: my_network: external: true name: test-network
services: nacos1: image: nacos/nacos-server:v2.3.1 container_name: nacos1 restart: always privileged: true environment: MODE: cluster NACOS_SERVERS: 10.1.1.40:8848,10.1.1.41:8848,10.1.1.42:8848 PREFER_HOST_MODE: hostname SPRING_DATASOURCE_PLATFORM: mysql MYSQL_SERVICE_HOST: 10.1.1.2 MYSQL_SERVICE_PORT: 3306 MYSQL_SERVICE_DB_NAME: nacos MYSQL_SERVICE_USER: xc_ai MYSQL_SERVICE_PASSWORD: fp!aRX33!zXS5tW NACOS_AUTH_ENABLE: true # 开启鉴权 NACOS_AUTH_TOKEN: jqn3m9i51vr4tu5ip57zwcb3axbz1r6y6vssh7i5027xq7z5odzfaqvmjnrxenvn NACOS_AUTH_IDENTITY_KEY: nacos NACOS_AUTH_IDENTITY_VALUE: zwcb3axb #JVM调优参数 JVM_XMS: 320m #-Xms default :2g JVM_MMS: 125m JVM_XMX: 320m #-Xmx default :2g JVM_XMN: 125m #-Xmn default :1g volumes: - /home/nacos/cluster1/logs:/home/nacos/logs - /home/nacos/cluster1/conf/custom.properties:/home/nacos/init.d/custom.properties - /home/nacos/cluster1/data:/home/nacos/data networks: my_network: ipv4_address: 10.1.1.40
nacos2: image: nacos/nacos-server:v2.3.1 container_name: nacos2 restart: always privileged: true environment: MODE: cluster NACOS_SERVERS: 10.1.1.40:8848,10.1.1.41:8848,10.1.1.42:8848 PREFER_HOST_MODE: hostname SPRING_DATASOURCE_PLATFORM: mysql MYSQL_SERVICE_HOST: 10.1.1.2 MYSQL_SERVICE_PORT: 3306 MYSQL_SERVICE_DB_NAME: nacos MYSQL_SERVICE_USER: xc_ai MYSQL_SERVICE_PASSWORD: fp!aRX33!zXS5tW NACOS_AUTH_ENABLE: true # 开启鉴权 NACOS_AUTH_TOKEN: jqn3m9i51vr4tu5ip57zwcb3axbz1r6y6vssh7i5027xq7z5odzfaqvmjnrxenvn NACOS_AUTH_IDENTITY_KEY: nacos NACOS_AUTH_IDENTITY_VALUE: zwcb3axb #JVM调优参数 JVM_XMS: 320m #-Xms default :2g JVM_MMS: 125m JVM_XMX: 320m #-Xmx default :2g JVM_XMN: 125m #-Xmn default :1g volumes: - /home/nacos/cluster2/logs:/home/nacos/logs - /home/nacos/cluster2/conf/custom.properties:/home/nacos/init.d/custom.properties - /home/nacos/cluster2/data:/home/nacos/data networks: my_network: ipv4_address: 10.1.1.41 nacos3: image: nacos/nacos-server:v2.3.1 container_name: nacos3 restart: always privileged: true environment: MODE: cluster NACOS_SERVERS: 10.1.1.40:8848,10.1.1.41:8848,10.1.1.42:8848 PREFER_HOST_MODE: hostname SPRING_DATASOURCE_PLATFORM: mysql MYSQL_SERVICE_HOST: 10.1.1.2 MYSQL_SERVICE_PORT: 3306 MYSQL_SERVICE_DB_NAME: nacos MYSQL_SERVICE_USER: xc_ai MYSQL_SERVICE_PASSWORD: fp!aRX33!zXS5tW NACOS_AUTH_ENABLE: true # 开启鉴权 NACOS_AUTH_TOKEN: jqn3m9i51vr4tu5ip57zwcb3axbz1r6y6vssh7i5027xq7z5odzfaqvmjnrxenvn NACOS_AUTH_IDENTITY_KEY: nacos NACOS_AUTH_IDENTITY_VALUE: zwcb3axb #JVM调优参数 JVM_XMS: 320m #-Xms default :2g JVM_MMS: 125m JVM_XMX: 320m #-Xmx default :2g JVM_XMN: 125m #-Xmn default :1g volumes: - /home/nacos/cluster3/logs:/home/nacos/logs - /home/nacos/cluster3/conf/custom.properties:/home/nacos/init.d/custom.properties - /home/nacos/cluster3/data:/home/nacos/data networks: my_network: ipv4_address: 10.1.1.42
|
编写nginx代理
2.0之后使用rpc访问有一个端口偏移,需要在nginx配置中指定
nginx.conf
cd /home/nginx/conf
vim nginx.conf
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
| user nginx; worker_processes 1;
error_log /var/log/nginx/error.log warn; pid /var/run/nginx.pid;
events { worker_connections 1024; }
http { include /etc/nginx/mime.types; default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
keepalive_timeout 65; include /etc/nginx/conf.d/*.conf; } # tpc服务 stream { # tcp负载均衡 upstream nacos-grpc { server 10.1.1.40:9848 weight=1; server 10.1.1.41:9848 weight=1; server 10.1.1.42:9848 weight=1; } # Nacos服务端gRPC请求服务端端口 server { listen 10999; proxy_pass nacos-grpc; } }
|
nacos.conf
cd /home/nginx/conf.d
vim nacos.conf
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| upstream nacosserver { server 10.1.1.40:8848 weight=1; server 10.1.1.41:8848 weight=1; server 10.1.1.42:8848 weight=1; }
server { listen 9999; server_name localhost; location / { proxy_pass http://nacosserver; }
}
|
执行启动命令
docker-compose up -d
最后只需要用nginx进行代理转发就好了