1. 程式人生 > 實用技巧 >微服務搭建說明

微服務搭建說明

一、微服務架構搭建說明

現在有兩套微服務搭建架構,一套是pdf-c;一套是demo。

pdf-c集成了騰訊的tsf,相對的封裝性更好,但是不夠靈活,集成了很多可能用不到的元件。

而demo就相對比較簡單,pom檔案中只引入了微服務基本的依賴與元件,後面需要什麼元件與功能,可以自己再新增。對於初學者來講,這個更容易上手,用來學習spring-boot、spring-cloud與微服務專案更加合適。

下面對本地搭建demo微服務開發環境需要的軟體、可能遇到的問題進行說明。

二、搭建中遇到的問題

參看連結https://www.cnblogs.com/zhangshuaivole/p/12222661.html,搭建過程進行了比較詳細的說明。

之後還成功搭建了一次pdf-c的開發環境,但是由於聯調問題,在第一次搭建成功之後就沒有再深入學習及應用過。

本文是我為了學習spring-boot、spring-cloud開發;學習微服務,redis等各種元件,二次搭建時,再次對微服務環境搭建及開發做的一次詳盡記錄。

1、首先:針對pdf-c中的搭建流程不在採用也不在做進一步的學習(其中的一些開發規範、設計思路還是有參考價值的)。

2、其次:人保再微服務新架構開發設計文件-張帥資料夾中是舊的資料字典及使用者系統的一些文件資料,也有我寫的新使用者系統的設計文件。(不再過多關注)

3、重點:人保再-架構文件及安裝檔案資料夾中有搭建微服務demo的所有資料。

三、軟體及流程

參看連結https://www.cnblogs.com/zhangshuaivole/p/12222661.html,搭建過程進行了比較詳細的說明。

後端軟體:用的idea。參看demo中後端的後端demo開發說明文件進行安裝。

安轉完postgresql(用我自己下載的就行)之後,用navicat premium連線postgresql。有sql指令碼:

CREATE TABLE t_template(
   template_id    varchar(20) PRIMARY KEY     NOT NULL,
   template_name  varchar(20)             NOT
NULL, update_time time NOT NULL ); insert into t_template(template_id,template_name,update_time) values ('1','zs',now()); insert into t_template(template_id,template_name,update_time) values ('2','zs',now()); insert into t_template(template_id,template_name,update_time) values ('3','zs',now()); insert into t_template(template_id,template_name,update_time) values ('4','zs',now()); select *from t_template; SELECT count(0) FROM (SELECT t.template_id AS templateId, t.template_name AS templateName, to_char(t.update_time, 'yyyy-MM-dd HH24:mi:ss') AS updateTime FROM t_template t WHERE t.template_name LIKE 'zs') table_count

通過postman進行測試:http://localhost:31010/demo/list?page=1&limit=1&templateName=zs

四、配置檔案

setting檔案用config中的,倉庫用repository-pdfc。

server.port= 31010

#  註冊中心配置
#開發
eureka.client.service-url.defaultZone=http://10.129.202.72:21000/eureka/
#獲取主機ip作為地址註冊到註冊中心
eureka.instance.prefer-ip-address=true
eureka.instance.instance-id=${spring.cloud.client.ipAddress}:${server.port}
[email protected]@

eureka.client.register-with-eureka=false
eureka.client.fetchRegistry=false
eureka.client.server.waitTimeInMsWhenSyncEmpty=0

# 獲取註冊資訊間隔時間  default 30
eureka.client.registry-fetch-interval-seconds=30
# 更新例項變化到服務端 default 30
eureka.client.instance-info-replication-interval-seconds=30
# 動態重新整理eureka的serviceURl地址的間隔時間  與Config整合需要  default 300
eureka.client.eureka-service-url-poll-interval-seconds=300

#開啟健康檢查(需要spring-boot-starter-actuator依賴)
#eureka.client.healthcheck.enabled = true
#租期更新時間間隔(預設30秒)
#eureka.instance.lease-renewal-interval-in-seconds =30
#租期到期時間(預設90秒)
#eureka.instance.lease-expiration-duration-in-seconds =90



#資料庫配置
spring.datasource.url= jdbc:postgresql://10.129.206.34:5432/postgres
spring.datasource.username= postgres
spring.datasource.password= root
spring.datasource.driver-class-name= org.postgresql.Driver

mybatis.type-aliases-package= cn.com.piccre.template.entity
mybatis.mapper-locations=classpath:/mapper/*Mapper.xml
#使用駝峰命名法轉換欄位。
mybatis.configuration.map-underscore-to-camel-case=true

#日誌掃描
logging.level.=info
logging.level.cn.com.piccre.template.dao=debug
logging.config=classpath:logback-test.xml

#apollo配置中心
apollo.bootstrap.enabled = true
### apollo server地址
apollo.meta=http://10.129.202.74:8080
### apollo server的應用id
app.id=ServiceTemplate

#redis配置
spring.redis.host=10.129.202.73
spring.redis.port=6379
spring.redis.password=picc123456
spring.redis.timeout=2000


#7.3使用者登入檢查(按使用者名稱和密碼形式)—非整合單點(checkLoginByPwd)介面地址
check_user_url=http://10.129.202.72:4789/UserTransferServer/userService/check
#3.3根據使用者獲取選單(getMenuByUser)
get_menu_url=http://10.129.202.72:4789/UserTransferServer/userService/menu
#10.4根據使用者程式碼獲取使用者詳細資訊(getUserMsg)
get_user_info=http://10.129.202.72:4789/UserTransferServer/userService/userInfo

#金鑰檔案用於加密token,將demo附帶的金鑰檔案放於伺服器對應目錄,只在登入時生成token用到
keyPublicPath=/opt/picc/jwt/cjp/key.pub
keyPrivatePath=/opt/picc/jwt/cjp/key.pri

標黃的部分需要新增和修改,剩下的都不用動。就可以通過postman正常訪問到專案了。

但是明顯Redis、apollo、使用者相關的都還不能用。現在的學習重點是spring-boot相關及redis先不管其它。

檢視本地ip及dns:ipconfig/all。

五、前端vue