1. Nacos download and install
- Download
https://github.com/alibaba/nacos/releases/tag/1.1.4 - Unzip
tar -zxvf nacos-server-1.1.4.tar.gz
- Rewrite the nacos script
in Linux and add it in nacos/config/application.properties
spring.datasource.platform=mysql
db.num=1
db.url.0=jdbc:mysql://127.0.0.1:3306/nacos_config?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true
db.user=root
db.password=123456
- Modify cluster.conf
hostname -I #查看可识别hostname
cp cluster.conf cluster.conf.init
vim cluster.conf
#在cluster.conf中添加
10.138.219.23:3333
10.138.219.23:4444
10.138.219.23:5555
- Edit Nacos' startup script startup.sh to enable him to receive different startup ports
#nacos/bin
cp startup.sh.example startup.sh
vim startup.sh
- Nginx configuration as a load balancer
firewall-cmd --list-all #查看开放的端口号
sudo firewall-cmd --add-port=80/tcp --permanent # 设置开放的端口号
firewall-cmd --reload #重启防火墙
Change setting
cd /usr/local/nginx/sbin
vim nginx.conf
upstream cluster{
server 127.0.0.1:3333;
server 127.0.0.1:4444;
server 127.0.0.1:5555;
}
# 修改端口
server {
listen 1111;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
#root html;
#index index.html index.htm;
proxy_pass http://cluster;
}
start up
./nginx -c /usr/local/nginx/conf/nginx.conf
2 Nacos cluster construction
- Start nacos
./startup.sh -p 3333
./startup.sh -p 4444
./startup.sh -p 5555
- Check whether to start 3 nacos
ps -ef|grep nacos|grep -v grep|wc -l
- Start nginx
./nginx -c /usr/local/nginx/conf/nginx.conf
#查看是否启动
ps -ef|grep nginx
nacos.inetutils.prefer-hostname-over-ip=false
4. 测试
-
10.138.219.23:1111/nacos successfully visited
-
After the configuration is added successfully, the database inserts a piece of data
-
Modify the microservice configuration file
spring:
application:
name: nacos-payment-provider
cloud:
nacos:
discovery:
#server-addr: localhost:8848
server-addr: 10.138.219.23:1111
- Start the microservice and register successfully