-- 1.创建数据库
CREATE DATABASE `nacos_config` CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- 2. 执行脚本/conf/nacos-mysql.sql
-----mysql 低版本不支持 `DEFAULT CURRENT_TIMESTAMP`,
----2.1
>mysql –uroot –p123456 -Dnacos_config < /home/jhs/clouds/nacos-cluster/nacos/conf/nacos-mysql.sql
----2.2
MariaDB [(none)]> use nacos_config;
MariaDB [nacos_config]> source /home/jhs/clouds/nacos-cluster/nacos/conf/nacos-mysql.sql;
--3. 创建数据库用户
grant all privileges on nacos_config.* to scott@'%' identified by '123456' WITH GRANT OPTION;
grant all privileges on nacos_config.* to scott@localhost identified by '123456' WITH GRANT OPTION;
[jhs@vm1 conf]$ cp application.properties application.properties.bak
[jhs@vm1 conf]$ vim application.properties
spring.datasource.platform=mysql
db.num=1
### Connect URL of DB:
db.url.0=jdbc:mysql://vm1:3306/nacos_config?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true
db.user=scott
db.password=123456
直接执行startup.sh -m standalone
命令启动,通过浏览器访问即可。
/conf/cluster.conf
#IP:PORT
vm1:8848
vm2:8848
vm3:8848
/conf/cluster.conf
#IP:PORT
vm1:8848
vm1:8848
vm1:5555
修改启动命令
由于是伪集群
,所以需要启动命令支持,设置端口
## 创建 nacos3333, nacos4444, nacos5555 分别修改它们 conf/application.properties
server.port= 3333 | 4444 | 5555
## 分别启动
sh nacos3333/bin/startup.sh
sh nacos4444/bin/startup.sh
sh nacos5555/bin/startup.sh
## upstream 名称不能有下划线
upstream nacos-cluster{
server vm1:3333;
server vm1:4444;
server vm1:5555;
}
server {
listen 80;
server_name localhost;
location ~ / {
proxy_pass http://nacos-cluster ;
}
}