背景:支持国产化需求,不再使用mysql
1.修改插件
git clone https://github.com/wuchubuzai2018/nacos-datasource-extend-plugins.git cd nacos-datasource-extend-plugins/nacos-postgresql-datasource-plugin-ext mvn package
编译成功后,插件包保存在nacos-datasource-extend-plugins/nacos-postgresql-datasource-plugin-ext/target目录下,名字一般是nacos-postgresql-datasource-plugin-ext-1.0.0-SNAPSHOT.jar,复制出来备用。
nacos-datasource-extend-plugins
acos-datasource-plugin-ext
acos-postgresql-datasource-plugin-extsrcmain
esourcesschema目录下的nacos-pg.sql用来创建库nacos。
2.安装配置Nacos
wget https://github.com/alibaba/nacos/releases/download/2.2.0/nacos-server-2.2.0.tar.gz tar zxvf nacos-server-2.2.0.tar.gz cd nacos mkdir plugins #将上面编译好的PostgreSQL数据源插件复制到plugins目录下
3.修改配置
nacos的配置文件有两个,位于nacos安装目录的conf目录下,分别是application.properties和cluster.conf(集群才用)
# application.properties #*************** Config Module Related Configurations ***************# ### If use MySQL as datasource: spring.datasource.platform=postgresql ### Count of DB: db.num=1 ### Connect URL of DB: db.url.0=jdbc:postgresql://192.168.0.23:5432,192.168.0.133:5432,192.168.0.157:5432/nacos?targetServerType=primary&tcpKeepAlive=true&reWriteBatchedInserts=true&ApplicationName=nacos_java db.user.0=nacos db.password.0=nacos123 ### Connection pool configuration: hikariCP db.pool.config.driverClassName=org.postgresql.Driver
4.启动运行
服务器系统 centos 7.9 ,以单机的方式启动nacos,
bin/startup.sh -m standalone
结果报错
Please set the JAVA_HOME variable in your environment, We need java(x64)! jdk8 or later is better! !!
开始安装JDK,配置环境变量,
yum list|grep jdk
yum -y install java-1.8.0-openjdk.x86_64
查看jre路径
ls -lrt /etc/alternatives/java
vim /etc/profile
export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.392.b08-2.el7_9.x86_64/jre export JRE_HOME=$JAVA_HOME/jre export CLASSPATH=$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATH export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH
source /etc/profile,重新启动就可以成功了,界面如下。(nacos/nacos)
5.测试
发布配置
curl -X POST “http://8.147.118.144:8848/nacos/v1/cs/configs?dataId=nacos.cfg.dataId&group=test&content=HelloWorld”
获取配置
curl -X GET “http://8.147.118.144:8848/nacos/v1/cs/configs?dataId=nacos.cfg.dataId&group=test”
pg数据库记录:
参考:
https://developer.aliyun.com/article/1347831
https://github.com/wuchubuzai2018/nacos-datasource-extend-plugins