创建数据挂载目录
mkdir -p /home/nacos/{conf,nacos-1/{logs},nacos-2/{logs,nginx}}
增加公共配置custom.properties
cd /home/nacos/confvim 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/nacosvim 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
|
集群环境
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
| version: '3' services: #nginx代理转发 nginx: image: nginx:1.19.6 container_name: nginx restart: always networks: - nacos_net ports: - 8848:8848 volumes: - /data/images/nacos/nacos-nginx/nginx.conf:/etc/nginx/nginx.conf nacos-server-one: image: nacos/nacos-server:1.3.2 container_name: nacos-server-one ports: - 8845:8845 restart: always networks: - nacos_net privileged: true environment: MODE: cluster NACOS_APPLICATION_PORT: 8845 PREFER_HOST_MODE: 192.168.0.10 #如果支持主机名可以使用hostname,否则使用ip,默认也是ip MYSQL_SERVICE_HOST: mysql #数据源平台 仅支持mysql或不保存empty NACOS_SERVER_IP: 192.168.0.10 #多网卡情况下,指定ip或网卡 NACOS_SERVERS: 192.168.0.10:8845,192.168.0.10:8846 #集群中其它节点[ip1:port ip2:port ip3:port] MYSQL_SERVICE_HOST: 192.168.0.10 #mysql配置,Master为主节点,Slave为从节点 MYSQL_SERVICE_PORT: 3306 MYSQL_SERVICE_DB_NAME: nacos MYSQL_SERVICE_USER: nacos MYSQL_SERVICE_PASSWORD: 8uDW456#
#JVM调优参数 JVM_XMS: 1g #-Xms default :2g JVM_XMX: 1g #-Xmx default :2g JVM_XMN: 512m #-Xmn default :1g #挂载目录 volumes: - /home/nacos/nacos-1/logs:/home/nacos/logs - /home/nacos/conf/custom.properties:/home/nacos/init.d/custom.properties nacos-server-two: image: nacos/nacos-server:1.3.2 container_name: nacos-server-two ports: - 8846:8846 restart: always networks: - nacos_net privileged: true environment: MODE: cluster NACOS_APPLICATION_PORT: 8846 PREFER_HOST_MODE: 192.168.0.10 #如果支持主机名可以使用hostname,否则使用ip,默认也是ip MYSQL_SERVICE_HOST: mysql #数据源平台 仅支持mysql或不保存empty NACOS_SERVER_IP: 192.168.0.10 #多网卡情况下,指定ip或网卡 NACOS_SERVERS: 192.168.0.10:8845,192.168.0.10:8846 #集群中其它节点[ip1:port ip2:port ip3:port] MYSQL_SERVICE_HOST: 192.168.0.10 #mysql配置,Master为主节点,Slave为从节点 MYSQL_SERVICE_PORT: 3306 MYSQL_SERVICE_DB_NAME: nacos MYSQL_SERVICE_USER: nacos MYSQL_SERVICE_PASSWORD: 8uDW456#
#JVM调优参数 JVM_XMS: 1g #-Xms default :2g JVM_XMX: 1g #-Xmx default :2g JVM_XMN: 512m #-Xmn default :1g #挂载目录 volumes: - /home/nacos/nacos-1/logs:/home/nacos/logs - /home/nacos/conf/custom.properties:/home/nacos/init.d/custom.properties networks: nacos_net: driver: bridge
|
编写nginx代理
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
| cd /home/nacos/nginx vim nginx.conf #如下配置 ---
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;
#nacos地址 upstream cluster{ server 192.168.0.10:8845 weight=1 max_fails=2 fail_timeout=30s; server 192.168.0.10:8846 weight=1 max_fails=2 fail_timeout=30s; } server{ listen 8848; server_name 124.71.56.227;
large_client_header_buffers 4 16k; # 读取大型客户端请求头的缓冲区的最大数量和大小 client_max_body_size 300m; #设置nginx能处理的最大请求主体大小。 client_body_buffer_size 128k; #请求主体的缓冲区大小。
fastcgi_connect_timeout 300; fastcgi_send_timeout 300; fastcgi_read_timeout 300; fastcgi_buffer_size 64k; fastcgi_buffers 8 32k; fastcgi_busy_buffers_size 128k; fastcgi_temp_file_write_size 64k;
location / { proxy_pass http://cluster; } } include /etc/nginx/conf.d/*.conf; }
---
|
执行启动命令
docker-compose up -d
最后只需要用nginx进行代理转发就好了