1. 程式人生 > 實用技巧 >nacos單機部署

nacos單機部署

nacos單機部署

註冊中心類似於通訊錄,可以查詢到服務和服務地址的對映關係
一、安裝jdk1.8

yum install java-1.8.0-openjdk.x86_64 -y
#yum方式安裝沒有配置JAVA_HOME環境變數
cat>>/etc/profile<<EOF
export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.232.b09-0.el7_7.x86_64/jre
export PATH=$PATH:$JAVA_HOME/bin
export CLASSPATH=.:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar
EOF
source /etc/profile

二、安裝參考官方文件
nacos下載穩定版:
https://github.com/alibaba/nacos/releases

#解壓
unzip nacos-server-1.1.0.zip -d/usr/local/ && cd /usr/local/nacos/bin
#啟動單機模式
sh startup.sh -m standalone

[root@nacos bin]# shstartup.sh-m standalone
/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.232.b09-0.el7_7.x86_64/jre/bin/java -Xms512m -Xmx512m -Xmn256m -Dnacos.standalone=true -Djava.ext.dirs=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.232.b09-0.el7_7.x86_64/jre/jre/lib/ext:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.232.b09-0.el7_7.x86_64/jre/lib/ext:/usr/local/nacos/plugins/cmdb:/usr/local/nacos/plugins/mysql -Xloggc:/usr/local/nacos/logs/nacos_gc.log -verbose:gc -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintGCTimeStamps -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=10 -XX:GCLogFileSize=100M -Dnacos.home=/usr/local/nacos -Dloader.path=/usr/local/nacos/plugins/health -jar /usr/local/nacos/target/nacos-server.jar --spring.config.location=classpath:/,classpath:/config/,file:./,file:./config/,file:/usr/local/nacos/conf/ --logging.config=/usr/local/nacos/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/logs/start.out

服務註冊&發現和配置管理

1、服務註冊
curl -X POST 'http://127.0.0.1:8848/nacos/v1/ns/instance?serviceName=nacos.naming.serviceName&ip=20.18.7.10&port=8080'
返回ok
2、服務發現
curl -X GET 'http://127.0.0.1:8848/nacos/v1/ns/instance/list?serviceName=nacos.naming.serviceName'
返回{"metadata":{},"dom":"nacos.naming.serviceName","cacheMillis":3000,"useSpecifiedURL":false,"hosts":[],"name":"DEFAULT_GROUP@@nacos.naming.serviceName","checksum":"a07d4655e7caf8a6aa987662a6179ad2","lastRefTime":1575104879006,"env":"","clusters":""}
3、釋出配置
curl -X POST "http://127.0.0.1:8848/nacos/v1/cs/configs?dataId=nacos.cfg.dataId&group=test&content=HelloWorld"
返回true
4、獲取配置
curl -X GET "http://127.0.0.1:8848/nacos/v1/cs/configs?dataId=nacos.cfg.dataId&group=test"
返回HelloWorld

關閉伺服器
sh /usr/local/nacos/bin/shutdown.sh
三、訪問nacos圖形介面(預設安裝)
http://ip:8848/nacos/
預設賬號密碼nacos/nacos