偷偷摘套内射激情视频,久久精品99国产国产精,中文字幕无线乱码人妻,中文在线中文a,性爽19p

聽句勸! Nacos集群搭建可以看看這篇教程

系統(tǒng) Linux
Nacos(Naming and Configuration Service)致力于幫助您發(fā)現(xiàn)、配置和管理微服務(wù)。Nacos 提供了一組簡(jiǎn)單易用的特性集,幫助您快速實(shí)現(xiàn)動(dòng)態(tài)服務(wù)發(fā)現(xiàn)、服務(wù)配置、服務(wù)元數(shù)據(jù)及流量管理。

[[386501]]

 一、Nacos 簡(jiǎn)介

Nacos(Naming and Configuration Service)致力于幫助您發(fā)現(xiàn)、配置和管理微服務(wù)。Nacos 提供了一組簡(jiǎn)單易用的特性集,幫助您快速實(shí)現(xiàn)動(dòng)態(tài)服務(wù)發(fā)現(xiàn)、服務(wù)配置、服務(wù)元數(shù)據(jù)及流量管理。

詳情查看Nacos 官方文檔[1]

二、Nacos 安裝

1、Nacos 依賴

Nacos 基于 java 開發(fā)的,運(yùn)行依賴于 java 環(huán)境。

依賴 64 bit JDK 1.8+,前往官網(wǎng)下載 JDK[2]

2、Nacos 安裝

下載編譯后壓縮包,最新穩(wěn)定版本[3]

  1. unzip nacos-server-$version.zip 或者 tar -xvf nacos-server-$version.tar.gz cd nacos/bin 

三、Nacos 部署

1、單實(shí)例部署

單實(shí)例部署不適合生產(chǎn)環(huán)境,單點(diǎn)故障是致命的。

Linux 單實(shí)例非集群模式啟動(dòng)命令

  1. startup.sh -m standalone 

Linux 單實(shí)例非集群模式關(guān)閉命令

  1. shutdown.sh 

訪問 nacos 管理頁(yè)面,初始化用戶名密碼均為 nacos


2、集群部署

1、集群架構(gòu)


  • 高可用 Nginx 集群
  • Nacos 集群(至少三個(gè)實(shí)例)
  • 高可用數(shù)據(jù)庫(kù)集群(取代 Nacos 內(nèi)嵌數(shù)據(jù)庫(kù))

2、本地虛擬機(jī)模擬集群部署

本地環(huán)境準(zhǔn)備

在本地 PC 機(jī)上利用 VMware workstation 虛擬出如上表所示的幾臺(tái)機(jī)器,其中 Nginx 和 MySQL 都是采用的單實(shí)例,僅做練習(xí)使用。

搭建步驟

初始化 nacos 必須的數(shù)據(jù)庫(kù)表并配置

找到 Nacos 安裝目錄下提供的數(shù)據(jù)庫(kù)腳本文件


在 MySQL 實(shí)例創(chuàng)建 nacos_config 庫(kù)并導(dǎo)入腳本


修改修改 Nacos 配置文件,指向 MySQL 實(shí)例,替換其內(nèi)嵌數(shù)據(jù)庫(kù)


  1. #*************** 切換Nacos內(nèi)嵌數(shù)據(jù)庫(kù)平臺(tái)為MySQL ***************# 
  2. spring.datasource.platform=mysql 
  3.  
  4. db.num=1 
  5. db.url.0=jdbc:mysql://192.168.15.141:3306/nacos_config?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useUnicode=true&useSSL=false&serverTimezone=UTC 
  6. db.user=root 
  7. db.password=123456 

說明:三臺(tái) nacos 實(shí)例都需要切換 MySQL 平臺(tái),均需執(zhí)行以上操作

nacos 集群配置

復(fù)制 cluster.conf 文件

Nacos 集群配置,修改 cluster.conf 文件

  1. [root@localhost conf]# vim ./cluster.conf 
  2. #it is ip 
  3. #example 
  4. 192.168.15.145 
  5. 192.168.15.147 
  6. 192.168.15.148 

說明:三臺(tái) nacos 實(shí)例都需要做以上集群配置,至此關(guān)于 nacos 的配置結(jié)束了,可以嘗試以集群模式啟動(dòng)三個(gè) nacos 實(shí)例了

以集群模式分別啟動(dòng)三個(gè) nacos 實(shí)例



嘗試訪問 nacos 管理頁(yè),測(cè)試三個(gè)實(shí)例是否正常


說明:如果三個(gè)實(shí)例以集群模式正常啟動(dòng),那么分別訪問三個(gè)實(shí)例的管理頁(yè)就是展示以上登錄頁(yè)了。如果不能訪問,則可能防火墻未開放 nacos 服務(wù)的端口,可執(zhí)行如下命令。

  1. [root@localhost bin]# firewall-cmd --add-port=8848/tcp --permanent 
  2. success 
  3. [root@localhost bin]# firewall-cmd --reload 
  4. success 
  5. [root@localhost bin]# firewall-cmd --list-all 
  6. public (active) 
  7.   target: default 
  8.   icmp-block-inversion: no 
  9.   interfaces: ens33 
  10.   sources: 
  11.   services: ssh dhcpv6-client 
  12.   ports: 27017/tcp 8848/tcp 
  13.   protocols: 
  14.   masquerade: no 
  15.   forward-ports: 
  16.   source-ports: 
  17.   icmp-blocks: 
  18.   rich rules: 
  19.  
  20. [root@localhost bin]# 

Nginx 配置

  • Nginx 安裝參考,Nginx 源碼安裝[4]
  • 修改 Nginx 配置文件 nginx.conf
  1. worker_processes  1; 
  2.  
  3. events { 
  4.     worker_connections  1024; 
  5.  
  6. http { 
  7.     include       mime.types; 
  8.     default_type  application/octet-stream; 
  9.  
  10.     sendfile        on
  11.  
  12.     keepalive_timeout  65; 
  13.  
  14.     #nacos集群負(fù)載均衡 
  15.     upstream nacos-cluster { 
  16.         server 192.168.15.145:8848; 
  17.         server 192.168.15.147:8848; 
  18.         server 192.168.15.148:8848; 
  19.     } 
  20.  
  21.     server { 
  22.         listen       80; 
  23.         server_name  192.168.15.146; 
  24.  
  25.         location / { 
  26.             #root   html; 
  27.             #index  index.html index.htm; 
  28.             proxy_pass http://nacos-cluster; 
  29.         } 
  30.  
  31.         error_page   500 502 503 504  /50x.html; 
  32.         location = /50x.html { 
  33.             root   html; 
  34.         } 
  35.     } 
  36.  

啟動(dòng) Nginx

  1. /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf 

微服務(wù)配置

微服務(wù)父 pom 配置

  1. <?xml version="1.0" encoding="UTF-8"?> 
  2.  
  3. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
  4.          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
  5.     <modelVersion>4.0.0</modelVersion> 
  6.  
  7.     <groupId>com.atguigu.springcloud</groupId> 
  8.     <artifactId>cloud2020</artifactId> 
  9.     <version>1.0-SNAPSHOT</version> 
  10.     <packaging>pom</packaging> 
  11.  
  12.     <!-- 模塊 --> 
  13.     <modules> 
  14.         <module>cloud-alibaba-nacos-config-client-3377</module> 
  15.     </modules> 
  16.  
  17.     <!-- 統(tǒng)一管理jar版本 --> 
  18.     <properties> 
  19.         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
  20.         <maven.compiler.source>1.8</maven.compiler.source> 
  21.         <maven.compiler.target>1.8</maven.compiler.target> 
  22.         <junit.version>4.12</junit.version> 
  23.         <log4j.version>1.2.17</log4j.version> 
  24.         <lombok.version>1.16.18</lombok.version> 
  25.         <mysql.version>5.1.47</mysql.version> 
  26.         <druid.version>1.1.16</druid.version> 
  27.         <mybatis.spring.boot.version>1.3.0</mybatis.spring.boot.version> 
  28.     </properties> 
  29.  
  30.     <!-- 統(tǒng)一依賴管理 --> 
  31.     <dependencyManagement> 
  32.         <dependencies> 
  33.             <!-- spring boot 2.2.2 --> 
  34.             <dependency> 
  35.                 <groupId>org.springframework.boot</groupId> 
  36.                 <artifactId>spring-boot</artifactId> 
  37.                 <version>2.2.2.RELEASE</version> 
  38.                 <type>pom</type> 
  39.                 <scope>import</scope> 
  40.             </dependency> 
  41.  
  42.             <!-- spring cloud Hoxton.SR1 --> 
  43.             <dependency> 
  44.                 <groupId>org.springframework.cloud</groupId> 
  45.                 <artifactId>spring-cloud-dependencies</artifactId> 
  46.                 <version>Hoxton.SR1</version> 
  47.                 <type>pom</type> 
  48.                 <scope>import</scope> 
  49.             </dependency> 
  50.  
  51.             <!-- spring cloud alibaba 2.1.0.RELEASE --> 
  52.             <dependency> 
  53.                 <groupId>com.alibaba.cloud</groupId> 
  54.                 <artifactId>spring-cloud-alibaba-dependencies</artifactId> 
  55.                 <version>2.1.0.RELEASE</version> 
  56.                 <type>pom</type> 
  57.                 <scope>import</scope> 
  58.             </dependency> 
  59.  
  60.             <!-- mysql連接器 --> 
  61.             <dependency> 
  62.                 <groupId>mysql</groupId> 
  63.                 <artifactId>mysql-connector-java</artifactId> 
  64.                 <version>${mysql.version}</version> 
  65.             </dependency> 
  66.  
  67.             <!--druid 數(shù)據(jù)源--> 
  68.             <dependency> 
  69.                 <groupId>com.alibaba</groupId> 
  70.                 <artifactId>druid</artifactId> 
  71.                 <version>${druid.version}</version> 
  72.             </dependency> 
  73.  
  74.             <!-- mybatis 整合 spring --> 
  75.             <dependency> 
  76.                 <groupId>org.mybatis.spring.boot</groupId> 
  77.                 <artifactId>mybatis-spring-boot-starter</artifactId> 
  78.                 <version>${mybatis.spring.boot.version}</version> 
  79.             </dependency> 
  80.  
  81.             <!-- junit --> 
  82.             <dependency> 
  83.                 <groupId>junit</groupId> 
  84.                 <artifactId>junit</artifactId> 
  85.                 <version>${junit.version}</version> 
  86.             </dependency> 
  87.  
  88.             <!-- log4j --> 
  89.             <dependency> 
  90.                 <groupId>log4j</groupId> 
  91.                 <artifactId>log4j</artifactId> 
  92.                 <version>${log4j.version}</version> 
  93.             </dependency> 
  94.  
  95.             <!-- lombok --> 
  96.             <dependency> 
  97.                 <groupId>org.projectlombok</groupId> 
  98.                 <artifactId>lombok</artifactId> 
  99.                 <version>${lombok.version}</version> 
  100.             </dependency> 
  101.         </dependencies> 
  102.  
  103.     </dependencyManagement> 
  104.  
  105.     <build> 
  106.         <plugins> 
  107.             <plugin> 
  108.                 <groupId>org.springframework.boot</groupId> 
  109.                 <artifactId>spring-boot-maven-plugin</artifactId> 
  110.                 <configuration> 
  111.                     <fork>true</fork> 
  112.                     <addResources>true</addResources> 
  113.                 </configuration> 
  114.             </plugin> 
  115.         </plugins> 
  116.     </build> 
  117.  
  118. </project> 

微服務(wù) pom 依賴

  1. <?xml version="1.0" encoding="UTF-8"?> 
  2. <project xmlns="http://maven.apache.org/POM/4.0.0" 
  3.          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
  4.          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
  5.     <parent> 
  6.         <artifactId>cloud2020</artifactId> 
  7.         <groupId>com.atguigu.springcloud</groupId> 
  8.         <version>1.0-SNAPSHOT</version> 
  9.     </parent> 
  10.     <modelVersion>4.0.0</modelVersion> 
  11.  
  12.     <artifactId>cloud-alibaba-nacos-config-client-3377</artifactId> 
  13.  
  14.     <dependencies> 
  15.  
  16.         <!-- nacos config --> 
  17.         <dependency> 
  18.             <groupId>com.alibaba.cloud</groupId> 
  19.             <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId> 
  20.         </dependency> 
  21.  
  22.         <!-- nacos discovery --> 
  23.         <dependency> 
  24.             <groupId>com.alibaba.cloud</groupId> 
  25.             <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId> 
  26.         </dependency> 
  27.  
  28.         <!-- web --> 
  29.         <dependency> 
  30.             <groupId>org.springframework.boot</groupId> 
  31.             <artifactId>spring-boot-starter-web</artifactId> 
  32.         </dependency> 
  33.  
  34.         <!-- actuator --> 
  35.         <dependency> 
  36.             <groupId>org.springframework.boot</groupId> 
  37.             <artifactId>spring-boot-starter-actuator</artifactId> 
  38.         </dependency> 
  39.  
  40.         <!-- test --> 
  41.         <dependency> 
  42.             <groupId>org.springframework.boot</groupId> 
  43.             <artifactId>spring-boot-starter-test</artifactId> 
  44.             <scope>test</scope> 
  45.         </dependency> 
  46.  
  47.         <!-- devtools --> 
  48.         <dependency> 
  49.             <groupId>org.springframework.boot</groupId> 
  50.             <artifactId>spring-boot-devtools</artifactId> 
  51.             <scope>runtime</scope> 
  52.             <optional>true</optional> 
  53.         </dependency> 
  54.  
  55.         <!-- lombok --> 
  56.         <dependency> 
  57.             <groupId>org.projectlombok</groupId> 
  58.             <artifactId>lombok</artifactId> 
  59.             <optional>true</optional> 
  60.         </dependency> 
  61.     </dependencies> 
  62. </project> 

微服務(wù) bootstrap.yml 配置

  1. server: 
  2.   port: 3377 
  3.  
  4. spring: 
  5.   application: 
  6.     name: nacos-config-client 
  7.  
  8.   cloud: 
  9.     nacos: 
  10.       discovery: 
  11.         #server-addr: my.nacos.com:8848 
  12.         #nacos集群配置(Nginx) 
  13.         server-addr: 192.168.15.146:80 
  14.       config: 
  15.         #server-addr: my.nacos.com:8848 
  16.         #nacos集群配置(Nginx) 
  17.         server-addr: 192.168.15.146:80 
  18.         #指定yaml格式的配置 
  19.         file-extension: yaml 
  20.         #指定分組 
  21.         group: DEV_GROUP 
  22.         #指定命名空間ID 
  23.         namespace: my_nacos_namespace 

微服務(wù)啟動(dòng)類配置

  1. package com.atguigu.springcloud; 
  2.  
  3. import org.springframework.boot.SpringApplication; 
  4. import org.springframework.boot.autoconfigure.SpringBootApplication; 
  5. import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 
  6.  
  7. @SpringBootApplication 
  8. @EnableDiscoveryClient 
  9. public class NacosConfigClientMain3377 { 
  10.  
  11.     public static void main(String[] args) { 
  12.         SpringApplication.run(NacosConfigClientMain3377.class, args); 
  13.     } 
  14.  

微服務(wù) Controller 讀取 nacos 配置

  1. package com.atguigu.springcloud.controller; 
  2.  
  3. import lombok.extern.slf4j.Slf4j; 
  4. import org.springframework.beans.factory.annotation.Value; 
  5. import org.springframework.cloud.context.config.annotation.RefreshScope; 
  6. import org.springframework.web.bind.annotation.GetMapping; 
  7. import org.springframework.web.bind.annotation.RestController; 
  8.  
  9. @RestController 
  10. @Slf4j 
  11. @RefreshScope //支持Nacos的動(dòng)態(tài)刷新功能 
  12. public class ConfigClientController { 
  13.  
  14.     @Value("${config.info}"
  15.     private String configInfo; 
  16.  
  17.     @GetMapping("/config/info"
  18.     public String getConfigInfo() { 
  19.         return configInfo; 
  20.     } 

在 nacos 管理頁(yè)上維護(hù)一個(gè)配置



本地啟動(dòng)微服務(wù)并訪問


參考

[1]Nacos 官方文檔: https://nacos.io/zh-cn/docs/what-is-nacos.html

[2]前往官網(wǎng)下載 JDK: https://www.oracle.com/java/technologies/javase/javase-jdk8-downloads.html

[3]最新穩(wěn)定版本: https://github.com/alibaba/nacos/releases[4]Nginx 源碼安裝: https://segmentfault.com/a/1190000022860417

 

責(zé)任編輯:姜華 來源: 今日J(rèn)ava
相關(guān)推薦

2021-07-13 12:21:34

PythonRPC通信

2021-05-19 10:09:23

消息隊(duì)列架構(gòu)

2019-12-25 10:45:30

Java悲觀鎖

2019-10-09 10:06:48

容器監(jiān)控軟件

2019-12-19 17:00:01

Java線程

2020-03-25 11:04:18

APIUrl架構(gòu)

2021-08-13 11:06:05

Kubernetes優(yōu)化運(yùn)維

2019-09-24 14:52:35

CPU負(fù)載Linux

2015-10-12 17:11:34

老板重構(gòu)系統(tǒng)

2015-11-10 09:17:29

重構(gòu)程序員代碼

2022-04-26 05:57:18

微服務(wù)Nacos

2019-10-31 10:08:15

Synchronize面試線程

2018-02-24 14:59:39

區(qū)塊鏈公共區(qū)塊鏈私有區(qū)塊鏈

2019-05-30 15:20:04

webpack前端開發(fā)

2021-09-30 07:59:06

zookeeper一致性算法CAP

2019-08-16 09:41:56

UDP協(xié)議TCP

2020-10-23 07:43:37

Log配置性能

2025-02-17 00:00:20

itext生成庫(kù)pdf

2023-11-06 08:31:58

業(yè)務(wù)代碼多線程

2021-05-07 07:52:51

Java并發(fā)編程
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)