介绍
欢迎来到 Nacos 的世界!
Nacos /nɑ:kəʊs/ 是 Dynamic Naming and Configuration Service的首字母简称,一个更易于构建云原生应用的动态服务发现、配置管理和服务管理平台。
Nacos 致力于帮助您发现、配置和管理微服务。Nacos 提供了一组简单易用的特性集,帮助您快速实现动态服务发现、服务配置、服务元数据及流量管理。
Nacos 帮助您更敏捷和容易地构建、交付和管理微服务平台。 Nacos 是构建以“服务”为中心的现代应用架构 (例如微服务范式、云原生范式) 的服务基础设施。
安装Nacos
选择nacos版本:2.0.3,原因如下:
Spring Cloud Alibaba Version、Spring Cloud Version、Spring Boot Version版本
2、服务器节点说明
节点 | IP地址 | PORT | 说明 |
nacos1 | 192.168.160.100 | 8848、18848、3306 | 安装mysql、nacos节点、nginx |
nacos2 | 192.168.160.101 | 8848 | 安装nacos |
nacos3 | 192.168.160.102 | 8848 | 安装nacos |
3、nacos集群安装
分别解压缩各节点nacos安装包
tar -xvf nacos-server-2.0.3.tar.gz
4、配置集群配置文件
# ip:port
192.168.160.100:8848
192.168.160.101:8848
192.168.160.102:8848
5、配置Mysql数据源,mysql安装参考链接
初始化 MySQL 数据库 脚本nacos-mysql.sql
[root@localhost conf]# pwd
/root/nacos/nacos/conf
[root@localhost conf]# ll
总用量 92
-rw-r--r--. 1 502 games 1224 6月 18 2021 1.4.0-ipv6_support-update.sql
-rw-r--r--. 1 502 games 9516 10月 15 23:34 application.properties
-rw-r--r--. 1 502 games 9506 7月 27 2021 application.properties.example
-rw-r--r--. 1 root root 103 10月 15 23:35 cluster.conf
-rw-r--r--. 1 502 games 670 3月 18 2021 cluster.conf.example
-rw-r--r--. 1 502 games 31156 7月 15 2021 nacos-logback.xml
-rw-r--r--. 1 502 games 10660 6月 18 2021 nacos-mysql.sql
-rw-r--r--. 1 502 games 8795 6月 18 2021 schema.sql
application.properties 配置
#*************** Config Module Related Configurations ***************#
### If use MySQL as datasource:
spring.datasource.platform=mysql
### Count of DB:
db.num=1
### Connect URL of DB:
db.url.0=jdbc:mysql://192.168.160.100:3306/nacos_config?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useUnicode=true&useSSL=false&serverTimezone=UTC
db.user.0=root
db.password.0=Dl123456
6、启动服务器
分别到各节点nacos服务器,启动脚本startup.sh(默认集群模式启动)
[root@localhost bin]# pwd
/root/nacos/nacos/bin
[root@localhost bin]# ll
总用量 20
drwxr-xr-x. 2 root root 72 10月 16 00:00 logs
-rwxr-xr-x. 1 502 games 954 5月 14 2020 shutdown.cmd
-rwxr-xr-x. 1 502 games 951 3月 18 2021 shutdown.sh
-rwxr-xr-x. 1 502 games 3340 6月 18 2021 startup.cmd
-rwxr-xr-x. 1 502 games 4977 7月 27 2021 startup.sh
drwxr-xr-x. 3 root root 20 10月 15 23:19 work
[root@localhost bin]# ./startup.sh
/usr/local/jdk1.8.0_201//bin/java -Djava.ext.dirs=/usr/local/jdk1.8.0_201//jre/lib/ext:/usr/local/jdk1.8.0_201//lib/ext -server -Xms2g -Xmx2g -Xmn1g -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=320m -XX:-OmitStackTraceInFastThrow -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/root/nacos/nacos/logs/java_heapdump.hprof -XX:-UseLargePages -Dnacos.member.list= -Xloggc:/root/nacos/nacos/logs/nacos_gc.log -verbose:gc -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintGCTimeStamps -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=10 -XX:GCLogFileSize=100M -Dloader.path=/root/nacos/nacos/plugins/health,/root/nacos/nacos/plugins/cmdb -Dnacos.home=/root/nacos/nacos -jar /root/nacos/nacos/target/nacos-server.jar --spring.config.additional-location=file:/root/nacos/nacos/conf/ --logging.config=/root/nacos/nacos/conf/nacos-logback.xml --server.max-http-header-size=524288
nacos is starting with cluster
nacos is starting,you can check the /root/nacos/nacos/logs/start.out
另外,单节点启动
sh startup.sh -m standalone
Nginx安装&配置
1、安装依赖
yum -y install gcc gcc-c++ make libtool zlib zlib-devel openssl openssl-devel pcre pcre-devel
2、Nginx下载地址
3、安装NGINX
tar -zxvf nginx-1.22.0.tar.gz
cd nginx-1.22.0
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
make&make install
4、配置NGINX
nginx.conf----->http----->server增加如下内容:
upstream nacos-cluster {
server 192.168.160.100:8848;
server 192.168.160.101:8848;
server 192.168.160.102:8848;
}
server {
listen 18848;
server_name localhost;
location /nacos {
proxy_pass http://nacos-cluster;
}
}
5、启动、停止、重启
[root@localhost nginx]# cat start.sh
/usr/local/nginx/sbin/nginx
[root@localhost nginx]# cat stop.sh
/usr/local/nginx/sbin/nginx -s stop
[root@localhost nginx]# cat reload.sh
/usr/local/nginx/sbin/nginx -s reload
[root@localhost nginx]# cat reopen.sh
/usr/local/nginx/sbin/nginx -s reopen
配置本地Hosts文件
C:\Windows\System32\drivers\etc\hosts
内容如下:
192.168.160.100 server01
访问nacos地址:http://server01:18848/nacos 账号和密码:nacos/nacos