Install Nacos 2.x on Linux and Windows platforms

Get into the habit of writing together! This is the sixth day of my participation in the "Nuggets Daily New Plan · April Update Challenge", click to view the details of the event .

Environmental preparation

  • 64-bit OS, Windows 10 / Linux Centos 7
  • JDK 1.8

Download the installation package

Installation package download official address: github.com/alibaba/nac…

Select the corresponding Nacos version, and the installation of the corresponding platform to download, this demo Nacos 2.0.4 version.

1650090282981-ced5ba0b-24e7-4d25-8e29-b99362119d71.png

Linux platform installation

 # 解压安装包
 tar -zxvf nacos-server-2.0.4.tar.gz
 ​
 # 移动到想要安装的目录下,并改名
 mv nacos /usr/local/nacos-2.0.4
 ​
 # 进入主目录
 cd /usr/local/nacos-2.0.4/
 ​
 # 非集群模式启动
 [root@chenpihost nacos-2.0.4]# sh bin/startup.sh -m standalone
 /usr/local/java/jdk1.8.0_212/bin/java -Djava.ext.dirs=/usr/local/java/jdk1.8.0_212/jre/lib/ext:/usr/local/java/jdk1.8.0_212/lib/ext  -Xms512m -Xmx512m -Xmn256m -Dnacos.standalone=true -Dnacos.member.list= -Xloggc:/usr/local/nacos-2.0.4/logs/nacos_gc.log -verbose:gc -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintGCTimeStamps -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=10 -XX:GCLogFileSize=100M -Dloader.path=/usr/local/nacos-2.0.4/plugins/health,/usr/local/nacos-2.0.4/plugins/cmdb,/usr/local/nacos-2.0.4/plugins/selector -Dnacos.home=/usr/local/nacos-2.0.4 -jar /usr/local/nacos-2.0.4/target/nacos-server.jar  --spring.config.additional-location=file:/usr/local/nacos-2.0.4/conf/ --logging.config=/usr/local/nacos-2.0.4/conf/nacos-logback.xml --server.max-http-header-size=524288
 nacos is starting with standalone
 nacos is starting,you can check the /usr/local/nacos-2.0.4/logs/start.out
 ​
 # 查看服务是否启动成功
 [root@chenpihost nacos-2.0.4]# ps -ef | grep nacos
 root       3282      1 99 15:22 pts/0    00:00:23 /usr/local/java/jdk1.8.0_212/bin/java -Djava.ext.dirs=/usr/local/java/jdk1.8.0_212/jre/lib/ext:/usr/local/java/jdk1.8.0_212/lib/ext -Xms512m -Xmx512m -Xmn256m -Dnacos.standalone=true -Dnacos.member.list= -Xloggc:/usr/local/nacos-2.0.4/logs/nacos_gc.log -verbose:gc -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintGCTimeStamps -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=10 -XX:GCLogFileSize=100M -Dloader.path=/usr/local/nacos-2.0.4/plugins/health,/usr/local/nacos-2.0.4/plugins/cmdb,/usr/local/nacos-2.0.4/plugins/selector -Dnacos.home=/usr/local/nacos-2.0.4 -jar /usr/local/nacos-2.0.4/target/nacos-server.jar --spring.config.additional-location=file:/usr/local/nacos-2.0.4/conf/ --logging.config=/usr/local/nacos-2.0.4/conf/nacos-logback.xml --server.max-http-header-size=524288 nacos.nacos
 root       3504   1419  0 15:22 pts/0    00:00:00 grep --color=auto nacos
 ​
 # 防火墙设置,控制台默认端口是8848,Nacos2.0版本相比1.X新增了gRPC的通信方式,因此需要增加2个端口
 [root@chenpihost nacos-2.0.4]# firewall-cmd --zone=public --list-ports
 3306/tcp 15672/tcp 5672/tcp
 [root@chenpihost nacos-2.0.4]# firewall-cmd --zone=public --add-port=8848/tcp --permanent    
 success
 [root@chenpihost nacos-2.0.4]# firewall-cmd --zone=public --add-port=9848/tcp --permanent    
 success
 [root@chenpihost nacos-2.0.4]# firewall-cmd --zone=public --add-port=9849/tcp --permanent    
 success
 [root@chenpihost nacos-2.0.4]# systemctl restart firewalld
 [root@chenpihost nacos-2.0.4]# firewall-cmd --zone=public --list-ports                   
 3306/tcp 15672/tcp 5672/tcp 8848/tcp 9848/tcp 9849/tcp
 [root@chenpihost nacos-2.0.4]# 
 ​
 # 关闭服务
 [root@chenpihost nacos-2.0.4]# sh bin/shutdown.sh 
 The nacosServer(3282) is running...
 Send shutdown request to nacosServer(3282) OK
复制代码

Windows platform installation

Unzip the installation package to the installation directory and rename it to nacos-2.0.4. Then go to the bin directory, open the CMD window, and use the following command to start the service in non-cluster mode.

 startup.cmd -m standalone
复制代码

1650092838251-70de0031-0ffc-43d0-b703-20fcacb45195.png

If you want to close the Nacos service, just double-click to close the script file shutdown.cmd.

source code

You can also download the source code from Github, and then compile and install it. This method needs to ensure that the platform has installed JDK and Maven, and use the following method to compile and install.

 git clone https://github.com/alibaba/nacos.git
 cd nacos/
 mvn -Prelease-nacos -Dmaven.test.skip=true clean install -U  
 ls -al distribution/target/
 ​
 // change the $version to your actual path
 cd distribution/target/nacos-server-$version/nacos/bin
复制代码

The next steps are the same as installing the package.

management background

Visit the Nacos console address: http://ip:8848/nacos . Both username and password are nacos.

1650093364998-2a44537e-9b76-4383-9761-23fbad18d7fc.png

After successful login, enter the following interface.

1650094039390-dea32170-5653-4663-9fa4-1ad1a225d1c5.png

Simple example of service registration discovery and configuration management

The following examples are to simply verify whether the Nacos service is available, and experience the two most important functions of Nacos, service registration and discovery, and configuration management.

service registration

 curl -X POST 'http://127.0.0.1:8848/nacos/v1/ns/instance?serviceName=nacos.naming.serviceName&ip=20.18.7.10&port=8080'
复制代码

service discovery

 curl -X GET 'http://127.0.0.1:8848/nacos/v1/ns/instance/list?serviceName=nacos.naming.serviceName'
复制代码

publish configuration

 curl -X POST "http://127.0.0.1:8848/nacos/v1/cs/configs?dataId=nacos.cfg.dataId&group=test&content=HelloWorld"
复制代码

get configuration

 curl -X GET "http://127.0.0.1:8848/nacos/v1/cs/configs?dataId=nacos.cfg.dataId&group=test"
复制代码

This sharing ends here~~

I'm Chen Pi , an ITer in Internet Coding . If you think the article is helpful to you, like, favorite, follow, comment, your support is the biggest motivation for my creation!

Guess you like

Origin juejin.im/post/7087561459277758478