Nacos installation and configuration detailed process

1.Nacos installation

1.1 Overview

Nacos /nɑ:kəʊs/ is the abbreviation of Dynamic Naming and Configuration Service, a dynamic service discovery, configuration management and service management platform that makes it easier to build cloud native applications.

Nacos is dedicated to helping users discover, configure and manage microservices. Nacos provides an easy-to-use feature set that can quickly implement dynamic service discovery, service configuration, service metadata and traffic management.

Nacos makes it more agile and easier to build, deliver and manage microservices platforms. Nacos is a service infrastructure for building modern application architecture centered on "services" (such as microservice paradigm, cloud native paradigm).

1.2.Download

Download address: https://github.com/alibaba/nacos/tags

Insert image description here

1.3.Installation

#进入压缩包所在的文件夹:
[root@localhost ~]# cd /usr/upload
#把文件解压到/user/local目录下:
[root@localhost upload]# tar -zxvf nacos-server-1.4.1.tar.gz -C /usr/local	

1.4. Startup and shutdown

  • 2.3.1.Startup
#进入nacos的bin包:
[root@localhost local]# cd nacos/bin/
#非集群模式启动:
[root@localhost bin]# ./startup.sh -m standalone
  • 2.3.2.Close
[root@localhost bin]# ./shutdown.sh

1.5.Testing

Check the IP address of Linux:

[root@localhost bin]# ifconfig

Browser access: http://192.168.204.156:8848/nacos, the default username/password is: nacos/nacos

Insert image description here

Insert image description here

2.Nacos persistence

2.1 Why persistence?

Nacos comes with its own embedded database derby by default. However, if you use cluster mode, you cannot use your own database. Otherwise, there will be one database for each node, and the data will not be unified. You need to use external mysql.

2.2 Configure Nacos persistence

2.2.1.Switch database

Modify application.properties

​ vim /usr/local/nacos/conf/application.properties:

Added support for mysql data source configuration (currently only supports mysql, version requirement: 5.6.5+)

### If use MySQL as datasource:
spring.datasource.platform=mysql

### Count of DB:
db.num=1

### Connect URL of DB:
db.url.0=jdbc:mysql://192.168.31.19:3306/nacos?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useUnicode=true&useSSL=false&serverTimezone=UTC
db.user.0=root
db.password.0=1111

2.2.2.Initialize the database

Create nacos database and import sql

Insert image description here

2.2.3.Testing

Restart nacos to test whether all data written to the embedded database by nacos is written to mysql:

Insert image description here

3.Nacos cluster

3.1. Deployment architecture diagram:

Insert image description here

1. How to distribute requests evenly? Use nginx
2. Why 3? Vote to elect leader
3. How to synchronize data? leader

3.2.Cluster

3.2.1.Node planning

node port
192.168.204.156 8848
192.168.204.156 8849
192.168.204.156 8850

3.2.2.Configuring the cluster

  1. Find conf/cluster.conf.example, rename it conf/cluster.conf, and change the content to the following:
# ip:port
192.168.209.129:8848
192.168.209.129:8849
192.168.209.129:8850
  1. Make three copies of Nacos
[root@localhost bin]# cd /usr/local
新建文件夹命令
[root@localhost java]# mkdir nacos_cluster
复制文件夹命令
[root@localhost java]# cp -r nacos nacos_cluster/nacos_8848
[root@localhost java]# cp -r nacos nacos_cluster/nacos_8849
[root@localhost java]# cp -r nacos nacos_cluster/nacos_8850
  1. Change the port numbers in to conf/application.properties:
nacos_8848的叫8848,下面的两个以此类推
server.port=8848
server.port=8849
server.port=8850

3.3.Configure proxy service

3.3.1.Install nginx

  • Install nginx dependent libraries
yum -y install gcc pcre pcre-devel zlib zlib-devel openssl openssl-devel
  • Download nginx
wget -c https://nginx.org/download/nginx-1.12.0.tar.gz
  • Unzip the installation package
tar -zxvf nginx-1.12.0.tar.gz
  • Configure nginx installation package
cd nginx-1.12.0

./configure --prefix=/usr/local/nginx

Function : ./configure configures nginx to be installed in the /usr/local/nginx directory

  • Compile and install
make && make install

8.3.2. Configure nginx proxy nacos

Modify nginx.conf:

#新建一个参数
upstream nacos {
  server 192.168.209.129:8848;
  server 192.168.209.129:8849;
  server 192.168.209.129:8850;
}
#修改server.location
server {
  listen 80;
  server_name  localhost;
  location / {
    proxy_pass http://nacos;
  }
}

3.3.2. Test nginx

  • Enter the nginx toolkit

cd /usr/local/nginx/sbin

  • turn on

./nginx

  • closure

./nginx -s stop

  • Restart

./nginx -s reload

  • View status

ps -ef | grep nginx

In the same way, you can also use this command to view nacos:

ps -ef | grep nacos

3.4.Testing

1. Start nacos cluster

[root@localhost upload]# cd /usr/local/nacos_cluster/nacos_8848/bin
[root@localhost bin]# ./startup.sh
[root@localhost bin]# cd /usr/local/nacos_cluster/nacos_8849/bin
[root@localhost bin]# ./startup.sh
[root@localhost bin]# cd /usr/local/nacos_cluster/nacos_8850/bin
[root@localhost bin]# ./startup.sh

2. Start nginx

[root@localhost nginx]# cd /usr/local/nginx/sbin/
[root@localhost sbin]# ./nginx 

3. Register the microservice to the Nacos cluster

Insert image description here

4.Access nacos cluster

Start the nacos-config service and access the nacos cluster through nginx: http://192.168.209.129/nacos

Insert image description here

Insert image description here

4.Nacos starts automatically after booting

4.1.Write startup file

  • Add nacos.service file
vim /lib/systemd/system/nacos.service
  • The contents of the file are as follows:
[Unit]
Description=nacos
After=network.target

[Service]
Type=forking
ExecStart=/usr/local/nacos/bin/startup.sh -m standalone
ExecReload=/usr/local/nacos/bin/shutdown.sh
ExecStop=/usr/local/nacos/bin/shutdown.sh
PrivateTmp=true

[Install]
WantedBy=multi-user.target

4.2. Modify nacos startup.sh

  • The three lines of configuration after modifying the JAVA_HOME path and logging out are as follows:
[ ! -e "$JAVA_HOME/bin/java" ] && JAVA_HOME=/usr/local/jdk1.8.0_191 
#[ ! -e "$JAVA_HOME/bin/java" ] && JAVA_HOME=/usr/java
#[ ! -e "$JAVA_HOME/bin/java" ] && JAVA_HOME=/opt/taobao/java
#[ ! -e "$JAVA_HOME/bin/java" ] && unset JAVA_HOME

4.3. Set up startup

systemctl daemon-reload        #重新加载服务配置
systemctl enable nacos.service #设置为开机启动
systemctl start nacos.service  #启动nacos服务
systemctl stop nacos.service   #停止nacos服务
systemctl status nacos.service   #查看nacos服务的状态

4.4 Testing

  • Restart and check the nacos service status

5.Supplement

5.1mysql installation

  • Enter a folder and download the YUM library
wget  http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
  • Install YUM library
rpm -ivh mysql57-community-release-el7-10.noarch.rpm
  • Install mysql
yum -y install mysql-community-server  --nogpgcheck
  • startup and shutdown
#启动
systemctl start mysqld
#关闭
systemctl stop mysqld
#重启
systemctl restart mysqld
#查看状态:
systemctl status mysqld
#设置开机自启:
systemctl enable mysqld
  • Log in
#查询默认密码:
grep "password" /var/log/mysqld.log
#登录:
mysql -u root -p
#登出:
exit
  • change Password
#修改密码策略
mysql> SET GLOBAL validate_password_policy=LOW;
mysql> SET GLOBAL validate_password_length=4;
#修改密码
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '1111';
  • Enable remote login permissions
mysql> use mysql;
mysql> select User,Host from user;
mysql> update user set host ="%" where user = "root";
#刷新
mysql> flush privileges;

Guess you like

Origin blog.csdn.net/qq_52830988/article/details/128319218