Write at the top
Nacos official website document: https://nacos.io/zh-cn/docs/cluster-mode-quick-start.html
Environment configuration:
操作系统: CentOS7 64位
JDK版本: 1.8
Nacos版本: 1.1.4
MySQL版本: 5.7
Nginx版本: 1.18.0
CentOS7 install JDK1.8: https://blog.csdn.net/single_0910/article/details/113033380
CentOS7 install MySQL5.7: https://blog.csdn.net/qq_42969074/article/details/84853307
CentOS7 install Nginx 1.18 .0: https://blog.csdn.net/single_0910/article/details/113061140
1: Download the Nacos installation package
Download link: https://github.com/alibaba/nacos/releases/tag/1.1.4
The cluster mode recommended by Nacos official website (VIP=virtual IP 虚拟IP
, this article uses Nginx1.18.0 to achieve)
Create a new blank folder:
mkdir /usr/local/nacos-1.1.4
nacos-server-1.1.4.tar.gz
Upload the downloaded file to the /usr/local/nacos-1.1.4 directory, and then unzip:
tar -zxvf nacos-server-1.1.4.tar.gz
After the decompression is complete, a nacos
folder will appear :
cd /usr/local/nacos-1.1.4/nacos
The directory structure is as follows:
2. Two schemes of Nacos cluster configuration:
- 2.1: Copy the decompressed
nacos
file into three copies, modify the application.properties in the conf directory, modify the server.port in it to 3333, 4444 and 5555 respectively, and then configure the following contents in their respective cluster.conf:
192.168.226.128:3333
192.168.226.128:4444
192.168.226.128:5555
Note: it 192.168.226.128
is my linux system ip, you can use it to hostname -i
view ip
Then start nacos separately, and the cluster can be set up successfully.
- 2.2: Virtual cluster (this method is used in this article, mainly because of laziness)
Please back up ( 万一玩坏了呢
) before you fumble , enter the bin
directory, and it will startup.sh
be backed up:
cp startup.sh startup.bak
Modify the content of startup.sh: p:
and p) PORT=$OPTARG;;
add the penultimate line: -Dserver.port=${PORT}
configure the following content in cluster.conf in the conf directory:
192.168.226.128:3333
192.168.226.128:4444
192.168.226.128:5555
So far, the Nacos cluster is set up
3. MySQL persistent configuration
Official website help document: https://nacos.io/zh-cn/docs/cluster-mode-quick-start.html
Run sql source file:
cd /usr/local/nacos-1.1.4/nacos/conf
Create a new nacos_config
database in the MySQL database (required by the official website), executenacos-mysql.sql
Configure Nacos persistence:
vim /usr/local/nacos-1.1.4/nacos/conf/application.properties
Add at the end:
spring.datasource.platform=mysql
db.num=1
db.url.0=jdbc:mysql://192.168.226.128:3306/nacos_config?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true
db.user=test
db.password=Nacos_test123
Description: db.url.0
Write the database ip
db.user
you want to configure,
db.password
write the database user name you want to configure, and write the database user password you want to configure
4. Nginx load balancing
Enter the Nginx configuration directory:
cd /usr/local/nginx/conf
Modify nginx.conf
:
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
upstream cluster {
server 192.168.226.128:3333;
server 192.168.226.128:4444;
server 192.168.226.128:5555;
}
server {
listen 80;
server_name localhost;
location / {
#root html;
#index index.html index.htm;
proxy_pass http://cluster;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
5: Start test
---------------------------------------slightly---------- ------------------------------