1. Nacos安装
# 下载nacos包
wget -P /opt https://github.com/alibaba/nacos/releases/download/2.0.1/nacos-server-2.0.1.tar.gz
# 解压
cd /opt
tar -zxvf nacos-server-*
# 删除
rm nacos-server-*
2. 配置Nacos配置文件
# spring
server.servlet.contextPath=${SERVER_SERVLET_CONTEXTPATH:/nacos}
server.contextPath=/nacos
server.port=${NACOS_APPLICATION_PORT:8848}
#spring.datasource.platform=${SPRING_DATASOURCE_PLATFORM:"mysql"}
nacos.cmdb.dumpTaskInterval=3600
nacos.cmdb.eventTaskInterval=10
nacos.cmdb.labelTaskInterval=300
nacos.cmdb.loadDataAtStart=false
#db.num=${MYSQL_DATABASE_NUM:1}
spring.datasource.platform=mysql
db.num=1
db.url.0=jdbc:mysql://localhost:3306/database?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useUnicode=true&useSSL=false&serverTimezone=UTC
db.user= username
db.password= password
#db.url.0=jdbc:mysql://${MYSQL_SERVICE_HOST}:${MYSQL_SERVICE_PORT:3306}/${MYSQL_SERVICE_DB_NAME}?${MYSQL_SERVICE_DB_PARAM:characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true}
#db.url.1=jdbc:mysql://${MYSQL_SERVICE_HOST}:${MYSQL_SERVICE_PORT:3306}/${MYSQL_SERVICE_DB_NAME}?${MYSQL_SERVICE_DB_PARAM:characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true}
#db.user=${MYSQL_SERVICE_USER}
#db.password=${MYSQL_SERVICE_PASSWORD}
### The auth system to use, currently only 'nacos' is supported:
nacos.core.auth.system.type=${NACOS_AUTH_SYSTEM_TYPE:nacos}
### The token expiration in seconds:
nacos.core.auth.default.token.expire.seconds=${NACOS_AUTH_TOKEN_EXPIRE_SECONDS:18000}
### The default token:
nacos.core.auth.default.token.secret.key=${NACOS_AUTH_TOKEN:SecretKey012345678901234567890123456789012345678901234567890123456789}
### Turn on/off caching of auth information. By turning on this switch, the update of auth information would have a 15 seconds delay.
nacos.core.auth.caching.enabled=${NACOS_AUTH_CACHE_ENABLE:false}
nacos.core.auth.enable.userAgentAuthWhite=${NACOS_AUTH_USER_AGENT_AUTH_WHITE_ENABLE:false}
nacos.core.auth.server.identity.key=${NACOS_AUTH_IDENTITY_KEY:serverIdentity}
nacos.core.auth.server.identity.value=${NACOS_AUTH_IDENTITY_VALUE:security}
server.tomcat.accesslog.enabled=${TOMCAT_ACCESSLOG_ENABLED:false}
server.tomcat.accesslog.pattern=%h %l %u %t "%r" %s %b %D
# default current work dir
server.tomcat.basedir=
## spring security config
### turn off security
nacos.security.ignore.urls=${NACOS_SECURITY_IGNORE_URLS:/,/error,/**/*.css,/**/*.js,/**/*.html,/**/*.map,/**/*.svg,/**/*.png,/**/*.ico,/console-fe/public/**,/v1/auth/**,/v1/console/health/**,/actuator/**,/v1/console/server/**}
# metrics for elastic search
management.metrics.export.elastic.enabled=false
management.metrics.export.influx.enabled=false
nacos.naming.distro.taskDispatchThreadCount=10
nacos.naming.distro.taskDispatchPeriod=200
nacos.naming.distro.batchSyncKeyCount=1000
nacos.naming.distro.initDataRatio=0.9
nacos.naming.distro.syncRetryDelay=5000
nacos.naming.data.warmup=true
3. Nacos配置开机启动
1. 编写启动配置文件
vim /lib/systemd/system/nacos.service
配置文件如下:
[Unit]
Description=nacos
After=network.target
[Service]
Type=forking
ExecStart=/opt/nacos/bin/startup.sh -m standalone
ExecReload=/opt/nacos/bin/shutdown.sh
ExecStop=/opt/nacos/bin/shutdown.sh
PrivateTmp=true
[Install]
WantedBy=multi-user.target
[scode type=“blue”]其中/opt/nacos
为本机安装的nacos文件路径,-m standalone
表示作为单机启动,不加的话表示集群启动,目前先作为单机启动。[/scode]
[collapse status=“false” title=“vim 编辑文件的小tips”]
修改完成后,使用Esc 按键退出编辑模式。 此时回到的还是一般指令模式。 若想保存编辑内容并到Linux终端,则需要输入 :wq (冒号一定要记得输入) 不想保存并退出可以输入 :q
关于其他指令: :w 保存文件但不退出vi :w file 将修改另外保存到file中,不退出vi :w! 强制保存,不推出vi :wq 保存文件并退出vi :wq! 强制保存文件,并退出vi :q 不保存文件,退出vi :q!不保存文件,强制退出vi :e! 放弃所有修改,从上次保存文件开始再编辑
[/collapse]
2. 设置开机启动
systemctl daemon-reload # 先进行文件生效配置
systemctl enable nacos.service # 设置为开机启动
systemctl start nacos.service # 启动nacos服务
systemctl stop nacos.service # 停止nacos服务
3. 启动并查看是否成功
systemctl status nacos.service
4. 遇到的问题
sh文件中的java路径错误 或者是 没有java环境