环境:Docker 19.03.13、Nacos 2.0.0、Mysql 8.0、Nginx 1.19.4
1.下载Nacos容器
docker pull nacos/nacos-server:2.0.0
2.下载完成之后 依次启动 3个Nacos
每个命令中都加入了mysql的持久化,日志挂载到外部,内存设置为128m。
nacos1:
docker run -d -e PREFER_HOST_MODE=hostname -e MODE=cluster -e NACOS_APPLICATION_PORT=8846 -e NACOS_SERVERS="123.56.9.39:8846 123.56.9.39:8847 123.56.9.39:8848" -e SPRING_DATASOURCE_PLATFORM=mysql -e MYSQL_SERVICE_HOST=123.56.9.39 -e MYSQL_SERVICE_PORT=3306 -e MYSQL_SERVICE_USER=root -e MYSQL_SERVICE_PASSWORD=passw0rd -e MYSQL_SERVICE_DB_NAME=nacos_config -e NACOS_SERVER_IP=123.56.9.39 -e JVM_XMS=128m -e JVM_XMX=128m -p 8846:8846 -v /home/nacos/logs:/home/nacos/logs --name mynacos1 nacos/nacos-server:2.0.0
nacos2:
docker run -d -e PREFER_HOST_MODE=hostname -e MODE=cluster -e NACOS_APPLICATION_PORT=8847 -e NACOS_SERVERS="123.56.9.39:8846 123.56.9.39:8847 123.56.9.39:8848" -e SPRING_DATASOURCE_PLATFORM=mysql -e MYSQL_SERVICE_HOST=123.56.9.39 -e MYSQL_SERVICE_PORT=3306 -e MYSQL_SERVICE_USER=root -e MYSQL_SERVICE_PASSWORD=passw0rd -e MYSQL_SERVICE_DB_NAME=nacos_config -e NACOS_SERVER_IP=123.56.9.39 -e JVM_XMS=128m -e JVM_XMX=128m -p 8847:8847 -v /home/nacos/logs:/home/nacos/logs --name mynacos2 nacos/nacos-server:2.0.0
nacos3:
docker run -d -e PREFER_HOST_MODE=hostname -e MODE=cluster -e NACOS_APPLICATION_PORT=8848 -e NACOS_SERVERS="123.56.9.39:8846 123.56.9.39:8847 123.56.9.39:8848" -e SPRING_DATASOURCE_PLATFORM=mysql -e MYSQL_SERVICE_HOST=123.56.9.39 -e MYSQL_SERVICE_PORT=3306 -e MYSQL_SERVICE_USER=root -e MYSQL_SERVICE_PASSWORD=passw0rd -e MYSQL_SERVICE_DB_NAME=nacos_config -e NACOS_SERVER_IP=123.56.9.39 -e JVM_XMS=128m -e JVM_XMX=128m -p 8848:8848 -v /home/nacos/logs:/home/nacos/logs --name mynacos3 nacos/nacos-server:2.0.0
nacos启动成功之后进行访问;
3.下载nginx容器
docker pull nginx:latest
4.启动nginx容器
docker run -d --name nginx -v /cluster/n/nginx.conf:/etc/nginx/nginx.conf -p 80:80 nginx
5.编辑/cluster/n/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/logs/nginx/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
include /etc/nginx/conf.d/*.conf;
server {
listen 80;
server_name 123.56.9.39;
location /nacos {
proxy_pass http://nacos;
}
}
upstream nacos{
server 123.56.9.39:8848;
server 123.56.9.39:8847;
server 123.56.9.39:8846;
}
}
6.访问123.56.9.39/nacos
配置nginx+docker集群成功。