首页 > 系统相关 >CentOS Stream 安装 Nacos

CentOS Stream 安装 Nacos

时间:2022-11-07 14:02:31浏览次数:66  
标签:java Stream CentOS spring jar nacos Nacos context RELEASE

版本
Linux CentOS Stream release 8
Nacos 2.0.3
MySQL 8.0.29

Step1:下载 并解压

unzip nacos-server-$version.zip 
# 或者 
tar -zxvf nacos-server-$version.tar.gz

sudo mkdir -p /opt/nacos
sudo mv nacos /opt/nacos/nacos-server-2.1.0

cd /opt/nacos/nacos-server-$version/bin

Step2:启动

启动命令(standalone代表着单机模式运行,非集群模式):

sh startup.sh -m standalone

如果您使用的是ubuntu系统,或者运行脚本报错提示[[符号找不到,可尝试如下运行:

bash startup.sh -m standalone

Step3:关闭服务

sh shutdown.sh

设置自启动

# 编写服务脚本
vim /lib/systemd/system/nacos.service

# 添加以下内容
[Unit]
Description=nacos
After=network.target

[Service]
Type=forking
Environment="JAVA_HOME=/opt/java/jdk1.8.0_321" # 改成自己的jdk路径,因为服务脚本的环境和系统环境变量不能共享,所以还得设置才能生效。
ExecStart=/opt/nacos/nacos-server-2.0.3/bin/startup.sh -m standalone # standalone 是单机,默认是集群 cluster
ExecReload=/opt/nacos/nacos-server-2.0.3/bin/shutdown.sh
ExecStop=/opt/nacos/nacos-server-2.0.3/bin/shutdown.sh
PrivateTmp=true

[Install]
WantedBy=multi-user.target

# 重新加载所有service服务
systemctl daemon-reload
# 开机启动nacos
systemctl enable nacos.service
# 查看该service是否开机启用
systemctl is-enabled nacos.service
# 启动该服务
systemctl start nacos.service
# 查看该服务状态
systemctl status nacos.service

Linux 开启 8848,9848,9849 端口

为什么要开启 9848,9849 端口?https://nacos.io/zh-cn/docs/2.0.0-compatibility.html

如果没有开启上述两个端口,可能会出现 Request nacos server failed 异常。

com.alibaba.nacos.api.exception.NacosException: Request nacos server failed: 
	at com.alibaba.nacos.client.naming.remote.gprc.NamingGrpcClientProxy.requestToServer(NamingGrpcClientProxy.java:279) ~[nacos-client-2.0.3.jar:na]
	at com.alibaba.nacos.client.naming.remote.gprc.NamingGrpcClientProxy.doRegisterService(NamingGrpcClientProxy.java:129) ~[nacos-client-2.0.3.jar:na]
	at com.alibaba.nacos.client.naming.remote.gprc.NamingGrpcClientProxy.registerService(NamingGrpcClientProxy.java:115) ~[nacos-client-2.0.3.jar:na]
	at com.alibaba.nacos.client.naming.remote.NamingClientProxyDelegate.registerService(NamingClientProxyDelegate.java:95) ~[nacos-client-2.0.3.jar:na]
	at com.alibaba.nacos.client.naming.NacosNamingService.registerInstance(NacosNamingService.java:145) ~[nacos-client-2.0.3.jar:na]
	at com.alibaba.cloud.nacos.registry.NacosServiceRegistry.register(NacosServiceRegistry.java:74) ~[spring-cloud-starter-alibaba-nacos-discovery-2.2.7.RELEASE.jar:2.2.7.RELEASE]
	at org.springframework.cloud.client.serviceregistry.AbstractAutoServiceRegistration.register(AbstractAutoServiceRegistration.java:239) [spring-cloud-commons-2.2.9.RELEASE.jar:2.2.9.RELEASE]
	at com.alibaba.cloud.nacos.registry.NacosAutoServiceRegistration.register(NacosAutoServiceRegistration.java:78) [spring-cloud-starter-alibaba-nacos-discovery-2.2.7.RELEASE.jar:2.2.7.RELEASE]
	at org.springframework.cloud.client.serviceregistry.AbstractAutoServiceRegistration.start(AbstractAutoServiceRegistration.java:138) [spring-cloud-commons-2.2.9.RELEASE.jar:2.2.9.RELEASE]
	at org.springframework.cloud.client.serviceregistry.AbstractAutoServiceRegistration.bind(AbstractAutoServiceRegistration.java:101) [spring-cloud-commons-2.2.9.RELEASE.jar:2.2.9.RELEASE]
	at org.springframework.cloud.client.serviceregistry.AbstractAutoServiceRegistration.onApplicationEvent(AbstractAutoServiceRegistration.java:88) [spring-cloud-commons-2.2.9.RELEASE.jar:2.2.9.RELEASE]
	at org.springframework.cloud.client.serviceregistry.AbstractAutoServiceRegistration.onApplicationEvent(AbstractAutoServiceRegistration.java:47) [spring-cloud-commons-2.2.9.RELEASE.jar:2.2.9.RELEASE]
	at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172) [spring-context-5.2.15.RELEASE.jar:5.2.15.RELEASE]
	at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165) [spring-context-5.2.15.RELEASE.jar:5.2.15.RELEASE]
	at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139) [spring-context-5.2.15.RELEASE.jar:5.2.15.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:404) [spring-context-5.2.15.RELEASE.jar:5.2.15.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:361) [spring-context-5.2.15.RELEASE.jar:5.2.15.RELEASE]
	at org.springframework.boot.web.servlet.context.WebServerStartStopLifecycle.start(WebServerStartStopLifecycle.java:46) [spring-boot-2.3.12.RELEASE.jar:2.3.12.RELEASE]
	at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:182) [spring-context-5.2.15.RELEASE.jar:5.2.15.RELEASE]
	at org.springframework.context.support.DefaultLifecycleProcessor.access$200(DefaultLifecycleProcessor.java:53) [spring-context-5.2.15.RELEASE.jar:5.2.15.RELEASE]
	at org.springframework.context.support.DefaultLifecycleProcessor$LifecycleGroup.start(DefaultLifecycleProcessor.java:360) [spring-context-5.2.15.RELEASE.jar:5.2.15.RELEASE]
	at org.springframework.context.support.DefaultLifecycleProcessor.startBeans(DefaultLifecycleProcessor.java:158) [spring-context-5.2.15.RELEASE.jar:5.2.15.RELEASE]
	at org.springframework.context.support.DefaultLifecycleProcessor.onRefresh(DefaultLifecycleProcessor.java:122) [spring-context-5.2.15.RELEASE.jar:5.2.15.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:895) [spring-context-5.2.15.RELEASE.jar:5.2.15.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:554) [spring-context-5.2.15.RELEASE.jar:5.2.15.RELEASE]
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:143) [spring-boot-2.3.12.RELEASE.jar:2.3.12.RELEASE]
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:755) [spring-boot-2.3.12.RELEASE.jar:2.3.12.RELEASE]
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:747) [spring-boot-2.3.12.RELEASE.jar:2.3.12.RELEASE]
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:402) [spring-boot-2.3.12.RELEASE.jar:2.3.12.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:312) [spring-boot-2.3.12.RELEASE.jar:2.3.12.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1247) [spring-boot-2.3.12.RELEASE.jar:2.3.12.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1236) [spring-boot-2.3.12.RELEASE.jar:2.3.12.RELEASE]
	at com.xt.nacosconsumer.NacosConsumerApplication.main(NacosConsumerApplication.java:37) [classes/:na]
Caused by: com.alibaba.nacos.api.exception.NacosException: Client not connected,current status:STARTING
	at com.alibaba.nacos.common.remote.client.RpcClient.request(RpcClient.java:655) ~[nacos-client-2.0.3.jar:na]
	at com.alibaba.nacos.common.remote.client.RpcClient.request(RpcClient.java:635) ~[nacos-client-2.0.3.jar:na]
	at com.alibaba.nacos.client.naming.remote.gprc.NamingGrpcClientProxy.requestToServer(NamingGrpcClientProxy.java:269) ~[nacos-client-2.0.3.jar:na]
	... 32 common frames omitted

开放防火墙端口

# Step1: 查看当前防火墙状态
sudo firewall-cmd --list-all

# Step2: 添加端口
sudo firewall-cmd --permanent --add-port=8848/tcp
sudo firewall-cmd --permanent --add-port=9848-9849/tcp

# Step3: 重启防火墙
sudo service firewalld restart

# Step4: 查看是否生效
sudo firewall-cmd --query-port=8848/tcp

# 删除端口
sudo firewall-cmd --permanent --remove-port=8848/tcp

单机模式支持mysql

在 0.7 版本之前,在单机模式时 nacos 使用嵌入式数据库实现数据的存储,不方便观察数据存储的基本情况。0.7 版本增加了支持 mysql 数据源能力,具体的操作步骤:

  • 1.安装数据库,版本要求:5.6.5+
  • 2.初始化mysql数据库,数据库初始化文件:nacos-db.sql
  • 3.修改 conf/application.properties 文件,增加支持 mysql 数据源配置(目前只支持 mysql ),添加 mysql 数据源的 url、用户名和密码。
spring.datasource.platform=mysql

db.num=1
db.url.0=jdbc:mysql://localhost:3306/nacos?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true
db.user=nacos
db.password=nacos

再以单机模式启动nacos,nacos所有写嵌入式数据库的数据都写到了mysql

实战

一个非常适合学习的 Spring Cloud 开源项目:

Gitee GitHub
后端 https://gitee.com/linjiabin100/pi-cloud.git https://github.com/zengpi/pi-cloud.git
前端 https://gitee.com/linjiabin100/pi-cloud-web.git https://github.com/zengpi/pi-cloud-web.git

标签:java,Stream,CentOS,spring,jar,nacos,Nacos,context,RELEASE
From: https://www.cnblogs.com/zn-pi/p/16860283.html

相关文章

  • VMware 16 安装 CentOS Stream
    环境版本Windows10VMwareWorkstation16ProCentOS8-stream下载CentOS8stream安装包点击阿里云开源镜像站或网易开源镜像站,选择要下载的版......
  • CentOS 7 安装 MySQL 8
    本文档在以下环境中安装测试通过:版本MySQL8.0.30LinuxCentOSLinuxrelease7.9.2009(Core)内核版本:3.10.0-1160.el7.x86_64使用Yum安装Step1:添......
  • centos8 安装mysql8 国内源
    从mysql.com下载了安装源之后,发现在yuminstallmysql-server之后一直卡住,要么就报timeout错误其实完全可以从国内下载 推荐地址:http://mirrors.ustc.edu.cn/mysql-re......
  • CentOS 7下mysql数据库定时备份创建定时任务
    1.创建定时任务脚本vi/usr/bin/bakeup_mysql.sh内容:#!/bin/bash#deleteoldbakeuprm-rf/data/mysql_bak/*backup_dir='/data/mysql_bak/'current_time=$(date+'%......
  • CentOS 安装Cosmos开发环境
    1、Goinstall.wgethttps://go.dev/dl/go1.19.3.linux-amd64.tar.gzrm-rf/usr/local/go&&tar-C/usr/local-xzfgo1.19.3.linux-amd64.tar.gzexportPATH=$PATH:......
  • 006 Rust 异步编程,Stream 介绍
    Stream介绍​​Stream​​​和​​Future​​​类似,但是​​Future​​​对应的是一个​​item​​​的状态的变化,而​​Stream​​​则是类似于​​iterator​​​,在结束......
  • windows10安装wsl的centos7版本,并启动ssh服务远程访问
    1.安装wsl的centos版本wsl是什么就不多说了,不清楚的自己去谷歌吧。也可以参考下面几篇文章:[https://learn.microsoft.com/zh-cn/windows/wsl/install-manual](microsoft......
  • CentOS 7.9 Redis 设置开机自启动
    CentOS7.9Redis设置开机自启动 1、创建Redis的开机自启动文件在/etc/systemd/system/目录下创建redis.service文件,并加入如下内容:[Unit]Description=redis-......
  • java--Stream流基础
    Stream流操作方法执行完此方法之后,Stream流依然可以继续执行其他操作Stream流的思想 Stream流的三类方法  获取Stream流    好比创建一条流水线,并把数据放......
  • .net core在centos上使用libgdiplus库图像处理
    #Seehttps://aka.ms/containerfastmodetounderstandhowVisualStudiousesthisDockerfiletobuildyourimagesforfasterdebugging.FROMmcr.microsoft.com/......