[] Nacos local cluster deployment

About Nacos has launched a four introductory article:

Preliminary Nacos (a) - Stand-alone mode is activated

Preliminary Nacos (two) - SpringCloud use of service registration and discovery Nacos

Preliminary Nacos (c) - Integration Dubbo and Nacos under SpringBoot

Preliminary Nacos (four) - Under SpringBoot use as a distribution center Nacos

Today, we begin to further explore the use of Nacos, distributed cluster mode deployment Nacos. (In addition, the current Nacos1.0.0 stable version has been released for the current test did not find the problem temporarily, to demonstrate our re-use 1.0.0.)

Of course, we still refer to the official document: cluster deployment instructions , due to the need to use a database cluster model, here we are a good default Mysql database you have installed, and then we have to download the latest https://github.com/alibaba/nacos/releases Installation package.

wget https://github.com/alibaba/nacos/releases/download/1.0.0/nacos-server-1.0.0.zip
复制代码

unzip nacos-server-1.0.0.zip

nacos cd

cp conf/cluster.conf.example conf/cluster.conf

You need to configure three or more than three nodes, the production environment is recommended distributed across multiple servers, currently we only tested on a machine.

vi conf / cluster.conf

127.0.0.1:8848
127.0.0.1:8849
127.0.0.1:8850
复制代码

Then enter mysql, create a database named nacos_config of import config / nacos-mysql.sql. (Used here to test the single temporary database, the production environment is recommended contour may be a master-slave mode)

After completing construction of the database, the default on official documents using embedded cmdb database, Mysql database is not configured, ignorant people a little forced, Baidu a bit to find the configuration.

vi conf/application.properties

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=数据库用户名
db.password=数据密码
复制代码

In addition, because we ran three on a single machine, so the startup and shutdown scripts need to do a little modification.

cp bin/startup.sh bin/startup-port.sh

we bin / startup-port.sh

export MODE="cluster"
export FUNCTION_MODE="all"
export SERVER_PORT="8848" while getopts ":m:f:p:" opt do case $opt in m) MODE=$OPTARG;; f) FUNCTION_MODE=$OPTARG;; p) SERVER_PORT=$OPTARG;; ?) echo "Unknown parameter" exit 1;; esac done JAVA_OPT="${JAVA_OPT} -Dserver.port=${SERVER_PORT}" 复制代码

cp bin/shutdown.sh bin/shutdown-port.sh

we bin / shutdown-port.sh

PORT=$1
if [ ! $PORT ]; then
  echo "please select stop port!" >&2 exit 1 fi pid=`ps ax | grep -i 'nacos.nacos' |grep java |grep ${PORT} | grep -v grep | awk '{print $1}'` 复制代码

Start as follows:

sh bin/startup-port.sh -p 8848

sh bin/startup-port.sh -p 8849

sh bin/startup-port.sh -p 8850

Closed as follows:

sh bin/shutdown-port.sh 8848

sh bin/shutdown-port.sh 8849

sh bin/shutdown-port.sh 8850

After the start can be opened in a browser http://127.0.0.1:8848/nacos/,http://127.0.0.1:8849/nacos/,http://127.0.0.1:8850/nacos/ to see console, the default user name / password nacos / nacos.

Annex 1: only one address is accessible via the load balancer to configure Nginx three nodes:

upstream nacos-cluster{
    server 127.0.0.1:8848;
    server 127.0.0.1:8849;
    server 127.0.0.1:8850;
}
复制代码

Appendix 2: Console clustered mode username and password exists the users table in the database, the user name directly modify on the line, need password encryption org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder.

Then we can try the demo project, just in application.properties in stand-alone mode to change the configuration from the cluster mode:

spring.cloud.nacos.discovery.server-addr=127.0.0.1:8848,127.0.0.1:8849,127.0.0.1:8850
复制代码

Configuring the center need to be modified as follows:

nacos.config.server-addr=127.0.0.1:8848,127.0.0.1:8849,127.0.0.1:8850
复制代码

dubbo configuration needs to be modified as follows:

dubbo.registry.address=nacos://127.0.0.1:8848?backup=127.0.0.1:8849,127.0.0.1:8850
复制代码

After starting the program, you can test the service registration and discovery, configuration centers can use as a stand-alone mode as normal. We can try to shut down one or two nacos, still does not affect the normal operation of the system.



Transfer: https: //juejin.im/post/5cbad19ef265da038b20165e

Guess you like

Origin www.cnblogs.com/itplay/p/11039416.html