搭建
Nacos
叢集可以參考下面這篇部落格:
- Spring Cloud Alibaba:搭建Nacos叢集
部署
Nginx
來代理
Nacos
叢集,應用通過通路
Nginx
,可以間接通路
Nacos
叢集,
Nginx
會将請求轉發到内網中的
Nacos
叢集(内網更加安全),并且會進行負載均衡。
Nginx
的安裝與運作,部落客在之前的部落格中已經介紹過了:
- Nginx:Nginx安裝與運作
部落客就在
192.168.1.196
這台虛拟機上部署
Nginx
,部署
Nginx
不應該和
Nacos
叢集在相同的伺服器上,這裡部落客隻是為了圖友善。
根據上面這篇部落格的步驟進行安裝與運作
Nginx
即可。
Nginx
部署成功了。
修改配置檔案:
[root@localhost sbin]# cd /usr/local/nginx/conf
[root@localhost conf]# ll
total 68
-rw-r--r--. 1 root root 1077 Nov 11 01:30 fastcgi.conf
-rw-r--r--. 1 root root 1077 Nov 11 01:30 fastcgi.conf.default
-rw-r--r--. 1 root root 1007 Nov 11 01:30 fastcgi_params
-rw-r--r--. 1 root root 1007 Nov 11 01:30 fastcgi_params.default
-rw-r--r--. 1 root root 2837 Nov 11 01:30 koi-utf
-rw-r--r--. 1 root root 2223 Nov 11 01:30 koi-win
-rw-r--r--. 1 root root 5231 Nov 11 01:30 mime.types
-rw-r--r--. 1 root root 5231 Nov 11 01:30 mime.types.default
-rw-r--r--. 1 root root 2656 Nov 11 01:30 nginx.conf
-rw-r--r--. 1 root root 2656 Nov 11 01:30 nginx.conf.default
-rw-r--r--. 1 root root 636 Nov 11 01:30 scgi_params
-rw-r--r--. 1 root root 636 Nov 11 01:30 scgi_params.default
-rw-r--r--. 1 root root 664 Nov 11 01:30 uwsgi_params
-rw-r--r--. 1 root root 664 Nov 11 01:30 uwsgi_params.default
-rw-r--r--. 1 root root 3610 Nov 11 01:30 win-utf
[root@localhost conf]# vim nginx.conf
reload nginx
:
[root@localhost conf]# cd ..
[root@localhost nginx]# cd sbin
[root@localhost sbin]# ./nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@localhost sbin]# ./nginx -s reload
很顯然
Nginx
代理成功了。
修改應用的
application.yml
:
server:
port: 8080
spring:
application:
name: nacos
cloud:
nacos:
discovery:
server-addr: 192.168.1.196:80
重新啟動應用:
應用服務成功注冊到
Nacos
叢集上。