微服务spring cloud alibaba搭建记录 - 实践篇 Nacos集群

实现目标:

微服务spring cloud alibaba搭建记录 - 实践篇 Nacos集群_第1张图片

 

3.1 高可用MYSQL

#启动
docker run --name mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 -d mysql:5.7.17
#给nacos建库
docker exec -i mysql mysql -uroot -p123456  <<< "CREATE DATABASE IF NOT EXISTS nacos DEFAULT CHARSET utf8 COLLATE utf8_general_ci"


#进入容器->bash
docker exec -it mysql bash
#登录mysql -> sql
mysql -u root -p

3.2 nacos

默认单机,但是带了集群配置文件,打开即可

[root@localhost docker]# wget https://github.com/alibaba/nacos/releases/download/1.2.0/nacos-server-1.2.0.tar.gz
[root@localhost software]# tar -zxvf nacos-server-1.2.0.tar.gz -C /opt

# cd /opt/nacos 建库
[root@localhost nacos]# docker exec -i mysql mysql -uroot -p123456 -f nacos < ./conf/nacos-mysql.sql

# 开启集群配置
[root@localhost conf]# mv cluster.conf.example  cluster.conf
[root@localhost conf]# cat cluster.conf
#it is ip
#example
127.0.0.1:8848
127.0.0.1:8849

# 修改MYSQL连接
# vim application.properties
# db
db.num=1
db.url.0=jdbc:mysql://192.168.1.245:3306/nacos?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true
db.user=root
db.password=123456

Q&A

Q1: no suitabled driver 驱动找不到
A: nacos v1.2.0   - > nacos v1.1.4  


Q2 : java.lang.IllegalStateException: unable to find local peer: 192.168.1.245:8848, all peers: [127.0.0.1:8849, 127.0.0.1:8848]
A:不使用127.0.0.1  ,  直接用内网地址192.168.1.245    
参考 https://blog.csdn.net/ooyhao/article/details/102745641

Q3 : 页面访问异常
端口需要放开

Q4 : raft failed , no leader
单机集群多端口有问题,需要多机集群

 辅助小脚本

sh /opt/nacos/bin/shutdown.sh
rm -rf /opt/nacos/logs/start.out /opt/nacos/logs/nacos.log  /opt/nacos/logs/naming-raft.log

sh /opt/nacos/bin/startup.sh

cat /opt/nacos/logs/start.out
cat /opt/nacos/logs/nacos.log
cat /opt/nacos/logs/naming-raft.log

3.3 Monitor

//TODO

 

你可能感兴趣的:(docker,docker,spring,boot)