Nacos /nɑ:kəʊs/ 是 Dynamic Naming and Configuration Service的首字母简称,一个更易于构建云原生应用的动态服务发现、配置管理和服务管理平台。
开始搭建Nacos集群,这次Nacos版本是2.1.0,本文选用官方推荐的第三种方法
1、准备三台虚拟机,并且安装JDK8和mysql客户端
虚拟机ip:
192.168.176.10
192.168.176.11
192.168.176.12
安装软件
yum install -y java-1.8.0-openjdk-devel.x86_64
yum install mysql -y
在192.168.176.10服务器执行
docker run -d --name mysql5.7 -p 3306:3306 -e MYSQL_ROOT_PASSWORD=root mysql:5.7
mysql账号密码:root/root
4、分别手动安装包上传到3台服务器
[root@VM-4-12-centos opt]# mkdir nacos1
[root@VM-12-13-centos opt]# cd nacos1
[root@VM-4-12-centos nacos1]# pwd
/opt/nacos1
[root@VM-4-12-centos nacos1]# ll
total 114700
-rw-r--r-- 1 root root 117452521 Apr 30 13:22 nacos-server-2.1.0.tar.gz
5、解压
[root@VM-4-12-centos nacos1]# tar -zxvf nacos-server-2.1.0.tar.gz
6、初始化数据库
mysql> create database nacos_config;
mysql> use nacos_config
mysql> source /opt/nacos1/nacos/conf/nacos-mysql.sql;
7、修改 application.properties
### Specify local server's IP:
nacos.inetutils.ip-address=192.168.176.10
spring.datasource.platform=mysql
db.num=1
db.url.0=jdbc:mysql://192.168.176.10:3306/nacos_config?characterEncoding=utf8&connectTimeout=1000&socket
Timeout=3000&autoReconnect=true
db.user=root
db.password=your password
8、修改cluster.conf
[root@VM-4-12-centos conf]# cp cluster.conf.example cluster.conf
[root@VM-4-12-centos conf]# vim cluster.conf
#2022-09-22T15:24:40.440
192.168.176.10:8848
192.168.176.11:8848
192.168.176.12:8848
9、进入Nacos bin 目录下,启动一台Nacos
[root@VM-4-12-centos bin]# ./startup.sh -m cluster
/opt/jdk01/jdk1.8.0_311/bin/java -Djava.ext.dirs=/opt/jdk01/jdk1.8.0_311/jre/lib/ext:/opt/jdk01/jdk1.8.0_311/lib/ext -server -Xms2g -Xmx2g -Xmn1g -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=320m -XX:-OmitStackTraceInFastThrow -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/opt/nacos1/nacos/logs/java_heapdump.hprof -XX:-UseLargePages -Dnacos.member.list= -Xloggc:/opt/nacos1/nacos/logs/nacos_gc.log -verbose:gc -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintGCTimeStamps -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=10 -XX:GCLogFileSize=100M -Dloader.path=/opt/nacos1/nacos/plugins/health,/opt/nacos1/nacos/plugins/cmdb,/opt/nacos1/nacos/plugins/selector -Dnacos.home=/opt/nacos1/nacos -jar /opt/nacos1/nacos/target/nacos-server.jar --spring.config.additional-location=file:/opt/nacos1/nacos/conf/ --logging.config=/opt/nacos1/nacos/conf/nacos-logback.xml --server.max-http-header-size=524288
nacos is starting with cluster
nacos is starting,you can check the /opt/nacos1/nacos/logs/start.out
9、同理要修改第二台、第三台服务器,其中nacos.inetutils.ip-address要更换成每台服务器自己的ip
nacos.inetutils.ip-address=192.168.176.11
10、三台服务器启动完成以后,需要开通服务器端口8848,然后任意一台连接上去
nacos控制台:http://192.168.176.10:8848/nacos
账号密码:nacos/nacos
./startup.sh -m cluster 启动nacos
./shutdown.sh -m cluster 关闭nacos
11、到了这里,集群部分已经结束了,但是按照官方要求,不要暴露ip到外网,尽量用域名,所以需要用到Nginx
安装nginx
1、wget http://nginx.org/packages/centos/7/x86_64/RPMS/nginx-1.18.0-2.el7.ngx.x86_64.rpm
2、rpm -qa|grep nginx 查询是否已经安装了nginx
3、rpm -ivh nginx-1.18.0-1.el7.ngx.x86_64.rpm 安装
4、systemctl enable nginx.service
5、systemctl start nginx.service
12、修改nginx的 nacos.conf文件
upstream nacos-cluster {
server 192.168.176.10:8848;
server 192.168.176.11:8848;
server 192.168.176.12:8848;
}
server {
listen 80;
location / {
proxy_pass http://nacos-cluster;
}
}
13、我这边就不加https、dns解析和域名了,最后成果:http://192.168.176.10/nacos
https://blog.csdn.net/gubeichengxuyuan/article/details/124511446