mkdir -p /apps/nacos
# 切换到nacos目录
cd /apps/nacos
# 创建nginx配置文件
touch nginx.conf
# 写nginx.conf文件信息
vim nginx.conf
以下为nginx.conf内容
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 4096;
}
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;
# 添加负载均衡配置
upstream nacos {
server nacos-server01:8846 weight=1 max_fails=2 fail_timeout=10s;
server nacos-server02:8847 weight=1 max_fails=2 fail_timeout=10s;
server nacos-server03:8848 weight=1 max_fails=2 fail_timeout=10s;
}
server {
listen 80;
listen [::]:80;
# 修改为宿主机的 IP地址
server_name 10.1.125.145;
# To allow special characters in headers
ignore_invalid_headers off;
# Allow any size file to be uploaded.
# Set to a value such as 1000m; to restrict file size to a specific value
client_max_body_size 0;
# To disable buffering
proxy_buffering off;
proxy_request_buffering off;
location / {
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_connect_timeout 300;
# Default is HTTP/1, keepalive is only enabled in HTTP/1.1
proxy_http_version 1.1;
proxy_set_header Connection "";
chunked_transfer_encoding off;
# 添加代理配置
proxy_pass http://nacos;
}
}
}
# 切换到nacos目录
cd /apps/nacos
# 创建docker-compose.yaml文件
touch docker-compose.yaml
# 写docker-compose.yaml文件信息
vim docker-compose.yaml
# 以下为docker-compose.yaml内容,注意MYSQL_SERVICE_*相关为数据库配置,nacos-nginx的volumes为挂载读取同目录下的nginx.conf配置
version: "3"
services:
nacos1:
container_name: nacos-server01
hostname: nacos-server01
image: nacos/nacos-server:2.0.3
environment:
- MODE=cluster
- PREFER_HOST_MODE=hostname
- NACOS_SERVERS=nacos-server01:8848 nacos-server02:8848 nacos-server03:8848
- SPRING_DATASOURCE_PLATFORM=mysql
- MYSQL_SERVICE_HOST=Mysql的Ip
- MYSQL_SERVICE_PORT=端口
- MYSQL_SERVICE_USER=用户
- MYSQL_SERVICE_PASSWORD=密码
- MYSQL_SERVICE_DB_NAME=nacos_config nacos数据库
- JVM_XMS=128m
- JVM_XMX=128m
- JVM_XMN=128m
volumes:
- ./cluster-logs/nacos1:/home/nacos/logs
- ./init.d/custom.properties:/home/nacos/init.d/custom.properties
ports:
- 8846:8848
- 9848:9848
- 9555:9555
restart: on-failure
nacos2:
container_name: nacos-server02
hostname: nacos-server02
image: nacos/nacos-server:2.0.3
environment:
- MODE=cluster
- PREFER_HOST_MODE=hostname
- NACOS_SERVERS=nacos-server01:8848 nacos-server02:8848 nacos-server03:8848
- SPRING_DATASOURCE_PLATFORM=mysql
- MYSQL_SERVICE_HOST=192.168.120.253
- MYSQL_SERVICE_PORT=3306
- MYSQL_SERVICE_USER=root
- MYSQL_SERVICE_PASSWORD=root
- MYSQL_SERVICE_DB_NAME=nacos_config
- JVM_XMS=128m
- JVM_XMX=128m
- JVM_XMN=128m
volumes:
- ./cluster-logs/nacos1:/home/nacos/logs
- ./init.d/custom.properties:/home/nacos/init.d/custom.properties
ports:
- 8847:8848
- 9849:9848
restart: on-failure
nacos3:
container_name: nacos-server03
hostname: nacos-server03
image: nacos/nacos-server:2.0.3
environment:
- MODE=cluster
- PREFER_HOST_MODE=hostname
- NACOS_SERVERS=nacos-server01:8848 nacos-server02:8848 nacos-server03:8848
- SPRING_DATASOURCE_PLATFORM=mysql
- MYSQL_SERVICE_HOST=192.168.120.253
- MYSQL_SERVICE_PORT=3306
- MYSQL_SERVICE_USER=root
- MYSQL_SERVICE_PASSWORD=root
- MYSQL_SERVICE_DB_NAME=nacos_config
- JVM_XMS=128m
- JVM_XMX=128m
- JVM_XMN=128m
volumes:
- ./cluster-logs/nacos1:/home/nacos/logs
- ./init.d/custom.properties:/home/nacos/init.d/custom.properties
ports:
- 8848:8848
- 9850:9848
restart: on-failure
nacos-nginx:
container_name: nacos-nginx
image: nginx:1.21.1
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf:ro
ports:
- 8845:80
restart: on-failure
# 编排docker-compose.yaml
# docker-compose -f <编排文件路径> up -d
docker-compose -f docker-compose.yaml up -d
# 查看运行情况
docker ps -n 5
先自我介绍一下,小编13年上师交大毕业,曾经在小公司待过,去过华为OPPO等大厂,18年进入阿里,直到现在。深知大多数初中级java工程师,想要升技能,往往是需要自己摸索成长或是报班学习,但对于培训机构动则近万元的学费,着实压力不小。自己不成体系的自学效率很低又漫长,而且容易碰到天花板技术停止不前。因此我收集了一份《java开发全套学习资料》送给大家,初衷也很简单,就是希望帮助到想自学又不知道该从何学起的朋友,同时减轻大家的负担。添加下方名片,即可获取全套学习资料哦