nacos cluster based on docker container (3 nodes)
1, Preparation before installation
1.1. Server preparation
Nacos cluster construction requires three or more Nacos nodes to form a cluster, so at least three server resources are required. This construction uses the three containers built by redis cluster and rocketmq cluster as three server resources.
Server resources | Ip port |
---|---|
10.25.27.116 | 8848 |
10.25.27.117 | 8848 |
10.25.27.118 | 8848 |
192.168.200.129 (host, acting as mysql database resource machine) | 3306 |
1.2 preparation for software installation
Serial number | Software name | Functional use |
---|---|---|
1 | nacos-server-1.4.1 | Registration / configuration center |
2 | mysql | Data storage |
3 | nginx-1.17.0 | Load Balancer |
4 | pcre-8.37 | nginx dependent components |
5 | zlib | nginx dependent components |
6 | openssl | nginx dependent components |
7 | gcc,gcc-c++ | nginx, pcre dependent components |
2, Software installation
2.1. Install and compile software
1. gcc,gcc-c + + installation (root operation)
Check whether gcc is installed. Check the gcc installation and version of the server through the command. If it is not installed, install it.
#View gcc version gcc --version g++ --version # perhaps rpm -qa | grep gcc # install yum install gcc,gcc-c++
2. Zlib installation
If gcc is not installed, check whether it is installed first
# Check the installation rpm -qa | grep zlib # install yum install zlib-devel
3. Openssl installation
Like gcc, check whether it is installed first. If not, install it again
# Check the installation rpm -qa | grep openssl # install yum install openssl-devel
Note: if the installation of yum fails or the download speed is slow, you can modify the source of yum to Alibaba. The specific steps are Baidu.
2.2 nacos installation
1. Upload the installation package to the software directory and enter the software directory
cd /home/test01/software
2. Unzip the installation package to the directory / home/test01/
tar -zxvf nacos-server-1.4.1.tar.gz -C /home/test01/
2.3. Modify the cluster configuration file
1. Go to / home/test01/nacos/conf and copy cluster Conf.example is cluster conf
cd /home/test01/nacos/conf cp cluster.conf.example cluster.conf
2. Edit cluster Conf configure cluster parameters
# Enter directory cd /home/test01/naocs/conf # Edit cluster Conf file and add node configuration (fill in IP according to the actual website address) vim cluster.conf #Add the following 10.25.27.116:8848 10.25.27.117:8848 10.25.27.118:8848
2.4. Initialize the database required by nacos
This time, in order to facilitate the direct use of the mysql database of the host machine (the host machine has been installed before, so I'm too lazy to install it again, and installing mysql is not the focus of this article), if necessary, you can create a docker container as the mysql installation server. No matter where mysql is installed, you need to ensure that the server where nacos is installed can connect to the ip address of myslq.
# Test the connectivity of mysqlIP on three resource servers. ping 192.168.200.129
Use the database tool to connect the prepared database and create a new database nacos_config_cluster, and then execute Nacos MySQL in the / home/test01/nacos/conf directory SQL database script to create corresponding tables.
2.5. Configure connection database
Modify the application. In the nacos/conf directory Add the following content at the end of the properties file:
# The following contents are added at the end (connect to the database according to the actual situation) spring.datasource.platform=mysql #Persist using mysql db.num=1 #ip, port number and database name can be modified according to your own situation. db.url.0=jdbc:mysql://192.168.200.129:3306/nacos_config_cluster?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true #Database connection user name db.user=XXXX #Database connection password db.password=XXXXXX
3, Start three nacos nodes in turn
Use scp to copy the configured nacos to the other two servers
scp -r test01@10.25.27.116:/home/test01/nacos ./
Start nacos
cd /home/test01/nacos/bin ./startup.sh #View the current number of server nodes ps -ef|grep nacos|grep -v grep|wc -l
Note: if you think that the jvm takes up a large amount of memory after startup, you can modify startup jvm startup parameters in the SH file.
4, Using nginx load balancer (116 servers)
4.1. Install nginx dependent component pcre
Upload the installation package to / home/test01/software directory.
# Unzip the installation package tar -zxvf pcre-8.37.tar.gz # Enter directory cd pcre-8.37 # Execute configure ./configure # compile make # After installation, the directory creation fails. You can use the root user make install # View version pcre-config --version
Installation of ng2.in4
Upload the installation package to / home/test01/software directory.
# Unzip the installation package tar -zxvf nginx-1.17.0.tar.gz # Enter directory cd nginx-1.17.0 # Execute configure ./configure --prefix=/home/test01/nginx # Compile and install make && make install
4.3. Modify the configuration conf of nginx
Enter / home/test01/nginx/conf directory to edit nginx Conf file, modify or add the following configuration after http {
upstream cluster{ # The ip address is configured according to your actual situation server 10.25.27.116:8848; server 10.25.27.117:8848; server 10.25.27.118:8848; } server { listen 8012; server_name localhost; location / { proxy_pass http://cluster; } }
4.4. Start or refresh nginx
/home/test01/nginx/sbin/nginx -c /home/test01/nginx/conf/nginx.conf
The 116 container opens the 8012 port mapping and maps to the 8012 port of the host. See the previous article or Baidu for details.
Enter the host address in the browser to access nginx: http://192.168.200.129:8012/nacos The initial account and password are all Nacos. Click cluster to view the status of Nacos cluster.