nacos单节点搭建
- 1.安装jdk 1.8.0_391(注:nacos依赖jdk1.8及以上版本)
curl -sL http://iso.sqlfans.cn/jdk/install_jdk_8u391.sh | bash
source /etc/bashrc
java -version
- 2.创建nacos数据库和账号,导入初始化脚本(参考
.conf/mysql-schema.sql
)
curl -sL http://iso.sqlfans.cn/linux/nacos-schema-2.2.3.sql -o /opt/nacos-schema-2.2.3.sql
mysql -uroot -p -S /tmp/mysql_3306.sock -e"CREATE DATABASE IF NOT EXISTS nacos DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;"
mysql -uroot -p -S /tmp/mysql_3306.sock -e"CREATE USER IF NOT EXISTS 'user_nacos'@'%' IDENTIFIED with mysql_native_password BY 'KKi3Vr4aHB_SkmX2';"
mysql -uroot -p -S /tmp/mysql_3306.sock -e"GRANT ALL PRIVILEGES ON nacos.* TO 'user_nacos'@'%';"
mysql -uroot -p -S /tmp/mysql_3306.sock -e"FLUSH PRIVILEGES;"
mysql -uroot -p -S /tmp/mysql_3306.sock nacos -e"source /opt/nacos-schema-2.2.3.sql;"
mkdir -p /data/
curl -L http://iso.sqlfans.cn/linux/nacos-server-2.2.3.tar.gz -o /opt/nacos-server-2.2.3.tar.gz
tar -zxf /opt/nacos-server-2.2.3.tar.gz -C /opt/
mv /opt/nacos /data/nacos_8848
- 4.开启鉴权登录(注意:Nacos 2.2.0.1以前的版本默认开启auth鉴权)
sed -i 's/^nacos.core.auth.system.type.*/nacos.core.auth.system.type=nacos/' /data/nacos_8848/conf/application.properties
sed -i 's/^nacos.core.auth.enabled.*/nacos.core.auth.enabled=true/' /data/nacos_8848/conf/application.properties
sed -i 's/^nacos.core.auth.server.identity.key.*/nacos.core.auth.server.identity.key=nacos/' /data/nacos_8848/conf/application.properties
sed -i 's/^nacos.core.auth.server.identity.value.*/nacos.core.auth.server.identity.value=nacos/' /data/nacos_8848/conf/application.properties
sed -i 's/^nacos.core.auth.plugin.nacos.token.secret.key.*/nacos.core.auth.plugin.nacos.token.secret.key=VGhpc0lzTXlDdXN0b21TZWNyZXRLZXkwMTIzNDU2Nzg=/' /data/nacos_8848/conf/application.properties
cat /data/nacos_8848/conf/application.properties | grep "^nacos.core.auth.default.token.secret.key" || echo "nacos.core.auth.default.token.secret.key=" >> /data/nacos_8848/conf/application.properties
sed -i 's/^nacos.core.auth.default.token.secret.key.*/nacos.core.auth.default.token.secret.key=/' /data/nacos_8848/conf/application.properties
cat /data/nacos_8848/conf/application.properties | grep "^nacos.core.auth"
- 5.配置mysql信息,示例mysql节点为
10.30.3.234
cat /data/nacos_8848/conf/application.properties | grep "^spring.datasource.platform=" || echo "spring.datasource.platform=mysql" >> /data/nacos_8848/conf/application.properties
cat /data/nacos_8848/conf/application.properties | grep "^db.num=" || echo "db.num=1" >> /data/nacos_8848/conf/application.properties
cat /data/nacos_8848/conf/application.properties | grep "^db.url.0=" || echo "db.url.0=jdbc:mysql://10.30.3.234:3306/nacos?allowPublicKeyRetrieval=true&characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useUnicode=true&useSSL=false&serverTimezone=UTC" >> /data/nacos_8848/conf/application.properties
cat /data/nacos_8848/conf/application.properties | grep "^db.user.0=" || echo "db.user.0=user_nacos" >> /data/nacos_8848/conf/application.properties
cat /data/nacos_8848/conf/application.properties | grep "^db.password.0=" || echo "db.password.0=KKi3Vr4aHB_SkmX2" >> /data/nacos_8848/conf/application.properties
cat /data/nacos_8848/conf/application.properties | egrep "(^spring.datasource.platform|^db.num|^db.url.0|^db.user|^db.password.0)"
sh /data/nacos_8848/bin/startup.sh -m standalone
sleep 5 && netstat -lnpt | egrep "(7848|8848|9848|9849)"
cat /etc/rc.local | grep nacos || echo 'sh /data/nacos_8848/bin/startup.sh -m standalone' >> /etc/rc.local
- 8.登录nacos页面控制台,修复初始弱密码,比如
10.30.3.231
地址:http://10.30.3.231:8848/nacos
账号:nacos
密码:nacos