nacos cluster 1.3.1

1 Preparation
Environment: centos7, nacos tar package: nacos-server-1.3.1.tar.gz, mysql5.7.30 code package

Download https://github.com/alibaba/nacos/releases nacos-server-1.3.1.tar.gz source

Enter the /opt directory

[[email protected] nacos]# cd /opt/
[[email protected] opt]# ls
[[email protected] opt]# ls
nacos-server-1.3.1.tar.gz
[[email protected] opt]# tar -zxvf nacos-server-1.3.1.tar.gz

Figure:

Insert picture description here


Do not operate nacos directly, copy a copy, and execute the command: cp -r nacos /usr/local/fire/nacos/; (the /usr/local/fire directory exists under / (/nacos will be generated by itself))

Insert picture description here


2 Cluster configuration
2.1 Build a database and build a table
Install a mysql database on linux, create a nacos_config library, and execute nacos-mysql.sql under the path /usr/local/fire/nacos/conf (or sql prepared by yourself).

Insert picture description here


2.2 Modify application.properties
Modify the application.properties configuration file of /usr/local/fire/nacos/conf (for safety, make a backup of this file yourself).

Backup configuration file: cp application.properties application.properties.bk

Modify the configuration file: vi application.properties

Add the content in the configuration file as follows (in fact, there is a corresponding configuration in the application.properties configuration, which is annotated, you can open the annotation yourself and make the corresponding modification):

// 实际环境需要修改
###################################################
spring.datasource.platform=mysql
db.num=1
db.url.0=jdbc:mysql://1.1.1.1:3306/nacos_config?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true
db.user=root
db.password=root

2.3 Cluster configuration cluster.cnf
copy cluster.conf.example under /usr/local/fire/nacos/conf as cluster.conf, add cluster configuration in cluster.conf, configuration as shown below:
configure three different hosts, ports Can be the same or different

Insert picture description here

The configuration is relatively simple, as long as the form of ip:port is fine, the official website requires at least three cluster configurations. It should be noted that the 127.0.0.1:port format cannot be used for ip.

2.4 Startup script startup.sh configuration
Enter the /usr/local/fire/nacos/bin directory, modify startup.sh (make a copy

Insert picture description here


before

Insert picture description here


modification ) before modification 1: after modification 1:
be sure to add the top line:

export SERVER_PORT=""
d)
            SERVER_PORT=$OPTARG;;
Insert picture description here
	JAVA_OPT="${JAVA_OPT} -Dserver.port=8848"
	JAVA_OPT="${JAVA_OPT} -Dnacos.server.ip=192.168.xx.xx"
Insert picture description here

Before modification 2:

Insert picture description here


After modification 2:

-Dserver.port=${SERVER_PORT}
Insert picture description here

The default settings for several parameters of the JVM are too large. If the memory of the virtual machine is not enough, you can adjust it yourself.

Insert picture description here

Description:

-Xms500m: -Xms is the memory allocated when the jvm starts, for example -Xms500m means 500M is allocated.

-Xmx500m:-Xmx is the maximum memory that can be used during jvm operation. If the program requires more memory to run, and this value is exceeded, an OOM exception will be thrown.

-Xmn256m: -Xmn represents the size of the young generation. Heap size = young generation size + old generation size + persistent generation size. The size of the permanent generation is generally fixed at 64m, so when the young generation is increased, the size of the old generation will be reduced. This value has a greater impact on system performance. Sun officially recommends a configuration of 3/8 of the entire heap.

2.5 Nginx configuration
Enter /usr/local/nginx/conf and modify the nginx.conf configuration file. The main modification is in the http block.
Nginx installation

https://blog.csdn.net/bighuan/article/details/106601905

Configuration:

Insert picture description here

-1 Start command is executed
in the /usr/local/nginx/sbin directory. /nginx
-2 Close command is executed
in the /usr/local/nginx/sbin directory. /nginx -s stop
-3 Reload command is executed
in /usr/ Execute under the local/nginx/sbin directory. /nginx -s reload
-4 View the version
. /nginx -v;

Question 1:

// centos启动Nginx提示nginx: [emerg] still could not bind() 
// 同时页面访问也会出现 nginx 403 Forbidden
[[email protected] ~]# /usr/local/nginx/sbin/nginx 
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] still could not bind()

Solution:

Check the configured port according to the Nginx configuration file (port 80 is used in this article), and then check the port occupancy according to the port

[[email protected] ~]# netstat -ntlp|grep 80  
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      7043/nginx: worker

Use the kill command to kill the occupied process, and then restart Nginx

kill -9 7043

2.6 Start the cluster
2.6.1 Start the nacos cluster
Enter the /usr/local/fire/nacos/bin directory of nacos,

Insert picture description here

http://192.168.xx.xx:1111/nacos/#/login

Insert picture description here