Nacos installation and cluster construction under Linux

1. Nacos download and install

  1. Download
    https://github.com/alibaba/nacos/releases/tag/1.1.4
  2. Unzip
tar -zxvf nacos-server-1.1.4.tar.gz
  1. 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
  1. 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
  1. 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

Insert picture description here

  1. 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

  1. Start nacos
./startup.sh -p 3333
./startup.sh -p 4444
./startup.sh -p 5555
  1. Check whether to start 3 nacos
ps -ef|grep nacos|grep -v grep|wc -l
  1. Start nginx
./nginx -c /usr/local/nginx/conf/nginx.conf
#查看是否启动
ps -ef|grep nginx

nacos.inetutils.prefer-hostname-over-ip=false
4. 测试

  1. 10.138.219.23:1111/nacos successfully visited

  2. After the configuration is added successfully, the database inserts a piece of data
    Insert picture description here

  3. 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
  1. Start the microservice and register successfully
    Insert picture description here

Guess you like

Origin blog.csdn.net/qq_40857365/article/details/112720609